Skip to content

--computed: read the left origin as the right's - #62

Merged
tmashara merged 2 commits into
mainfrom
claude/issue-59-computed-origin
Oct 29, 2026
Merged

tmashara merged 2 commits into
mainfrom
claude/issue-59-computed-origin

Conversation

@tmashara

@tmashara tmashara commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Part of #59 (first item: --computed doesn't normalize the origin).

What / why

--computed snapshots carry each side's origin in three places: selector keys (a[href="http://127.0.0.1:4611/x"]), the walked markup (href, src, srcset, inline style url()…), and computed styles (getComputedStyle resolves every url() to an absolute URL, even a relative one in CSS). With two ports, or a local build against production, that alone produced dom differs, unmatched elements and background-image/content findings that were only the port.

diffSnapshots is the single compare point, so it now rewrites the left page's origin (full and protocol-relative) to the right page's in the whole left snapshot before comparing. It rewrites left to right instead of stripping both, so a local build that hard-codes production URLs matches production. run.ts passes leftPage.url() / rightPage.url() so redirects use the document's real origin. Same origin and opaque (about:blank, data:) origins are a no-op.

Known limits

  • Finding values show the right origin on both sides (url("…:4612/a.png")→url("…:4612/b.png")). That's correct, just slightly odd to read.
  • Percent-encoded origins (?url=http%3A%2F%2F…, e.g. Next image) aren't rewritten.
  • a[href] only goes into a key when the raw href is under 60 chars. With origins of different lengths, an absolute href near that limit can be keyed on one side only.
  • Pixel-mode locate still keys a[href] by the raw value (pairing falls back to text matching). Out of scope here.

How tested

  • Unit (tests/unit/computed.test.ts): same host on two ports, covering the key, srcset with a protocol-relative URL, and computed background-image. The diff is empty. :46110 against :46120 (which a rewrite without the port boundary would match) and a different path still differ.
  • End to end: a new byte-identical guard-rail fixture origin (absolute a[href] set at parse time from location.origin, plus a relative url() background) is added to the --computed controls test. It asserts dom 0, no findings at /origin and dom identical on 3 of 4.
  • Both new tests failed before the fix (unit: dom 3 plus a finding; e2e: /origin dom [2, 2]) and pass with it.
  • npm run typecheck, lint, format:check, npm test (294 pass), npm run test:visual (329 pass), after rebasing on Capture: a deadline per shot so a hung renderer can't hang the run #61.

🤖 Generated with Claude Code

tmashara and others added 2 commits October 29, 2026 16:57
Absolute URLs in snapshot keys, markup and computed url() values carry each
side's origin, so two ports or a local build against production reported dom
differences and style findings that were only the origin. diffSnapshots now
rewrites the left page's origin to the right page's before comparing.

Part of #59

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmashara
tmashara force-pushed the claude/issue-59-computed-origin branch from 3f61f9c to f190549 Compare October 29, 2026 16:00
@tmashara
tmashara merged commit c022c72 into main Oct 29, 2026
3 checks passed
@tmashara
tmashara deleted the claude/issue-59-computed-origin branch October 29, 2026 16:06
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.

1 participant