test(svg-renderer): add visual-fidelity test for sanitizeSvgText#558
Open
test(svg-renderer): add visual-fidelity test for sanitizeSvgText#558
Conversation
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
Adds pixel-level (“visual fidelity”) regression coverage for sanitizeSvgText in @scratch/scratch-svg-renderer, complementing the existing string-equality sanitizer tests and supporting upcoming SVG sandbox work.
Changes:
- Add a new Tap test that renders the same SVG before/after
sanitizeSvgTextand asserts pixel-identical output. - Add a committed PNG snapshot baseline for the sanitized render, plus a shared
cat-costume.svgfixture. - Add
canvas(node-canvas) as a devDependency to enable headless rendering in tests (with corresponding lockfile updates).
Reviewed changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/scratch-svg-renderer/test/visual-fidelity.js | New pixel-diff and snapshot-based visual regression tests for sanitizeSvgText. |
| packages/scratch-svg-renderer/test/fixtures/cat-costume.svg | New shared SVG fixture used for visual fidelity rendering. |
| packages/scratch-svg-renderer/package.json | Adds canvas devDependency needed by the new test. |
| package-lock.json | Lockfile updates for canvas and its transitive dependencies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Render the cat costume SVG twice — once raw, once after sanitizeSvgText — and assert the canvases are pixel-identical. Also pin a committed PNG snapshot of the sanitized render so future drift in sanitizer, fonts, or canvas/librsvg shows up as a test failure rather than a silent regression. Pulls in node-canvas as a devDep.
1790c71 to
7646525
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves
Adds a second axis of coverage for
sanitizeSvgText— pixel-level fidelity — in service of the SVG sandbox work that's about to start. No behavior change.Proposed Changes
packages/scratch-svg-renderer/test/visual-fidelity.js. Renders the cat costume SVG twice — once raw, once aftersanitizeSvgText— and asserts the canvases are pixel-identical (tolerance 0).test/snapshots/cat-costume.sanitized.png. Future runs assert against this baseline, so drift in the sanitizer, fonts, or canvas/librsvg surfaces as a test failure on its own — not just relative to the raw input.test/fixtures/cat-costume.svg, extracted fromscratch-vm/test/fixtures/default.sb3'sbcf454ac…svg.node-canvasadded as a devDep for the rendering primitive.Reason for Changes
The existing
test/sanitize-svg.jsasserts string equality between raw fixtures and.sanitized.svgcompanions. That's good for catching policy changes, but it can't catch a sanitizer change that quietly alters rendered pixels — say, a future tightening that drops a fill rule or a presentation attribute that the policy file accidentally categorizes as ornamental. The pixel-level check covers the gap.The committed snapshot is a separate kind of guarantee from the cross-comparison: even if
sanitizeSvgTextis byte-for-byte unchanged, a font asset update or a librsvg upgrade that subtly alters rendering would be invisible to the cross-comparison (raw and sanitized both render the new way) but visible against the snapshot.Test Coverage
npm test --workspace=packages/scratch-svg-rendererpasses locally (168 / 168 tap tests with the new file).npm run build --workspace=packages/scratch-svg-renderersucceeds.