Skip to content

Add --stale to skip the contract wasm prebuild in sandbox recipes#525

Merged
peer2f00l merged 2 commits into
devfrom
chore/test-sandbox-stale-flag
Jul 23, 2026
Merged

Add --stale to skip the contract wasm prebuild in sandbox recipes#525
peer2f00l merged 2 commits into
devfrom
chore/test-sandbox-stale-flag

Conversation

@peer2f00l

@peer2f00l peer2f00l commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

just test-sandbox rebuilds all fourteen contract wasms on every run, which is pure overhead when you are iterating on non-contract code. --stale reuses whatever is already in target/near:

just test-sandbox --stale -p templar-market-contract
just test --stale
just sandbox-up --stale

How it works

No new environment variable. TEST_CONTRACTS_PREBUILT already means "the prebuilt wasms are in target/near" — it is what sandbox-up.sh exports so gateway/testing/src/wasm.rs reads artifacts instead of building them in-test. --stale just sets it on the way in, and sandbox-up.sh's job becomes: establish that invariant (build), or verify it when the caller asserts it already holds.

Verification is a new prebuild-test-contracts --check mode: it stats every ArtifactId::ALL entry's target/near path and reports the missing ones, so a --stale run with incomplete artifacts fails immediately instead of panicking mid-test after the ~30s node boot. The script echoes when it takes the verify path, so an ambient TEST_CONTRACTS_PREBUILT=1 in someone's shell is visible rather than a silent behavior change.

Also drops dead code in script/prebuild-test-contracts.sh: a sourced-vs-executed guard and a trailing export that nothing could observe (no caller sources that script).

Verification

  • just test-sandbox --stale -p templar-registry-contract — no builds, 3/3 pass
  • with target/near/mock_ft moved aside: exits 1 before node boot, naming the missing path
  • just test-sandbox -p templar-registry-contract --test-threads 2 — unchanged, still prebuilds, 2 nodes, 3/3 pass
  • just sandbox-up --stale boots the pool with no rebuild; just sandbox-up --bogus exits 2
  • cargo fmt, cargo clippy -p templar-contract-artifacts --features workspace-loader,clap --tests -- -D warnings clean, 38/38 crate tests pass

🤖 Generated with Claude Code


This change is Reviewable

`just test-sandbox --stale` (also accepted by `just test` and `just
sandbox-up`) reuses the wasms already in `target/near` instead of
rebuilding all fourteen of them on every run.

The flag sets `TEST_CONTRACTS_PREBUILT` on the way in, so no second
variable is needed: `sandbox-up.sh` now either establishes that invariant
by building, or verifies it with a new `prebuild-test-contracts --check`
mode that reports missing artifacts and fails before booting any nodes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5da12b42-7358-497c-80f2-73ab95c84b02

📥 Commits

Reviewing files that changed from the base of the PR and between 37771c1 and 8401aaa.

📒 Files selected for processing (1)
  • contract/artifacts/src/prebuild.rs

📝 Walkthrough

Summary

  • Adds --stale support to just test-sandbox, just test, and just sandbox-up to reuse prebuilt contract Wasm artifacts in target/near instead of rebuilding.
  • Introduces prebuild-test-contracts --check: a preflight mode that verifies each expected selected artifact exists as a regular file (path.is_file()) and fails fast before node startup when missing/invalid.
  • Updates script/sandbox-up.sh to:
    • run prebuild-test-contracts.sh --check when TEST_CONTRACTS_PREBUILT is set (printing an error and exiting non-zero with guidance to unset it on failure),
    • otherwise run the normal prebuild/build path.
  • Keeps normal (non-stale) behavior rebuilding artifacts; also simplifies script/prebuild-test-contracts.sh argument forwarding ("$@" always passed through) and removes redundant env/export logic.
  • Updates docs/CLI help to reflect the new --stale and --check behaviors and clarifies artifact CLI --artifact comma-separated input.

Human review focus

  • Confirm --stale is propagated correctly through all relevant justfile entrypoints (test, test-sandbox, and sandbox-up) and that only intended flags are accepted for sandbox-up.
  • Verify the stale preflight ordering: sandbox-up.sh must fail before starting neard nodes if required Wasms are missing or not regular files.
  • Check prebuild-test-contracts --check coverage/selection logic: it derives the expected target/near paths from Cargo metadata and the selected --artifact set (or all artifacts when not specified).
  • Review the TEST_CONTRACTS_PREBUILT lifecycle: ensure the “on failure, instruct to unset” behavior in sandbox-up.sh aligns with how just exports it for stale runs.
  • Skim docs for consistency with actual behavior (especially the --artifact delimiter and the “verify only, don’t build” promise of --check).

Walkthrough

Changes

Prebuilt contract workflow

Layer / File(s) Summary
Artifact check mode
contract/artifacts/src/prebuild.rs, contract/artifacts/src/prebuild/tests/args.rs, contract/artifacts/README.md
Adds --check parsing and verification of expected Wasms under target/near, with CLI coverage and updated usage documentation.
Stale sandbox orchestration
justfile, script/prebuild-test-contracts.sh, script/sandbox-up.sh, AGENTS.md, docs/src/testing.md
Routes --stale runs through prebuilt-artifact verification, preserves normal builds otherwise, and documents the updated test workflow.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Justfile
  participant sandbox_up
  participant prebuild_script
  participant prebuild_cli
  Justfile->>sandbox_up: Set TEST_CONTRACTS_PREBUILT for --stale
  sandbox_up->>prebuild_script: Invoke with --check
  prebuild_script->>prebuild_cli: Forward --check
  prebuild_cli->>prebuild_cli: Verify expected target/near Wasms
  prebuild_cli-->>sandbox_up: Return success or failure
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/test-sandbox-stale-flag

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • LINEAR integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@contract/artifacts/src/prebuild.rs`:
- Around line 69-92: Add unit tests targeting check_all that cover every
artifact existing, one artifact missing, and an artifact path that exists but is
not a file. Use temporary workspace/target fixtures and the existing artifact
metadata/path helpers, assert the corresponding Result, and run the narrowest
templar-contract-artifacts test command.
- Around line 69-92: Update check_all to validate each computed artifact path
with is_file() instead of exists(), so directories and other non-regular paths
are rejected. Revise the missing prebuilt artifact diagnostic to state that the
expected path is absent or not a regular file, while preserving the existing
missing flag and preflight failure behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 801f3513-94cb-427a-90ce-57b487094fd4

📥 Commits

Reviewing files that changed from the base of the PR and between 8bca6af and 37771c1.

📒 Files selected for processing (8)
  • AGENTS.md
  • contract/artifacts/README.md
  • contract/artifacts/src/prebuild.rs
  • contract/artifacts/src/prebuild/tests/args.rs
  • docs/src/testing.md
  • justfile
  • script/prebuild-test-contracts.sh
  • script/sandbox-up.sh

Comment thread contract/artifacts/src/prebuild.rs
`Path::exists()` is also true for a directory, which would pass the
stale-mode preflight and only fail later when the harness tried to load
it. `is_file()` fails fast instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@peer2f00l
peer2f00l merged commit 92d0c33 into dev Jul 23, 2026
15 of 17 checks passed
@peer2f00l
peer2f00l deleted the chore/test-sandbox-stale-flag branch July 23, 2026 18:33
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