Skip to content

Add snap.MatchJSON with dotted-path value masking - #447

Merged
skyrpex merged 2 commits into
claude/go-testing-tools-11f5d0from
claude/snap-matchjson-stdlib
Aug 11, 2026
Merged

Add snap.MatchJSON with dotted-path value masking#447
skyrpex merged 2 commits into
claude/go-testing-tools-11f5d0from
claude/snap-matchjson-stdlib

Conversation

@skyrpex

@skyrpex skyrpex commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Motivation

Plain-text snapshots need regex sanitizers for volatile values; JSON output deserves structured masking instead — per-path placeholders that also assert the masked field exists.

Solution

snap.MatchJSON(t, raw, "data.currentVersion", ...) — stdlib only, no new dependencies:

  • Unmarshals, replaces values at the given dotted paths with <any>, re-encodes canonically (two-space indent, sorted keys via encoding/json, HTML escaping off so the placeholder stays readable), and snapshots through the existing snap.Match machinery (same create/update/CI/cleanup semantics).
  • A mask path that doesn't resolve is a hard failure, so a masked field silently disappearing is caught.
  • Objects only, no array-index syntax — deliberate; add when a test needs it.
  • Demonstrated on internal/output: TestEnvelopeSink_UpdateCheckedEnvelopeJSON pins the full --json envelope shape with version fields masked.

Second commit fixes a subtle test-harness bug found while writing tests: MatchJSON's fatal paths lacked return after t.Fatalf, which is invisible under a real *testing.T (Fatalf stops the goroutine) but wrote bogus snapshots under the test suite's fake TB. Regression test included.

Stacked on #443 (in-house must/snap helpers) — merge that first; this diff is only the MatchJSON commits.

Docs

Docs impact

Nothing to document externally — test-internal tooling. CLAUDE.md's Testing section is updated in this PR with MatchJSON usage.

Review

Human review advisable: same test-tooling direction decision as #443; small diff but it fixes the public helper surface other packages will adopt.

Co-Authored-By: Claude noreply@anthropic.com

@skyrpex skyrpex added semver: patch docs: skip Pull request does not require documentation changes labels Aug 11, 2026
skyrpex and others added 2 commits August 11, 2026 14:43
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@skyrpex
skyrpex force-pushed the claude/go-testing-tools-11f5d0 branch from cd92645 to f3cd58b Compare August 11, 2026 12:43
@skyrpex
skyrpex force-pushed the claude/snap-matchjson-stdlib branch from 52f7f7f to 862b2c8 Compare August 11, 2026 12:43
@skyrpex
skyrpex marked this pull request as ready for review August 11, 2026 12:45
@skyrpex
skyrpex requested a review from a team as a code owner August 11, 2026 12:45
@skyrpex
skyrpex merged commit f22dd0d into claude/go-testing-tools-11f5d0 Aug 11, 2026
17 checks passed
@skyrpex
skyrpex deleted the claude/snap-matchjson-stdlib branch August 11, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: skip Pull request does not require documentation changes semver: patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant