Skip to content

test(PocketIC): check canister snapshot download without dfx - #10983

Open
mraszyk wants to merge 4 commits into
masterfrom
mraszyk/snapshot-test-no-dfx
Open

test(PocketIC): check canister snapshot download without dfx#10983
mraszyk wants to merge 4 commits into
masterfrom
mraszyk/snapshot-test-no-dfx

Conversation

@mraszyk

@mraszyk mraszyk commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

The test canister_snapshots used to validate the canister snapshot downloaded by PocketIC by downloading the same snapshot using dfx and comparing the two directories. Instead, the test now asserts the expected list of files in the downloaded snapshot directory and their expected contents:

  • wasm_module.bin must match the installed test canister WASM;
  • stable_memory.bin must match the pattern written by the test canister and is absent iff the stable memory is empty;
  • the directory wasm_chunk_store/ must exist iff the wasm chunk store is not empty;
  • wasm_chunk_store/<hash>.bin must match the uploaded WASM chunks and the directory is absent iff the WASM chunk store is empty;
  • metadata.json is checked for equality except for timestamp and globals for which only certain properties are enforced;
  • the contents of wasm_memory.bin are hard to reproduce and thus only its size is checked (against the WASM memory size in the metadata).

This drops the dependency of the test on dfx and also makes the test cover the same ground on Windows, where the dfx part used to be skipped since there is no Windows build of dfx.

The test `canister_snapshots` used to validate the canister snapshot
downloaded by PocketIC by downloading the same snapshot using `dfx` and
comparing the two directories. Instead, the test now asserts the expected
list of files in the downloaded snapshot directory and their expected
contents:

- `wasm_module.bin` must match the installed test canister WASM;
- `stable_memory.bin` must match the pattern written by the test canister
  and is absent iff the stable memory is empty;
- `wasm_chunk_store/<hash>.bin` must match the uploaded WASM chunks
  and the directory is absent iff the WASM chunk store is empty;
- `metadata.json` is checked field by field after parsing it;
- the contents of `wasm_memory.bin` are hard to reproduce and thus only
  its size is checked (against the WASM memory size in the metadata).

This drops the dependency of the test on `dfx` and also makes the test
cover the same ground on Windows, where the `dfx` part used to be skipped
since there is no Windows build of `dfx`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

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.

Pull request overview

This PR updates the packages/pocket-ic canister snapshot integration test to validate snapshot contents directly (without invoking dfx), so the same checks can run on Windows as well as Unix-like platforms.

Changes:

  • Reworked the canister_snapshots test to assert expected snapshot files and validate file contents/metadata fields directly.
  • Removed the dfx runtime dependency from the canister_snapshots Bazel test target.
  • Added helper utilities for recursive file listing and optional file-size checks to support the new assertions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/pocket-ic/tests/canister_snapshots.rs Replaces dfx-based comparison with direct validation of downloaded snapshot files and parsed metadata.
packages/pocket-ic/BUILD.bazel Drops dfx from test data/env for the canister_snapshots target.

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

Comment thread packages/pocket-ic/tests/canister_snapshots.rs Outdated
Comment thread packages/pocket-ic/BUILD.bazel
mraszyk and others added 3 commits July 31, 2026 11:19
…JSON

Instead of checking the fields of the canister snapshot metadata one by one,
the expected metadata is now assembled into a
`ReadCanisterSnapshotMetadataResponse` and compared against the contents of
the `metadata.json` file as pretty-printed JSON (line by line so that the
error message stays readable). The timestamp and the globals are still
checked separately (and copied over into the expected metadata) since the
former is only known to be within the interval in which the snapshot was
taken and the values of the latter depend on how the test canister WASM is
compiled.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The test used to shell out to the external `diff` binary to compare the
snapshot directory downloaded from the uploaded snapshot against the
originally downloaded snapshot directory. Since the test is supposed to run
on all platforms (including Windows, where `diff` is not available), the
comparison is now done in pure Rust by comparing the list of files in the
two directories and then the contents of each file (except `metadata.json`,
which is compared separately after parsing it since some of its fields are
expected to differ).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`list_files` only collects files and thus an empty WASM chunk store
directory in a downloaded snapshot would go unnoticed. The test now asserts
explicitly that the WASM chunk store directory is present if and only if the
WASM chunk store is expected to be non-empty (and that the snapshot
downloaded after the upload agrees with the originally downloaded one).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mraszyk
mraszyk marked this pull request as ready for review July 31, 2026 11:36
@mraszyk
mraszyk requested a review from a team as a code owner July 31, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants