@@ -4024,20 +4024,41 @@ describe("ClaudeAdapterV2 background wake turns", () => {
40244024 });
40254025
40264026 it.effect.each([
4027- { failure: "authentication_failed", apiErrorStatus: undefined, opensFreshProcess: true },
4028- { failure: "server_error", apiErrorStatus: undefined, opensFreshProcess: false },
4029- { failure: "authentication_failed", apiErrorStatus: 403, opensFreshProcess: false },
4027+ {
4028+ failure: "authentication_failed",
4029+ apiErrorStatus: undefined,
4030+ opensFreshProcess: true,
4031+ backgroundShell: false,
4032+ },
4033+ {
4034+ failure: "authentication_failed",
4035+ apiErrorStatus: undefined,
4036+ opensFreshProcess: true,
4037+ backgroundShell: true,
4038+ },
4039+ {
4040+ failure: "server_error",
4041+ apiErrorStatus: undefined,
4042+ opensFreshProcess: false,
4043+ backgroundShell: false,
4044+ },
4045+ {
4046+ failure: "authentication_failed",
4047+ apiErrorStatus: 403,
4048+ opensFreshProcess: false,
4049+ backgroundShell: false,
4050+ },
40304051 ] as const)(
4031- "after a turn fails with $failure (API status: $apiErrorStatus), the next turn opens a fresh process: $opensFreshProcess",
4032- ({ failure, apiErrorStatus, opensFreshProcess }) =>
4052+ "after a turn fails with $failure (API status: $apiErrorStatus), the next turn opens a fresh process: $opensFreshProcess (background shell: $backgroundShell) ",
4053+ ({ failure, apiErrorStatus, opensFreshProcess, backgroundShell }) =>
40334054 Effect.gen(function* () {
40344055 let closeCount = 0;
40354056 const harness = yield* makeWakeHarnessWithOptions({
40364057 freshQueueOnReopen: true,
4037- close: () =>
4058+ close: (messages ) =>
40384059 Effect.sync(() => {
40394060 closeCount += 1;
4040- }),
4061+ }).pipe(Effect.andThen(Queue.shutdown(messages))) ,
40414062 });
40424063 const now = yield* DateTime.now;
40434064 const startTurn = (attempt: string, text: string) =>
@@ -4053,6 +4074,7 @@ describe("ClaudeAdapterV2 background wake turns", () => {
40534074 );
40544075
40554076 yield* startTurn("attempt-claude-relogin-1", "Continue.");
4077+ if (backgroundShell) yield* harness.offerAndWait(wakeTaskStarted);
40564078 yield* Queue.offerAll(harness.sdkMessages, [
40574079 makeAssistantErrorFrame({ uuid: "00000000-0000-4000-8000-000000000611", error: failure }),
40584080 makeResultFrame({
@@ -4066,6 +4088,25 @@ describe("ClaudeAdapterV2 background wake turns", () => {
40664088 const failed = yield* Queue.take(harness.terminalReceipts);
40674089 assert.equal(failed.status, "failed");
40684090
4091+ if (backgroundShell) {
4092+ const refused = yield* startTurn("attempt-claude-relogin-blocked", "Try again.").pipe(
4093+ Effect.result,
4094+ );
4095+ assert.equal(refused._tag, "Failure");
4096+ if (refused._tag === "Failure") {
4097+ assert.instanceOf(
4098+ refused.failure.cause,
4099+ ClaudeAdapterV2.ClaudeBackgroundWorkBlocksQueryReplacementError,
4100+ );
4101+ }
4102+ assert.lengthOf(harness.processQueues, 1);
4103+ assert.equal(closeCount, 0);
4104+ yield* harness.runtime.interruptTurn({
4105+ providerThread: harness.providerThread,
4106+ providerTurnId: failed.providerTurnId,
4107+ requestRuntimeRestart: true,
4108+ });
4109+ }
40694110 yield* startTurn("attempt-claude-relogin-2", "Try again.");
40704111 assert.equal(harness.processQueues.length, opensFreshProcess ? 2 : 1);
40714112 assert.equal(closeCount, opensFreshProcess ? 1 : 0);
0 commit comments