Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CodexTextGeneration.test.ts

654 lines24.3 KB

1import {
2 DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER,
3 ProviderDriverKind,
4 type ModelSelection,
5 type ServerProvider,
6} from "@t3tools/contracts";
7import type { ProviderInstance } from "@t3tools/provider-core/server/driver";
8import * as ProviderInstanceRegistry from "../provider/ProviderInstanceRegistry.ts";
9import * as ServerSettings from "../serverSettings.ts";
10import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts";
11import * as NodeServices from "@effect/platform-node/NodeServices";
12import { it } from "@effect/vitest";
13import * as Cause from "effect/Cause";
14import * as Effect from "effect/Effect";
15import * as Exit from "effect/Exit";
16import * as Fiber from "effect/Fiber";
17import * as FileSystem from "effect/FileSystem";
18import * as Layer from "effect/Layer";
19import * as Path from "effect/Path";
20import * as Schema from "effect/Schema";
21import * as Scope from "effect/Scope";
22import { createModelSelection } from "@t3tools/shared/model";
23import { expect } from "vite-plus/test";
24​
25import { CodexSettings, ProviderInstanceId } from "@t3tools/contracts";
26​
27import * as ServerConfig from "../config.ts";
28import { makeProcessProbe, processProbeSource } from "../testUtils/processProbe.ts";
29import * as TextGeneration from "./TextGeneration.ts";
30import { makeCodexTextGeneration } from "./CodexTextGeneration.ts";
31import { writeFakeCli } from "@t3tools/provider-testing/fakeCli";
32const decodeCodexSettings = Schema.decodeSync(CodexSettings);
33​
34const DEFAULT_TEST_MODEL_SELECTION = createModelSelection(
35 ProviderInstanceId.make("codex"),
36 "gpt-5.4-mini",
37);
38​
39const layerCodexTextGenerationTest = ServerConfig.ServerConfig.layerTest(process.cwd(), {
40 prefix: "t3code-codex-text-generation-test-",
41}).pipe(Layer.provideMerge(NodeServices.layer));
42​
43interface FakeCodexInput {
44 output: string;
45 lifecycle?: { port: number; command: "exec" | "mcp list" };
46 exitCode?: number;
47 stderr?: string;
48 requireImage?: boolean;
49 requireServiceTier?: string;
50 requireReasoningEffort?: string;
51 forbidReasoningEffort?: boolean;
52 requireArg?: string;
53 forbidArg?: string;
54 stdinMustContain?: string;
55 stdinMustNotContain?: string;
56 mcpServers?: ReadonlyArray<{ name: string; enabled: boolean }> | number;
57 requiredCwd?: string;
58 requireInstructions?: string;
60​
61function makeFakeCodexBinary(dir: string, input: FakeCodexInput) {
62 const check = JSON.stringify({
63 requireImage: input.requireImage ?? false,
64 requireServiceTier: input.requireServiceTier ?? null,
65 requireReasoningEffort: input.requireReasoningEffort ?? null,
66 forbidReasoningEffort: input.forbidReasoningEffort ?? false,
67 requireArg: input.requireArg ?? null,
68 forbidArg: input.forbidArg ?? null,
69 stdinMustContain: input.stdinMustContain ?? null,
70 stdinMustNotContain: input.stdinMustNotContain ?? null,
71 mcpServers: input.mcpServers ?? [],
72 requiredCwd: input.requiredCwd ?? null,
73 requireInstructions: input.requireInstructions ?? null,
74 stderr: input.stderr ?? null,
75 output: input.output,
76 exitCode: input.exitCode ?? 0,
77 });
78 return Effect.gen(function* () {
79 const path = yield* Path.Path;
80 return writeFakeCli({
81 directory: path.join(dir, "bin"),
82 name: "codex",
83 source: [
84 'import * as NodeFS from "node:fs";',
85 `const check = ${check};`,
86 "const args = process.argv.slice(2);",
87 'const isMcpList = args.includes("mcp") && args.includes("list");',
88 ...(input.lifecycle === undefined
89 ? []
90 : [
91 `if (isMcpList === ${input.lifecycle.command === "mcp list"}) {`,
92 'process.on("SIGTERM", () => {});',
93 processProbeSource(input.lifecycle.port),
94 "await new Promise(() => {});",
95 "}",
96 ]),
97 "if (isMcpList) {",
98 ' if (typeof check.mcpServers === "number") process.exit(check.mcpServers);',
99 " process.stdout.write(JSON.stringify(check.mcpServers));",
100 " process.exit(0);",
101 "}",
102 'const originalArgs = ` ${args.join(" ")} `;',
103 "let outputPath = null;",
104 "let seenImage = false;",
105 'let seenServiceTier = "";',
106 'let seenReasoningEffort = "";',
107 'let instructions = "";',
108 "for (let index = 0; index < args.length; index += 1) {",
109 ' if (args[index] === "--image") {',
110 " index += 1;",
111 " if (args[index]) seenImage = true;",
112 ' } else if (args[index] === "--config") {',
113 " index += 1;",
114 ' const value = args[index] ?? "";',
115 ' if (value.startsWith("developer_instructions=")) instructions = JSON.parse(value.slice("developer_instructions=".length));',
116 ' if (value.startsWith("service_tier=")) seenServiceTier = value;',
117 ' if (value.startsWith("model_reasoning_effort=")) seenReasoningEffort = value;',
118 ' } else if (args[index] === "--output-last-message") {',
119 " index += 1;",
120 " outputPath = args[index] ?? null;",
121 " }",
122 "}",
123 "const chunks = [];",
124 "for await (const chunk of process.stdin) chunks.push(chunk);",
125 'const stdinContent = Buffer.concat(chunks).toString("utf8");',
126 "function fail(message, code) {",
127 ' process.stderr.write(message + "\\n");',
128 " process.exit(code);",
129 "}",
130 'if (check.requiredCwd !== null && process.cwd() !== check.requiredCwd) fail("cannot inspect checkout", 10);',
131 'if (check.requireInstructions !== null && !instructions.includes(check.requireInstructions)) fail("missing writer task", 11);',
132 "if (check.requireArg !== null && !originalArgs.includes(` ${check.requireArg} `)) {",
133 ' fail("missing arg: " + check.requireArg, 8);',
134 "}",
135 "if (check.forbidArg !== null && originalArgs.includes(` ${check.forbidArg} `)) {",
136 ' fail("forbidden arg: " + check.forbidArg, 9);',
137 "}",
138 'if (check.requireImage && !seenImage) fail("missing --image input", 2);',
139 "if (",
140 " check.requireServiceTier !== null &&",
141 ' seenServiceTier !== `service_tier="${check.requireServiceTier}"`',
142 ") {",
143 ' fail("unexpected service tier config: " + seenServiceTier, 5);',
144 "}",
145 "if (",
146 " check.requireReasoningEffort !== null &&",
147 ' seenReasoningEffort !== `model_reasoning_effort="${check.requireReasoningEffort}"`',
148 ") {",
149 ' fail("unexpected reasoning effort config: " + seenReasoningEffort, 6);',
150 "}",
151 "if (check.forbidReasoningEffort && seenReasoningEffort.length > 0) {",
152 ' fail("reasoning effort config should be omitted: " + seenReasoningEffort, 7);',
153 "}",
154 "if (check.stdinMustContain !== null && !stdinContent.includes(check.stdinMustContain)) {",
155 ' fail("stdin missing expected content", 3);',
156 "}",
157 "if (check.stdinMustNotContain !== null && stdinContent.includes(check.stdinMustNotContain)) {",
158 ' fail("stdin contained forbidden content", 4);',
159 "}",
160 'if (check.stderr !== null) process.stderr.write(check.stderr + "\\n");',
161 'if (outputPath !== null) NodeFS.writeFileSync(outputPath, check.output + "\\n");',
162 "process.exitCode = check.exitCode;",
163 "",
164 ].join("\n"),
165 });
166 });
168​
169function withFakeCodexEnv<A, E, R>(
170 input: FakeCodexInput & {
171 launchArgs?: string;
172 environment?: NodeJS.ProcessEnv;
173 models?: ReadonlyArray<string>;
174 defaultModel?: string;
175 customModels?: ReadonlyArray<string>;
176 managedRuntime?: boolean;
177 },
178 effectFn: (textGeneration: TextGeneration.TextGeneration["Service"]) => Effect.Effect<A, E, R>,
179) {
180 return Effect.gen(function* () {
181 const fs = yield* FileSystem.FileSystem;
182 const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3code-codex-text-" });
183 const codexPath = yield* makeFakeCodexBinary(tempDir, input);
184 const config = decodeCodexSettings({
185 binaryPath: codexPath,
186 launchArgs: input.launchArgs,
187 customModels: input.customModels,
188 });
189 const textGeneration = yield* makeCodexTextGeneration(
190 config,
191 input.environment === undefined ? undefined : { ...process.env, ...input.environment },
192 Effect.succeed(
193 (input.models ?? []).map((slug) => ({
194 slug,
195 name: slug,
196 isCustom: false,
197 ...(slug === input.defaultModel ? { isDefault: true } : {}),
198 capabilities: null,
199 })),
200 ),
201 input.managedRuntime
202 ? Effect.succeed({
203 config,
204 environment: input.environment ?? process.env,
205 revision: "test",
206 })
207 : undefined,
208 );
209 return yield* effectFn(textGeneration);
210 }).pipe(Effect.scoped);
212​
213it.layer(layerCodexTextGenerationTest)("CodexTextGeneration", (it) => {
214 it.effect.each(["exec", "mcp list"] as const)(
215 "kills a stalled %s CLI when its request is interrupted",
216 (command) =>
217 Effect.gen(function* () {
218 const probe = yield* makeProcessProbe;
219 yield* withFakeCodexEnv(
220 { output: "", lifecycle: { port: probe.port, command } },
221 (textGeneration) =>
222 Effect.gen(function* () {
223 const fiber = yield* textGeneration
224 .generateThreadTitle({
225 cwd: process.cwd(),
226 message: "Name this thread",
227 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
228 })
229 .pipe(Effect.forkScoped);
230 yield* probe.started;
231​
232 const interrupted = yield* Fiber.interrupt(fiber).pipe(Effect.forkScoped);
233 yield* probe.exited;
234 yield* Fiber.join(interrupted);
235 const exit = yield* Fiber.await(fiber);
236 expect(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)).toBe(true);
237 }),
238 );
239 }),
240 );
241​
242 it.effect.each([
243 {
244 selectedModel: "gpt-5.6-luna",
245 models: ["openai.gpt-5.6-luna"],
246 expected: "openai.gpt-5.6-luna",
247 },
248 {
249 selectedModel: "openai.gpt-5.6-luna",
250 models: ["openai.gpt-5.6-luna"],
251 expected: "openai.gpt-5.6-luna",
252 },
253 {
254 selectedModel: "openai.gpt-5.6-luna",
255 models: ["gpt-6-astra", "gpt-5.6-luna"],
256 defaultModel: "gpt-6-astra",
257 expected: "gpt-5.6-luna",
258 },
259 {
260 selectedModel: "gpt-6-luna",
261 models: ["gpt-5.6-luna", "gpt-6-astra"],
262 defaultModel: "gpt-6-astra",
263 expected: "gpt-6-astra",
264 },
265 { selectedModel: "gpt-6-luna", models: ["gpt-5.6-luna"], expected: "gpt-5.6-luna" },
266 { selectedModel: "gpt-6-luna", models: [], expected: "gpt-6-luna" },
267 ])(
268 "dispatches $expected for $selectedModel from $models",
269 ({ selectedModel, models, defaultModel, expected }) =>
270 withFakeCodexEnv(
271 {
272 output: JSON.stringify({ title: "Live title" }),
273 models,
274 ...(defaultModel ? { defaultModel } : {}),
275 requireArg: `--model ${expected}`,
276 },
277 (textGeneration) =>
278 Effect.gen(function* () {
279 const result = yield* textGeneration.generateThreadTitle({
280 cwd: process.cwd(),
281 message: "Describe this change",
282 modelSelection: createModelSelection(ProviderInstanceId.make("codex"), selectedModel),
283 });
284 expect(result.title).toBe("Live title");
285 }),
286 ),
287 );
288​
289 it.effect("drops the requested model's options when falling back to another model", () =>
290 withFakeCodexEnv(
291 {
292 output: JSON.stringify({ title: "Live title" }),
293 models: ["gpt-6-astra"],
294 requireArg: '--model gpt-6-astra --config model_reasoning_effort="low"',
295 forbidArg: 'service_tier="priority"',
296 },
297 (textGeneration) =>
298 textGeneration.generateThreadTitle({
299 cwd: process.cwd(),
300 message: "Describe this change",
301 modelSelection: createModelSelection(ProviderInstanceId.make("codex"), "gpt-6-luna", [
302 { id: "reasoningEffort", value: "none" },
303 { id: "serviceTier", value: "priority" },
304 ]),
305 }),
306 ),
307 );
308​
309 it.effect("sends a configured custom model the managed snapshot leaves out", () =>
310 withFakeCodexEnv(
311 {
312 output: JSON.stringify({ title: "Live title" }),
313 models: ["gpt-6-astra", "gpt-5.6-luna"],
314 defaultModel: "gpt-6-astra",
315 customModels: ["gpt-5.6-luna-preview"],
316 managedRuntime: true,
317 requireArg: '--model gpt-5.6-luna-preview --config model_reasoning_effort="high"',
318 },
319 (textGeneration) =>
320 textGeneration.generateThreadTitle({
321 cwd: process.cwd(),
322 message: "Describe this change",
323 modelSelection: createModelSelection(
324 ProviderInstanceId.make("codex"),
325 "gpt-5.6-luna-preview",
326 [{ id: "reasoningEffort", value: "high" }],
327 ),
328 }),
329 ),
330 );
331​
332 it.effect("omits a persisted service tier for managed ChatGPT text generation", () =>
333 withFakeCodexEnv(
334 {
335 output: JSON.stringify({ subject: "Update project", body: "" }),
336 managedRuntime: true,
337 forbidArg: 'service_tier="priority"',
338 },
339 (textGeneration) =>
340 textGeneration.generateCommitMessage({
341 cwd: process.cwd(),
342 branch: "feature/chatgpt",
343 stagedSummary: "M README.md",
344 stagedPatch: "diff --git a/README.md b/README.md",
345 modelSelection: createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.4", [
346 { id: "serviceTier", value: "priority" },
347 ]),
348 }),
349 ),
350 );
351​
352 it.effect("preserves custom PR instructions while allowing checkout inspection", () =>
353 withFakeCodexEnv(
354 {
355 output: JSON.stringify({ title: "Remove default shapes", body: "Removes default shapes." }),
356 launchArgs: "--config 'developer_instructions=\"Use TEAM: as the PR title prefix\"'",
357 requiredCwd: process.cwd(),
358 requireInstructions: "Use TEAM: as the PR title prefix",
359 forbidArg: "--config features.shell_tool=false",
360 mcpServers: [
361 { name: "augmenter", enabled: true },
362 { name: "my.server", enabled: true },
363 { name: "already-off", enabled: false },
364 ],
365 requireArg:
366 '--config features.plugins=false --config features.apps=false --config mcp_servers={"augmenter"={enabled=false},"my.server"={enabled=false}}',
367 },
368 (textGeneration) =>
369 Effect.gen(function* () {
370 const result = yield* textGeneration.generatePrContent({
371 cwd: process.cwd(),
372 baseBranch: "main",
373 headBranch: "remove-default-shapes",
374 commitSummary: "Remove default shapes",
375 diffSummary: "shapes.ts | 2 --",
376 diffPatch: "-addDefaultShapes();",
377 threadContext: "user: in a few minutes PR will be up then $babysit-pr",
378 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
379 });
380 expect(result.title).toBe("Remove default shapes");
381 }),
382 ),
383 );
384​
385 it.effect("still generates when Codex cannot list its MCP servers", () =>
386 withFakeCodexEnv(
387 {
388 output: JSON.stringify({ branch: "remove-default-shapes" }),
389 mcpServers: 2,
390 requireArg: "--config features.plugins=false --config features.apps=false --ephemeral",
391 forbidArg: "mcp_servers=",
392 },
393 (textGeneration) =>
394 Effect.gen(function* () {
395 const result = yield* textGeneration.generateBranchName({
396 cwd: process.cwd(),
397 message: "Remove default shapes from characters",
398 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
399 });
400 expect(result.branch).toBe("remove-default-shapes");
401 }),
402 ),
403 );
404​
405 it.effect("keeps plugins and apps off over launch args that turn them on", () =>
406 withFakeCodexEnv(
407 {
408 output: JSON.stringify({ title: "Remove default shapes" }),
409 launchArgs: "--config features.plugins=true --config features.apps=true",
410 requireArg:
411 "--config features.plugins=true --config features.apps=true --config features.plugins=false --config features.apps=false --ephemeral",
412 },
413 (textGeneration) =>
414 Effect.gen(function* () {
415 const result = yield* textGeneration.generateThreadTitle({
416 cwd: process.cwd(),
417 message: "Remove default shapes from characters",
418 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
419 });
420 expect(result.title).toBe("Remove default shapes");
421 }),
422 ),
423 );
424​
425 it.effect("passes exec-safe launch args into codex exec", () =>
426 withFakeCodexEnv(
427 {
428 output: JSON.stringify({
429 subject: "Add important change",
430 body: "",
431 }),
432 launchArgs: "--strict-config --listen off",
433 requireArg: "--strict-config",
434 forbidArg: "--listen",
435 },
436 (textGeneration) =>
437 textGeneration.generateCommitMessage({
438 cwd: process.cwd(),
439 branch: "feature/codex-effect",
440 stagedSummary: "M README.md",
441 stagedPatch: "diff --git a/README.md b/README.md",
442 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
443 }),
444 ),
445 );
446​
447 it.effect("generates branch names even when the ambient scope is already closed", () =>
448 withFakeCodexEnv(
449 {
450 output: JSON.stringify({
451 branch: "feat/background-generation",
452 }),
453 },
454 (textGeneration) =>
455 Effect.gen(function* () {
456 // Background fibers can outlive request scopes; temp files scoped there would be reaped on creation.
457 const closedScope = yield* Scope.make();
458 yield* Scope.close(closedScope, Exit.void);
459​
460 const generated = yield* textGeneration
461 .generateBranchName({
462 cwd: process.cwd(),
463 message: "Please update session handling.",
464 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
465 })
466 .pipe(Effect.provideService(Scope.Scope, closedScope));
467​
468 expect(generated.branch).toBe("feat/background-generation");
469 }),
470 ),
471 );
472​
473 it.effect("returns the refinement signal for an unresolved subject", () =>
474 withFakeCodexEnv(
475 { output: JSON.stringify({ title: "Investigate issue", needsRefinement: true }) },
476 (textGeneration) =>
477 Effect.gen(function* () {
478 expect(
479 yield* textGeneration.generateThreadTitle({
480 cwd: process.cwd(),
481 message: "Fix this",
482 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
483 }),
484 ).toEqual({ title: "Investigate issue", needsRefinement: true });
485 }),
486 ),
487 );
488​
489 it.effect("resolves persisted attachment ids to files for codex image inputs", () =>
490 withFakeCodexEnv(
491 {
492 output: JSON.stringify({
493 branch: "fix/ui-regression",
494 }),
495 requireImage: true,
496 },
497 (textGeneration) =>
498 Effect.gen(function* () {
499 const fs = yield* FileSystem.FileSystem;
500 const path = yield* Path.Path;
501 const { attachmentsDir } = yield* ServerConfig.ServerConfig;
502 const attachmentId = "thread-1-attachment";
503 const imagePath = path.join(attachmentsDir, `${attachmentId}.png`);
504 yield* fs.makeDirectory(attachmentsDir, { recursive: true });
505 yield* fs.writeFile(imagePath, Buffer.from("hello"));
506​
507 const generated = yield* textGeneration
508 .generateBranchName({
509 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
510 cwd: process.cwd(),
511 message: "Fix layout bug from screenshot.",
512 attachments: [
513 {
514 type: "image",
515 id: attachmentId,
516 name: "bug.png",
517 mimeType: "image/png",
518 sizeBytes: 5,
519 },
520 ],
521 })
522 .pipe(
523 Effect.tap(() =>
524 fs.stat(imagePath).pipe(
525 Effect.map((fileInfo) => {
526 expect(fileInfo.type).toBe("File");
527 }),
528 ),
529 ),
530 Effect.ensuring(fs.remove(imagePath).pipe(Effect.ignore)),
531 );
532​
533 expect(generated.branch).toBe("fix/ui-regression");
534 }),
535 ),
536 );
537});
538​
539const PREFLIGHT_PRIMARY_STATES = [
540 "ready",
541 "pending",
542 "exhausted",
543 "not installed",
544 "signed out",
545 "signed out, fallback failed",
546] as const;
547​
548it.effect.each(PREFLIGHT_PRIMARY_STATES)("text generation preflight: %s", (primaryState) =>
549 Effect.gen(function* () {
550 const primary = ProviderInstanceId.make("codex");
551 const fallback = ProviderInstanceId.make("claude_work");
552 const selection = {
553 instanceId: primary,
554 model: "chat-model",
555 options: [{ id: "effort", value: "high" }],
556 };
557 const calls: ModelSelection[] = [];
558 const instances: ProviderInstance[] = [primary, fallback].map((instanceId) => {
559 const driver = ProviderDriverKind.make(instanceId === primary ? "codex" : "claudeAgent");
560 const snapshot: ServerProvider = {
561 instanceId,
562 driver,
563 enabled: true,
564 installed: true,
565 status: "ready",
566 auth: { status: "authenticated" },
567 version: null,
568 checkedAt: "1970-01-01T00:00:00Z",
569 models: [],
570 slashCommands: [],
571 skills: [],
572 ...(primaryState === "pending" && instanceId === primary
573 ? { installed: false, status: "warning", auth: { status: "unknown" } }
574 : {}),
575 ...(primaryState === "not installed" && instanceId === primary
576 ? { installed: false, status: "error", auth: { status: "unknown" } }
577 : {}),
578 ...(primaryState.startsWith("signed out") && instanceId === primary
579 ? { status: "error", auth: { status: "unauthenticated" } }
580 : {}),
581 ...(primaryState === "signed out, fallback failed" && instanceId === fallback
582 ? { status: "error", auth: { status: "unknown" } }
583 : {}),
584 ...(primaryState === "exhausted" && instanceId === primary
585 ? {
586 usageLimits: {
587 checkedAt: "1970-01-01T00:00:00Z",
588 windows: [{ id: "session", kind: "session", label: "Session", usedPercent: 100 }],
589 },
590 }
591 : {}),
592 };
593 return {
594 instanceId,
595 driverKind: driver,
596 continuationIdentity: { driverKind: driver, continuationKey: instanceId },
597 displayName: undefined,
598 enabled: true,
599 snapshot: { getSnapshot: Effect.succeed(snapshot) } as ProviderInstance["snapshot"],
600 orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
601 textGeneration: TextGeneration.TextGeneration.of({
602 generateCommitMessage: () => Effect.die("unused"),
603 generatePrContent: () => Effect.die("unused"),
604 generateBranchName: () => Effect.die("unused"),
605 generateReviewGuide: () => Effect.die("unused"),
606 generateTranscriptionPostProcessing: () => Effect.die("unused"),
607 generateThreadTitle: (input) =>
608 Effect.sync(() => {
609 calls.push(input.modelSelection);
610 return { title: "Generated title" };
611 }),
612 }),
613 };
614 });
615 const service = yield* TextGeneration.make.pipe(
616 Effect.provide(
617 Layer.mergeAll(
618 Layer.mock(ProviderInstanceRegistry.ProviderInstanceRegistry)({
619 listInstances: Effect.succeed(instances),
620 getInstance: (id) =>
621 Effect.succeed(instances.find((instance) => instance.instanceId === id)),
622 }),
623 ServerSettings.layerTest({
624 providerInstances: {
625 [fallback]: { driver: ProviderDriverKind.make("claudeAgent"), config: {} },
626 },
627 }),
628 Layer.mock(SourceControlProviderRegistry.SourceControlProviderRegistry)({
629 resolveLink: () => Effect.die("unused"),
630 }),
631 ),
632 ),
633 );
634 expect(
635 yield* service.generateThreadTitle({
636 cwd: "/tmp",
637 message: "hello",
638 linkedContext: "",
639 modelSelection: selection,
640 }),
641 ).toEqual({ title: "Generated title" });
642 expect(calls).toEqual([
643 primaryState === "ready" ||
644 primaryState === "pending" ||
645 primaryState === "signed out, fallback failed"
646 ? selection
647 : {
648 instanceId: fallback,
649 model:
650 DEFAULT_TEXT_GENERATION_MODEL_BY_PROVIDER[ProviderDriverKind.make("claudeAgent")],
651 },
652 ]);
653 }),
654);