Skip to content

Compare SVG snapshot pixels instead of raw bytes - #4711

Merged
rushabhcodes merged 1 commit into
tscircuit:mainfrom
rushabhcodes:fix-svg-pixel-comparison
Sep 11, 2026
Merged

Compare SVG snapshot pixels instead of raw bytes#4711
rushabhcodes merged 1 commit into
tscircuit:mainfrom
rushabhcodes:fix-svg-pixel-comparison

Conversation

@rushabhcodes

Copy link
Copy Markdown
Contributor

SVG snapshot checks can fail even when the rendered board is unchanged. Asynchronous footprint loading can change generated IDs and the order of independent SVG elements; the AP3429A snapshot failure in tscircuit/sparkfun-boards#328 is one example. Plain tsci snapshot compares raw buffers, and the image comparator used by --ci/--test also falls back to byte equality for SVG input because it only decodes PNGs.

Render differing SVGs to PNGs with the existing Resvg helper before comparing them. Use this visual comparison for normal checks as well as checks that produce diff artifacts. Identical buffers take a fast path, and explicit --update without diff generation continues to refresh metadata and other nonvisual SVG text. SVG mismatch artifacts remain SVG files; PNG diff generation is preserved.

Regression coverage verifies that changed IDs, comments, and reordered non-overlapping elements pass, while changed colors and reordered overlapping shapes fail. CLI tests cover normal, --ci, and --test checks, explicit updates, and real visual mismatches. The captured AP3429A SVG pair has different bytes and compares equal with this change.

The comparison uses the SVG's native rendered dimensions and the existing tolerance of 2. This makes snapshot validation visual; it does not promise to detect subpixel geometry changes or make Circuit JSON generation deterministic.

Validation on current upstream main:

  • 12 targeted tests passed, including SVG equality, visual mismatch detection, metadata updates, all snapshot check modes, and PCB/schematic/3D diff artifacts.
  • TypeScript check and package build passed.
  • Formatting and git diff --check passed.
  • Manually verified the actual AP3429A SVG mismatch is accepted by the patched comparator.

Copilot AI lite review requested due to automatic review settings September 11, 2026 16:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@rushabhcodes
rushabhcodes merged commit d108bee into tscircuit:main Sep 11, 2026
10 checks passed
@tscircuitbot

Copy link
Copy Markdown
Contributor

Thank you for your contribution! 🎉

PR Rating: ⭐⭐
Impact: Minor

Track your contributions and see the leaderboard at: tscircuit Contribution Tracker


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.

4 participants