Skip to content

test(e2e): add e2e sync tests#47

Merged
lwshang merged 10 commits intomainfrom
lwshang/SDK-2698_test_p4
May 8, 2026
Merged

test(e2e): add e2e sync tests#47
lwshang merged 10 commits intomainfrom
lwshang/SDK-2698_test_p4

Conversation

@lwshang
Copy link
Copy Markdown
Collaborator

@lwshang lwshang commented May 7, 2026

Summary

Adds the first set of end-to-end tests for the asset sync pipeline, exercising the full stack: plugin.wasm loaded by icp → assets synced to a live canister on a local replica.

Tests added (e2e/tests/sync.rs)

  • basic_deploy — deploys a fixture project and asserts /index.html is present in the canister
  • basic_deploy_with_proxy — same, but goes through a proxy canister (--proxy flag)
  • no_op_sync — runs deploy twice; second run must report "up to date" with no state change
  • content_update — modifies a file and re-syncs; verifies the SHA256 on the canister changed for the updated file and is unchanged for untouched files
  • asset_deletion — removes a file locally and re-syncs; verifies the key is deleted from the canister while other keys survive
  • multi_directory_sync — configures two source directories; verifies files from both appear in the canister

Rationale: e2e vs. unit tests

E2e tests in this project are intentionally narrow in scope. They exist only when icp-cli must be involved to wire up canister.wasm and plugin.wasm together — things that cannot be observed in isolation. Everything else belongs in unit tests.

A concrete example from this PR: the initial draft included an initial_sync test that wrote a PNG file and asserted content_type == "image/png" on the canister. That assertion was removed from the e2e layer and replaced with a load_infers_png_mime unit test in assets-sync/src/content.rs. MIME detection is a pure extension lookup in Content::load() — no canister, no CLI, no replica needed. Keeping it in e2e would have added replica startup overhead to test a one-liner in mime_guess.

The rule of thumb: if the behaviour under test lives entirely inside assets-sync (scan, MIME inference, diff logic, encoding), it gets a unit test. E2e tests cover only the seam between the CLI, the plugin, and the canister.

Test plan

  • cargo test -p assets-sync passes (includes new load_infers_png_mime)
  • cargo test -p e2e passes (requires icp on PATH and dfx or equivalent for local replica)
  • CI green

🤖 Generated with Claude Code

lwshang and others added 9 commits May 7, 2026 15:50
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Move copy_dir_contents, setup_project into e2e/src/lib.rs so all
future test files can share them without duplication. Add list_assets
and generate_minimal_png helpers in the same place. Move hex and
tempfile from dev-dependencies to dependencies since lib.rs now uses
them at compile time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Deploy an empty canister with one HTML file and one runtime-generated
PNG (no binary committed); assert both keys are present and content
types are correct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Run deploy twice with no file changes; assert the second run reports
"up to date" and the canister asset list is unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Modify one file's content and re-sync; assert the updated file's
identity SHA256 changes on the canister while the untouched file's
SHA256 stays the same.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove one file from the local dist directory and re-sync; assert
the deleted key is absent from the canister while the remaining
asset is still intact.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add a multi-dir fixture with two source directories (dist-a, dist-b)
containing non-overlapping files. Test deploys from both dirs and
asserts all keys appear on the canister with correct leading-slash
paths. Also marks the basic sync E2E checklist item complete in
TEST.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`initial_sync` duplicated `basic_deploy` and used a 60-line hand-rolled
PNG generator solely to check content-type detection, which is purely
extension-based and belongs in a unit test. Replace it with a
`load_infers_png_mime` unit test in `assets-sync/src/content.rs`, delete
`generate_minimal_png`, consolidate `basic.rs` into `sync.rs`, and
update TEST.md accordingly.

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds the first end-to-end Rust tests that exercise the full asset sync stack (icp CLI → plugin.wasm → live local replica canister), plus a small unit test to keep MIME inference coverage in the assets-sync layer.

Changes:

  • Added e2e sync workflow tests (deploy, proxy deploy, no-op, content update, deletion, multi-dir).
  • Refactored shared e2e helpers into e2e/src/lib.rs and updated dependencies accordingly.
  • Added a unit test for PNG MIME inference and updated TEST.md to reflect the testing strategy.

Reviewed changes

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

Show a summary per file
File Description
TEST.md Updates test-plan documentation for the new e2e test setup and scenarios.
e2e/tests/sync.rs Introduces the main set of e2e sync tests and assertions.
e2e/tests/fixture/multi-dir/icp.yaml Adds a fixture config that syncs from two directories.
e2e/tests/fixture/multi-dir/dist-b/app.js Adds a multi-dir fixture asset (JS).
e2e/tests/fixture/multi-dir/dist-a/page.html Adds a multi-dir fixture asset (HTML).
e2e/tests/basic.rs Removes the earlier/basic e2e test file (superseded by sync.rs).
e2e/src/lib.rs Adds reusable fixture setup + list_assets helper used by integration tests.
e2e/Cargo.toml Moves hex into normal dependencies (now used by the library helper).
assets-sync/src/content.rs Adds a unit test for PNG MIME inference in Content::load().

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

Comment thread e2e/tests/sync.rs Outdated
Comment thread e2e/tests/sync.rs
Compare SHA256s and encodings (not just keys) after the second deploy,
so the test catches content or encoding changes that leave the key list
unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lwshang lwshang marked this pull request as ready for review May 7, 2026 22:12
@lwshang lwshang requested a review from a team as a code owner May 7, 2026 22:12
@lwshang lwshang changed the title test(e2e): add first set of e2e sync tests test(e2e): add e2e sync tests May 7, 2026
@lwshang lwshang merged commit 293f162 into main May 8, 2026
12 checks passed
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.

3 participants