Testing Golden Artifacts
Use this skill when a test should lock down a produced artifact: generated code,
serialized JSON, command output, reports, migration files, rendered documents, or
other outputs where a reviewer needs to see the exact shape. A good golden test
answers one question: did the intended contract change, or did the implementation
drift?
Operating Rule
A golden artifact is a reviewed contract, not a cache. The test may help produce
an updated candidate, but replacing the expected artifact must be an explicit
approval step with a readable diff and a named reason.
Fit Check
Use golden artifacts when at least one of these is true:
- The artifact is the public or integration-facing behavior.
- The output has enough structure that individual assertions would miss
ordering, formatting, omission, or compatibility regressions.
- Reviewers can make sense of a diff faster than they can reconstruct the
expected output from many small assertions.
- The artifact is part of an approval workflow, such as generated docs, schemas,
prompts, reports, migrations, or CLI transcripts.
Prefer ordinary assertions when the expected value is small, when the behavior is
purely numeric or boolean, or when the fixture would mostly encode incidental
implementation details.
Design Workflow
Define the artifact contract.
Name the user-visible behavior the artifact represents. Do not snapshot an
entire directory or object graph just because it is easy to serialize.
Isolate generation from comparison.
Generate the actual artifact into a temporary location, normalize it, then
compare it with the committed expected artifact. Keep production code unaware
of test update mode.
Normalize volatility before comparison.
Remove or canonicalize timestamps, absolute paths, random IDs, hostnames,
map ordering, locale-specific formatting, line endings, and other values that
do not belong to the contract.
Compare with a stable diff.
Text artifacts should fail with a unified diff or a structure-aware diff.
Binary artifacts need a reviewable companion representation such as metadata,
dimensions, checksums, extracted text, perceptual hash, or a generated preview.
Require explicit approval for updates.
A failing test may write an actual artifact to a temporary path or an
ignored candidate file. It must not silently overwrite the committed golden.
Verify update discipline.
CI runs in read-only mode. Local update mode must be opt-in, deterministic,
and followed by a clean rerun plus review of the changed fixture files.
Normalization Checklist
- Sort maps, object keys, directory entries, and unordered collections.
- Format structured files canonically: stable JSON indentation, stable YAML key
order when possible, normalized markdown whitespace, and LF line endings.
- Scrub absolute workspace paths to placeholders such as
<workspace>.
- Replace timestamps, UUIDs, process IDs, ports, and random suffixes only when
they are not part of the behavior under test.
- Seed randomness when random data matters to the scenario.
- Redact secrets before writing any actual or expected artifact.
- Keep normalizers narrow. A normalizer that deletes large sections of output is
usually hiding the wrong contract.
Stable Diff Rules
- Prefer small, named goldens over one large omnibus artifact.
- Keep generated actual files available on failure so the reviewer can inspect
the full output, not only the diff excerpt.
- Use path-stable artifact names. Avoid test names that depend on package order,
wall-clock time, or temporary directories.
- For structured data, compare the parsed form after canonical serialization
when formatting is not part of the contract.
- For formatting-sensitive artifacts, compare the final bytes after line-ending
normalization and make whitespace changes visible in the diff command.
- For binary outputs, commit a reviewable surrogate when the raw binary diff is
not useful.
Fixture Ownership
Every golden fixture needs one clear owner:
- The owning test, scenario, or package is named in the fixture path or filename.
- Shared fixtures are read-only inputs; generated expected artifacts are owned by
the test that approves them.
- A fixture update should be attributable to one behavior change. If one code
change updates unrelated goldens, split the work or explain the shared cause.
- Do not let two tests update the same expected file from different paths.
- Delete obsolete fixtures in the same change that removes the behavior they
represented.
Approval Workflow
Use a two-step workflow:
Read-only check.
The default test command generates actual output, normalizes it, compares it
to the committed expected artifact, and fails with a stable diff plus an
update command hint.
Explicit update.
A local maintainer runs an opt-in command or environment flag such as
UPDATE_GOLDENS=1. The update writes expected artifacts deterministically,
then the maintainer reviews the git diff and reruns the read-only test.
Approval is not complete until the diff has been reviewed. Never make CI update
goldens, and never make a passing test depend on uncommitted generated files.
Update Discipline
- Update goldens in the same change as the behavior that requires them.
- Keep the reason visible in the commit, PR, bead, or test note.
- Regenerate the smallest fixture set that proves the change.
- Reject blanket "update all snapshots" churn unless the underlying behavior is
intentionally global.
- Rerun the read-only test after update mode and confirm the working tree has
only intended artifact changes.
- If a golden changes often without product behavior changing, fix the
normalization or replace the golden with targeted assertions.
Review Checklist
Before accepting a golden-artifact test, verify:
- The artifact contract is named and belongs in a golden test.
- The normalizer removes volatility without erasing meaningful behavior.
- Failures produce a diff a reviewer can act on.
- Update mode is explicit, local-only, deterministic, and documented by the test
failure or nearby test helper.
- Fixture ownership is clear from paths, test names, or scenario names.
- The changed fixtures are reviewed as product evidence, not accepted as
generated noise.
Output Specification
When applying this skill, return a concise plan or review with these sections:
- Scope: artifact type, owning test surface, and behavior under contract.
- Artifact contract: what is intentionally frozen and what is excluded.
- Normalization: volatile fields and how they are canonicalized.
- Comparator and diff: command, helper, or assertion strategy.
- Fixture ownership: where expected artifacts live and who updates them.
- Approval workflow: read-only command, update command, and CI posture.
- Update discipline: review requirements and limits on fixture churn.
- Verification: commands run and residual risks.
1---2name: golden-artifact-testing3description: Use when designing or repairing golden-file, snapshot, fixture, or generated-artifact tests. Triggers:4---5
6# Testing Golden Artifacts
7
8Use this skill when a test should lock down a produced artifact: generated code,
9serialized JSON, command output, reports, migration files, rendered documents, or
10other outputs where a reviewer needs to see the exact shape. A good golden test
11answers one question: did the intended contract change, or did the implementation
12drift?
13
14## Operating Rule
15
16A golden artifact is a reviewed contract, not a cache. The test may help produce
17an updated candidate, but replacing the expected artifact must be an explicit
18approval step with a readable diff and a named reason.
19
20## Fit Check
21
22Use golden artifacts when at least one of these is true:
23
24- The artifact is the public or integration-facing behavior.
25- The output has enough structure that individual assertions would miss
26 ordering, formatting, omission, or compatibility regressions.
27- Reviewers can make sense of a diff faster than they can reconstruct the
28 expected output from many small assertions.
29- The artifact is part of an approval workflow, such as generated docs, schemas,
30 prompts, reports, migrations, or CLI transcripts.
31
32Prefer ordinary assertions when the expected value is small, when the behavior is
33purely numeric or boolean, or when the fixture would mostly encode incidental
34implementation details.
35
36## Design Workflow
37
381. Define the artifact contract.
39 Name the user-visible behavior the artifact represents. Do not snapshot an
40 entire directory or object graph just because it is easy to serialize.
41
422. Isolate generation from comparison.
43 Generate the actual artifact into a temporary location, normalize it, then
44 compare it with the committed expected artifact. Keep production code unaware
45 of test update mode.
46
473. Normalize volatility before comparison.
48 Remove or canonicalize timestamps, absolute paths, random IDs, hostnames,
49 map ordering, locale-specific formatting, line endings, and other values that
50 do not belong to the contract.
51
524. Compare with a stable diff.
53 Text artifacts should fail with a unified diff or a structure-aware diff.
54 Binary artifacts need a reviewable companion representation such as metadata,
55 dimensions, checksums, extracted text, perceptual hash, or a generated preview.
56
575. Require explicit approval for updates.
58 A failing test may write an actual artifact to a temporary path or an
59 ignored candidate file. It must not silently overwrite the committed golden.
60
616. Verify update discipline.
62 CI runs in read-only mode. Local update mode must be opt-in, deterministic,
63 and followed by a clean rerun plus review of the changed fixture files.
64
65## Normalization Checklist
66
67- Sort maps, object keys, directory entries, and unordered collections.
68- Format structured files canonically: stable JSON indentation, stable YAML key
69 order when possible, normalized markdown whitespace, and LF line endings.
70- Scrub absolute workspace paths to placeholders such as `<workspace>`.
71- Replace timestamps, UUIDs, process IDs, ports, and random suffixes only when
72 they are not part of the behavior under test.
73- Seed randomness when random data matters to the scenario.
74- Redact secrets before writing any actual or expected artifact.
75- Keep normalizers narrow. A normalizer that deletes large sections of output is
76 usually hiding the wrong contract.
77
78## Stable Diff Rules
79
80- Prefer small, named goldens over one large omnibus artifact.
81- Keep generated actual files available on failure so the reviewer can inspect
82 the full output, not only the diff excerpt.
83- Use path-stable artifact names. Avoid test names that depend on package order,
84 wall-clock time, or temporary directories.
85- For structured data, compare the parsed form after canonical serialization
86 when formatting is not part of the contract.
87- For formatting-sensitive artifacts, compare the final bytes after line-ending
88 normalization and make whitespace changes visible in the diff command.
89- For binary outputs, commit a reviewable surrogate when the raw binary diff is
90 not useful.
91
92## Fixture Ownership
93
94Every golden fixture needs one clear owner:
95
96- The owning test, scenario, or package is named in the fixture path or filename.
97- Shared fixtures are read-only inputs; generated expected artifacts are owned by
98 the test that approves them.
99- A fixture update should be attributable to one behavior change. If one code
100 change updates unrelated goldens, split the work or explain the shared cause.
101- Do not let two tests update the same expected file from different paths.
102- Delete obsolete fixtures in the same change that removes the behavior they
103 represented.
104
105## Approval Workflow
106
107Use a two-step workflow:
108
1091. Read-only check.
110 The default test command generates actual output, normalizes it, compares it
111 to the committed expected artifact, and fails with a stable diff plus an
112 update command hint.
113
1142. Explicit update.
115 A local maintainer runs an opt-in command or environment flag such as
116 `UPDATE_GOLDENS=1`. The update writes expected artifacts deterministically,
117 then the maintainer reviews the git diff and reruns the read-only test.
118
119Approval is not complete until the diff has been reviewed. Never make CI update
120goldens, and never make a passing test depend on uncommitted generated files.
121
122## Update Discipline
123
124- Update goldens in the same change as the behavior that requires them.
125- Keep the reason visible in the commit, PR, bead, or test note.
126- Regenerate the smallest fixture set that proves the change.
127- Reject blanket "update all snapshots" churn unless the underlying behavior is
128 intentionally global.
129- Rerun the read-only test after update mode and confirm the working tree has
130 only intended artifact changes.
131- If a golden changes often without product behavior changing, fix the
132 normalization or replace the golden with targeted assertions.
133
134## Review Checklist
135
136Before accepting a golden-artifact test, verify:
137
138- The artifact contract is named and belongs in a golden test.
139- The normalizer removes volatility without erasing meaningful behavior.
140- Failures produce a diff a reviewer can act on.
141- Update mode is explicit, local-only, deterministic, and documented by the test
142 failure or nearby test helper.
143- Fixture ownership is clear from paths, test names, or scenario names.
144- The changed fixtures are reviewed as product evidence, not accepted as
145 generated noise.
146
147## Output Specification
148
149When applying this skill, return a concise plan or review with these sections:
150
151- Scope: artifact type, owning test surface, and behavior under contract.
152- Artifact contract: what is intentionally frozen and what is excluded.
153- Normalization: volatile fields and how they are canonicalized.
154- Comparator and diff: command, helper, or assertion strategy.
155- Fixture ownership: where expected artifacts live and who updates them.
156- Approval workflow: read-only command, update command, and CI posture.
157- Update discipline: review requirements and limits on fixture churn.
158- Verification: commands run and residual risks.