Background
tests/test_template/test_snapshots.py normalises 40-hex SHA-pinned uses: refs before comparing against the syrupy snapshot, so routine Dependabot SHA bumps don't churn the snapshot. Today this is done by pre-transforming the data with hand-rolled recursion (_redact_pinned_shas + _redact_mapping_entry).
Since that test already uses syrupy, the redaction could instead be expressed as a syrupy matcher= on the snapshot call. syrupy already walks the structure, so the container recursion collapses to a single leaf transform:
def _redact_uses(*, data: object, path: object) -> object:
"""Redact 40-hex SHA-pinned ``uses`` refs so Dependabot bumps don't churn snapshots."""
match data:
case str() if path and path[-1][0] == "uses":
return _PINNED_USES_RE.sub(r"\g<ref>@<sha>", data)
case _:
return data
# in the test:
assert {...} == snapshot(matcher=_redact_uses)
(path is a tuple of (name, type) pairs; path[-1][0] is the current leaf's dict key / list index.)
Why not now
We have a planned overhaul of snapshot testing once AST-aware snapshots for Markdown files are ready. The matcher swap should land as part of that overhaul rather than as an isolated change, to avoid churning the snapshot infrastructure twice.
Scope
- In scope:
tests/test_template/test_snapshots.py — replace _redact_pinned_shas/_redact_mapping_entry with a syrupy matcher; regenerate the snapshot and confirm byte-identical .ambr output.
- Out of scope: the contract helpers in
tests/helpers/tooling_contracts/. They match refs by regex against raw rendered text (_is_pinned_action) with targeted failure messages — the correct tool there — and do not use syrupy.
Notes
- syrupy 5.5.3 (currently pinned) supports
matcher= plus syrupy.matchers.path_type / path_value; a custom matcher is the cleanest fit for this key-based rule.
- Trade-off accepted: a matcher couples to syrupy's
(name, type) path representation and still checks str() at the leaf, versus the current pure, independently-testable function.
Tracked from a # FIXME in tests/test_template/test_snapshots.py.
Background
tests/test_template/test_snapshots.pynormalises 40-hex SHA-pinneduses:refs before comparing against the syrupy snapshot, so routine Dependabot SHA bumps don't churn the snapshot. Today this is done by pre-transforming the data with hand-rolled recursion (_redact_pinned_shas+_redact_mapping_entry).Since that test already uses syrupy, the redaction could instead be expressed as a syrupy
matcher=on the snapshot call. syrupy already walks the structure, so the container recursion collapses to a single leaf transform:(
pathis a tuple of(name, type)pairs;path[-1][0]is the current leaf's dict key / list index.)Why not now
We have a planned overhaul of snapshot testing once AST-aware snapshots for Markdown files are ready. The matcher swap should land as part of that overhaul rather than as an isolated change, to avoid churning the snapshot infrastructure twice.
Scope
tests/test_template/test_snapshots.py— replace_redact_pinned_shas/_redact_mapping_entrywith a syrupymatcher; regenerate the snapshot and confirm byte-identical.ambroutput.tests/helpers/tooling_contracts/. They match refs by regex against raw rendered text (_is_pinned_action) with targeted failure messages — the correct tool there — and do not use syrupy.Notes
matcher=plussyrupy.matchers.path_type/path_value; a custom matcher is the cleanest fit for this key-based rule.(name, type)path representation and still checksstr()at the leaf, versus the current pure, independently-testable function.Tracked from a
# FIXMEintests/test_template/test_snapshots.py.