From 5a59755437a108a62c8f84ea10146d1b9c90db08 Mon Sep 17 00:00:00 2001 From: Nife-tanny Date: Thu, 27 Aug 2026 22:58:33 +0100 Subject: [PATCH] test: remove non-enforcing snapshot drift CI step The 'Snapshot drift detection' CI step was a no-op: it only printed advice when .snap fixtures existed, but never failed on drift, and it did not even fire because contracts/test_snapshots/ does not exist and is gitignored. No snapshot-golden mechanism exists in the Rust tests (SNAPSHOT_UPDATE is never read by any code), so there is no baseline to commit and no way to ever produce one that survives a commit. Remove the dead step and the orphaned tooling/docs that only existed to support it (scripts/update_snapshots.sh, the CONTRIBUTING/README/PR template snapshot sections). A maintainer who wants real snapshot testing can build a proper harness (e.g. insta) later, but as-is this step misled contributors into thinking drift was being caught. Closes #415 --- .github/PULL_REQUEST_TEMPLATE.md | 4 -- .github/workflows/ci.yml | 14 ------- CONTRIBUTING.md | 27 -------------- README.md | 8 ++-- scripts/update_snapshots.sh | 63 -------------------------------- 5 files changed, 3 insertions(+), 113 deletions(-) delete mode 100755 scripts/update_snapshots.sh diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6274dfea..05bdd756 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -72,7 +72,3 @@ *If yes, note details:* > [Provide details here] -## Snapshot policy - -- [ ] If snapshot files under `contracts/test_snapshots/` changed, I reviewed the diff and confirmed every change is intentional -- [ ] If snapshot drift was reported in CI, I either regenerated snapshots or marked the drift as expected in the PR description diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2ef4eb7..c909051a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,20 +56,6 @@ jobs: - name: Benchmark report (cost/gas regression guardrails) run: cargo test --package xelma-contract cost_benchmarks --locked -- --nocapture - - name: Snapshot drift detection - run: | - if [ -d "contracts/test_snapshots" ] && ls contracts/test_snapshots/*.snap 1>/dev/null 2>&1; then - echo "--- Snapshot drift check ---" - echo "Snapshot golden files exist. To regenerate intentionally:" - echo " ./scripts/update_snapshots.sh" - echo "" - echo "If you did not intend to change snapshots, check for accidental" - echo "storage or event mutations in your branch." - echo "---" - else - echo "No snapshot golden files to check." - fi - - name: Run cargo clippy run: cargo clippy --workspace --all-targets --locked -- -D warnings diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2dee224b..5d5f2290 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -110,33 +110,6 @@ cd Xelma-Blockchain pip install pre-commit pre-commit install ``` -## Snapshot Tests - -The project uses storage-snapshot golden files (`contracts/test_snapshots/`) to detect -unintentional changes to contract state, event emissions, and error behavior. - -### When snapshots should change - -- You modified contract logic, storage keys, event payloads, or error variants. -- You made non-semantic refactors that still cause snapshot output to differ (rare). - -### When snapshots should NOT change - -- Your change is in an unrelated module, test infrastructure, or documentation. -- CI reports snapshot drift that you did not intend — investigate before regenerating. - -### Updating snapshots - -After an intentional behavior change, regenerate golden files from the repo root: - -```bash -./scripts/update_snapshots.sh -``` - -Then review the diff, run the full suite, and commit the updated snapshots alongside -your logic change. See [`contracts/test_snapshots/README.md`](./contracts/test_snapshots/README.md) -for a step-by-step guide. - ## Security Checks (local) The CI `security-audit` job runs two checks that maintainers and contributors can reproduce locally. diff --git a/README.md b/README.md index 9e25536c..85b46280 100644 --- a/README.md +++ b/README.md @@ -235,8 +235,7 @@ Xelma-Blockchain/ │ │ ├── ttl_tests.rs │ │ └── windows.rs │ │ └── ... (20+ test files total — see docs/CONTRIBUTOR_MAP.md) -│ ├── Cargo.toml # Rust dependencies -│ └── test_snapshots/ # Test execution records +│ └── Cargo.toml # Rust dependencies │ ├── bindings/ # TypeScript bindings (auto-generated) │ ├── src/ @@ -770,7 +769,6 @@ This repository contains both source files and generated artifacts. Understandin - **`target/`** - Rust build outputs (WASM binaries, compiled Rust) - **`bindings/dist/`** - Compiled TypeScript output (JavaScript + type definitions) - **`node_modules/`** - npm dependencies -- **`contracts/test_snapshots/`** - Test execution records (generated during tests) - **`contracts/proptest-regressions/`** - Property test regression files (generated during tests) - **`.soroban/`** - Soroban CLI artifacts @@ -806,14 +804,14 @@ cd ../contracts cargo test ``` -> **Note:** Test snapshots and proptest regressions are automatically generated when running tests. These files help ensure test consistency but should not be committed. +> **Note:** Proptest regression files are automatically generated when running tests. These files help ensure test consistency but should not be committed. #### Before Submitting a PR: 1. **Verify no build artifacts are staged:** ```bash git status - # Ensure target/, bindings/dist/, node_modules/, test_snapshots/, proptest-regressions/ are not listed + # Ensure target/, bindings/dist/, node_modules/, proptest-regressions/ are not listed ``` 2. **If you modified the contract**, regenerate bindings: diff --git a/scripts/update_snapshots.sh b/scripts/update_snapshots.sh deleted file mode 100755 index 871c9289..00000000 --- a/scripts/update_snapshots.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -# -# update_snapshots.sh — Regenerate snapshot golden files deterministically. -# -# Usage: -# ./scripts/update_snapshots.sh -# -# This script: -# 1. Sets SNAPSHOT_UPDATE=1 so snapshot tests overwrite golden files. -# 2. Runs snapshot-related tests under contracts/. -# 3. Reports which files changed. -# -# Run from the repository root. - -set -euo pipefail - -SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" - -SNAPSHOT_DIR="$REPO_ROOT/contracts/test_snapshots" - -echo "============================================" -echo " Snapshot Golden Update" -echo "============================================" -echo "" - -# Ensure the snapshot directory exists -mkdir -p "$SNAPSHOT_DIR" - -# Record current snapshot hashes before regeneration -echo "[1/3] Recording current snapshot state …" -PRE_HASH="" -if ls "$SNAPSHOT_DIR"/*.snap 1>/dev/null 2>&1; then - PRE_HASH=$(sha256sum "$SNAPSHOT_DIR"/*.snap | sort) -fi - -# Run snapshot tests with update mode enabled -echo "[2/3] Regenerating snapshots …" -SNAPSHOT_UPDATE=1 \ - cargo test --package xelma-contract --locked -- --nocapture \ - 2>&1 | tail -20 - -# Report what changed -echo "" -echo "[3/3] Checking for changes …" -POST_HASH="" -if ls "$SNAPSHOT_DIR"/*.snap 1>/dev/null 2>&1; then - POST_HASH=$(sha256sum "$SNAPSHOT_DIR"/*.snap | sort) -fi - -if [[ "$PRE_HASH" != "$POST_HASH" ]]; then - echo " Snapshot files updated:" - (diff <(echo "$PRE_HASH") <(echo "$POST_HASH") 2>/dev/null || true) | grep '^[<>]' || echo " (new snapshots created)" - echo "" - echo " Review the diff with: git diff $SNAPSHOT_DIR" -else - echo " No snapshot changes detected." -fi - -echo "" -echo "============================================" -echo " Done. Run 'cargo test --workspace' to verify." -echo "============================================"