Skip to content

Commit 64fd224

Browse files
committed
test(orchestration-v2): verify checkpoint effects share the stop guard
1 parent 4a529be commit 64fd224

1 file changed

Lines changed: 41 additions & 13 deletions

File tree

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

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3246,19 +3246,25 @@ it.effect("omits run_interrupt_result when superseded attempt request is already
32463246

32473247
it.effect("does not overwrite Stop when ownership changes after the finalization read", () =>
32483248
Effect.gen(function* () {
3249-
const { written, observed } = yield* captureRootRunTermination({
3250-
key: "stop-wins-finalization-gap",
3251-
shouldFinalizeRun: () => Effect.succeed(true),
3252-
rejectTerminalWrite: true,
3253-
});
3249+
const { written, observed, submittedEffects, committedEffects } =
3250+
yield* captureRootRunTermination({
3251+
key: "stop-wins-finalization-gap",
3252+
shouldFinalizeRun: () => Effect.succeed(true),
3253+
rejectTerminalWrite: true,
3254+
});
32543255
assert.deepEqual(written, []);
32553256
assert.deepEqual(observed, []);
3257+
assert.deepEqual(
3258+
submittedEffects.map((effect) => effect.request.type),
3259+
["checkpoint.capture"],
3260+
);
3261+
assert.deepEqual(committedEffects, []);
32563262
}),
32573263
);
32583264

32593265
it.effect("emits run_interrupt_result when hard-stop finalizes the active attempt", () =>
32603266
Effect.gen(function* () {
3261-
const { written, observed } = yield* captureRootRunTermination({
3267+
const { written, observed, committedEffects } = yield* captureRootRunTermination({
32623268
key: "hard-stop",
32633269
shouldFinalizeRun: () => Effect.succeed(true),
32643270
});
@@ -3267,6 +3273,10 @@ it.effect("emits run_interrupt_result when hard-stop finalizes the active attemp
32673273
["run_interrupt_result"],
32683274
);
32693275
assert.deepEqual(observed, ["run:interrupted", "pull-requests-refreshed"]);
3276+
assert.deepEqual(
3277+
committedEffects.map((effect) => effect.request.type),
3278+
["checkpoint.capture"],
3279+
);
32703280
}),
32713281
);
32723282

@@ -3416,6 +3426,8 @@ function captureRootRunTermination(input: {
34163426
});
34173427
const writtenItems = yield* Ref.make<ReadonlyArray<OrchestrationV2TurnItem>>([]);
34183428
const observed = yield* Ref.make<ReadonlyArray<string>>([]);
3429+
const submittedEffects = yield* Ref.make<ReadonlyArray<PendingOrchestrationEffectV2>>([]);
3430+
const committedEffects = yield* Ref.make<ReadonlyArray<PendingOrchestrationEffectV2>>([]);
34193431
const ingestionDone = yield* Deferred.make<void>();
34203432
const captureTurnItem = (payload: OrchestrationV2TurnItem) =>
34213433
Ref.update(writtenItems, (current) => [...current, payload]);
@@ -3444,13 +3456,24 @@ function captureRootRunTermination(input: {
34443456
}
34453457
return [];
34463458
}),
3447-
writeWithEffects: (payload) => captureFinalEvents(payload.events).pipe(Effect.as([])),
3459+
writeWithEffects: (payload) =>
3460+
Effect.gen(function* () {
3461+
yield* Ref.update(submittedEffects, (current) => [...current, ...payload.effects]);
3462+
yield* Ref.update(committedEffects, (current) => [...current, ...payload.effects]);
3463+
yield* captureFinalEvents(payload.events);
3464+
return [];
3465+
}),
34483466
writeIfRunCurrent: (payload) =>
3449-
input.rejectTerminalWrite === true
3450-
? Effect.succeed({ committed: false, storedEvents: [] })
3451-
: captureFinalEvents(payload.events).pipe(
3452-
Effect.as({ committed: true, storedEvents: [] }),
3453-
),
3467+
Effect.gen(function* () {
3468+
const effects = payload.effects ?? [];
3469+
yield* Ref.update(submittedEffects, (current) => [...current, ...effects]);
3470+
if (input.rejectTerminalWrite === true) {
3471+
return { committed: false, storedEvents: [] };
3472+
}
3473+
yield* Ref.update(committedEffects, (current) => [...current, ...effects]);
3474+
yield* captureFinalEvents(payload.events);
3475+
return { committed: true, storedEvents: [] };
3476+
}),
34543477
}),
34553478
IdAllocator.layer,
34563479
Layer.mock(ProviderEventIngestor.ProviderEventIngestorV2)({
@@ -3559,7 +3582,12 @@ function captureRootRunTermination(input: {
35593582
}).pipe(Effect.provide(testLayer));
35603583

35613584
yield* Deferred.await(ingestionDone);
3562-
return { written: yield* Ref.get(writtenItems), observed: yield* Ref.get(observed) };
3585+
return {
3586+
written: yield* Ref.get(writtenItems),
3587+
observed: yield* Ref.get(observed),
3588+
submittedEffects: yield* Ref.get(submittedEffects),
3589+
committedEffects: yield* Ref.get(committedEffects),
3590+
};
35633591
});
35643592
}
35653593

0 commit comments

Comments
 (0)