Skip to content

chore: migrate rust/guards to icp-cli#1396

Merged
raymondk merged 14 commits into
masterfrom
chore/migrate-rust-guards-to-icp-cli
Jun 19, 2026
Merged

chore: migrate rust/guards to icp-cli#1396
raymondk merged 14 commits into
masterfrom
chore/migrate-rust-guards-to-icp-cli

Conversation

@marc0olo

@marc0olo marc0olo commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

Migrates rust/guards from dfx to icp-cli.

Removed: dfx.json, BUILD.md, guards.did, .devcontainer/

Changed:

  • Rust source moved from src/lib.rs to backend/lib.rs with a workspace Cargo.toml at root
  • Management canister usage updated from removed ic_cdk::api::management_canister to ic-cdk-management-canister = "0.1.1"

Added:

  • icp.yaml with @dfinity/rust@v3.3.0 recipe
  • test.sh with 5 tests covering guard/async behavior (TrueAsyncCall vs FalseAsyncCall, state reset) via icp-cli — demonstrates the icp-cli workflow
  • backend/tests/tests.rs — PocketIC integration tests (updated from the original tests/ to pocket-ic 14.0.0 API) covering the same scenarios plus parallel processing prevention, which requires PocketIC's submit_call/await_call to test concurrent calls
  • CI workflow .github/workflows/guards.yml running both bash test.sh and cargo test

Test plan

  • icp network start -d && icp deploy && bash test.sh passes locally
  • cargo build --package backend --target wasm32-unknown-unknown --release && cargo test --package backend passes locally (requires PocketIC server)
  • CI workflow passes

🤖 Generated with Claude Code

@marc0olo marc0olo force-pushed the chore/migrate-rust-guards-to-icp-cli branch 2 times, most recently from fa92d10 to b4d4ceb Compare June 18, 2026 16:58
@marc0olo marc0olo marked this pull request as ready for review June 19, 2026 06:28
@marc0olo marc0olo requested review from a team as code owners June 19, 2026 06:28
@marc0olo marc0olo requested a review from Copilot June 19, 2026 06:28

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Migrates the rust/guards example from dfx to icp-cli, restructuring it into the repo’s newer Rust example layout and updating dependencies to current ic-cdk conventions.

Changes:

  • Replaced dfx.json/PocketIC integration tests with icp.yaml + a bash-based test.sh flow.
  • Restructured the Rust canister into a workspace with backend/ (and updated management canister usage to ic-cdk-management-canister).
  • Added a dedicated CI workflow for rust/guards using the standard ICP dev env container.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
rust/guards/tests/tests.rs Removed PocketIC-based integration tests.
rust/guards/test.sh Added icp-cli-driven integration tests for guard + async behavior.
rust/guards/rust-toolchain.toml Simplified toolchain configuration (targets only).
rust/guards/README.md Updated docs to icp-cli commands and refreshed links/content.
rust/guards/icp.yaml Added icp-cli project definition for the backend canister.
rust/guards/guards.did Removed dfx-era candid file.
rust/guards/dfx.json Removed dfx project configuration.
rust/guards/Cargo.toml Converted to a workspace root manifest.
rust/guards/Cargo.lock Updated lockfile for the new workspace + dependency set.
rust/guards/BUILD.md Removed ICP Ninja/dfx migration doc.
rust/guards/backend/lib.rs Updated raw_rand call to ic-cdk-management-canister and added export_candid!().
rust/guards/backend/Cargo.toml Added backend crate manifest with updated dependencies.
rust/guards/.devcontainer/devcontainer.json Removed per-example devcontainer config.
.github/workflows/guards.yml Added CI workflow that deploys and runs test.sh.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread rust/guards/test.sh Outdated
Comment thread rust/guards/test.sh Outdated
Comment thread rust/guards/test.sh Outdated
Comment thread rust/guards/test.sh Outdated
Comment thread rust/guards/README.md
Comment thread rust/guards/test.sh
marc0olo and others added 9 commits June 19, 2026 08:32
Replace dfx.json with icp.yaml using @dfinity/rust@v3.3.0, restructure
source into backend/ subdirectory, update management canister usage to
ic-cdk-management-canister, add Makefile with guard behavior tests, and
add CI workflow.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Transitive dependencies pulled in by ic-cdk 0.20 require edition2024
support (stabilized in Rust 1.85). Removing the 1.78 pin lets rustup
use the current stable toolchain.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Required for the icp-cli recipe to extract the Candid interface from
the compiled WASM via get_candid_pointer.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ster calls

The panicking calls return a non-zero exit code (canister rejection).
In the old script, 'A && B; C' meant if B failed, set -e exited before
C ran — so the assertion after the panic was never checked.

Fix: split setup and panicking call onto separate lines, add '|| true'
to the panicking call to explicitly allow failure. The setup call still
uses '&&' so it fails loudly if the state reset itself fails.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lock

- Restore #inter-canister-calls-and-rollbacks and
  #securely-handle-traps-in-callbacks fragment identifiers that were
  dropped during migration
- Remove redundant networks block from icp.yaml (managed mode is default)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The old URL now redirects to the inter-canister calls page.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@marc0olo marc0olo force-pushed the chore/migrate-rust-guards-to-icp-cli branch from 32ac3ee to 41cb6ce Compare June 19, 2026 06:34
marc0olo and others added 4 commits June 19, 2026 09:10
- Restore backend/tests/tests.rs with pocket-ic 14.0.0 API (updated from
  original v5 — WasmResult/UserError replaced by direct Vec<u8>/RejectResponse)
- Covers all original scenarios including parallel processing prevention
  (submit_call/await_call for concurrent calls — not expressible in bash)
- Fix remaining building-apps/ doc links to guides/security/inter-canister-calls
- README explains both test approaches and how to run PocketIC tests locally
- CI downloads pocket-ic server via gh release download (authenticated, no
  rate limit risk) and runs cargo test as a separate step

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Capture stderr from expected-panicking calls and verify it contains
'panicking callback!' — same check the PocketIC tests perform.

Extracted into assert_traps() helper to avoid repetition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
gh CLI is not available in the icp-dev-env-rust container.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 14 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

rust/guards/backend/tests/tests.rs:13

  • FutureType is passed to candid::Encode!() in several calls below, but it only derives CandidType. Encode! requires the values to implement serde::Serialize, so this enum should also derive Serialize (and import it) to avoid a compile error in the integration tests.

@gregorydemay gregorydemay 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.

Thanks @marc0olo !

Comment thread .github/workflows/guards.yml Outdated
Replaces manual curl download with the official dfinity/pocketic composite
action — handles OS/arch detection, rate-limit-safe, sets POCKET_IC_BIN
automatically.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@raymondk raymondk merged commit b36cce0 into master Jun 19, 2026
6 checks passed
@raymondk raymondk deleted the chore/migrate-rust-guards-to-icp-cli branch June 19, 2026 20:41
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.

4 participants