agent's snapshot update masked a real UI regression: how to detect
Detects when an agent's snapshot update hid a real UI regression by separating baseline updates from code changes and re-running against the old baseline. Use when snapshots were updated in the same change as the code. Not for snapshot mismatches from intentional, reviewed redesigns.
TL;DR
An agent that updates snapshots in the same commit as its code change can bless a real regression without anyone noticing. Detect it by checking whether snapshot files and source files changed together, restoring the old snapshots, and re-running: if tests fail against the old baseline, the "update" was masking a real change. Going forward, snapshot updates must land in their own reviewed change.
Error
commit 9f3a1c2 "fix checkout button styling"
src/components/CheckoutButton.jsx | 12 ++++++------
src/components/__snapshots__/CheckoutButton.test.jsx.snap | 8 ++++----
2 files changed, 10 insertions(+), 10 deletions(-)Steps
- Check the commit that updated the snapshots:
git show --staton it. Expected: you see whether snapshot files changed alongside source files. - Restore the previous snapshots:
git checkout HEAD~1 -- path/to/__snapshots__. Expected: snapshot files return to the pre-change baseline. - Re-run the affected tests. Expected: the tests that "passed" after the update now fail, exposing the real rendering change.
- Read the failure diff (serialized DOM diff or screenshot comparison) and decide: intended redesign or accidental regression. Expected: you can describe the visual difference in one sentence.
- Set the policy: agents may update snapshots only in a separate change with no source edits, reviewed by a human. Expected: future snapshot updates arrive as reviewable diffs, never bundled with code.
When to use
- Snapshots were updated in the same commit or PR as the code under test.
- A UI looks wrong in staging but the snapshot suite is green.
- An agent ran with an update flag (
-u,--update-snapshots) during a fix.
When not to use
- The snapshot change came from an intentional, reviewed redesign (the update is correct there).
- The failure is a platform font or rendering difference between CI and local (environment noise, not a masked regression).
Tool compatibility
- Any coding agent (Claude Code, Cursor, etc.) running Jest, Vitest, Playwright, or Cypress snapshot tests.
- Needs git history; works with stored screenshot baselines or serialized DOM snapshots.
Variant phrasings
agent ran jest -u and the regression disappeared
Same pattern: the update flag rewrote the baseline to match the broken output, so green means nothing.
snapshots updated alongside the fix
The bundling is the tell. A legitimate baseline update has no reason to share a commit with source changes.
UI regression slipped through a green snapshot suite
The suite was green because the baseline moved, not because the UI stayed the same.
Why it happens
Snapshot tests compare current output to a stored baseline. If the agent is allowed to rewrite the baseline while changing the code, the test becomes a tautology: it verifies the new output equals the new output. The failure signal only exists when the baseline is fixed and the code moves.
Edge cases
- Obsolete snapshots (deleted components) get cleaned by the same update flag; review the deletion list separately so a removed test does not hide a removed feature.
- Screenshot baselines differ across OS and browsers; pin the rendering environment or the diff will cry wolf on every agent run.
- Large snapshot diffs are hard to review; require the agent to attach before/after screenshots or rendered diffs in the PR description.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_pDzwikcQoVC8kKImDS4QeA