Skip to content

docs: normalize governance test snapshot layout and add drift check - #647

Open
Rafiat30 wants to merge 2 commits into
Betta-Pay:mainfrom
Rafiat30:docs/normalize-test-snapshots
Open

docs: normalize governance test snapshot layout and add drift check#647
Rafiat30 wants to merge 2 commits into
Betta-Pay:mainfrom
Rafiat30:docs/normalize-test-snapshots

Conversation

@Rafiat30

Copy link
Copy Markdown

Closes #533

Summary

Governance's test_snapshots directory had a convoluted, inconsistent layout: anchor_removal_tests.rs wrapped its two tests in a redundant mod tests { } block even though it's declared as its own top-level module (mod anchor_removal_tests; in lib.rs) — unlike its sibling test files (anchor_auth_tests.rs, anchor_event_tests.rs, anchor_no_event_error_tests.rs), none of which have that extra wrapper. Soroban's Env test harness names each snapshot file after the test's full module path, so that stray wrapper produced a nested path (test_snapshots/anchor_removal_tests/tests/*.json) instead of the flat one every sibling module uses (test_snapshots/anchor_removal_tests/*.json).

CONTRIBUTING.md also only documented the single flat test_snapshots/tests/ case, which doesn't match the two other legitimate shapes that already exist in this workspace (per-file top-level modules in governance_contract, and the nested tests::<submodule> shape from settlement_contract's src/tests/ directory) — so the docs actively pointed contributors at the wrong path.

Changes

Modified files

  • governance_contract/src/anchor_removal_tests.rs — removed the redundant inner mod tests { } wrapper (functions are now direct members of the anchor_removal_tests module, matching every sibling test file); switched use crate::*; to use super::*; to match sibling import style.
  • CONTRIBUTING.md — rewrote the "Test snapshots" section to document all three snapshot-path shapes that occur in this workspace (flat root tests module, per-file top-level test modules, and nested tests::<submodule> groups) and when each applies; updated the "CI parity" section to mention the new snapshot drift check.
  • Makefile — added a check_snapshots target wired into make all. Also fixed a pre-existing duplicate-target bug: a second fmt/all recipe block later in the file was silently overriding the first (Make uses the last definition), which meant make all was actually only running fmt check clippy testtest_scripts and wasm_size had been silently dropped despite CONTRIBUTING.md documenting both as part of it.

New files

  • scripts/check_test_snapshots.sh — re-runs cargo test --workspace (which is how Soroban's test harness (re)writes snapshot files) and then fails with a diff summary if that leaves anything under */test_snapshots/ modified, added, or removed relative to the committed state. Follows the existing pattern in scripts/check_wasm_size.sh (sources scripts/lib/common.sh for logging helpers).

Test files

  • governance_contract/test_snapshots/anchor_removal_tests/anchor_removal_clears_entry.1.json and .../rejects_removing_unregistered_anchor.1.json — regenerated at the corrected, flat path (git recognizes these as renames from the old nested .../tests/ location).

No production contract logic changed — this is a test-infrastructure and documentation normalization only.

Implementation details

  • The snapshot path is entirely a function of the Rust module path of the #[test] function; there's no snapshot-naming config to change. Fixing the layout meant fixing the module structure (removing the stray mod tests wrapper) and letting the test harness regenerate the file at the now-correct path.
  • check_test_snapshots.sh intentionally re-runs the full suite rather than trying to infer staleness some other way — that's the same mechanism that produces the files in the first place, so it's the only reliable way to detect drift.

Tests added

No new contract test cases were needed (this issue is about test plumbing, not contract behavior) — the two existing tests in anchor_removal_tests.rs are unchanged in behavior, only in module structure. Coverage added:

  • scripts/check_test_snapshots.sh itself is the "test" for this issue: it fails the build if test_snapshots/ ever drifts from committed state again (e.g. if someone reintroduces a stray mod tests wrapper, or forgets to commit a regenerated snapshot after an intentional behavior change).

How to test

# Build WASM once (governance_contract's tests embed it via include_bytes!)
cargo build --target wasm32-unknown-unknown --release

# Full workspace suite — should be green, including the two
# anchor_removal_tests under their new flat path
cargo test --workspace

# The new snapshot drift check (also runs as part of `make all`)
make check_snapshots
# or directly:
bash scripts/check_test_snapshots.sh

# Confirm the old nested directory is gone and the new flat layout exists
find governance_contract/test_snapshots/anchor_removal_tests -type f

anchor_removal_tests.rs wrapped its tests in a redundant `mod tests { }`
block even though it's already declared as its own top-level module
(`mod anchor_removal_tests;` in lib.rs), unlike its sibling test files
(anchor_auth_tests.rs, anchor_event_tests.rs,
anchor_no_event_error_tests.rs). That produced a convoluted nested
snapshot path (test_snapshots/anchor_removal_tests/tests/*.json) instead
of the flat one every sibling module uses
(test_snapshots/anchor_removal_tests/*.json), and CONTRIBUTING.md only
documented the single flat-`tests/` case, not the per-file-module or
nested-submodule shapes that actually exist in the workspace.

- Remove the redundant `mod tests` wrapper from anchor_removal_tests.rs
  and align its imports with its sibling test files.
- Regenerate the governance snapshot files at the corrected, flat path.
- Rewrite CONTRIBUTING.md's "Test snapshots" section to document all
  three snapshot-path shapes that occur in this workspace and when each
  applies.
- Add scripts/check_test_snapshots.sh, which re-runs the workspace test
  suite and fails if that leaves test_snapshots/ dirty, and wire it into
  `make all` as a new `check_snapshots` target so drift is caught in CI.
- Fix a pre-existing duplicate-target bug in the Makefile where a second
  `all:` recipe silently overrode the first, dropping `test_scripts` and
  `wasm_size` from `make all` despite CONTRIBUTING.md documenting both
  as part of it.

Closes Betta-Pay#533
@drips-wave

drips-wave Bot commented Aug 26, 2026

Copy link
Copy Markdown

@Rafiat30 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Test snapshots directory structure is inconsistent

2 participants