Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
ci(studio): gate opening a film in Studio on work counts that only go down (#4457)
Miguel Ángel73519b645213
diff --git a/.fallowrc.jsonc b/.fallowrc.jsoncindex e05bb9295b..2bcb54ac9e 100644--- a/.fallowrc.jsonc+++ b/.fallowrc.jsonc@@ -4,6 +4,8 @@// IconButton, Tabs and cn are exported before their first consumer exists."packages/studio/src/components/ui/index.ts","packages/producer/src/**/*.test.ts",+ // Studio's browser-journey helpers are plain .mjs under tests/e2e; their unit tests live beside them.+ "packages/studio/tests/e2e/*.test.mjs","packages/aws-lambda/src/**/*.test.ts","packages/gcp-cloud-run/src/**/*.test.ts","packages/gcp-cloud-run/terraform/*.test.ts",diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 6a93f1f6aa..680d5ecf91 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -761,7 +761,7 @@ jobs:needs: [changes]if: needs.changes.outputs.studio == 'true'runs-on: ubuntu-latest- timeout-minutes: 12+ timeout-minutes: 18steps:- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2@@ -782,6 +782,19 @@ jobs:mkdir -p packages/studio/data/projectscp -R packages/studio/tests/e2e/fixtures/timeline-virtualization \packages/studio/data/projects/timeline-virtualization+ cp -R packages/studio/tests/e2e/fixtures/studio-open \+ packages/studio/data/projects/studio-open+ - name: Read the base branch's work-count ceilings+ # A ceiling may not rise or disappear against the branch this PR merges into.+ if: github.event_name == 'pull_request'+ env:+ BASE_REF: ${{ github.base_ref }}+ run: |+ git fetch --no-tags --depth=1 origin "$BASE_REF"+ if ! git show FETCH_HEAD:packages/studio/tests/e2e/perf-ceilings.json > /tmp/base-perf-ceilings.json; then+ rm -f /tmp/base-perf-ceilings.json+ echo "The base branch has no perf-ceilings.json yet"+ fi- name: Run both arms of the timeline viewport gaterun: |set -euo pipefail@@ -854,6 +867,30 @@ jobs:echo "FAIL: default=${DEFAULT_STATUS}, disabled=${DISABLED_STATUS}"exit 1fi+ - name: Count the work of opening a film in Studio+ # Counts, not ms: thumbnail renders, page loads and requests do not move+ # with runner load, so perf-ceilings.json can hold them exactly.+ if: success() || failure()+ run: |+ set -euo pipefail+ NODE_ENV=production bun run --cwd packages/studio dev -- --port 5315 --strictPort &+ SERVER_PID=$!+ trap 'kill "$SERVER_PID" 2>/dev/null || true' EXIT+ for i in $(seq 1 60); do+ if curl -sf "http://localhost:5315/" >/dev/null 2>&1; then break; fi+ sleep 1+ done+ if ! curl -sf "http://localhost:5315/" >/dev/null 2>&1; then+ echo "FAIL: studio dev server did not start on port 5315"+ exit 1+ fi+ STUDIO_URL="http://localhost:5315/#project/studio-open" \+ STUDIO_PROJECT_DIR="$PWD/packages/studio/data/projects/studio-open" \+ node packages/studio/tests/e2e/studio-open-counts.mjs \+ | tee /tmp/studio-open-counts.json+ node packages/studio/tests/e2e/perf-ratchet.mjs check \+ packages/studio/tests/e2e/perf-ceilings.json studio-open /tmp/studio-open-counts.json \+ /tmp/base-perf-ceilings.json- name: Upload gate evidence# The gate's whole output is machine-readable evidence, and a red run is# exactly when someone needs to read it. Keep it on failure too.@@ -861,7 +898,9 @@ jobs:uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4with:name: timeline-viewport-gate-evidence- path: /tmp/timeline-gate-*.json+ path: |+ /tmp/timeline-gate-*.json+ /tmp/studio-open-counts.jsonif-no-files-found: errorsmoke-global-install:diff --git a/packages/studio/tests/e2e/fixtures/studio-open/README.md b/packages/studio/tests/e2e/fixtures/studio-open/README.mdnew file mode 100644index 0000000000..3327aa316c--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/README.md@@ -0,0 +1,9 @@+# Studio open work-count fixture++A 60 s film of twelve 5 s scenes, each its own composition file, with no media. It has the+shape of a real multi-scene film (a timeline clip thumbnail and a composition card per scene,+one preview document) at a size that belongs in the repository. `studio-open-counts.mjs` opens+it and counts the work Studio does until the film can play and in the 20 s after.++The repository's `.gitignore` excludes `compositions/`, so the scene files are committed with+`git add -f`. The journey refuses to measure when a scene `index.html` mounts is missing.diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-0.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-0.htmlnew file mode 100644index 0000000000..04ef7f2827--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-0.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene0-root"+ data-hf-id="scene0-root"+ data-composition-id="scene0"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene0-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene0-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene0-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #f97316;+ }+ </style>+ <h1 class="title" data-hf-id="scene0-title">Scene 1</h1>+ <div class="shape" data-hf-id="scene0-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-1.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-1.htmlnew file mode 100644index 0000000000..b0b9ef1149--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-1.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene1-root"+ data-hf-id="scene1-root"+ data-composition-id="scene1"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene1-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene1-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene1-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #14b8a6;+ }+ </style>+ <h1 class="title" data-hf-id="scene1-title">Scene 2</h1>+ <div class="shape" data-hf-id="scene1-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-10.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-10.htmlnew file mode 100644index 0000000000..63d6630d02--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-10.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene10-root"+ data-hf-id="scene10-root"+ data-composition-id="scene10"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene10-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene10-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene10-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #f43f5e;+ }+ </style>+ <h1 class="title" data-hf-id="scene10-title">Scene 11</h1>+ <div class="shape" data-hf-id="scene10-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-11.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-11.htmlnew file mode 100644index 0000000000..83b4bf1221--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-11.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene11-root"+ data-hf-id="scene11-root"+ data-composition-id="scene11"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene11-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene11-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene11-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #8b5cf6;+ }+ </style>+ <h1 class="title" data-hf-id="scene11-title">Scene 12</h1>+ <div class="shape" data-hf-id="scene11-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-2.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-2.htmlnew file mode 100644index 0000000000..cd9d29a685--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-2.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene2-root"+ data-hf-id="scene2-root"+ data-composition-id="scene2"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene2-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene2-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene2-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #a855f7;+ }+ </style>+ <h1 class="title" data-hf-id="scene2-title">Scene 3</h1>+ <div class="shape" data-hf-id="scene2-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-3.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-3.htmlnew file mode 100644index 0000000000..d53bb725c8--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-3.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene3-root"+ data-hf-id="scene3-root"+ data-composition-id="scene3"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene3-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene3-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene3-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #eab308;+ }+ </style>+ <h1 class="title" data-hf-id="scene3-title">Scene 4</h1>+ <div class="shape" data-hf-id="scene3-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-4.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-4.htmlnew file mode 100644index 0000000000..1c3a62f532--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-4.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene4-root"+ data-hf-id="scene4-root"+ data-composition-id="scene4"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene4-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene4-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene4-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #ef4444;+ }+ </style>+ <h1 class="title" data-hf-id="scene4-title">Scene 5</h1>+ <div class="shape" data-hf-id="scene4-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-5.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-5.htmlnew file mode 100644index 0000000000..47ec3db9db--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-5.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene5-root"+ data-hf-id="scene5-root"+ data-composition-id="scene5"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene5-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene5-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene5-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #22c55e;+ }+ </style>+ <h1 class="title" data-hf-id="scene5-title">Scene 6</h1>+ <div class="shape" data-hf-id="scene5-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-6.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-6.htmlnew file mode 100644index 0000000000..e3c6f8d854--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-6.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene6-root"+ data-hf-id="scene6-root"+ data-composition-id="scene6"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene6-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene6-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene6-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #3b82f6;+ }+ </style>+ <h1 class="title" data-hf-id="scene6-title">Scene 7</h1>+ <div class="shape" data-hf-id="scene6-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-7.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-7.htmlnew file mode 100644index 0000000000..61b1434e9a--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-7.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene7-root"+ data-hf-id="scene7-root"+ data-composition-id="scene7"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene7-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene7-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene7-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #ec4899;+ }+ </style>+ <h1 class="title" data-hf-id="scene7-title">Scene 8</h1>+ <div class="shape" data-hf-id="scene7-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-8.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-8.htmlnew file mode 100644index 0000000000..5644b33570--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-8.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene8-root"+ data-hf-id="scene8-root"+ data-composition-id="scene8"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene8-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene8-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene8-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #06b6d4;+ }+ </style>+ <h1 class="title" data-hf-id="scene8-title">Scene 9</h1>+ <div class="shape" data-hf-id="scene8-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-9.html b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-9.htmlnew file mode 100644index 0000000000..2a1b5a19c3--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/compositions/scene-9.html@@ -0,0 +1,37 @@+<template>+ <section+ id="scene9-root"+ data-hf-id="scene9-root"+ data-composition-id="scene9"+ data-width="1920"+ data-height="1080"+ data-duration="5"+ >+ <style>+ #scene9-root {+ position: absolute;+ inset: 0;+ font-family: Arial, sans-serif;+ color: #fff;+ }+ #scene9-root .title {+ position: absolute;+ left: 80px;+ top: 830px;+ margin: 0;+ font-size: 96px;+ }+ #scene9-root .shape {+ position: absolute;+ left: 1300px;+ top: 250px;+ width: 220px;+ height: 220px;+ border-radius: 28px;+ background: #84cc16;+ }+ </style>+ <h1 class="title" data-hf-id="scene9-title">Scene 10</h1>+ <div class="shape" data-hf-id="scene9-shape"></div>+ </section>+</template>diff --git a/packages/studio/tests/e2e/fixtures/studio-open/hyperframes.json b/packages/studio/tests/e2e/fixtures/studio-open/hyperframes.jsonnew file mode 100644index 0000000000..5fb1d6d872--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/hyperframes.json@@ -0,0 +1,9 @@+{+ "$schema": "https://hyperframes.heygen.com/schema/hyperframes.json",+ "registry": "https://raw.githubusercontent.com/heygen-com/hyperframes/main/registry",+ "paths": {+ "blocks": "compositions",+ "components": "compositions/components",+ "assets": "assets"+ }+}diff --git a/packages/studio/tests/e2e/fixtures/studio-open/index.html b/packages/studio/tests/e2e/fixtures/studio-open/index.htmlnew file mode 100644index 0000000000..8dc8f1cf41--- /dev/null+++ b/packages/studio/tests/e2e/fixtures/studio-open/index.html@@ -0,0 +1,154 @@+<!doctype html>+<html lang="en">+ <head>+ <meta charset="UTF-8" />+ <title>Studio open work-count fixture</title>+ <style>+ html,+ body {+ width: 1920px;+ height: 1080px;+ margin: 0;+ overflow: hidden;+ background: #0f172a;+ }+ .scene {+ position: absolute;+ inset: 0;+ }+ </style>+ </head>+ <body>+ <main+ id="studio-open"+ data-hf-id="studio-open"+ data-composition-id="studio-open"+ data-width="1920"+ data-height="1080"+ data-start="0"+ data-duration="60"+ data-fps="30"+ >+ <div+ id="s0"+ class="scene"+ data-hf-id="s0"+ data-composition-id="scene0"+ data-composition-src="compositions/scene-0.html"+ data-start="0"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s1"+ class="scene"+ data-hf-id="s1"+ data-composition-id="scene1"+ data-composition-src="compositions/scene-1.html"+ data-start="5"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s2"+ class="scene"+ data-hf-id="s2"+ data-composition-id="scene2"+ data-composition-src="compositions/scene-2.html"+ data-start="10"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s3"+ class="scene"+ data-hf-id="s3"+ data-composition-id="scene3"+ data-composition-src="compositions/scene-3.html"+ data-start="15"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s4"+ class="scene"+ data-hf-id="s4"+ data-composition-id="scene4"+ data-composition-src="compositions/scene-4.html"+ data-start="20"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s5"+ class="scene"+ data-hf-id="s5"+ data-composition-id="scene5"+ data-composition-src="compositions/scene-5.html"+ data-start="25"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s6"+ class="scene"+ data-hf-id="s6"+ data-composition-id="scene6"+ data-composition-src="compositions/scene-6.html"+ data-start="30"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s7"+ class="scene"+ data-hf-id="s7"+ data-composition-id="scene7"+ data-composition-src="compositions/scene-7.html"+ data-start="35"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s8"+ class="scene"+ data-hf-id="s8"+ data-composition-id="scene8"+ data-composition-src="compositions/scene-8.html"+ data-start="40"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s9"+ class="scene"+ data-hf-id="s9"+ data-composition-id="scene9"+ data-composition-src="compositions/scene-9.html"+ data-start="45"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s10"+ class="scene"+ data-hf-id="s10"+ data-composition-id="scene10"+ data-composition-src="compositions/scene-10.html"+ data-start="50"+ data-duration="5"+ data-track-index="0"+ ></div>+ <div+ id="s11"+ class="scene"+ data-hf-id="s11"+ data-composition-id="scene11"+ data-composition-src="compositions/scene-11.html"+ data-start="55"+ data-duration="5"+ data-track-index="0"+ ></div>+ </main>+ </body>+</html>diff --git a/packages/studio/tests/e2e/perf-ceilings.json b/packages/studio/tests/e2e/perf-ceilings.jsonnew file mode 100644index 0000000000..c7b69bcabc--- /dev/null+++ b/packages/studio/tests/e2e/perf-ceilings.json@@ -0,0 +1,11 @@+{+ "studio-open": {+ "browser": "153",+ "counts": {+ "thumbnailRenders": 20,+ "total.frameNavigations": 7,+ "total.requests.document": 2,+ "total.requests.thumbnail": 20+ }+ }+}diff --git a/packages/studio/tests/e2e/perf-counters.mjs b/packages/studio/tests/e2e/perf-counters.mjsnew file mode 100644index 0000000000..b6936a3527--- /dev/null+++ b/packages/studio/tests/e2e/perf-counters.mjs@@ -0,0 +1,120 @@+/**+ * Deterministic work counts for a Studio browser journey: how much work ran,+ * not how long it took, so the numbers do not move with runner load.+ * Compare them against perf-ceilings.json with perf-ratchet.mjs.+ */++/** Runs in every frame before any page script; child frames add into the top frame's tally. */+function installInPage(options) {+ const counts = sharedCounts();+ const add = (key) => {+ counts[key] = (counts[key] ?? 0) + 1;+ };+ installReactHook();+ if (options.pageActivity) installPageActivity();++ // Helpers stay inside: the page receives this one function's source, nothing around it.+ function sharedCounts() {+ try {+ return (window.top.__hfWorkCounts ??= {});+ } catch {+ return (window.__hfWorkCounts ??= {});+ }+ }++ function installReactHook() {+ if (window !== window.top || window.__REACT_DEVTOOLS_GLOBAL_HOOK__) return;+ // React calls this hook on every commit, production builds included.+ window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = {+ supportsFiber: true,+ renderers: new Map(),+ // The key exists once React connects, so a hook React never found reads as not measured.+ inject: () => {+ counts.reactCommits ??= 0;+ return 1;+ },+ onCommitFiberRoot: () => add("reactCommits"),+ onCommitFiberUnmount() {},+ onPostCommitFiberRoot() {},+ checkDCE() {},+ };+ }++ function installPageActivity() {+ new MutationObserver((records) => {+ counts.domMutations = (counts.domMutations ?? 0) + records.length;+ }).observe(document, { subtree: true, childList: true, attributes: true, characterData: true });+ countCallbacks("setTimeout", "timerCallbacks");+ countCallbacks("setInterval", "timerCallbacks");+ countCallbacks("requestAnimationFrame", "rafCallbacks");+ }++ function countCallbacks(name, key) {+ const native = window[name];+ window[name] = function (callback, ...rest) {+ if (typeof callback !== "function") return native.call(this, callback, ...rest);+ return native.call(+ this,+ function (...args) {+ add(key);+ return callback.apply(this, args);+ },+ ...rest,+ );+ };+ }+}++/**+ * Start counting on `page` before it navigates. `pageActivity` adds DOM+ * mutations, timer and animation-frame callbacks; leave it off where the+ * observer itself would weigh on a timed measurement.+ */+export async function startWorkCounters(browser, page, { pageActivity = true } = {}) {+ await page.evaluateOnNewDocument(installInPage, { pageActivity });+ const client = await page.createCDPSession();+ await client.send("Performance.enable");+ const tally = { requests: {}, frameNavigations: 0, targetsCreated: 0 };+ page.on("request", (request) => {+ const kind = request.url().includes("/thumbnail/") ? "thumbnail" : request.resourceType();+ tally.requests[kind] = (tally.requests[kind] ?? 0) + 1;+ });+ page.on("framenavigated", () => {+ tally.frameNavigations += 1;+ });+ browser.on("targetcreated", () => {+ tally.targetsCreated += 1;+ });++ return {+ /** A flat snapshot of every counter so far; subtract two snapshots for a window. */+ async read() {+ const { metrics } = await client.send("Performance.getMetrics");+ const inPage = await page.evaluate(() => ({ ...window.__hfWorkCounts }));+ const snapshot = {+ ...inPage,+ frameNavigations: tally.frameNavigations,+ targetsCreated: tally.targetsCreated,+ };+ // A metric Chrome stops reporting is left out, so the ratchet fails it as not measured.+ for (const [counter, name] of [+ ["styleRecalcs", "RecalcStyleCount"],+ ["layouts", "LayoutCount"],+ ]) {+ const entry = metrics.find((metric) => metric.name === name);+ if (entry) snapshot[counter] = entry.value;+ }+ for (const [kind, count] of Object.entries(tally.requests)) {+ snapshot[`requests.${kind}`] = count;+ }+ return snapshot;+ },+ };+}++/** `after - before` per counter; a counter absent from `before` started at zero. */+export function diffCounts(after, before) {+ return Object.fromEntries(+ Object.entries(after).map(([key, value]) => [key, value - (before[key] ?? 0)]),+ );+}diff --git a/packages/studio/tests/e2e/perf-ratchet.mjs b/packages/studio/tests/e2e/perf-ratchet.mjsnew file mode 100644index 0000000000..aad7165dfa--- /dev/null+++ b/packages/studio/tests/e2e/perf-ratchet.mjs@@ -0,0 +1,249 @@+#!/usr/bin/env node+/**+ * Work-count ratchet: each gated counter has a ceiling in perf-ceilings.json that may only go+ * down. A journey fails when a counter rises above its ceiling or falls below it (bank the+ * improvement), or when a ceiling was raised or removed against the base branch's file.+ *+ * node perf-ratchet.mjs check <ceilings.json> <journey> <evidence.json> [<base-ceilings.json>]+ * node perf-ratchet.mjs lower <ceilings.json> <journey> <evidence.json>+ * node perf-ratchet.mjs correlate <variant>=<evidence.json> ...+ *+ * Ceilings: `{ <journey>: { browser: "<Chrome major>", counts: { <counter>: n } } }`.+ * Evidence is a journey's JSON output: `workCounts`, `wallMs` and the browser it ran in.+ */+import { existsSync, readFileSync, realpathSync, writeFileSync } from "node:fs";+import { pathToFileURL } from "node:url";++// A counter gates only if it tracks wall-clock across variants and repeats exactly within+// one: a ceiling on a counter that wobbles fails at random.+const MIN_CORRELATION = 0.7;+const MAX_SPREAD_RATIO = 0;++const raisedAgainst = (ceiling, base) => Number.isFinite(base) && ceiling > base;++function measuredStatus(ceiling, value) {+ if (!Number.isFinite(value)) return "missing";+ if (value === ceiling) return "at";+ return value > ceiling ? "rose" : "below";+}++function ceilingRow(counter, ceiling, value, base) {+ if (raisedAgainst(ceiling, base)) return { counter, ceiling, base, status: "raised" };+ return { counter, ceiling, value, status: measuredStatus(ceiling, value) };+}++/** Passes only when every gated counter sits exactly at a ceiling no higher than the base's. */+export function checkCeilings(ceilings, counts, baseCeilings = {}) {+ const rows = Object.entries(ceilings).map(([counter, ceiling]) =>+ ceilingRow(counter, ceiling, counts[counter], baseCeilings[counter]),+ );+ if (rows.length === 0)+ throw new Error("no gated counters: a ratchet that checks nothing passes nothing");+ for (const [counter, base] of Object.entries(baseCeilings)) {+ if (!(counter in ceilings)) rows.push({ counter, base, status: "removed" });+ }+ return { passed: rows.every((row) => row.status === "at"), rows };+}++/** `, +67%`: a rise as a share of its ceiling, or nothing for a zero ceiling. */+const riseShare = (rise, ceiling) =>+ ceiling === 0 ? "" : `, +${Math.round((rise / ceiling) * 100)}%`;++const ROW_TEXT = {+ at: ({ counter, value }) => `ok ${counter} ${value}`,+ missing: ({ counter, ceiling }) => `FAIL ${counter}: not measured (ceiling ${ceiling})`,+ rose: ({ counter, ceiling, value }) =>+ `FAIL ${counter} rose ${ceiling} -> ${value} (+${round(value - ceiling)}${riseShare(value - ceiling, ceiling)})`,+ below: ({ counter, ceiling, value }) =>+ `FAIL ${counter} fell ${ceiling} -> ${value}: bank it by setting its ceiling to ${value} (perf-ratchet.mjs lower)`,+ raised: ({ counter, ceiling, base }) =>+ `FAIL ${counter}: ceiling raised ${base} -> ${ceiling} against the base branch; ceilings only go down`,+ removed: ({ counter, base }) =>+ `FAIL ${counter}: ceiling ${base} removed against the base branch; ceilings only go down`,+};++export function formatRow(row) {+ return ROW_TEXT[row.status](row);+}++/** New ceilings: each gated counter drops to what was measured, never rises. */+export function lowerCeilings(ceilings, counts) {+ return Object.fromEntries(+ Object.entries(ceilings).map(([counter, ceiling]) => [+ counter,+ Number.isFinite(counts[counter]) ? Math.min(ceiling, counts[counter]) : ceiling,+ ]),+ );+}++/**+ * For each counter over runs `{ variant, wallMs, counts }`: Pearson r against+ * wall-clock across all runs, and the worst spread between runs of one variant.+ */+export function correlate(runs) {+ const counters = [...new Set(runs.flatMap((run) => Object.keys(run.counts)))].sort();+ return counters.map((counter) => {+ const points = runs.filter((run) => Number.isFinite(run.counts[counter]));+ const r = pearson(+ points.map((run) => run.counts[counter]),+ points.map((run) => run.wallMs),+ );+ let spreadRatio = 0;+ for (const variant of new Set(points.map((run) => run.variant))) {+ const values = points+ .filter((run) => run.variant === variant)+ .map((run) => run.counts[counter]);+ const mean = values.reduce((sum, value) => sum + value, 0) / values.length;+ spreadRatio = Math.max(+ spreadRatio,+ (Math.max(...values) - Math.min(...values)) / Math.max(1, mean),+ );+ }+ return {+ counter,+ r,+ spreadRatio,+ gateable: Number.isFinite(r) && r >= MIN_CORRELATION && spreadRatio <= MAX_SPREAD_RATIO,+ };+ });+}++function pearson(xs, ys) {+ const n = xs.length;+ const mean = (values) => values.reduce((sum, value) => sum + value, 0) / n;+ const mx = mean(xs);+ const my = mean(ys);+ let sxy = 0;+ let sxx = 0;+ let syy = 0;+ for (let i = 0; i < n; i += 1) {+ sxy += (xs[i] - mx) * (ys[i] - my);+ sxx += (xs[i] - mx) ** 2;+ syy += (ys[i] - my) ** 2;+ }+ return sxx === 0 || syy === 0 ? Number.NaN : sxy / Math.sqrt(sxx * syy);+}++const round = (value) => Math.round(value * 100) / 100;+const readJson = (path) => JSON.parse(readFileSync(path, "utf8"));++const versionOf = (evidence) => String(evidence.browser ?? evidence.environment?.browser);++/** Chrome's major version from a journey's evidence, e.g. "153" from "HeadlessChrome/153.0.1.2". */+export function browserMajor(evidence) {+ const match = /\/(\d+)\./.exec(versionOf(evidence));+ return match ? match[1] : null;+}++/** The whole ceilings file, the journey named in it, and that journey's evidence. */+function journeyInputs([ceilingsPath, journey, evidencePath]) {+ const all = readJson(ceilingsPath);+ if (!all[journey]) throw new Error(`${ceilingsPath} has no journey "${journey}"`);+ const evidence = readJson(evidencePath);+ return { all, ceilingsPath, journey, evidence, counts: evidence.workCounts ?? {} };+}++const isObject = (value) => typeof value === "object" && value !== null;++/**+ * The base branch's ceilings for `journey`, and the base journeys this file no longer has. A+ * base file in a shape this script does not write throws: an unreadable base must not pass.+ */+export function readBase(base, all, journey) {+ assertBaseShape(base);+ return {+ counts: base[journey]?.counts,+ removedJourneys: Object.keys(base).filter((name) => !Object.hasOwn(all, name)),+ };+}++function assertBaseShape(base) {+ for (const [name, entry] of Object.entries(base)) {+ if (!isObject(entry?.counts)) throw new Error(`base ceilings: "${name}" has no counts object`);+ }+}++/** Absent while the base branch has no ceilings file yet (and on runs without a base). */+function loadBase(path, all, journey) {+ if (!path || !existsSync(path)) return { counts: undefined, removedJourneys: [] };+ return readBase(readJson(path), all, journey);+}++function printNotes(recorded, evidence, rows) {+ const measuredOn = browserMajor(evidence);+ if (measuredOn !== recorded.browser) {+ console.log(+ `[perf-ratchet] note: measured on Chrome ${measuredOn}, ceilings recorded on Chrome ${recorded.browser}`,+ );+ }+ if (rows.some((row) => row.status === "rose")) {+ console.log(+ "[perf-ratchet] If this change should not add that work, confirm the counter still repeats " ++ "exactly: run the journey a few times and compare with perf-ratchet.mjs correlate.",+ );+ }+}++function printResult(journey, ok, rows, removedJourneys) {+ console.log(`[perf-ratchet] ${journey}: ${ok ? "PASS" : "FAIL"}`);+ for (const row of rows) console.log(`[perf-ratchet] ${formatRow(row)}`);+ for (const name of removedJourneys) {+ console.log(+ `[perf-ratchet] FAIL journey ${name} removed against the base branch; ceilings only go down`,+ );+ }+}++function runCheck(args) {+ const { all, journey, evidence, counts } = journeyInputs(args);+ const base = loadBase(args[3], all, journey);+ const { passed, rows } = checkCeilings(all[journey].counts, counts, base.counts);+ const ok = passed && base.removedJourneys.length === 0;+ printResult(journey, ok, rows, base.removedJourneys);+ printNotes(all[journey], evidence, rows);+ return ok ? 0 : 1;+}++function runLower(args) {+ const { all, ceilingsPath, journey, evidence, counts } = journeyInputs(args);+ const measuredOn = browserMajor(evidence);+ if (measuredOn !== all[journey].browser) {+ throw new Error(+ `evidence is from Chrome ${measuredOn} but ${journey}'s ceilings were recorded on Chrome ` ++ `${all[journey].browser}: take the evidence from the CI job, which runs that browser`,+ );+ }+ all[journey].counts = lowerCeilings(all[journey].counts, counts);+ writeFileSync(ceilingsPath, `${JSON.stringify(all, null, 2)}\n`);+ return 0;+}++function runCorrelate(args) {+ const runs = args.map((arg) => {+ const [variant, path] = arg.split("=");+ const evidence = readJson(path);+ return { variant, wallMs: evidence.wallMs, counts: evidence.workCounts };+ });+ console.log("counter\tr\tspread\tgate");+ for (const row of correlate(runs)) {+ const gate = row.gateable ? "yes" : "no";+ console.log(`${row.counter}\t${round(row.r)}\t${round(row.spreadRatio * 100)}%\t${gate}`);+ }+ return 0;+}++const COMMANDS = { check: runCheck, lower: runLower, correlate: runCorrelate };++function main([command, ...args]) {+ if (Object.hasOwn(COMMANDS, command)) return COMMANDS[command](args);+ console.error(+ "usage: perf-ratchet.mjs check|lower <ceilings.json> <journey> <evidence.json> [<base-ceilings.json>]",+ );+ console.error(" perf-ratchet.mjs correlate <variant>=<evidence.json> ...");+ return 2;+}++// Real paths on both sides: a symlinked path (macOS /var, /tmp) must still run the CLI.+if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href) {+ process.exit(main(process.argv.slice(2)));+}diff --git a/packages/studio/tests/e2e/perf-ratchet.test.mjs b/packages/studio/tests/e2e/perf-ratchet.test.mjsnew file mode 100644index 0000000000..087a231dd5--- /dev/null+++ b/packages/studio/tests/e2e/perf-ratchet.test.mjs@@ -0,0 +1,131 @@+import { execFileSync } from "node:child_process";+import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";+import { fileURLToPath } from "node:url";+import { describe, expect, it } from "vitest";+import {+ browserMajor,+ checkCeilings,+ correlate,+ formatRow,+ lowerCeilings,+ readBase,+} from "./perf-ratchet.mjs";++describe("checkCeilings", () => {+ it("fails a counter that rose and names it with the rise", () => {+ const { passed, rows } = checkCeilings({ thumbnailRenders: 12 }, { thumbnailRenders: 20 });+ expect(passed).toBe(false);+ expect(formatRow(rows[0])).toBe("FAIL thumbnailRenders rose 12 -> 20 (+8, +67%)");+ });++ it("passes only at the ceiling", () => {+ expect(checkCeilings({ a: 5 }, { a: 5 }).passed).toBe(true);+ });++ it("fails a counter that fell until the improvement is banked", () => {+ const { passed, rows } = checkCeilings({ a: 5 }, { a: 3 });+ expect(passed).toBe(false);+ expect(formatRow(rows[0])).toMatch(/^FAIL a fell 5 -> 3: bank it by setting its ceiling to 3/);+ });++ it("fails a ceiling raised or removed against the base branch", () => {+ const { passed, rows } = checkCeilings({ a: 6 }, { a: 6 }, { a: 5, b: 2 });+ expect(passed).toBe(false);+ expect(rows.map((row) => row.status)).toEqual(["raised", "removed"]);+ });++ it("fails a gated counter the journey did not measure", () => {+ expect(checkCeilings({ reactCommits: 4 }, {}).passed).toBe(false);+ expect(checkCeilings({ reactCommits: 4 }, { reactCommits: Number.NaN }).passed).toBe(false);+ });++ it("refuses an empty ceiling set", () => {+ expect(() => checkCeilings({}, { a: 1 })).toThrow(/checks nothing/);+ });+});++describe("readBase", () => {+ const all = { open: { browser: "153", counts: { a: 1 } } };++ it("names base journeys this file dropped", () => {+ const base = { open: { counts: { a: 2 } }, scroll: { counts: { b: 1 } } };+ expect(readBase(base, all, "open")).toEqual({ counts: { a: 2 }, removedJourneys: ["scroll"] });+ });++ it("refuses a base file in a shape it cannot compare", () => {+ expect(() => readBase({ open: { a: 13 } }, all, "open")).toThrow(/no counts object/);+ });+});++describe("browserMajor", () => {+ it("reads Chrome's major version from either evidence shape", () => {+ expect(browserMajor({ browser: "HeadlessChrome/153.0.8010.52" })).toBe("153");+ expect(browserMajor({ environment: { browser: "Chrome/152.0.1.1" } })).toBe("152");+ expect(browserMajor({})).toBe(null);+ });+});++describe("lower", () => {+ const cli = fileURLToPath(new URL("./perf-ratchet.mjs", import.meta.url));+ const setup = (browser) => {+ const dir = mkdtempSync(join(tmpdir(), "perf-ratchet-"));+ const ceilings = join(dir, "ceilings.json");+ const evidence = join(dir, "evidence.json");+ writeFileSync(ceilings, JSON.stringify({ j: { browser: "153", counts: { a: 5 } } }));+ writeFileSync(evidence, JSON.stringify({ browser, workCounts: { a: 2 } }));+ return { ceilings, evidence };+ };++ it("lowers from evidence taken on the recorded browser", () => {+ const { ceilings, evidence } = setup("HeadlessChrome/153.0.1.1");+ execFileSync(process.execPath, [cli, "lower", ceilings, "j", evidence]);+ expect(JSON.parse(readFileSync(ceilings, "utf8")).j.counts).toEqual({ a: 2 });+ });++ it("refuses evidence from another Chrome", () => {+ const { ceilings, evidence } = setup("HeadlessChrome/152.0.1.1");+ expect(() =>+ execFileSync(process.execPath, [cli, "lower", ceilings, "j", evidence], { stdio: "pipe" }),+ ).toThrow(/Chrome 152/);+ expect(JSON.parse(readFileSync(ceilings, "utf8")).j.counts).toEqual({ a: 5 });+ });+});++describe("lowerCeilings", () => {+ it("only ever lowers", () => {+ expect(lowerCeilings({ a: 10, b: 10, c: 10 }, { a: 7, b: 12 })).toEqual({ a: 7, b: 10, c: 10 });+ });+});++describe("correlate", () => {+ const run = (variant, wallMs, counts) => ({ variant, wallMs, counts });++ it("gates a counter that repeats within a variant and moves with wall-clock", () => {+ const runs = [+ run("main", 900, { renders: 20, noisy: 3 }),+ run("main", 950, { renders: 20, noisy: 9 }),+ run("fix", 400, { renders: 12, noisy: 5 }),+ run("fix", 420, { renders: 12, noisy: 4 }),+ ];+ const byCounter = Object.fromEntries(correlate(runs).map((row) => [row.counter, row]));+ expect(byCounter.renders.gateable).toBe(true);+ expect(byCounter.noisy.gateable).toBe(false);+ });++ it("does not gate a counter that wobbles even slightly within a variant", () => {+ const runs = [+ run("main", 900, { layouts: 100 }),+ run("main", 950, { layouts: 101 }),+ run("fix", 400, { layouts: 50 }),+ run("fix", 420, { layouts: 50 }),+ ];+ expect(correlate(runs)[0].gateable).toBe(false);+ });++ it("does not gate a counter that never moves", () => {+ const [row] = correlate([run("main", 900, { a: 1 }), run("fix", 400, { a: 1 })]);+ expect(row.gateable).toBe(false);+ });+});diff --git a/packages/studio/tests/e2e/studio-open-counts.mjs b/packages/studio/tests/e2e/studio-open-counts.mjsnew file mode 100644index 0000000000..cd7f92bcfe--- /dev/null+++ b/packages/studio/tests/e2e/studio-open-counts.mjs@@ -0,0 +1,154 @@+#!/usr/bin/env node+/**+ * Counts the work Studio does to open the studio-open fixture until the film+ * can play, then in the idle window after it. Prints evidence JSON whose+ * `workCounts` perf-ratchet.mjs checks against perf-ceilings.json.+ *+ * STUDIO_URL=http://127.0.0.1:5190/#project/studio-open \+ * STUDIO_PROJECT_DIR=packages/studio/data/projects/studio-open \+ * node packages/studio/tests/e2e/studio-open-counts.mjs+ *+ * The project's .thumbnails directory is emptied first: every file in it at+ * the end is one thumbnail the server rendered during this journey. Totals are+ * read once thumbnail work has gone quiet; `idle.*` is the fixed window.+ */+import { existsSync, readFileSync, readdirSync, rmSync } from "node:fs";+import { join } from "node:path";+import puppeteer from "puppeteer-core";+import { resolveChromeExecutable } from "./chrome-executable.mjs";+import { diffCounts, startWorkCounters } from "./perf-counters.mjs";++const STUDIO_URL = process.env.STUDIO_URL;+const PROJECT_DIR = process.env.STUDIO_PROJECT_DIR;+const IDLE_MS = Number(process.env.STUDIO_IDLE_MS || 20_000);+const SCENE_COUNT = 12;++if (!STUDIO_URL || !PROJECT_DIR) {+ console.error("STUDIO_URL and STUDIO_PROJECT_DIR are required");+ process.exit(2);+}+const executablePath = resolveChromeExecutable();+if (!executablePath) {+ console.error("No Chrome executable found; set PUPPETEER_EXECUTABLE_PATH");+ process.exit(2);+}++// A scene file that never made it into the fixture still opens and still renders a thumbnail,+// so check the film is whole before measuring it.+const indexHtml = readFileSync(join(PROJECT_DIR, "index.html"), "utf8");+const scenes = [...indexHtml.matchAll(/data-composition-src="([^"]+)"/g)].map((match) => match[1]);+const missingScenes = scenes.filter((scene) => !existsSync(join(PROJECT_DIR, scene)));+if (scenes.length !== SCENE_COUNT || missingScenes.length > 0) {+ console.error(+ `The fixture must mount ${SCENE_COUNT} scenes that exist; index.html mounts ${scenes.length}` ++ (missingScenes.length > 0 ? `, missing: ${missingScenes.join(", ")}` : ""),+ );+ process.exit(2);+}++const thumbnailDir = join(PROJECT_DIR, ".thumbnails");+/** `compositions/scene-3.html t=2.50` from a thumbnail URL, for reading which renders ran. */+const thumbnailLabel = (url) => {+ const { pathname, searchParams } = new URL(url);+ return `${decodeURIComponent(pathname.split("/thumbnail/")[1])} t=${searchParams.get("t")}`;+};+rmSync(thumbnailDir, { recursive: true, force: true });++const browser = await puppeteer.launch({+ executablePath,+ headless: true,+ args: ["--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu"],+});+try {+ const page = await browser.newPage();+ await page.setViewport({ width: 1600, height: 900 });+ const counters = await startWorkCounters(browser, page);+ const thumbnailsInFlight = new Set();+ const thumbnailOutcomes = [];+ let lastThumbnailActivity = 0;+ const isThumbnail = (request) => request.url().includes("/thumbnail/");+ page.on("request", (request) => {+ if (!isThumbnail(request)) return;+ thumbnailsInFlight.add(request);+ lastThumbnailActivity = Date.now();+ });+ for (const done of ["requestfinished", "requestfailed"]) {+ page.on(done, (request) => {+ if (!thumbnailsInFlight.delete(request)) return;+ lastThumbnailActivity = Date.now();+ const outcome = request.response()?.status() ?? request.failure()?.errorText;+ thumbnailOutcomes.push(+ `${thumbnailLabel(request.url())} ${request.resourceType()} ${outcome}`,+ );+ });+ }+ const started = performance.now();+ await page.goto(STUDIO_URL, { waitUntil: "domcontentloaded", timeout: 60_000 });+ // Open is done when the film can play and the timeline shows every scene.+ await page.waitForFunction(+ (sceneCount) => {+ const play = document.querySelector('button[aria-label="Play"]');+ const timeline = document.querySelector("[data-timeline-element-count]");+ return (+ play instanceof HTMLButtonElement &&+ !play.disabled &&+ Number(timeline?.getAttribute("data-timeline-element-count")) >= sceneCount+ );+ },+ { timeout: 60_000, polling: 50 },+ SCENE_COUNT,+ );+ const wallMs = Math.round(performance.now() - started);+ const open = await counters.read();+ await new Promise((resolve) => setTimeout(resolve, IDLE_MS));+ const idle = diffCounts(await counters.read(), open);+ // Studio asks for thumbnails a few at a time and the server finishes aborted ones, so a+ // count at a fixed time follows runner speed. Count the whole set Studio asks for instead.+ // ponytail: quiet = no request and no new file for 10 s; a single render slower than that ends early.+ const renderedFiles = () =>+ existsSync(thumbnailDir)+ ? readdirSync(thumbnailDir).filter((name) => !name.endsWith(".tmp")).length+ : 0;+ const settleDeadline = Date.now() + 240_000;+ let thumbnailRenders = renderedFiles();+ for (;;) {+ const files = renderedFiles();+ if (files !== thumbnailRenders) {+ thumbnailRenders = files;+ lastThumbnailActivity = Date.now();+ }+ if (thumbnailsInFlight.size === 0 && Date.now() - lastThumbnailActivity >= 10_000) break;+ if (Date.now() > settleDeadline) {+ const urls = [...thumbnailsInFlight].map((request) => request.url());+ throw new Error(`thumbnails never settled; in flight: ${urls.join(", ") || "none"}`);+ }+ await new Promise((resolve) => setTimeout(resolve, 250));+ }+ if (thumbnailOutcomes.length === 0 || thumbnailRenders === 0) {+ // Twelve clips on the timeline always ask for thumbnails; none means the journey is broken.+ throw new Error("Studio asked for or rendered no thumbnails; the journey measured nothing");+ }+ const total = await counters.read();++ // Whole-journey totals, because what lands just before or after "can play" varies run to run.+ const workCounts = { thumbnailRenders };+ for (const [key, value] of Object.entries(total)) workCounts[`total.${key}`] = value;+ for (const [key, value] of Object.entries(idle)) workCounts[`idle.${key}`] = value;+ console.log(+ JSON.stringify(+ {+ journey: "studio-open",+ browser: await browser.version(),+ idleMs: IDLE_MS,+ wallMs,+ workCounts,+ thumbnailRequests: thumbnailOutcomes.sort(),+ thumbnailFiles: existsSync(thumbnailDir) ? readdirSync(thumbnailDir).sort() : [],+ },+ null,+ 2,+ ),+ );+} finally {+ await browser.close();+}