Repository navigation
feat(cli): cloudhal import reads a site archive (#47, step 3) - #131
Merged
Merged
Conversation
importSite inserted bundle.project as given when the target lacked it, so a crafted bundle could plant any projects row. The row must now be the site node's project, a valid Project, with id and rev matching its body. Covers pull, the admin bundle route behind push, and the coming `cloudhal import`. Refs #47 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Madraka <[email protected]>
RFC-0039 rollout step 2. `cloudhal export [--out <file>] [--site <id>] [--no-media] [--latest-only]` writes one site of the local project to a .cloudhal file: exportSite's bundle as NDJSON parts, media streamed from the local blob store and verified, and the takedown ledger. - Default name <site-slug>-<YYYYMMDD>.cloudhal, dated by the newest row it holds (never the clock), so an unchanged site exports identically. A file at the default name is replaced only by the same archive; --out replaces any. - --site takes a site listed in cloudhal.json sites; --site, --no-media and --latest-only are refused on every other command. - --latest-only keeps the published and the latest snapshot and what they need; refused while a field operation is unfinished. - Ctrl-C and SIGTERM remove the partial file. - The summary lists what an archive never holds (RFC-0039 §4) and that its history names who made each change. archive-bundle.ts and archive-reassemble.ts convert a bundle to archive content and back (step 3's import reuses the second); the tests check the round trip deep-equals exportSite's bundle. Refs #47 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Madraka <[email protected]>
importSite wrote node bodies before its bootstrap conflict check, snapshots before its 1000-statement cap, and parsed bundle asset bodies in the media ledger after the node batch, so a refused or crafted bundle could leave part of itself behind. It now plans first and applies after: - planImport runs every check and target read in the old order and returns what an import would change (nodes added/changed/removed, snapshots and bodies to add, media present/missing/other size/taken down, takedowns); with report: true it returns a bootstrap conflict and missing media instead of throwing. - Every node body the target lacks must be a valid contract document of the kind, id and rev its snapshot refs name, of the bundle's site; an unreferenced body is refused. - Ids of another site, duplicate ids, kind/key and translation group/locale collisions, and malformed takedowns are refused up front. - The media ledger reads verified bodies only. sync.ts is split into sync-bundle (types), sync-checks, sync-plan and sync-ledger; every export of @cloudhal/core-ts stays. Refs #47 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Madraka <[email protected]>
RFC-0039 rollout step 3: `cloudhal import <file> [--dry-run]`, bootstrap mode. Pass 1 verifies the whole archive (sizes, SHA-256s, rows, node bodies), applies the site rule (the archive's site must be cloudhal.json's siteId or listed in sites) and plans against the local store with planImport; any refusal comes before a write, and a project without a store gets none. Pass 2 re-reads the file, refuses it if it changed, copies only the missing media and calls importSite, keeping the archive's published snapshot as pull does. --dry-run prints the manifest and what would be added, changed or removed (nodes by kind and title, snapshots, media) and exits 1 when the import would be refused. Takedowns stay down; local copies of content the archive took down are deleted and reported. Ctrl-C stops before the graph is written. --replace is refused as not yet available (step 4). Also fixes the export test that picked a tied snapshot that was not the (created_at, id) maximum. Refs #47 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Madraka <[email protected]>
… test The seed's clock moves in 20 ms steps, so other snapshots can already share the newest one's created_at; the test picked the first earlier row with a larger id instead of the largest, and failed when another tied row sorted after it (CI on #130). Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Madraka <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Step 3 of RFC-0039's rollout for #47:
cloudhal import <file> [--dry-run]in bootstrap mode. Stacked on #130 (cloudhal export); the diff shrinks to this step's commits once #130 merges.fix(core-ts): importSite checks everything before it writes;planImportToday
importSite(behindpull, the admin bundle routepushuses, and nowimport) writes node bodies before its bootstrap conflict check, inserts snapshots before its 1000-statement cap, and parses bundle asset bodies in the media ledger after the node batch. A refused or crafted bundle can therefore leave part of itself behind. It is now plan-then-apply:planImport(to, bundle, options)runs every check and target read in the old order and writes nothing. It returns the nodes added, changed and removed, the snapshots and bodies to add, whether the project row is new, the media present/missing/of another size/taken down on the target, and the takedowns. Withreport: trueit returns a bootstrap conflict and missing media instead of throwing them.sync.ts(658 lines) is split intosync-bundle(types),sync-checks,sync-planandsync-ledger. Every export of@cloudhal/core-tsstays.feat(cli):cloudhal importcloudhal.json'ssiteIdor be listed insites; any other id is refused, and the switch comes with--replacein step 4. It then plans against the local store. Every refusal comes before any write, and a project without a store gets none created.importSite, keeping the archive's published snapshot aspulldoes.--dry-runprints the manifest and what would be added, changed or removed: nodes by kind and title, snapshots, and media to copy. It exits 1 when the import would be refused.Verification (local)
packages/core-ts: the full suite passes, 55 files and 997 tests, including the sqlite and Miniflare D1 behavioural suites that callimportSite. The newsync-plan.test.tshas 9 tests covering the refusals with nothing written.packages/cli:import-cli(25),export-cli(16),archive-*andcli-commandsall pass, 182 tests in one process. That includes:--dry-runandimport;exportthenimport --dry-runinto an empty project validates every historical body.examples/ui-auditcopies (24 snapshots, media): import into an empty store, a second run that is a no-op, a refusal after a local edit, and re-export gives identical bytes.pnpm size:checkpass.Checklist
pnpm checkandcargo test --workspacepass locally. The core-ts suite was run in full; the CLI pieces that cover this change were run. There is no Rust or contract change, and CI runs the rest..changeset/import-plan.md(core-ts) and.changeset/site-archive-import.md(cli). The step-2 changesets lost their "import comes later" wording.git commit -s, DCO)help.tsis updated; the guide comes in step 5.Refs #47
🤖 Generated with Claude Code