Preserve tool review wakeup when a formal approval is cancelled

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-10-27 18:42:45 -05:00
1 parent 93b64abaec
commit dd844f4e8c
2 files changed
+9 -5

No files matched your search

@@ -102,7 +102,7 @@ const delay = DEFAULT_DECISION_ARCHIVE_DAYS * 86_400_000;
expect((await db.select().from(approvals).where(eq(approvals.id, row.id)))[0].status).toBe("pending");
});
it.each(["approved", "rejected"] as const)("wakes parked tool reviews only on formal %s resolution", async outcome => {
it.each(["approved", "rejected", "cancelled"] as const)("wakes parked tool reviews only on terminal %s transition", async outcome => {
const queues = [DELIVERY_QUEUES.toolReviewExpiry, DELIVERY_QUEUES.toolReviewRecovery,
DELIVERY_QUEUES.toolReviewInterruption, DELIVERY_QUEUES.toolReviewProjection];
const events = queues.map(() => [] as string[]);
@@ -116,7 +116,8 @@ const delay = DEFAULT_DECISION_ARCHIVE_DAYS * 86_400_000;
await approvalRecords(db).requestRevision(row.id, "board-user");
await approvalRecords(db).resubmit(row.id);
expect(events).toEqual(queues.map(() => []));
await approvalRecords(db).resolveApproval(row.id, outcome, "board-user", null);
if (outcome === "cancelled") await approvalRecords(db).cancel(row.id, "cancelled by user");
else await approvalRecords(db).resolveApproval(row.id, outcome, "board-user", null);
expect(events).toEqual(queues.map(() => ["intent", "settled"]));
} finally { for (const unsubscribe of subscriptions) unsubscribe(); }
});
+6 -3
View File
@@ -1,3 +1,4 @@
import { notifyToolReviewChange } from "./tool-review-work-notifications.js";
import { writeApprovalChange } from "./retention-work-notifications.js";
import { approvalResolutionRecords, resolvableApprovalStatuses as resolvableStatuses } from "../lib/approval-records.js";
import { notifyHireApproved } from "./hire-hook.js";
@@ -67,8 +68,9 @@ export function approvalRecords(db: Db) {
const now = new Date();
const [existing] = await db.select({ companyId: approvals.companyId }).from(approvals).where(eq(approvals.id, id));
if (!existing) return null;
const updated = await writeApprovalChange(db, tx => tx
.update(approvals)
const updated = await writeApprovalChange(db, async tx => {
await notifyToolReviewChange(tx, existing.companyId);
return tx.update(approvals)
.set({
status: "cancelled",
decisionNote: reason ?? null,
@@ -77,7 +79,8 @@ export function approvalRecords(db: Db) {
})
.where(and(eq(approvals.id, id), inArray(approvals.status, resolvableStatuses)))
.returning()
.then((rows) => rows[0] ?? null));
.then((rows) => rows[0] ?? null);
});
return updated;
},