| ... | ... | @@ -41,13 +41,37 @@ function makeFakeClaudeBinary(dir: string) { |
| 41 | 41 | name: "claude", |
| 42 | 42 | platform, |
| 43 | 43 | source: [ |
| 44 | | 'const args = process.argv.slice(2).join(" ");', |
| 44 | "const argv = process.argv.slice(2);", |
| 45 | 'const args = argv.join(" ");', |
| 46 | 'const { realpathSync } = await import("node:fs");', |
| 45 | 47 | "", |
| 46 | 48 | "function fail(message, code) {", |
| 47 | 49 | ' process.stderr.write(message + "\\n");', |
| 48 | 50 | " process.exit(code);", |
| 49 | 51 | "}", |
| 50 | 52 | "", |
| 53 | 'const toolsIndex = argv.indexOf("--tools");', |
| 54 | 'if (toolsIndex === -1 || argv[toolsIndex + 1] !== "") {', |
| 55 | ' fail("text generation must receive an explicit empty tool set", 6);', |
| 56 | "}", |
| 57 | 'if (argv.includes("--dangerously-skip-permissions")) {', |
| 58 | ' fail("text generation must not bypass permissions", 7);', |
| 59 | "}", |
| 60 | 'if (!argv.includes("--disable-slash-commands")) {', |
| 61 | ' fail("text generation must disable skills", 8);', |
| 62 | "}", |
| 63 | 'if (!argv.includes("--strict-mcp-config")) {', |
| 64 | ' fail("text generation must not load configured MCP servers", 9);', |
| 65 | "}", |
| 66 | 'const settingsIndex = argv.indexOf("--settings");', |
| 67 | "if (settingsIndex === -1 || JSON.parse(argv[settingsIndex + 1]).disableAllHooks !== true) {", |
| 68 | ' fail("text generation must disable hooks", 10);', |
| 69 | "}", |
| 70 | "const cwdMustNotBe = process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE;", |
| 71 | "if (cwdMustNotBe && realpathSync(process.cwd()) === realpathSync(cwdMustNotBe)) {", |
| 72 | ' fail("text generation ran in the project directory", 11);', |
| 73 | "}", |
| 74 | "", |
| 51 | 75 | 'let stdinContent = "";', |
| 52 | 76 | "if (!process.stdin.isTTY) {", |
| 53 | 77 | " const chunks = [];", |
| ... | ... | @@ -100,6 +124,7 @@ function withFakeClaudeEnv<A, E, R>( |
| 100 | 124 | argsMustNotContain?: string; |
| 101 | 125 | stdinMustContain?: string; |
| 102 | 126 | configDirMustBe?: string; |
| 127 | cwdMustNotBe?: string; |
| 103 | 128 | claudeConfig?: Partial<ClaudeSettings>; |
| 104 | 129 | }, |
| 105 | 130 | effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>, |
| ... | ... | @@ -117,6 +142,7 @@ function withFakeClaudeEnv<A, E, R>( |
| 117 | 142 | const previousArgsMustNotContain = process.env.T3_FAKE_CLAUDE_ARGS_MUST_NOT_CONTAIN; |
| 118 | 143 | const previousStdinMustContain = process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN; |
| 119 | 144 | const previousConfigDirMustBe = process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE; |
| 145 | const previousCwdMustNotBe = process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE; |
| 120 | 146 | |
| 121 | 147 | yield* Effect.acquireRelease( |
| 122 | 148 | Effect.sync(() => { |
| ... | ... | @@ -153,6 +179,12 @@ function withFakeClaudeEnv<A, E, R>( |
| 153 | 179 | delete process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN; |
| 154 | 180 | } |
| 155 | 181 | |
| 182 | if (input.cwdMustNotBe !== undefined) { |
| 183 | process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE = input.cwdMustNotBe; |
| 184 | } else { |
| 185 | delete process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE; |
| 186 | } |
| 187 | |
| 156 | 188 | if (input.configDirMustBe !== undefined) { |
| 157 | 189 | process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE = input.configDirMustBe; |
| 158 | 190 | } else { |
| ... | ... | @@ -199,6 +231,12 @@ function withFakeClaudeEnv<A, E, R>( |
| 199 | 231 | process.env.T3_FAKE_CLAUDE_STDIN_MUST_CONTAIN = previousStdinMustContain; |
| 200 | 232 | } |
| 201 | 233 | |
| 234 | if (previousCwdMustNotBe === undefined) { |
| 235 | delete process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE; |
| 236 | } else { |
| 237 | process.env.T3_FAKE_CLAUDE_CWD_MUST_NOT_BE = previousCwdMustNotBe; |
| 238 | } |
| 239 | |
| 202 | 240 | if (previousConfigDirMustBe === undefined) { |
| 203 | 241 | delete process.env.T3_FAKE_CLAUDE_CONFIG_DIR_MUST_BE; |
| 204 | 242 | } else { |
| ... | ... | @@ -227,7 +265,7 @@ it.layer(ClaudeTextGenerationTestLayer)("ClaudeTextGeneration", (it) => { |
| 227 | 265 | body: "", |
| 228 | 266 | }, |
| 229 | 267 | }), |
| 230 | | argsMustContain: '--settings {"alwaysThinkingEnabled":false}', |
| 268 | argsMustContain: '--settings {"disableAllHooks":true,"alwaysThinkingEnabled":false}', |
| 231 | 269 | argsMustNotContain: "--effort", |
| 232 | 270 | }, |
| 233 | 271 | (textGeneration) => |
| ... | ... | @@ -263,7 +301,7 @@ it.layer(ClaudeTextGenerationTestLayer)("ClaudeTextGeneration", (it) => { |
| 263 | 301 | body: "", |
| 264 | 302 | }, |
| 265 | 303 | }), |
| 266 | | argsMustContain: `--model ${SYNTHETIC_CLAUDE_COLLIDING_ALIAS} --dangerously-skip-permissions`, |
| 304 | argsMustContain: `--model ${SYNTHETIC_CLAUDE_COLLIDING_ALIAS} --settings`, |
| 267 | 305 | claudeConfig: { customModels: [SYNTHETIC_CLAUDE_COLLIDING_ALIAS] }, |
| 268 | 306 | }, |
| 269 | 307 | (textGeneration) => |
| ... | ... | @@ -302,7 +340,7 @@ it.layer(ClaudeTextGenerationTestLayer)("ClaudeTextGeneration", (it) => { |
| 302 | 340 | body: "Body", |
| 303 | 341 | }, |
| 304 | 342 | }), |
| 305 | | argsMustContain: `--model ${SYNTHETIC_CLAUDE_CAPABLE_MODEL}[expanded] --effort max --settings {"fastMode":true} --dangerously-skip-permissions`, |
| 343 | argsMustContain: `--model ${SYNTHETIC_CLAUDE_CAPABLE_MODEL}[expanded] --effort max --settings {"disableAllHooks":true,"fastMode":true}`, |
| 306 | 344 | claudeConfig: { customModels: [SYNTHETIC_CLAUDE_COLLIDING_ALIAS] }, |
| 307 | 345 | }, |
| 308 | 346 | (textGeneration) => |
| ... | ... | @@ -331,33 +369,58 @@ it.layer(ClaudeTextGenerationTestLayer)("ClaudeTextGeneration", (it) => { |
| 331 | 369 | ), |
| 332 | 370 | ); |
| 333 | 371 | |
| 334 | | it.effect("generates thread titles through the Claude provider", () => |
| 372 | it.effect( |
| 373 | "generates thread titles outside the project with tools, skills, and hooks disabled", |
| 374 | () => |
| 375 | withFakeClaudeEnv( |
| 376 | { |
| 377 | output: JSON.stringify({ |
| 378 | structured_output: { |
| 379 | title: |
| 380 | ' "Reconnect failures after restart because the session state does not recover" ', |
| 381 | }, |
| 382 | }), |
| 383 | cwdMustNotBe: process.cwd(), |
| 384 | stdinMustContain: "/call-script", |
| 385 | }, |
| 386 | (textGeneration) => |
| 387 | Effect.gen(function* () { |
| 388 | const generated = yield* textGeneration.generateThreadTitle({ |
| 389 | cwd: process.cwd(), |
| 390 | message: "/call-script", |
| 391 | modelSelection: { |
| 392 | instanceId: ProviderInstanceId.make("claudeAgent"), |
| 393 | model: SYNTHETIC_CLAUDE_STANDARD_MODEL, |
| 394 | }, |
| 395 | }); |
| 396 | |
| 397 | expect(generated.title).toBe( |
| 398 | sanitizeThreadTitle( |
| 399 | '"Reconnect failures after restart because the session state does not recover"', |
| 400 | ), |
| 401 | ); |
| 402 | }), |
| 403 | ), |
| 404 | ); |
| 405 | |
| 406 | it.effect("generates branch names from skill prompts without executable capabilities", () => |
| 335 | 407 | withFakeClaudeEnv( |
| 336 | 408 | { |
| 337 | | output: JSON.stringify({ |
| 338 | | structured_output: { |
| 339 | | title: |
| 340 | | ' "Reconnect failures after restart because the session state does not recover" ', |
| 341 | | }, |
| 342 | | }), |
| 343 | | stdinMustContain: "Please investigate reconnect failures after restarting the session.", |
| 409 | output: JSON.stringify({ structured_output: { branch: "call-script" } }), |
| 410 | stdinMustContain: "/call-script", |
| 344 | 411 | }, |
| 345 | 412 | (textGeneration) => |
| 346 | 413 | Effect.gen(function* () { |
| 347 | | const generated = yield* textGeneration.generateThreadTitle({ |
| 414 | const generated = yield* textGeneration.generateBranchName({ |
| 348 | 415 | cwd: process.cwd(), |
| 349 | | message: "Please investigate reconnect failures after restarting the session.", |
| 416 | message: "/call-script", |
| 350 | 417 | modelSelection: { |
| 351 | 418 | instanceId: ProviderInstanceId.make("claudeAgent"), |
| 352 | 419 | model: SYNTHETIC_CLAUDE_STANDARD_MODEL, |
| 353 | 420 | }, |
| 354 | 421 | }); |
| 355 | 422 | |
| 356 | | expect(generated.title).toBe( |
| 357 | | sanitizeThreadTitle( |
| 358 | | '"Reconnect failures after restart because the session state does not recover"', |
| 359 | | ), |
| 360 | | ); |
| 423 | expect(generated.branch).toBe("call-script"); |
| 361 | 424 | }), |
| 362 | 425 | ), |
| 363 | 426 | ); |