Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] });
Expand All @@ -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) => {
Expand Down
13 changes: 11 additions & 2 deletions packages/context-cli/src/project/close.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export async function readProjectCloseStatus(projectRoot: string): Promise<Proje
? parsed as Record<string, unknown>
: {};
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: [] }
Expand All @@ -172,14 +172,23 @@ export async function readProjectCloseStatus(projectRoot: string): Promise<Proje
}
}

/** A rollback replaces the revision a partial delivery was selected from; a
* selection left by an older rollback is stale and the rollback cleanup removes it. */
async function currentRevisionDelivery(projectRoot: string) {
const delivery = await readRevisionDelivery(projectRoot);
if (!delivery) return undefined;
const { readTaskRollback } = await import("./taskRollback.js");
return await readTaskRollback(projectRoot) ? undefined : delivery;
}

export async function closeProjectWorkspace(projectRoot: string): Promise<ProjectCloseResult> {
return withProjectWriteLock(projectRoot, "close-knowledge", async () => {
const candidates = await readCandidateRecords(projectRoot);
const draftCandidates = candidates.filter((candidate) =>
candidate.candidate_type === "indexer-artifact" && candidate.status === "draft"
);
const production = await readProductionStage(projectRoot);
const delivery = production ? undefined : await readRevisionDelivery(projectRoot);
const delivery = production ? undefined : await currentRevisionDelivery(projectRoot);
if (delivery?.partial) await assertPartialDeliveryCurrent(projectRoot, delivery.partial);
else await assertRequiredArticlesReviewed(projectRoot, candidates);
if (draftCandidates.length > 0 && !delivery?.partial) {
Expand Down
Loading