@@ -5751,67 +5751,105 @@ describe("ClaudeAdapterV2 background wake turns", () => {
57515751 ),
57525752 );
57535753
5754- it.effect.each(["environment", "settings"])(
5755- "uses the matching proxy reset from %s when Claude omits a reset time",
5756- (source) =>
5757- Effect.gen(function* () {
5758- const fs = yield* FileSystem.FileSystem;
5759- const path = yield* Path.Path;
5760- const configDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-proxy-reset-" });
5761- if (source === "settings")
5762- yield* fs.writeFileString(
5763- path.join(configDir, "settings.json"),
5764- JSON.stringify({ env: { ANTHROPIC_BASE_URL: "https://hub.test/v1" } }),
5765- );
5766- const harness = yield* makeWakeHarnessWithOptions({
5767- environment: {
5768- CLAUDE_CONFIG_DIR: configDir,
5769- ...(source === "environment" ? { ANTHROPIC_BASE_URL: "https://hub.test/v1" } : {}),
5770- },
5771- });
5772- const now = yield* DateTime.now;
5773- yield* harness.runtime.startTurn(
5774- makeClaudeTestTurnInput({
5775- threadId: harness.threadId,
5776- providerThread: harness.providerThread,
5777- now,
5778- attemptId: RunAttemptId.make("attempt-proxy-reset"),
5779- text: "Continue.",
5780- attachments: [],
5781- }),
5754+ it.effect.each([
5755+ "environment",
5756+ "settings",
5757+ "lenient settings",
5758+ "root local",
5759+ "launch inline",
5760+ "launch file",
5761+ ])("uses the matching proxy reset from %s when Claude omits a reset time", (source) =>
5762+ Effect.gen(function* () {
5763+ const fs = yield* FileSystem.FileSystem;
5764+ const path = yield* Path.Path;
5765+ const configDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-proxy-reset-" });
5766+ if (source === "settings")
5767+ yield* fs.writeFileString(
5768+ path.join(configDir, "settings.json"),
5769+ JSON.stringify({ env: { ANTHROPIC_BASE_URL: "https://hub.test/v1" } }),
5770+ );
5771+ const cwd = path.join(configDir, "repo", "nested");
5772+ yield* fs.makeDirectory(path.join(configDir, "repo", ".git"), { recursive: true });
5773+ yield* fs.makeDirectory(path.join(cwd, ".claude"), { recursive: true });
5774+ if (source === "lenient settings")
5775+ yield* fs.writeFileString(
5776+ path.join(configDir, "settings.json"),
5777+ '{ // Claude settings allow comments and trailing commas\n "env": { "ANTHROPIC_BASE_URL": "https://hub.test/v1", }, }',
5778+ );
5779+ if (source === "root local") {
5780+ yield* fs.writeFileString(
5781+ path.join(cwd, ".claude", "settings.local.json"),
5782+ JSON.stringify({ env: { ANTHROPIC_BASE_URL: "https://wrong.test" } }),
5783+ );
5784+ yield* fs.makeDirectory(path.join(configDir, "repo", ".claude"));
5785+ yield* fs.writeFileString(
5786+ path.join(configDir, "repo", ".claude", "settings.local.json"),
5787+ JSON.stringify({ env: { ANTHROPIC_BASE_URL: "https://hub.test/v1" } }),
57825788 );
5783- yield* Queue.offerAll(harness.sdkMessages, [
5784- makeAssistantErrorFrame({
5785- uuid: "00000000-0000-4000-8000-000000000652",
5786- error: "rate_limit",
5787- }),
5788- makeResultFrame({
5789- uuid: "00000000-0000-4000-8000-000000000653",
5790- result: "Usage limit reached.",
5791- terminalReason: "blocking_limit",
5792- isError: true,
5793- apiErrorStatus: 429,
5794- }),
5795- ]);
5796- const terminal = yield* Queue.take(harness.terminalReceipts);
5797- assert.equal(terminal.status, "failed");
5798- if (terminal.status !== "failed") return;
5799- assert.equal(terminal.failure.class, "usage_limit");
5800- assert.equal(terminal.failure.resetAt, "2099-01-01T02:00:00.000Z");
5801- }).pipe(
5802- Effect.provide([
5803- IdAllocator.layer,
5804- McpProviderSessions.layer,
5805- NodeServices.layer,
5806- Layer.mock(UsageLimitSources.UsageLimitSources)({
5807- resolveResetAt: (input) => {
5808- assert.equal(input.endpoint, "https://hub.test/v1");
5809- assert.isNotEmpty(input.model);
5810- return Effect.succeed("2099-01-01T02:00:00.000Z");
5811- },
5812- }),
5813- ]),
5814- ),
5789+ }
5790+ const launchSettings = JSON.stringify({ env: { ANTHROPIC_BASE_URL: "https://hub.test/v1" } });
5791+ if (source === "launch file")
5792+ yield* fs.writeFileString(path.join(cwd, "launch.json"), launchSettings);
5793+ const harness = yield* makeWakeHarnessWithOptions({
5794+ settings: {
5795+ ...DEFAULT_CLAUDE_SETTINGS,
5796+ launchArgs:
5797+ source === "launch inline"
5798+ ? `--settings '${launchSettings}'`
5799+ : source === "launch file"
5800+ ? "--settings launch.json"
5801+ : "",
5802+ },
5803+ environment: {
5804+ CLAUDE_CONFIG_DIR: configDir,
5805+ ANTHROPIC_BASE_URL:
5806+ source === "environment" ? "https://hub.test/v1" : "https://wrong.test",
5807+ },
5808+ });
5809+ const now = yield* DateTime.now;
5810+ yield* harness.runtime.startTurn(
5811+ makeClaudeTestTurnInput({
5812+ threadId: harness.threadId,
5813+ providerThread: harness.providerThread,
5814+ now,
5815+ attemptId: RunAttemptId.make("attempt-proxy-reset"),
5816+ text: "Continue.",
5817+ attachments: [],
5818+ runtimePolicy: { ...CLAUDE_TEST_RUNTIME_POLICY, cwd },
5819+ }),
5820+ );
5821+ yield* Queue.offerAll(harness.sdkMessages, [
5822+ makeAssistantErrorFrame({
5823+ uuid: "00000000-0000-4000-8000-000000000652",
5824+ error: "rate_limit",
5825+ }),
5826+ makeResultFrame({
5827+ uuid: "00000000-0000-4000-8000-000000000653",
5828+ result: "Usage limit reached.",
5829+ terminalReason: "blocking_limit",
5830+ isError: true,
5831+ apiErrorStatus: 429,
5832+ }),
5833+ ]);
5834+ const terminal = yield* Queue.take(harness.terminalReceipts);
5835+ assert.equal(terminal.status, "failed");
5836+ if (terminal.status !== "failed") return;
5837+ assert.equal(terminal.failure.class, "usage_limit");
5838+ assert.equal(terminal.failure.resetAt, "2099-01-01T02:00:00.000Z");
5839+ }).pipe(
5840+ Effect.provide([
5841+ IdAllocator.layer,
5842+ McpProviderSessions.layer,
5843+ NodeServices.layer,
5844+ Layer.mock(UsageLimitSources.UsageLimitSources)({
5845+ resolveResetAt: (input) => {
5846+ assert.equal(input.endpoint, "https://hub.test/v1");
5847+ assert.isNotEmpty(input.model);
5848+ return Effect.succeed("2099-01-01T02:00:00.000Z");
5849+ },
5850+ }),
5851+ ]),
5852+ ),
58155853 );
58165854
58175855 it.effect.each([
0 commit comments