@@ -7952,12 +7952,116 @@ describe("ClaudeAdapterV2 background wake turns", () => {
79527952 { autoCompactWindow: "200000", model: "claude-sonnet-4-6", threshold: undefined },
79537953 { autoCompactWindow: "650000", model: "claude-sonnet-4-6", threshold: undefined },
79547954 { autoCompactWindow: "650000", model: "uncatalogued-model", threshold: 617_000 },
7955+ {
7956+ autoCompactWindow: "",
7957+ model: "claude-opus-5-5",
7958+ userSettings: '{"autoCompactWindow":500000}',
7959+ threshold: 467_000,
7960+ },
7961+ {
7962+ autoCompactWindow: "300000",
7963+ model: "claude-opus-5-5",
7964+ userSettings: '{"autoCompactWindow":500000}',
7965+ threshold: 267_000,
7966+ },
7967+ {
7968+ autoCompactWindow: "",
7969+ model: "claude-opus-5-5",
7970+ userSettings: '{"autoCompactWindow":500000}',
7971+ projectSettings: '{"autoCompactWindow":400000}',
7972+ threshold: 367_000,
7973+ },
7974+ {
7975+ autoCompactWindow: "",
7976+ model: "claude-opus-5-5",
7977+ userSettings:
7978+ '{"autoCompactWindow":500000,"modelSettings":{"claude-opus-5-5":{"autoCompactWindow":450000}}}',
7979+ threshold: 417_000,
7980+ },
7981+ {
7982+ autoCompactWindow: "",
7983+ model: "claude-opus-5-5",
7984+ userSettings: '{"autoCompactWindow":500000}',
7985+ projectSettings: '{"modelSettings":{"claude-opus-5-5":{"autoCompactWindow":"auto"}}}',
7986+ threshold: undefined,
7987+ },
7988+ {
7989+ autoCompactWindow: "",
7990+ model: "claude-opus-5-5",
7991+ userSettings: '{"autoCompactWindow":500000}',
7992+ launchArgs: `--settings '{"autoCompactWindow":350000}'`,
7993+ threshold: 317_000,
7994+ },
7995+ {
7996+ autoCompactWindow: "",
7997+ model: "claude-opus-5-5",
7998+ userSettings: '{"autoCompactWindow":"invalid"}',
7999+ threshold: undefined,
8000+ },
8001+ {
8002+ autoCompactWindow: "",
8003+ model: "claude-opus-5-5",
8004+ userSettings: '{"autoCompactWindow":500000,}',
8005+ threshold: undefined,
8006+ },
8007+ {
8008+ autoCompactWindow: "",
8009+ model: "claude-opus-5-5",
8010+ userSettings: '{/* invalid */ "autoCompactWindow":500000}',
8011+ threshold: undefined,
8012+ },
8013+ {
8014+ autoCompactWindow: "",
8015+ model: "claude-opus-5-5",
8016+ userSettings: '{"autoCompactWindow":500000,"modelSettings":null}',
8017+ threshold: 467_000,
8018+ },
8019+ {
8020+ autoCompactWindow: "",
8021+ model: "claude-opus-5-5",
8022+ userSettings: '{"autoCompactWindow":500000}',
8023+ projectSettings: '{"autoCompactWindow":"auto"}',
8024+ threshold: 467_000,
8025+ },
8026+ {
8027+ autoCompactWindow: "",
8028+ model: "claude-opus-5-5",
8029+ userSettings: '{"autoCompactWindow":500000}',
8030+ projectSettings: '{"autoCompactWindow":50000}',
8031+ threshold: 467_000,
8032+ },
8033+ {
8034+ autoCompactWindow: "",
8035+ model: "claude-opus-5-5",
8036+ userSettings:
8037+ '{"autoCompactWindow":500000,"modelSettings":{"claude-opus-5-5":{"autoCompactWindow":50000}}}',
8038+ threshold: 467_000,
8039+ },
79558040 ])(
79568041 "ignores stale snapshots after compaction and reports threshold $autoCompactWindow for $model",
7957- ({ autoCompactWindow, model, threshold }) =>
8042+ ({ autoCompactWindow, model, threshold, userSettings, projectSettings, launchArgs }) =>
79588043 Effect.gen(function* () {
8044+ const fileSystem = yield* FileSystem.FileSystem;
8045+ const path = yield* Path.Path;
8046+ const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-compact-" });
8047+ const project = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-compact-" });
8048+ if (userSettings !== undefined) {
8049+ yield* fileSystem.writeFileString(path.join(home, "settings.json"), userSettings);
8050+ }
8051+ if (projectSettings !== undefined) {
8052+ yield* fileSystem.makeDirectory(path.join(project, ".claude"));
8053+ yield* fileSystem.writeFileString(
8054+ path.join(project, ".claude", "settings.json"),
8055+ projectSettings,
8056+ );
8057+ }
79598058 const harness = yield* makeWakeHarnessWithOptions({
7960- settings: { ...DEFAULT_CLAUDE_SETTINGS, autoCompactWindow },
8059+ settings: {
8060+ ...DEFAULT_CLAUDE_SETTINGS,
8061+ autoCompactWindow,
8062+ homePath: home,
8063+ launchArgs: launchArgs ?? "",
8064+ },
79618065 });
79628066 yield* harness.runtime.startTurn(
79638067 makeClaudeTestTurnInput({
@@ -7968,6 +8072,10 @@ describe("ClaudeAdapterV2 background wake turns", () => {
79688072 text: "Continue.",
79698073 attachments: [],
79708074 modelSelection: { ...CLAUDE_TEST_MODEL_SELECTION, model },
8075+ runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
8076+ ...CLAUDE_TEST_RUNTIME_POLICY,
8077+ cwd: project,
8078+ }),
79718079 }),
79728080 );
79738081 const usage = { ...zeroUsage, input_tokens: 1_000, output_tokens: 75 };
@@ -8013,6 +8121,89 @@ describe("ClaudeAdapterV2 background wake turns", () => {
80138121 ),
80148122 );
80158123
8124+ it.effect("reports the settings directory of a reused Claude query", () =>
8125+ Effect.gen(function* () {
8126+ const fileSystem = yield* FileSystem.FileSystem;
8127+ const path = yield* Path.Path;
8128+ const home = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-" });
8129+ const first = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-first-" });
8130+ const second = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-second-" });
8131+ for (const [directory, window] of [
8132+ [first, 150_000],
8133+ [second, 180_000],
8134+ ] as const) {
8135+ yield* fileSystem.makeDirectory(path.join(directory, ".claude"));
8136+ yield* fileSystem.writeFileString(
8137+ path.join(directory, ".claude", "settings.json"),
8138+ JSON.stringify({ autoCompactWindow: window }),
8139+ );
8140+ }
8141+ const harness = yield* makeWakeHarnessWithOptions({
8142+ settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath: home },
8143+ });
8144+ let firstOptions: ReturnType<typeof harness.getOpenedOptions>;
8145+ for (const [ordinal, cwd] of [
8146+ [1, first],
8147+ [2, second],
8148+ ] as const) {
8149+ yield* harness.runtime.startTurn(
8150+ makeClaudeTestTurnInput({
8151+ threadId: harness.threadId,
8152+ providerThread: harness.providerThread,
8153+ now: yield* DateTime.now,
8154+ attemptId: RunAttemptId.make(`attempt-compact-cwd-${ordinal}`),
8155+ providerTurnOrdinal: ordinal,
8156+ text: "Continue.",
8157+ attachments: [],
8158+ runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
8159+ ...CLAUDE_TEST_RUNTIME_POLICY,
8160+ cwd,
8161+ }),
8162+ }),
8163+ );
8164+ if (ordinal === 1) firstOptions = harness.getOpenedOptions();
8165+ else assert.strictEqual(harness.getOpenedOptions(), firstOptions);
8166+ yield* Queue.offer(
8167+ harness.sdkMessages,
8168+ usageSnapshotFrame(
8169+ `msg_cwd_${ordinal}`,
8170+ `00000000-0000-4000-8000-00000000080${ordinal}`,
8171+ {
8172+ ...zeroUsage,
8173+ input_tokens: 1_000,
8174+ output_tokens: 10,
8175+ },
8176+ ),
8177+ );
8178+ yield* Queue.offer(
8179+ harness.sdkMessages,
8180+ makeResultFrame({
8181+ uuid: `00000000-0000-4000-8000-00000000081${ordinal}`,
8182+ result: "Done.",
8183+ }),
8184+ );
8185+ assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "completed");
8186+ }
8187+ assert.deepEqual(
8188+ harness.events.flatMap((event) =>
8189+ event.type === "provider_turn.updated" && event.providerTurn.tokenUsage
8190+ ? [event.providerTurn.tokenUsage.autoCompactThreshold]
8191+ : [],
8192+ ),
8193+ [117_000, 117_000],
8194+ );
8195+ }).pipe(
8196+ Effect.provide(
8197+ Layer.mergeAll(
8198+ IdAllocator.layer,
8199+ McpProviderSessions.layer,
8200+ NodeServices.layer,
8201+ NodeCrypto.layer,
8202+ ),
8203+ ),
8204+ ),
8205+ );
8206+
80168207 it.effect("shows a hook-dropped Claude prompt once and skips info-level lines", () =>
80178208 Effect.gen(function* () {
80188209 const harness = yield* makeWakeHarness;
0 commit comments