test(audit): expand buzz-audit unit test coverage (12 → 32) - #3466
Closed
jewoos2921 wants to merge 1 commit into
Closed
test(audit): expand buzz-audit unit test coverage (12 → 32)#3466jewoos2921 wants to merge 1 commit into
jewoos2921 wants to merge 1 commit into
Conversation
The audit crate's core chain logic (hash computation, canonical JSON, action serialization, timestamp precision) had thin unit test coverage — most existing service tests require Postgres and are #[ignore]'d. Add 20 new DB-free unit tests covering: hash.rs (12 new): - canonical_json: nested key sorting recursion, array order preservation, empty/scalar values, special-character escaping with round-trip - compute_hash: object_id presence-tag, detail None-vs-empty, detail key-order invariance, detail value sensitivity, created_at sensitivity, sub-microsecond jitter invariance, genesis hash sentinel properties action.rs (4 new): - serde JSON roundtrip for all variants - serde snake_case agrees with as_str() - as_str values are unique (no ambiguous DB strings) - as_str/FromStr are exact inverses service.rs (3 new): - log_timestamp is idempotent under re-truncation - advisory lock key format is namespaced + community-scoped - different communities produce different lock keys All 32 runnable tests pass; clippy clean; fmt clean.
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.
Summary
The audit crate's core chain logic had thin unit test coverage — most existing
service.rstests require Postgres and are#[ignore]'d, leaving the hash-chain integrity logic under-tested injust test-unit.This PR adds 20 new DB-free unit tests, bringing runnable coverage from 12 → 32 tests.
What's covered
hash.rs(+12 tests)canonical_jsondepth:{},[],null, scalars)compute_hashedge cases:object_idpresence tag (NonevsSome("")— the same invariantactor_pubkeyhas)detailNone-vs-empty-object distinctiondetailkey-order invariance (canonical JSON working as designed)detailvalue sensitivitycreated_atfield sensitivity (1µs shift changes hash)to_storage_precision)GENESIS_HASHis all-zero sentinelprev_hash = Nonehashes identically toprev_hash = Some(GENESIS_HASH)action.rs(+4 tests)snake_caseagrees withas_str()(catches variant drift)as_str()values are unique (no ambiguous DB strings)as_str()/FromStrare exact inversesservice.rs(+3 tests)log_timestampis idempotent under re-truncation (write/read preimage safety)Verification
cargo test -p buzz-audit --lib— 32 passed, 6 ignored (Postgres), 0 failedcargo clippy -p buzz-audit -- -D warnings— cleancargo fmt --check -p buzz-audit— clean