Skip to content

test: stop pinning rustledger's directive hash in snapshots - #280

Merged
robcohen merged 1 commit into
mainfrom
fix/snapshot-meta-hash-redaction
Aug 10, 2026
Merged

test: stop pinning rustledger's directive hash in snapshots#280
robcohen merged 1 commit into
mainfrom
fix/snapshot-meta-hash-redaction

Conversation

@robcohen

@robcohen robcohen commented Aug 9, 2026

Copy link
Copy Markdown
Member

The coupling

test_get_ledger_data.json pinned 62 literal SHA-256 digests. Those are rustledger's directive-identity hash — an implementation detail of a separate repo, covered by its own tests. Nothing about rustfava's behaviour is asserted by their exact values. Pinning them means every change to that hash function turns this suite red and forces a lockstep regeneration, which is exactly what rustledger#1984 just did.

The snapshot machinery already tries to normalise hashes. It missed these because both patterns require the underscore:

_hash": ?"[0-9a-f]+

That matches entry_hash and misses the bare hash key inside meta — so one hash was normalised and the other 62 leaked into the file. Anchoring on the opening quote fixes it without touching entry_hash; requiring a full-length digest keeps user metadata that happens to be called hash from being silently swallowed.

Verification

test_get_ledger_data now passes against both components, which it could not do before — they produce different digests for identical input:

pinned v0.21.0 release asset component built from rustledger main
before pass fail
after pass pass

Full suite against the pinned v0.21.0 asset: 667 passed, 1 skipped.

Sabotage-checked, so this is a normalisation and not a blanket that hides everything:

sabotage result
change a lineno in the snapshot still FAILS
short (non-digest) hash metadata value survives redaction untouched ✓
entry_hash under the new pattern unaffected ✓

What this does not fix

Three snapshots still differ against rustledger main. All three are genuine behaviour changes, not churn, and I verified each is a correctness improvement:

  • test_api_errors — a spurious interpolation failed: multiple postings missing amounts... error is gone. I ran beancount directly against that fixture: it reports 3 errors and no interpolation error, so main now matches beancount and the released component was wrong.
  • test_serialise_entry_typesnumber-value metadata "10""20". The fixture is number-value: 10 + 10, and beancount evaluates metadata arithmetic, so 20 is correct.
  • account_report_off_by_one_journal and test_serialise_entry_types101.0101, -1.0-1. Every source literal involved is an integer (1 COM {100 USD}, price 101 USD), so the trailing zero was spurious.

These cannot be fixed in this PR: their expected values genuinely differ between the pinned release and main, so any single committed value is red on one side. I confirmed that empirically — regenerating all four against main makes the same four tests fail against v0.21.0, just inverted. They belong in whichever change advances RUSTLEDGER_VERSION.

🤖 Generated with Claude Code

https://claude.ai/code/session_018bGRsKA42peqSnz4VMreBG

test_get_ledger_data.json pinned 62 literal SHA-256 digests. They are
rustledger's directive-identity hash: an implementation detail of a
separate repo, covered by its own tests, and nothing about rustfava's
behaviour is asserted by their exact values. Pinning them means every
change to that hash function turns this suite red and forces a lockstep
snapshot regeneration - which is what rustledger#1984 just did.

The redaction the snapshot machinery already performs was meant to cover
this. It did not, because both patterns require the underscore:

    _hash": ?"[0-9a-f]+

That matches entry_hash and misses the bare hash key inside meta, so one
hash was normalised and the other 62 leaked into the file.

Anchoring on the opening quote fixes it without touching entry_hash, and
requiring a full-length digest keeps user metadata that happens to be
called hash from being silently swallowed.

Verified against both components: test_get_ledger_data now passes
against the pinned v0.21.0 release asset AND against a component built
from rustledger main, which it could not do before - the two produce
different digests for identical input.

Sabotage-checked, so this is not just a blanket that hides everything:
changing a lineno in the snapshot still fails the test, a short
hash-valued metadata entry survives redaction untouched, and entry_hash
is unaffected by the new pattern.

Full suite against the pinned v0.21.0 asset: 667 passed, 1 skipped.

This does not make the whole suite green against rustledger main. Three
snapshots still differ, and all three are genuine behaviour changes on
main rather than churn, each verified correct:

  - test_api_errors: a spurious "interpolation failed" error is gone.
    beancount itself reports no such error for that fixture, so main now
    matches it and the released component was wrong.
  - test_serialise_entry_types: number-value metadata "10" became "20".
    The fixture says 10 + 10, and beancount evaluates metadata
    arithmetic, so 20 is correct.
  - account_report and test_serialise_entry_types: 101.0 became 101,
    -1.0 became -1. Every source literal involved is an integer, so the
    trailing zero was spurious.

Those three cannot be fixed here: their expected values differ between
the pinned release and main, so any single value is red on one side.
They belong in whichever change advances RUSTLEDGER_VERSION.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018bGRsKA42peqSnz4VMreBG
@robcohen
robcohen merged commit 725fa14 into main Aug 10, 2026
33 checks passed
@robcohen
robcohen deleted the fix/snapshot-meta-hash-redaction branch August 10, 2026 00:27
robcohen added a commit that referenced this pull request Aug 10, 2026
Resolves the conflict in test_get_ledger_data.json by taking main's
version. This branch's update to that file is obsolete: #280 stopped
pinning rustledger's directive hash in snapshots at all, so the 62
digests this branch was refreshing no longer appear in the file, and
that test now passes against both the pinned release asset and a
component built from rustledger main.

What remains here is the part #280 could not fix - three snapshots whose
expected values genuinely differ between the pinned component and main,
so no single committed value is green on both sides.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018bGRsKA42peqSnz4VMreBG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant