Skip to content

feat(migration): sync plugin for the legacy dfx 0.32.0 assetstorage canister#71

Draft
lwshang wants to merge 1 commit into
mainfrom
migration
Draft

feat(migration): sync plugin for the legacy dfx 0.32.0 assetstorage canister#71
lwshang wants to merge 1 commit into
mainfrom
migration

Conversation

@lwshang
Copy link
Copy Markdown
Collaborator

@lwshang lwshang commented Jun 2, 2026

⚠️ This branch is never merged into main

The migration branch is a permanently separate line of work. Do not merge it.

Instead, we will git-tag commits on this branch and cut special GitHub releases that host the built sync-plugin wasm module. icp-cli projects (recipes, templates) reference that hosted wasm directly.

The driving use case: a companion assets recipe that swaps the sync mechanism from the old type: assets to type: plugin while keeping the canister wasm unchanged (the legacy dfx 0.32.0 assetstorage canister). This minimizes the upgrade effort for existing assets-recipe users when we drop type: assets sync in the upcoming icp-cli release.

What this branch does

Retargets sync-core / sync-plugin from this repo's V2 certified-assets canister to the legacy assetstorage canister shipped with dfx 0.32.0 (ic-certified-assets, which reports api_version == 2). Per-asset metadata is read from .ic-assets.json5 (full ic-asset parity) instead of the _headers / _redirects files used on main.

The legacy canister's wire protocol is nearly identical to this repo's V2 canister; the differences are narrow and handled here:

Concern main (new) legacy (0.32.0)
Redirect rules get_redirect_rules / SetRedirectRules absent (removed)
CreateAssetArguments adds enable_aliasing
SetAssetPropertiesArguments adds is_aliased
AssetProperties adds is_aliased
Per-asset config _headers + _redirects .ic-assets.json5
HTML routing synthesised redirect rules native enable_aliasing

sync-core

  • new config.rs.ic-assets.json5 / .ic-assets.json parser ported from ic-asset: nested config inheritance, glob match, ignore, headers, cache.max_age, enable_aliasing, allow_raw_access, encodings, security_policy.
  • new security_policy.rsstandard / hardened / disabled CSP presets.
  • scan.rs rewritten as gather_asset_descriptors (walkdir + config-driven ignore; .well-known kept; config files excluded).
  • canister.rs — add enable_aliasing / is_aliased; drop RedirectRule / RulePattern / SetRedirectRules / get_redirect_rules.
  • sync.rs — drive CreateAsset / SetAssetProperties from AssetConfig; drop redirect & html-handling; keep chunk packing + commit staging.
  • delete redirects.rs, headers.rs, html_handling.rs, glob.rs.
  • idempotency fix: the legacy canister injects a Set-Cookie: ic_env=... header into every HTML asset (driven by icp-cli's env-var step) and returns it from get_asset_properties. update_properties now ignores that canister-managed cookie so repeat syncs report "up to date" instead of clobbering it every run.

e2e

  • build.rs fetches the real assetstorage.wasm.gz from the dfx 0.32.0 release (sha256-pinned to the GH release digest, installed gzipped — no decompression) instead of building this repo's canister.
  • fixtures/tests converted to .ic-assets.json5; redirect / header / multi-dir cases removed; new config.rs end-to-end test (headers, max_age, aliasing, security_policy CSP, config-file-not-uploaded).

Test plan

  • cargo test -p sync-core — 75 unit tests pass.
  • cargo build -p sync-plugin --target wasm32-wasip2 --release — links under WASI.
  • cargo test -p e2e — deploys the real 0.32.0 assetstorage.wasm and exercises the plugin via icp deploy; config test + all sync tests (incl. idempotent no_op_sync) pass.

🤖 Generated with Claude Code

Retarget sync-core/sync-plugin from this repo's V2 certified-assets
canister to the legacy `assetstorage` canister shipped with dfx 0.32.0
(`ic-certified-assets`, api_version 2). Per-asset metadata now comes from
`.ic-assets.json5` instead of `_headers`/`_redirects`.

sync-core:
- new `config.rs`: full `.ic-assets.json5`/`.ic-assets.json` parser ported
  from ic-asset (nested inheritance, glob `match`, `ignore`, `headers`,
  `cache.max_age`, `enable_aliasing`, `allow_raw_access`, `encodings`,
  `security_policy`)
- new `security_policy.rs`: standard/hardened/disabled CSP presets
- `scan.rs` rewritten as gather_asset_descriptors (walkdir + config-driven
  ignore; `.well-known` kept; config files excluded)
- `canister.rs`: add `enable_aliasing` (CreateAsset) and `is_aliased`
  (SetAssetProperties + AssetProperties); drop RedirectRule/RulePattern/
  SetRedirectRules/get_redirect_rules
- `sync.rs`: drive CreateAsset/SetAssetProperties from AssetConfig; drop
  redirect/html-handling; keep chunk packing + commit staging
- delete redirects.rs, headers.rs, html_handling.rs, glob.rs
- update_properties ignores the canister-injected `Set-Cookie: ic_env=...`
  header (added by icp-cli's env-var step) so syncs stay idempotent

e2e:
- build.rs fetches the real 0.32.0 assetstorage.wasm.gz (sha256-pinned,
  installed gzipped, no decompress) instead of building this repo's canister
- convert fixtures/tests to `.ic-assets.json5`; remove redirect/header/
  multi-dir cases; add config.rs end-to-end test

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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