Skip to content

Commit 7589a23

Browse files
test(server): an approval withdrawn before projection still cancels
AI-assisted; verified with the tests and tools listed above.
1 parent 2fa638c commit 7589a23

1 file changed

Lines changed: 38 additions & 40 deletions

File tree

‎apps/server/src/orchestration-v2/ProviderEventIngestor.test.ts‎

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,10 @@ layer("ProviderEventIngestorV2", (it) => {
571571

572572
// regression: #24690 an answer commits before its outbox delivery reaches the provider
573573
it.effect.each([
574-
{ decision: "decline", feedback: "Use a safer command." },
575-
{ decision: "accept" },
576-
] as const)("keeps a committed $decision when the provider withdraws the approval", (answer) =>
574+
{ name: "keeps a committed decline", answer: { decision: "decline", feedback: "No." } },
575+
{ name: "keeps a committed accept", answer: { decision: "accept" } },
576+
{ name: "cancels an approval withdrawn before it was projected", answer: null },
577+
] as const)("$name when the provider withdraws the approval", ({ answer }) =>
577578
Effect.gen(function* () {
578579
const now = yield* DateTime.now;
579580
const eventSink = yield* EventSink.EventSinkV2;
@@ -664,47 +665,44 @@ layer("ProviderEventIngestorV2", (it) => {
664665
}),
665666
{ concurrency: 1 },
666667
);
667-
yield* ingest("waiting");
668-
669-
// The orchestrator's response transaction; its outbox delivery never runs here.
670-
const outcome = answer.decision === "accept" ? "completed" : "cancelled";
671-
const resolved = { ...request, status: "resolved" as const, resolvedAt: now, ...answer };
672-
const answeredNode: OrchestrationV2ExecutionNode = {
673-
...node,
674-
status: outcome,
675-
completedAt: now,
676-
};
677-
const answeredItem: OrchestrationV2TurnItem = { ...item, status: outcome, completedAt: now };
678-
const base = { threadId, nodeId, occurredAt: now };
679-
yield* eventSink.write({
680-
events: [
681-
{
682-
...base,
683-
id: yield* idAllocator.allocate.event({ threadId }),
684-
type: "runtime-request.updated",
685-
payload: resolved,
686-
},
687-
{
688-
...base,
689-
id: yield* idAllocator.allocate.event({ threadId }),
690-
type: "node.updated",
691-
payload: answeredNode,
692-
},
693-
{
694-
...base,
695-
id: yield* idAllocator.allocate.event({ threadId }),
696-
type: "turn-item.updated",
697-
payload: answeredItem,
698-
},
699-
],
700-
});
668+
const outcome = answer?.decision === "accept" ? "completed" : "cancelled";
669+
if (answer !== null) {
670+
yield* ingest("waiting");
671+
// The orchestrator's response transaction; its outbox delivery never runs here.
672+
const base = { threadId, nodeId, occurredAt: now };
673+
yield* eventSink.write({
674+
events: [
675+
{
676+
...base,
677+
id: yield* idAllocator.allocate.event({ threadId }),
678+
type: "runtime-request.updated",
679+
payload: { ...request, status: "resolved", resolvedAt: now, ...answer },
680+
},
681+
{
682+
...base,
683+
id: yield* idAllocator.allocate.event({ threadId }),
684+
type: "node.updated",
685+
payload: { ...node, status: outcome, completedAt: now },
686+
},
687+
{
688+
...base,
689+
id: yield* idAllocator.allocate.event({ threadId }),
690+
type: "turn-item.updated",
691+
payload: { ...item, status: outcome, completedAt: now },
692+
},
693+
],
694+
});
695+
}
701696

702697
yield* ingest("cancelled");
703698
const projection = yield* projectionStore.getThreadProjection(threadId);
704699
const stored = projection.runtimeRequests.find((entry) => entry.id === request.id);
705-
assert.equal(stored?.status, "resolved");
706-
assert.equal(stored?.decision, answer.decision);
707-
assert.equal(stored?.feedback, "feedback" in answer ? answer.feedback : undefined);
700+
assert.equal(stored?.status, answer === null ? "cancelled" : "resolved");
701+
assert.equal(stored?.decision, answer?.decision);
702+
assert.equal(
703+
stored?.feedback,
704+
answer !== null && "feedback" in answer ? answer.feedback : undefined,
705+
);
708706
assert.equal(projection.nodes.find((entry) => entry.id === nodeId)?.status, outcome);
709707
assert.equal(projection.turnItems.find((entry) => entry.id === item.id)?.status, outcome);
710708
}),

0 commit comments

Comments
 (0)