Files
PaperClipAI/server/src/services/acknowledged-native-stop.test.ts
T
DottaandPaperclip 245b4d3b79 Preserve cancelled workspaces after controllerless Stop (#18820)
Admit cancelled workspace preservation after an audited Stop acknowledgement when no live controller received an interrupt. Retain the strict dispatched receipt for provider termination and operator handoff. Existing source, lease, coordinator and result ownership checks remain enforced.

Validated with complete Stop/preservation suites (134 tests), real-file recovery, workspace typecheck and build, and green hosted CI. Greptile and Paperclip both reviewed the exact head at 5/5 with no unresolved findings.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-11-04 22:17:50 -08:00

31 lines
2.1 KiB
TypeScript

import { expect, it } from "vitest";
import { isAcknowledgedNativeReassignmentStop, isAcknowledgedNativeStop } from "./acknowledged-native-stop.js";
const run = { id: "run", companyId: "company", nativeIssueId: "issue", status: "cancelled", resultJson: {
cancelledByActorType: "user", cancelledByUserId: "board", nativeCancellation: {
schema: "paperclip.native-cancellation.v1", runId: "run", companyId: "company", issueId: "issue",
scope: "run", reasonCode: "cancellation_run_only", dispatchState: "acknowledged", dispatched: true,
intentAuditId: "intent", acknowledgementAuditId: "ack",
},
} };
it("recognizes the native receipt used by the Stop button", () => {
expect(isAcknowledgedNativeStop(run)).toBe(true);
});
it.each([{ runId: "other" }, { companyId: "other" }, { issueId: "other" }, { dispatchState: "pending" }, { dispatched: false },
{ scope: "subtree" }, { acknowledgementAuditId: undefined }])("refuses unrelated or incomplete receipts %j", change => {
expect(isAcknowledgedNativeStop({ ...run, resultJson: { ...run.resultJson,
nativeCancellation: { ...run.resultJson.nativeCancellation, ...change } } })).toBe(false);
});
it("recognizes an audited handoff without granting operator Stop semantics", () => {
const handoff = { ...run, resultJson: { reassignmentStopRequested: true, nativeCancellation: run.resultJson.nativeCancellation } };
expect(isAcknowledgedNativeReassignmentStop(handoff)).toBe(true);
expect(isAcknowledgedNativeStop(handoff)).toBe(false);
expect(isAcknowledgedNativeReassignmentStop({ ...handoff, status: "running" })).toBe(false);
expect(isAcknowledgedNativeReassignmentStop(run)).toBe(false);
});
it.each([{ runId: "other" }, { companyId: "other" }, { issueId: "other" }, { dispatchState: "pending" }, { dispatched: false },
{ scope: "subtree" }, { acknowledgementAuditId: undefined }])("requires an audited handoff receipt %j", change => {
expect(isAcknowledgedNativeReassignmentStop({ ...run, resultJson: { reassignmentStopRequested: true,
nativeCancellation: { ...run.resultJson.nativeCancellation, ...change } } })).toBe(false);
});