test(core): golden hash determinism guard across languages and versions#132
Merged
Connorrmcd6 merged 2 commits intoJun 15, 2026
Merged
Conversation
…ns (#4) * test(core): golden hash determinism guard across languages and versions The stored anchor hash is the only value every consumer compares against, yet nothing pinned its exact output. A tree-sitter grammar bump (the grammars are caret-pinned and only frozen by Cargo.lock, which Dependabot bumps) can rename a node kind and silently change every stored hash — a wave of false DIVERGED downstream, or worse, new collisions — with green CI. Add goldens for Rust/TS/TSX/Python/Go plus invariants: cosmetic edits (reformatting, consistent rename) keep the hash; logic edits (operator flip, swapped operands) move it. Runs on Linux and macOS in CI, so it also catches cross-platform drift between the release target triples. https://claude.ai/code/session_01T3Z35bgg6cvWzBDfyh6pQ8 * style: rustfmt golden_hash test (cherry picked from commit 7bb7a59)
Connorrmcd6
requested changes
Jun 15, 2026
Connorrmcd6
left a comment
Owner
There was a problem hiding this comment.
Great catch on the golden hash pinning, I didn't think of that! One minor change just to keep things tidy: could you drop cosmetic_edits_do_not_change_the_hash since it duplicates rust_quiet_on_reformat_and_rename (surf-core/tests/hash.rs:126)?
The cosmetic_edits_do_not_change_the_hash test re-verified Rust hash invariance under reformatting and consistent rename, which rust_quiet_on_reformat_and_rename (surf-core/tests/hash.rs:126) already covers. Per upstream review feedback, remove the duplicate; the unique value of golden_hash.rs is the pinned per-language hash values. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Thanks! Dropped |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Severity: MEDIUM — hash/normalization determinism
The stored anchor hash is the single value every Surface consumer compares against, yet no
test pins its exact output. The canonical token stream can change for an unchanged symbol
without anyone touching
hash.rs:caret-pinned in
Cargo.toml(tree-sitter-rust = "0.24.2"⇒^0.24.2) and only frozen byCargo.lock, which Dependabot bumps on a schedule;tree-sittercore bump changes traversal;Any of these silently re-hashes every anchored span in every downstream repo: a wave of false
DIVERGED, or — worse — two spans that should differ start colliding. CI stays green becausenothing asserts the hash value.
What this adds
surf-core/tests/golden_hash.rs, public-API only:Python, Go). Snippets include comments + non-canonical whitespace, so the goldens also
encode the "formatting/comments ignored" guarantee.
b - adoes not collide with
a - b.Because CI already runs the suite on
ubuntu-latestandmacos-14, this doubles as across-platform drift guard between the three release target triples — directly addressing
"is the stored hash stable across target triples / rust-version / grammar bumps?".
A failure here is the intended signal: the canonical form moved. The fix is to revert the
bump, or to ship the change deliberately (update CHANGELOG, treat as a hash-format break, tell
consumers to re-verify).
Verified:
cargo test -p surf-core --test golden_hash→ 3 passed.Applies equally upstream (Connorrmcd6/surface).
🤖 Generated with Claude Code