From a142eacf36584830c278e44ebc0850b34e5691ec Mon Sep 17 00:00:00 2001 From: qiansc Date: Fri, 13 Nov 2026 11:57:17 +0000 Subject: [PATCH] fix(context-cli): let close ignore a stale revision delivery during a rollback A rollback applied with an older version left its partial revision delivery selection behind; close validated it against the replaced revision and the rollback could not finish. Close and close status now ignore the selection while a rollback is active, and the rollback cleanup removes it. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- .../src/__tests__/projectKnowledgeUpdate.test.ts | 12 +++++++++++- packages/context-cli/src/project/close.ts | 13 +++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5a140da..5ad02518 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ All notable changes to Context are documented here. - While a rollback is active, the build no longer checks a partial-delivery selection that the rollback removed ("No reviewed articles can be delivered"); the rollback cleanup settles it. - Rollback cleanup removes production before the rollback record, so a cleanup that fails can be retried. - A production stage prepared after a rollback was applied (for example with a `prepare-current` command obtained earlier) is no longer deleted when that rollback finishes; the rollback now records that it found no stage, and only the stage it disclosed can be discarded. -- Rolling back a page revision with a requested partial delivery no longer stops `context close` with "Partial revision delivery is no longer active": the rollback cancels that delivery selection and lists its pages in the preview (`discarded_revision_delivery`). +- Rolling back a page revision with a requested partial delivery no longer stops `context close` with "Partial revision delivery is no longer active": the rollback cancels that delivery selection and lists its pages in the preview (`discarded_revision_delivery`). A selection left behind by a rollback applied with an older version is ignored by `context close`, and the rollback cleanup removes it. ## 0.7.98 - 2026-11-11 diff --git a/packages/context-cli/src/__tests__/projectKnowledgeUpdate.test.ts b/packages/context-cli/src/__tests__/projectKnowledgeUpdate.test.ts index 6fdbf3dd..76fe4416 100644 --- a/packages/context-cli/src/__tests__/projectKnowledgeUpdate.test.ts +++ b/packages/context-cli/src/__tests__/projectKnowledgeUpdate.test.ts @@ -328,7 +328,7 @@ test("a production stage prepared after a rollback without one is kept when the expect(await readProductionStage(root)).toEqual(later); }, 60_000); -test("rolling back a partially delivered page revision discards its delivery selection so close and build proceed", async () => { +test.each([false, true])("rolling back a partially delivered page revision (selection left by an older CLI: %p) closes, builds and finishes", async (legacy) => { const { rollbackProjectTask, finishTaskRollback, readTaskRollback } = await import("../project/taskRollback.js"); const root = await initialRevisionKnowledge(roots); await beginKnowledgeUpdate(root, { scopes: [scope] }); @@ -348,12 +348,22 @@ test("rolling back a partially delivered page revision discards its delivery sel const value = { summary: "Abandon the page revisions.", discard_unfinished: true as const, files: [] }; const plan = await rollbackProjectTask({ projectRoot: root, value }); expect(plan.discarded_revision_delivery).toEqual([`knowledge/${first.target.path}`]); + const { REVISION_DELIVERY_FILE } = await import("../project/revisionDelivery.js"); + const selection = await readFile(join(root, REVISION_DELIVERY_FILE), "utf8"); await rollbackProjectTask({ projectRoot: root, value, apply: true, plan_digest: plan.revision }); expect(await readRevisionDelivery(root)).toBeUndefined(); + if (legacy) { + // A rollback applied by an older CLI left the selection behind; retrying the + // rollback only reports already-applied, so close must ignore the stale record. + await writeFile(join(root, REVISION_DELIVERY_FILE), selection); + expect((await rollbackProjectTask({ projectRoot: root, value, apply: true, plan_digest: plan.revision })).action).toBe("already-applied"); + expect((await collectProjectStatus(root, { managed: true })).workflow.current?.reason_code).toBe("route.rollback.close-required"); + } await closeProjectWorkspace(root); await buildProjectPackages(root); await finishTaskRollback(root); expect(await readTaskRollback(root)).toBeUndefined(); + expect(await readRevisionDelivery(root)).toBeUndefined(); }, 60_000); test.each(["architecture", "standards"])("explicit page move to %s preserves identity and updates incoming navigation through Review apply", async (collection) => { diff --git a/packages/context-cli/src/project/close.ts b/packages/context-cli/src/project/close.ts index 6fba88b7..4477cd89 100644 --- a/packages/context-cli/src/project/close.ts +++ b/packages/context-cli/src/project/close.ts @@ -158,7 +158,7 @@ export async function readProjectCloseStatus(projectRoot: string): Promise : {}; const recorded = record.input_hash; - const delivery = await readProductionStage(projectRoot) ? undefined : await readRevisionDelivery(projectRoot); + const delivery = await readProductionStage(projectRoot) ? undefined : await currentRevisionDelivery(projectRoot); const deliveryNeedsClose = delivery !== undefined && delivery.closed !== true; return recorded === inputHash && !deliveryNeedsClose ? { state: "ready", inputHash, diagnostics: [] } @@ -172,6 +172,15 @@ export async function readProjectCloseStatus(projectRoot: string): Promise { return withProjectWriteLock(projectRoot, "close-knowledge", async () => { const candidates = await readCandidateRecords(projectRoot); @@ -179,7 +188,7 @@ export async function closeProjectWorkspace(projectRoot: string): Promise 0 && !delivery?.partial) {