Skip to content

fix(cli): check measures its screenshots outside the composition's page - #9079

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/check-compares-screenshots-outside-page
Nov 29, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/check-compares-screenshots-outside-page

Conversation

@miguel-heygen

Copy link
Copy Markdown
Collaborator

What

hyperframes check, validate and keyframes --shot measure their own screenshots in Node, or draw them on a blank page. The composition's page no longer receives a screenshot, or a colour or verdict read from one.

Why

Several checks took a screenshot and handed it back to functions living in the composition's own page, next to the composition's scripts. A composition that redefines a global, Image or a canvas method changed what the check measured. A check's reading should not depend on the code it is checking.

Related work

Follows #9059, which added the blank-stretch check on top of the same in-page comparison.

How

  • utils/framePixels.ts decodes PNGs with the engine's existing decodePng and owns the frame comparison and the one-colour test. Same thresholds as before (24 per channel, 16 pixels).
  • commands/contrast-measure.ts is the contrast measurement, moved out of contrast-audit.browser.js. It reuses contrast-sample.ts and contrast-bg.ts, which that script used to copy.
  • The page still says what it alone knows: which texts there are, their colours and boxes, and the stage's background colour. Node checks the shape of what it gets.
  • utils/blankPageShot.ts takes the filmstrip and the annotated overview on a blank page of the same size.

Every place in packages/cli that takes a screenshot

Line numbers are packages/cli/src on main at ef1d5db.

Went back into the composition's page, now does not:

Place What went back
utils/checkBrowser.ts:1165 stageIsEmpty full frame
utils/checkBrowser.ts:1143 framesDiffer (the never-moves check, and keepsMoving, whole page or inside a selector) two frames
utils/checkBrowser.ts:2086 finishContrast frame or clip
commands/validate.ts:341 runContrastAudit full frame
commands/motionShot.ts:734 filmstrip every frame, as images in the page's DOM
utils/checkBrowser.ts:1938 captureOverviewShot (--snapshots) which texts failed contrast, as boxes in the DOM
utils/checkBrowser.ts:1109 matchComponents (--components) whole findings with measured colours; now only each finding's selectors

Never went back, unchanged:

Place Where the picture goes
utils/checkBrowser.ts:697, :750 finding crops and frames files
commands/snapshot.ts:393 discarded (a 1x1 shot that makes Chrome paint)
commands/snapshot.ts:1538, :1548 files
commands/motionShot.ts:779 marker drawing a file
commands/compare.ts:302, commands/grade-compare.ts:590 files
server/studioServer.ts:951 the thumbnail response
capture/screenshotCapture.ts:128, :328, capture/mediaCapture.ts:192, :534 files, from captured websites

Two are not screenshots and stay: commands/snapshot.ts:1474 puts a video's own decoded frames in its place, and commands/motionShot.ts:597 (--ghost) reads the page's own canvases inside the page.

What still reaches the page: the selectors a finding names, when --components or the --snapshots frames look the elements up again, and the seeks a comparison makes. Neither carries pixels or colours.

Test plan

fails without the fix: packages/cli/src/utils/screenshotsOutsidePage.chromium.test.ts. It loads a film that hooks the receivers, Image, canvas and DOM insertion, before the scripts arrive and again at every seek, and reports what it is handed. On main its 10 rows fail ("asks whether the stage is empty", "compares the frames of a film that never moves", "compares the frames keepsMoving asks about", "measures contrast under check's default flags", "marks contrast failures on the overview frame", "asks which findings belong to a component", "measures contrast in validate", "lays out the keyframes filmstrip"). Each row also asserts that its check still ran and reported. An eleventh row proves the film's hooks see a PNG.

  • Unit tests added/updated. Putting each of the seven back one at a time turns its own row red; so do 11 changes to the comparison, the contrast maths, the parsing and the restoring of hidden text.
  • Manual testing performed. keyframes --shot filmstrip and check --snapshots overview compared with main's: same picture, only the label text's antialiasing differs. The second page renders the same in one-process headless shell. Not run: the macOS agent sandbox.
  • Documentation updated: none needed, no flag or report field changes.
  • Comments follow CONTRIBUTING.md "Comments".
    CORPUS_LINE

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at 0427c79. Requesting changes for one thing only: the PR's own red check.

Blocking: Fallow audit is red because of this diff. It reports two fallow/duplicate-export findings: Rgba is exported from both packages/cli/src/utils/framePixels.ts:11 (new) and packages/cli/src/commands/contrast-bg.ts:4 (existing). Keep one: framePixels.ts can import the type from contrast-bg.ts (or the other way round), and contrast-measure.ts then takes it from the single owner. No behaviour change. I will approve once that check is green on the new head.

The code itself reads clean; no other finding.

  • Compared measureContrast against the removed in-page __contrastAuditFinish line by line: same sample rect and grid (now the shared contrast-sample.ts functions), same known-backdrop rule (ownBg alpha >= 0.99, else solidBg), same skip on a transparent median, same weakest-fill pick and stronger-of-fill-and-stroke rule, same 2-decimal rounding and AA thresholds. The clip offset maths matches the old (y - oy) * width + (x - ox).
  • framePixels.ts keeps the thresholds (24 per channel, 16 pixels) and the kept reference decode; isOneColor replaces the old "paint a full frame in the page and compare" with the same comparison against one colour. The engine's decodePng accepts the 8-bit RGB and RGBA PNGs a screenshot produces, and ./alpha-blit is an existing engine export, now aliased in tsup.config.ts.
  • check: paint is restored right after the measurement shot and again in finally; matchComponents now hands the page only selector and containerSelector; the annotated overview and the filmstrip are drawn on a new blank page of the same viewport, closed in finally.
  • validate: same shot options as before, candidates shape-checked in Node, restore still in finally.
  • No reader of the three removed page functions is left in packages/ outside the new test.
  • Body has the fails without the fix: line naming screenshotsOutsidePage.chromium.test.ts.

Non-blocking:

  • The PR body ends with a stray CORPUS_LINE line.
  • The body says 10 rows fail on main and lists 8 names; worth making the two agree.

Read whole at head: framePixels.ts, blankPageShot.ts, contrast-measure.ts, contrast-audit.browser.js, blank-span.browser.js. Read as hunks: checkBrowser.ts, validate.ts, motionShot.ts, motion-signature.browser.js, contrast-bg.ts, contrast-sample.ts, tsup.config.ts. Tests: only the first 60 lines of the new Chromium test were read; the other test files were not read. Nothing was run (string searches only).

Need: yes · Size: fits (844/740, mostly a move) · Reuse: good, removes the in-page copies · Simpler: no · Structure: fine
Risk: low once the audit is green; measurement maths is unchanged.

— Rames

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 275 (base branch 273), smooth 82 of those

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

Newly passing (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)

  • seqscaletwice-scale-px-r0-root-z100
  • seqscaletwice-scale-px-r0-nested-z100

Quarantined, measured but not gated (0)

@miguel-heygen

Copy link
Copy Markdown
Collaborator Author

Answering the review at 0427c79; new head 4a557c6.

  • Duplicate Rgba (blocking): fixed. contrast-bg.ts owns it; framePixels.ts and contrast-measure.ts import it. Types only. Run at 4a557c6: lint, format, tsc, the Fallow audit, pre-push and every CLI test that covers a changed file, all green.
  • Stray CORPUS_LINE at the end of the body: a placeholder I meant to remove. Ignore it; the numbers it stood for are below.
  • 10 rows, 8 names: two names cover two rows each. "asks whether the stage is empty" runs with contrast on and off, and "compares the frames keepsMoving asks about" runs for the whole page and inside #root. That makes 10; the 11th row tests the film's own hooks.

Before and after: check --json --no-cache from main (ef1d5db) and from this branch, each run cold, on 120 of the repo's 538 fixture projects (all examples, the rest in seeded random order).

Projects with a browser pass 101 of 120 (a lint error stops the others on both builds)
Contrast section, and every never-moves, frozen and blank-stretch finding identical in all 120: 3,146 texts measured, 191 contrast findings
Whole report identical 88 of 101
Differs where main also differs from itself between two cold runs 12 (order of missing files, a pixel-wipe's cell, sample counts)
Differs where main agreed with itself 1, flowchart-vertical: one box 0.01 px wider. Main gave both values in 8 further runs

The branch build used for this was made before backdrop in contrast-measure.ts was split in two and before the type moved; the contrast tests and their deliberate breaks were rerun on the split, the corpus was not. Not run: the other 418 projects, and the macOS agent sandbox.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at 4a557c6. Re-review of my one open item.

Resolved: Rgba now has one owner (commands/contrast-bg.ts); utils/framePixels.ts, its test and contrast-measure.ts import it. The audit check that was red on the previous head passes here.

What I compared: the diff between the head I reviewed before (0427c79) and this one is a single commit, 3 files, +5 −5, type imports only, on the same merge base. No runtime line changed, so the earlier read of the rest of the change stands. The body still carries its fails without the fix: line.

Nothing was run; this is a git byte comparison plus a string search for the type's definitions.

Note, not blocking: a utils/ file now imports a type from commands/. It is type-only, so no runtime cycle; if more of the frame code ends up needing colour types, a small shared types file would read better.

Need: yes · Size: unchanged · Reuse: one type, one owner · Simpler: n/a · Structure: fine, see note
Risk: low; type-only delta on top of the already reviewed change.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit 511edae Nov 29, 2026
91 checks passed
@miguel-heygen
miguel-heygen deleted the fix/check-compares-screenshots-outside-page branch November 29, 2026 10:55
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