Skip to content

test(studio): share one sealed preview frame that delivers messages like a browser - #8165

Merged
miguel-heygen merged 5 commits into
mainfrom
test/studio-sealed-frame-helper
Nov 18, 2026
Merged

miguel-heygen merged 5 commits into
mainfrom
test/studio-sealed-frame-helper

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

One shared fake for a preview frame Studio cannot script, sealedPreviewFrame() in packages/studio/src/player/lib/sealedPreviewFrame.test-helpers.ts, replacing the local copies in 14 Studio test files (+85 / −381).

It behaves like a real cross-origin frame in the two ways the copies did not:

  • Delivery. A browser delivers each postMessage on a later task, to every listener present when the dispatch begins. The copies delivered synchronously, which hid the bug fixed in fix(core): each editing client takes its own port, so a sealed preview answers Studio again #8154 (two editing clients took the same handed-over port). The helper, and serveEditingRequests in timelinePlayerTestHarness.ts, now deliver on a later task.
  • Reads. The frame's window throws SecurityError on every property except postMessage, and the iframe's contentDocument is null, so a test fails if Studio reaches into the frame instead of going through the editing port.

The frame's real runtime agent answers, and its messages carry the frame as their source, so the editing port's source check runs as in the app. sealedPreviewFrame({ port }) wraps each handed-over port, for tests that hold or inspect replies (the caption overlay test).

Capture check

scripts/check-pr-captures.mjs now treats .test-helpers. files as tests, as it already treats .test. and .spec. files. .test-helpers.ts is the repo's existing name for test helpers (10 files across core, parsers, studio, studio-server and cli). Its test gains a .test-helpers.ts row that fails with main's checker.

Tests

New in packages/studio/src/hooks/useAppHotkeys.previewForwarding.test.tsx, "leaves Studio's own reads of the preview answered while it forwards keys": the shortcut watcher and Studio's own client open on one sealed frame in the same tick, and Studio's read must still get its answer.

fails without the fix: on this branch with #8154's change taken out of packages/core/src/runtime/editingPort.ts, that test fails:

× leaves Studio's own reads of the preview answered while it forwards keys
AssertionError: expected { watching: 28 } to deeply equal { zIndex: 7 }

The shortcut watcher's client took the port and got Studio's reply. With #8154 the test passes, along with the 14 converted files and every other user of serveEditingRequests: useConsoleErrorCapture, useElementPicker, previewMessageRouter.manifest, usePlaybackKeyboard, previewChannel and previewElements (21 files, 209 tests).

No visible change

Test code only.

terencecho
terencecho previously approved these changes Nov 18, 2026

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 0f0be1f against stack base 218835e (#8154). No blocker found in this test-only diff. #8154 must land first; recheck the retargeted head/diff before merge.

The shared helper keeps the real editing agent and frame-source identity, queues message delivery onto a later task, refuses cross-origin property reads and exposes a null contentDocument. The port-wrapper hook remains available for delayed-reply tests, and the runtime agent is disposed at test completion. Existing assertions in the 14 migrated files are retained; the additional regression opens the shortcut and Studio clients together and checks that Studio receives its own read result.

Validation: all 209 tests across the 21 migrated/helper-consumer suites pass at this head. Removing #8154's port-claim guard from the source and built client makes the new race test fail with { watching: 28 } instead of { zIndex: 7 }; restoring it passes. Full workspace build passed after retrying one SIGTERM, before the final test-only option rename; that final rename and its caller are covered by the 21 suites. The comment-share gate passes locally and CI is green (11 success, four skipped). The required fails-without-the-fix line is present; no visible product change or browser walk is claimed.

— tai (automated review)

Base automatically changed from fix/editing-port-one-client-per-port to main November 18, 2026 09:16
@miguel-heygen
miguel-heygen dismissed terencecho’s stale review November 18, 2026 09:16

The base branch was changed.

@miguel-heygen
miguel-heygen force-pushed the test/studio-sealed-frame-helper branch from 0f0be1f to d75a061 Compare November 18, 2026 09:18

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rechecked retargeted head d75a061 against main e95cdf7. #8154 is merged at that base. Both child commits are '=' in range-diff, all 17 changed files are byte-identical to approved 0f0be1f, and the base editingPort implementation matches the previously tested parent. No new behavior issue found, but the retargeted CI run exposes two required blockers:

[P2] Make the unused postLater helper private (or use it through a real consumer). The Fallow PR report flags fallow/unused-export at sealedPreviewFrame.test-helpers.ts:7. I read the failed audit job and report; this is the reason its gate is red.

[P2] Put the new test helper under a recognized test path, or deliberately update the capture checker's test-helper classification with coverage. The capture job counts 41 changed non-test lines (39 from this helper plus the harness change), so its under-20-lines No visible change exemption rejects the body. scripts/check-pr-captures.mjs currently recognizes /tests/, /tests/ or .test./.spec. paths, not .test-helpers.ts. This PR is test-only; use the supported test classification so its No visible change declaration is accepted.

Prior validation carries forward because the patch and affected file contents are unchanged: 209 tests in 21 files passed, and removing the parent port-claim guard made the new race test fail with watching:28 instead of zIndex:7. No tests/build were rerun for this rebase-only comparison. The required fails-without-the-fix line is present. Approval can be re-pinned once these CI blockers are resolved.

— tai (automated review)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Both fixed at 5d323e5.

  • Unused export: postLater is private now (5d323e5); nothing outside the helper used it.
  • Capture check: fixed in the checker instead of moving the file (08a780d). .test-helpers.ts is already the repo's name for test helpers (packages/core/src/runtime/editingAgent.test-helpers.ts, packages/studio/src/hooks/gsapParsedTween.test-helpers.ts and eight more), and scripts/check-pr-captures.mjs counted all of them as product code. TEST_PATH now matches .test-helpers. as well as .test./.spec.. The checker's test "test files under a watched package need no capture" gains a c.test-helpers.ts row: with main's checker it fails (74 pass, 1 fail), with the fix all 75 pass. The workflow runs the PR's own checker, so this PR's "No visible change" counts only the 3-line harness change.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 5d323e5. The earlier Fallow and capture blockers are fixed: postLater is private, the checker recognizes .test-helpers files, and both CI gates are green. All 75 capture-checker tests pass locally; restoring the old classifier makes the newly extended test fail, then restoring this head passes again.

[P2] Exclude the new test-only helper from Studio's production typecheck, consistently with core's existing .test-helpers convention.

The required Typecheck job now fails with eight TS2339 errors in core/src/runtime/editingAgent.ts for __player, __hfStartupError, __clipManifest, __clipTree, __hfWaitForSeekCompletion and __hf. The new sealedPreviewFrame.test-helpers.ts imports the core test agent, but Studio's tsconfig includes all src and excludes only src/**/.test.ts. It therefore pulls this runtime source into Studio's type program without the core runtime Window augmentations. Core already excludes **/.test-helpers.ts in both tsconfigs.

Finish the test-only wiring in Studio's TypeScript configuration (or use a test path consistently excluded there) and rerun Studio/the required typecheck. The failing CI log identifies this exact import/type boundary; no runtime declaration weakening is needed.

The helper's message/port behavior is unchanged, so the prior 209-test and two-client race validation carries forward. Those package suites were not rerun for this small checker/private-export delta. No new product behavior issue found; the remaining blocker is the introduced required typecheck failure.

— tai (automated review)

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 62 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

Unstable (1)

  • seqplainkeys-none-px-r0-nested-z100: tracking 0.07, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.07, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true / tracking 0.07, pressJump 0, drop 0, reload 0, render 0.03, renderKey -, undo true, teleport true

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Fixed at 5ec72c3: packages/studio/tsconfig.json now excludes src/**/*.test-helpers.ts, as core's two tsconfigs already do. Only .test.ts files (excluded already) import the helper, so the core runtime source no longer enters Studio's program.

Studio tsc --noEmit -p . on this branch: 0 errors. With the previous tsconfig: the same 8 TS2339 errors in core/src/runtime/editingAgent.ts.

@terencecho terencecho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed 5ec72c3. The remaining typecheck blocker is resolved: Studio excludes src/**/*.test-helpers.ts, consistent with core's existing test-helper convention. The helper's consumers are excluded .test.ts files, so this removes the fake/core-test-agent import tree from the production type program without changing runtime test discovery.

Full workspace build and Studio typecheck pass at this head. Restoring the previous tsconfig reproduces the eight TS2339 Window-property errors; restoring this exclusion makes typecheck pass again. All 30 preview-selection tests using the shared helper pass, confirming those tests still run with the helper excluded from production typechecking. The prior 209-test suite and two-client race validation carry forward because helper behavior is unchanged.

The previous unused-export and capture-classification fixes remain; their CI gates are green. The required fails-without-the-fix line is present. No remaining blocker found. CI Typecheck and other jobs are still running with no failed checks when submitted; local typecheck is green. No merge performed.

— tai (automated review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 640cb37 Nov 18, 2026
81 checks passed
@miguel-heygen
miguel-heygen deleted the test/studio-sealed-frame-helper branch November 18, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants