fix(check): preserve text in audit snapshots#2306
Conversation
james-russo-rames-d-jusso
left a comment
There was a problem hiding this comment.
Reviewed at eb1366c0.
Right fix at the right layer. The invariant it depends on — finishContrast runs __contrastAuditFinish which restores the text paint hidden by prepareContrast — is enforced by the same code the finally block at checkBrowser.ts:542 doubles down on (safety-net call to __contrastAuditRestoreIfPending). So by the time the new overviewShot capture runs at line 528, text is guaranteed painted.
The two-screenshot design keeps concerns cleanly separated:
measurementShot— glyph-free, feeds contrast pixel-sampling math viafinishContrast. Must stay untouched by annotations, must stay glyph-free.overviewShot— text restored, feedscaptureOverviewShotwith the annotation overlay. What lands on disk as user-facing QA evidence.
The old code aliased measurementShot into both roles, which is exactly why blank text landed in the persisted PNGs. Splitting them is the load-bearing correctness change; the added screenshot is the minimum cost to preserve the contrast-math isolation.
Test coverage is precise: mock-installed __contrastAuditFinish that calls __contrastAuditRestoreIfPending?.(), page.screenshot returns "text-hidden-base64" when color: transparent, "text-visible-base64" otherwise. Assertions prove both (a) screenshot called twice — measurement + overview, and (b) the persisted result is the visible one. Ratchet.
Verified against feedback_narrow_titled_bugfix_check_root_cause: title says "preserve text in audit snapshots" — the fix is exactly the sibling to the finally block's restore invariant, no broader / narrower scope drift.
LGTM.
jrusso1020
left a comment
There was a problem hiding this comment.
Approving on Rames-D's go (R2 delta clean, nit round addressed) + Magi's CI-green confirmation. Verified at final head eb1366c0: CI green, no changes-requested, mergeable.
Summary
check --snapshotsoverview frames only after contrast auditing restores temporarily hidden text paintReproduction
On 0.7.55, a minimal 71-second composition containing ordinary text produced blank
check --snapshotsPNGs at 44s, 57s, and 70.2s. Standalonesnapshotat those times showed the text correctly. The contrast auditor hides text to sample background pixels, and the check pipeline incorrectly persisted that measurement image.Verification
bun run --cwd packages/cli test --run src/utils/checkBrowser.test.ts src/commands/check.test.ts(45 passed)bun run --cwd packages/cli typecheck