Skip to content

feat(pic): support canister snapshots - #310

Merged
marc0olo merged 5 commits into
mainfrom
feat/canister-snapshots
Sep 29, 2026
Merged

marc0olo merged 5 commits into
mainfrom
feat/canister-snapshots

Conversation

@marc0olo

@marc0olo marc0olo commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #299

Adds canister snapshot support:

  • takeCanisterSnapshot (with replaceSnapshot and uninstallCode), loadCanisterSnapshot, listCanisterSnapshots and deleteCanisterSnapshot, which call the management canister.
  • downloadCanisterSnapshot and uploadCanisterSnapshot, which use the PocketIC server's canister_snapshot_download/canister_snapshot_upload endpoints. snapshotDir is a path on the machine running the server, as in the Rust library.

sender defaults to the anonymous principal, as in canisterStatus. It must be a controller of the canister, except that listing and downloading are also allowed for principals that the canister's snapshotVisibility permits.

The test canister gains set_value/get_value. The tests check that state is restored, that a snapshot round-trips from one canister to another through download and upload, and that snapshotVisibility viewers can list and download but not delete.

Adds a canister snapshots guide. I checked by hand that snapshots round-trip between icp-cli 1.5.0 and PocketIC 16 in both directions: an icp canister snapshot download from a local network uploads and loads through PicJS, and a downloadCanisterSnapshot output uploads through icp canister snapshot upload.

🤖 Generated with Claude Code

Adds takeCanisterSnapshot, loadCanisterSnapshot, listCanisterSnapshots
and deleteCanisterSnapshot, and downloadCanisterSnapshot and
uploadCanisterSnapshot to transfer a snapshot through a directory on the
machine running the PocketIC server, as in the Rust library.
@marc0olo
marc0olo requested a review from a team as a code owner September 28, 2026 11:21
Copilot AI lite review requested due to automatic review settings September 28, 2026 11:21

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Rebuild and commit the test WASM artifact containing the new methods.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Adds canister snapshot management and download/upload support to PocketIC.

Changes:

  • Adds snapshot lifecycle APIs and types.
  • Implements Candid handling and transfer endpoints.
  • Extends the test canister and integration tests.

Blocking finding: The committed test_canister.wasm.gz lacks the new set_value and get_value methods, so snapshot tests will fail. Rebuild and commit the artifact.

File Summary
packages/​pic/​tests/​test-canister/​test_canister.did Updated test-canister interface
packages/​pic/​tests/​test-canister/​main.mo Added state helper methods
packages/​pic/​tests/​test-canister/​declarations/​test_canister.did.js Updated JavaScript declarations
packages/​pic/​tests/​test-canister/​declarations/​test_canister.did.d.ts Updated TypeScript declarations
packages/​pic/​tests/​src/​canister-snapshots.spec.ts Added snapshot integration tests
packages/​pic/​src/​util/​candid.ts Added snapshot conversion logic
packages/​pic/​src/​pocket-ic.ts Added public snapshot APIs
packages/​pic/​src/​pocket-ic-types.ts Added snapshot types and options
packages/​pic/​src/​pocket-ic-client.ts Added transfer endpoint calls
packages/​pic/​src/​pocket-ic-client-types.ts Added transfer request and response types
packages/​pic/​src/​management-canister.ts Added snapshot Candid support

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/pic/tests/test-canister/main.mo

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

The guide incorrectly states that every snapshot operation requires controller authorization.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (1)

Comment thread docs/src/content/docs/guides/canister-snapshots.mdx Outdated

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Public API documentation is inaccurate and the upload replacement path lacks test coverage.

Review effort: Balanced
Findings: None

Resolved since last review (1)
Previously missed (2)

In code that hasn't changed since last review

Medium severity Add test coverage for upload snapshot replacement

packages/​pic/​src/​pocket-ic.ts:897

The new replaceSnapshot branch for uploads is not exercised by the snapshot suite: the only upload call omits it, while replacement is tested only for takeCanisterSnapshot. Add an upload-replacement case that passes an existing snapshot ID and verifies the old snapshot is replaced, so the distinct REST encoding and server behavior are covered.

Low severity Correct snapshot documentation to exclude canister settings

packages/​pic/​src/​pocket-ic.ts:748

Canister snapshots do not capture canister settings; loading one restores execution state while the target canister's settings remain in place. Describing settings as snapshot contents makes the public API documentation misleading and also conflicts with the guide's concrete contents list. Please limit this description to code and execution state/memory.

Copilot AI 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.

Copilot review overview

🟢 Approval recommended

The APIs, codecs, tests, generated artifacts, authorization behavior, and documentation form a consistent implementation with no unresolved issues.

Review effort: Balanced
Findings: None

@marc0olo
marc0olo added this pull request to the merge queue Sep 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Sep 29, 2026
# Conflicts:
#	packages/pic/src/util/candid.ts
#	packages/pic/tests/test-canister/declarations/test_canister.did.d.ts
#	packages/pic/tests/test-canister/declarations/test_canister.did.js
#	packages/pic/tests/test-canister/test_canister.wasm.gz
@marc0olo
marc0olo enabled auto-merge September 29, 2026 09:01
@marc0olo
marc0olo added this pull request to the merge queue Sep 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 29, 2026
@marc0olo
marc0olo added this pull request to the merge queue Sep 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 29, 2026
@marc0olo
marc0olo added this pull request to the merge queue Sep 29, 2026
Merged via the queue into main with commit bc6b5cd Sep 29, 2026
23 of 24 checks passed
@marc0olo
marc0olo deleted the feat/canister-snapshots branch September 29, 2026 09:29
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.

Support canister snapshots

3 participants