@@ -9261,78 +9261,85 @@ describe("ClaudeAdapterV2 background wake turns", () => {
92619261 ),
92629262 );
92639263
9264- it.effect("settles a continuation whose opened wake turn a user turn already answered", () =>
9265- Effect.scoped(
9266- Effect.gen(function* () {
9267- const harness = yield* makeWakeHarness;
9268- const now = yield* DateTime.now;
9264+ it.effect.each(["live in the user turn", "buffered before the user turn"] as const)(
9265+ "settles a continuation whose opened wake turn a user turn already answered: assistant %s",
9266+ (assistantFrame) =>
9267+ Effect.scoped(
9268+ Effect.gen(function* () {
9269+ const harness = yield* makeWakeHarness;
9270+ const now = yield* DateTime.now;
92699271
9270- yield* harness.runtime.startTurn(
9271- makeClaudeTestTurnInput({
9272- threadId: harness.threadId,
9273- providerThread: harness.providerThread,
9274- now,
9275- attemptId: RunAttemptId.make("attempt-claude-wake-answered-1"),
9276- text: "Run the build in the background.",
9277- attachments: [],
9278- }),
9279- );
9280- yield* Queue.offer(harness.sdkMessages, wakeTaskStarted);
9281- yield* Queue.offer(harness.sdkMessages, turnOneResult);
9282- yield* harness.awaitTerminal(1);
9283- yield* harness.offerAndWait(wakeNotification);
9284- yield* harness.offerAndWait(wakeTurnInit);
9285- assert.lengthOf(harness.continuationRequests, 1);
9272+ yield* harness.runtime.startTurn(
9273+ makeClaudeTestTurnInput({
9274+ threadId: harness.threadId,
9275+ providerThread: harness.providerThread,
9276+ now,
9277+ attemptId: RunAttemptId.make("attempt-claude-wake-answered-1"),
9278+ text: "Run the build in the background.",
9279+ attachments: [],
9280+ }),
9281+ );
9282+ yield* Queue.offer(harness.sdkMessages, wakeTaskStarted);
9283+ yield* Queue.offer(harness.sdkMessages, turnOneResult);
9284+ yield* harness.awaitTerminal(1);
9285+ yield* harness.offerAndWait(wakeNotification);
9286+ yield* harness.offerAndWait(wakeTurnInit);
9287+ if (assistantFrame === "buffered before the user turn") {
9288+ yield* harness.offerAndWait(wakeAssistant);
9289+ }
9290+ assert.lengthOf(harness.continuationRequests, 1);
92869291
9287- yield* harness.runtime.startTurn(
9288- makeClaudeTestTurnInput({
9289- threadId: harness.threadId,
9290- providerThread: harness.providerThread,
9291- now,
9292- attemptId: RunAttemptId.make("attempt-claude-wake-answered-2"),
9293- text: "How is the build going?",
9294- attachments: [],
9295- providerTurnOrdinal: 2,
9296- }),
9297- );
9298- yield* harness.until(() => harness.offeredMessages.length === 2);
9299- yield* Queue.offer(harness.sdkMessages, wakeAssistant);
9300- yield* Queue.offer(
9301- harness.sdkMessages,
9302- makeResultFrame({
9303- uuid: "00000000-0000-4000-8000-000000000105",
9304- result: "The build passed; nothing else pending.",
9305- }),
9306- );
9307- yield* harness.awaitTerminal(2);
9308- assert.equal(harness.terminalEvents()[1]?.status, "completed");
9292+ yield* harness.runtime.startTurn(
9293+ makeClaudeTestTurnInput({
9294+ threadId: harness.threadId,
9295+ providerThread: harness.providerThread,
9296+ now,
9297+ attemptId: RunAttemptId.make("attempt-claude-wake-answered-2"),
9298+ text: "How is the build going?",
9299+ attachments: [],
9300+ providerTurnOrdinal: 2,
9301+ }),
9302+ );
9303+ yield* harness.until(() => harness.offeredMessages.length === 2);
9304+ if (assistantFrame === "live in the user turn") {
9305+ yield* Queue.offer(harness.sdkMessages, wakeAssistant);
9306+ }
9307+ yield* Queue.offer(
9308+ harness.sdkMessages,
9309+ makeResultFrame({
9310+ uuid: "00000000-0000-4000-8000-000000000105",
9311+ result: "The build passed; nothing else pending.",
9312+ }),
9313+ );
9314+ yield* harness.awaitTerminal(2);
9315+ assert.equal(harness.terminalEvents()[1]?.status, "completed");
93099316
9310- yield* harness.runtime.startTurn(
9311- makeClaudeTestTurnInput({
9312- threadId: harness.threadId,
9313- providerThread: harness.providerThread,
9314- now,
9315- attemptId: RunAttemptId.make("attempt-claude-wake-answered-3"),
9316- text: "Background task completed.",
9317- attachments: [],
9318- providerTurnOrdinal: 3,
9319- messageCreatedBy: "agent",
9320- messageCreationSource: "provider",
9321- }),
9322- );
9323- yield* TestClock.adjust("3 minutes");
9324- assert.lengthOf(
9325- harness.terminalEvents(),
9326- 3,
9327- "the continuation for an already-answered wake never settled",
9328- );
9329- assert.equal(harness.terminalEvents()[2]?.status, "completed");
9330- }).pipe(
9331- Effect.provide(
9332- Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
9317+ yield* harness.runtime.startTurn(
9318+ makeClaudeTestTurnInput({
9319+ threadId: harness.threadId,
9320+ providerThread: harness.providerThread,
9321+ now,
9322+ attemptId: RunAttemptId.make("attempt-claude-wake-answered-3"),
9323+ text: "Background task completed.",
9324+ attachments: [],
9325+ providerTurnOrdinal: 3,
9326+ messageCreatedBy: "agent",
9327+ messageCreationSource: "provider",
9328+ }),
9329+ );
9330+ yield* TestClock.adjust("3 minutes");
9331+ assert.lengthOf(
9332+ harness.terminalEvents(),
9333+ 3,
9334+ "the continuation for an already-answered wake never settled",
9335+ );
9336+ assert.equal(harness.terminalEvents()[2]?.status, "completed");
9337+ }).pipe(
9338+ Effect.provide(
9339+ Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
9340+ ),
93339341 ),
93349342 ),
9335- ),
93369343 );
93379344
93389345 it.effect("ignores a zero-turn task-notification origin result during a normal user turn", () =>
0 commit comments