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

textGeneration.test.ts

640 lines24.1 KB

1import { ProviderInstanceId, settingsSecretLiteral, TextGenerationError } from "@t3tools/contracts";
2import { OpenCodeSettings } from "../settings.ts";
3import * as NodeServices from "@effect/platform-node/NodeServices";
4import { it } from "@effect/vitest";
5import * as Cause from "effect/Cause";
6import * as Deferred from "effect/Deferred";
7import * as Duration from "effect/Duration";
8import * as Effect from "effect/Effect";
9import * as Exit from "effect/Exit";
10import * as Fiber from "effect/Fiber";
11import * as Layer from "effect/Layer";
12import * as Schema from "effect/Schema";
13import * as TestClock from "effect/testing/TestClock";
14import * as NetService from "@t3tools/shared/Net";
15import { beforeEach, expect } from "vite-plus/test";
16​
17import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
18import * as OpenCodeRuntime from "./OpenCodeRuntime.ts";
19import * as OpenCodeServerOwner from "./OpenCodeServerOwner.ts";
20import * as OpenCodeTextGeneration from "./textGeneration.ts";
21import type { ProviderTextGeneration } from "@t3tools/provider-core/server/textGeneration";
22​
23const runtimeMock = {
24 state: {
25 startCalls: [] as string[],
26 promptUrls: [] as string[],
27 promptParts: [] as ReadonlyArray<unknown>[],
28 authHeaders: [] as Array<string | null>,
29 closeCalls: [] as string[],
30 sessionCreateCalls: 0,
31 sessionCalls: [] as string[],
32 onSessionCreate: undefined as ((signal?: AbortSignal) => Promise<never>) | undefined,
33 onPrompt: undefined as
34 | ((signal?: AbortSignal) => Promise<{ data: { parts: ReadonlyArray<unknown> } }>)
35 | undefined,
36 onAbort: undefined as ((signal?: AbortSignal) => Promise<never>) | undefined,
37 connectionError: undefined as Error | undefined,
38 sessionCreateError: undefined as unknown,
39 sessionResult: undefined as { data?: { id: string } } | undefined,
40 promptRequestError: undefined as unknown,
41 promptResult: undefined as
42 | { data?: { info?: { error?: unknown }; parts?: Array<unknown> } }
43 | undefined,
44 },
45 reset() {
46 this.state.startCalls.length = 0;
47 this.state.promptUrls.length = 0;
48 this.state.promptParts.length = 0;
49 this.state.authHeaders.length = 0;
50 this.state.closeCalls.length = 0;
51 this.state.sessionCreateCalls = 0;
52 this.state.sessionCalls.length = 0;
53 this.state.onSessionCreate = undefined;
54 this.state.onPrompt = undefined;
55 this.state.onAbort = undefined;
56 this.state.connectionError = undefined;
57 this.state.sessionCreateError = undefined;
58 this.state.sessionResult = undefined;
59 this.state.promptRequestError = undefined;
60 this.state.promptResult = undefined;
61 },
62};
63​
64const OpenCodeRuntimeTestDouble: OpenCodeRuntime.OpenCodeRuntime["Service"] = {
65 startOpenCodeServerProcess: ({ binaryPath, serverPassword, environment }) =>
66 Effect.gen(function* () {
67 const index = runtimeMock.state.startCalls.length + 1;
68 const url = `http://127.0.0.1:${4_300 + index}`;
69 runtimeMock.state.startCalls.push(binaryPath);
70 yield* Effect.addFinalizer(() =>
71 Effect.sync(() => {
72 runtimeMock.state.closeCalls.push(url);
73 }),
74 );
75 const effectiveServerPassword = OpenCodeRuntime.resolveOpenCodeServerPassword({
76 external: false,
77 ...(serverPassword !== undefined ? { serverPassword } : {}),
78 ...(environment !== undefined ? { environment } : {}),
79 });
80 return {
81 url,
82 ...(effectiveServerPassword !== undefined
83 ? { serverPassword: effectiveServerPassword }
84 : {}),
85 version: "1.14.19",
86 isRunning: Effect.succeed(true),
87 exitCode: Effect.never,
88 };
89 }),
90 connectToOpenCodeServer: ({ serverUrl, serverPassword }) =>
91 runtimeMock.state.connectionError
92 ? Effect.fail(
93 new OpenCodeRuntime.OpenCodeRuntimeError({
94 operation: "global.health",
95 detail: runtimeMock.state.connectionError.message,
96 cause: runtimeMock.state.connectionError,
97 }),
98 )
99 : Effect.succeed({
100 url: serverUrl ?? "http://127.0.0.1:4301",
101 ...(serverPassword ? { serverPassword } : {}),
102 version: "1.14.19",
103 exitCode: null,
104 external: Boolean(serverUrl),
105 }),
106 runOpenCodeCommand: () => Effect.succeed({ stdout: "", stderr: "", code: 0 }),
107 createOpenCodeSdkClient: ({ baseUrl, serverPassword }) =>
108 ({
109 session: {
110 create: async (_input: unknown, options?: { readonly signal?: AbortSignal }) => {
111 runtimeMock.state.sessionCreateCalls += 1;
112 if (runtimeMock.state.onSessionCreate) {
113 return runtimeMock.state.onSessionCreate(options?.signal);
114 }
115 if (runtimeMock.state.sessionCreateError !== undefined) {
116 throw runtimeMock.state.sessionCreateError;
117 }
118 return runtimeMock.state.sessionResult ?? { data: { id: `${baseUrl}/session` } };
119 },
120 abort: async (
121 input: { readonly sessionID: string },
122 options?: { readonly signal?: AbortSignal },
123 ) => {
124 runtimeMock.state.sessionCalls.push(`abort ${input.sessionID}`);
125 if (runtimeMock.state.onAbort) return runtimeMock.state.onAbort(options?.signal);
126 return { data: true };
127 },
128 delete: async (input: { readonly sessionID: string }) => {
129 runtimeMock.state.sessionCalls.push(`delete ${input.sessionID}`);
130 return { data: true };
131 },
132 prompt: async (
133 input: { readonly parts: ReadonlyArray<unknown> },
134 options?: { readonly signal?: AbortSignal },
135 ) => {
136 runtimeMock.state.promptUrls.push(baseUrl);
137 runtimeMock.state.promptParts.push(input.parts);
138 runtimeMock.state.authHeaders.push(
139 serverPassword ? `Basic ${btoa(`opencode:${serverPassword}`)}` : null,
140 );
141 if (runtimeMock.state.onPrompt) return runtimeMock.state.onPrompt(options?.signal);
142 if (runtimeMock.state.promptRequestError !== undefined) {
143 throw runtimeMock.state.promptRequestError;
144 }
145 return (
146 runtimeMock.state.promptResult ?? {
147 data: {
148 parts: [
149 {
150 type: "text",
151 text: JSON.stringify({
152 subject: "Improve OpenCode reuse",
153 body: "Reuse one server for the full action.",
154 }),
155 },
156 ],
157 },
158 }
159 );
160 },
161 },
162 }) as unknown as ReturnType<
163 OpenCodeRuntime.OpenCodeRuntime["Service"]["createOpenCodeSdkClient"]
164 >,
165 loadOpenCodeInventory: () =>
166 Effect.fail(
167 new OpenCodeRuntime.OpenCodeRuntimeError({
168 operation: "loadOpenCodeInventory",
169 detail: "OpenCodeRuntimeTestDouble.loadOpenCodeInventory not used in this test",
170 cause: null,
171 }),
172 ),
173 loadOpenCodeSkills: () => Effect.succeed([]),
174};
175​
176const DEFAULT_TEST_MODEL_SELECTION = {
177 instanceId: ProviderInstanceId.make("opencode"),
178 model: "openai/gpt-5",
179};
180const DEFAULT_COMMIT_MESSAGE_INPUT = {
181 cwd: process.cwd(),
182 branch: "feature/opencode-reuse",
183 stagedSummary: "M README.md",
184 stagedPatch: "diff --git a/README.md b/README.md",
185 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
186};
187​
188const OPENCODE_TEXT_GENERATION_IDLE_TTL_MS = 30_000;
189​
190const layerOpenCodeTextGenerationTest = Layer.succeed(
191 OpenCodeRuntime.OpenCodeRuntime,
192 OpenCodeRuntimeTestDouble,
193).pipe(
194 Layer.provideMerge(TestProviderHost.layer()),
195 Layer.provideMerge(NetService.layer),
196 Layer.provideMerge(NodeServices.layer),
197);
198​
199const layerOpenCodeTextGenerationExistingServerTest = Layer.succeed(
200 OpenCodeRuntime.OpenCodeRuntime,
201 OpenCodeRuntimeTestDouble,
202).pipe(
203 Layer.provideMerge(TestProviderHost.layer()),
204 Layer.provideMerge(NetService.layer),
205 Layer.provideMerge(NodeServices.layer),
206);
207​
208const DEFAULT_OPENCODE_SETTINGS = Schema.decodeSync(OpenCodeSettings)({
209 binaryPath: "fake-opencode",
210});
211const EXISTING_SERVER_OPENCODE_SETTINGS = Schema.decodeSync(OpenCodeSettings)({
212 binaryPath: "fake-opencode",
213 serverUrl: "http://127.0.0.1:9999",
214 serverPassword: "secret-password",
215});
216const EXTERNAL_SERVER_WITHOUT_AUTH_OPENCODE_SETTINGS = Schema.decodeSync(OpenCodeSettings)({
217 binaryPath: "fake-opencode",
218 serverUrl: "http://127.0.0.1:9999",
219});
220​
221function withOpenCodeTextGeneration<A, E, R>(
222 settings: OpenCodeSettings,
223 effectFn: (textGeneration: ProviderTextGeneration) => Effect.Effect<A, E, R>,
224 environment?: NodeJS.ProcessEnv,
225) {
226 return Effect.gen(function* () {
227 const serverOwner = yield* OpenCodeServerOwner.make({
228 binaryPath: settings.binaryPath,
229 directory: process.cwd(),
230 ...(settingsSecretLiteral(settings.serverPassword)
231 ? { serverPassword: settingsSecretLiteral(settings.serverPassword) }
232 : {}),
233 ...(environment ? { environment } : {}),
234 });
235 const textGeneration = yield* OpenCodeTextGeneration.makeOpenCodeTextGeneration(settings).pipe(
236 Effect.provideService(OpenCodeServerOwner.OpenCodeServerOwner, serverOwner),
237 );
238 return yield* effectFn(textGeneration);
239 }).pipe(Effect.scoped);
241​
242beforeEach(() => {
243 runtimeMock.reset();
244});
245​
246const advanceIdleClock = Effect.gen(function* () {
247 yield* Effect.yieldNow;
248 yield* TestClock.adjust(Duration.millis(OPENCODE_TEXT_GENERATION_IDLE_TTL_MS + 1));
249 yield* Effect.yieldNow;
250});
251​
252it.layer(layerOpenCodeTextGenerationTest)("OpenCodeTextGeneration", (it) => {
253 it.effect("cancels or times out an in-flight session creation before prompting", () =>
254 withOpenCodeTextGeneration(EXISTING_SERVER_OPENCODE_SETTINGS, (textGeneration) =>
255 Effect.gen(function* () {
256 const timedOut = yield* Deferred.make<AbortSignal | undefined>();
257 runtimeMock.state.onSessionCreate = (signal) => {
258 Deferred.doneUnsafe(timedOut, Effect.succeed(signal));
259 return new Promise<never>(() => {});
260 };
261 const timedOutFiber = yield* textGeneration
262 .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
263 .pipe(Effect.forkChild);
264 const timedOutSignal = yield* Deferred.await(timedOut);
265 yield* TestClock.adjust(Duration.minutes(3));
266 const timeoutError = yield* Fiber.join(timedOutFiber).pipe(Effect.flip);
267 expect(timeoutError).toBeInstanceOf(TextGenerationError);
268 expect(timeoutError.detail).toBe("OpenCode did not finish generating in time.");
269 expect(timedOutSignal?.aborted).toBe(true);
270​
271 const started = yield* Deferred.make<AbortSignal | undefined>();
272 runtimeMock.state.onSessionCreate = (signal) => {
273 Deferred.doneUnsafe(started, Effect.succeed(signal));
274 return new Promise<never>(() => {});
275 };
276 const fiber = yield* textGeneration
277 .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
278 .pipe(Effect.forkChild);
279 const signal = yield* Deferred.await(started);
280 yield* Fiber.interrupt(fiber);
281​
282 const exit = yield* Fiber.await(fiber);
283 expect(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)).toBe(true);
284 expect(signal?.aborted).toBe(true);
285 expect(runtimeMock.state.promptUrls).toEqual([]);
286 expect(runtimeMock.state.sessionCalls).toEqual([]);
287 }),
288 ),
289 );
290​
291 it.effect("cancels only its prompt session while another generation uses the shared server", () =>
292 withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
293 Effect.gen(function* () {
294 const started = yield* Deferred.make<AbortSignal | undefined>();
295 runtimeMock.state.sessionResult = { data: { id: "cancelled-session" } };
296 runtimeMock.state.onPrompt = (signal) => {
297 Deferred.doneUnsafe(started, Effect.succeed(signal));
298 return new Promise<never>(() => {});
299 };
300 const fiber = yield* textGeneration
301 .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
302 .pipe(Effect.forkChild);
303 const signal = yield* Deferred.await(started);
304​
305 const otherStarted = yield* Deferred.make<AbortSignal | undefined>();
306 const otherReply = Promise.withResolvers<{ data: { parts: ReadonlyArray<unknown> } }>();
307 runtimeMock.state.sessionResult = { data: { id: "other-session" } };
308 runtimeMock.state.onPrompt = (otherSignal) => {
309 Deferred.doneUnsafe(otherStarted, Effect.succeed(otherSignal));
310 return otherReply.promise;
311 };
312 const otherFiber = yield* textGeneration
313 .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
314 .pipe(Effect.forkChild);
315 const otherSignal = yield* Deferred.await(otherStarted);
316 yield* Fiber.interrupt(fiber);
317​
318 const exit = yield* Fiber.await(fiber);
319 expect(Exit.isFailure(exit) && Cause.hasInterruptsOnly(exit.cause)).toBe(true);
320 expect(signal?.aborted).toBe(true);
321 expect(otherSignal?.aborted).toBe(false);
322 expect(runtimeMock.state.sessionCalls).toEqual([
323 "abort cancelled-session",
324 "delete cancelled-session",
325 ]);
326 expect(runtimeMock.state.closeCalls).toEqual([]);
327​
328 otherReply.resolve({
329 data: {
330 parts: [{ type: "text", text: '{"subject":"Other generation completed","body":""}' }],
331 },
332 });
333 expect((yield* Fiber.join(otherFiber)).subject).toBe("Other generation completed");
334 expect(runtimeMock.state.startCalls).toEqual(["fake-opencode"]);
335 expect(runtimeMock.state.promptUrls).toEqual([
336 "http://127.0.0.1:4301",
337 "http://127.0.0.1:4301",
338 ]);
339 expect(runtimeMock.state.sessionCalls).toEqual([
340 "abort cancelled-session",
341 "delete cancelled-session",
342 "delete other-session",
343 ]);
344 expect(runtimeMock.state.closeCalls).toEqual([]);
345 }),
346 ),
347 );
348​
349 it.effect("excludes generic files from thread title generation", () =>
350 withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
351 Effect.gen(function* () {
352 runtimeMock.state.promptResult = {
353 data: {
354 parts: [{ type: "text", text: '{"title":"Review uploaded report"}' }],
355 },
356 };
357​
358 yield* textGeneration.generateThreadTitle({
359 cwd: process.cwd(),
360 message: "Review these attachments.",
361 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
362 attachments: [
363 {
364 type: "image",
365 id: "thread-image-attachment",
366 name: "screenshot.png",
367 mimeType: "image/png",
368 sizeBytes: 3,
369 },
370 {
371 type: "file",
372 id: "thread-report-attachment-pdf",
373 name: "report.pdf",
374 mimeType: "application/pdf",
375 sizeBytes: 42,
376 },
377 ],
378 });
379​
380 expect(runtimeMock.state.promptParts[0]).toEqual([
381 expect.objectContaining({ type: "text" }),
382 expect.objectContaining({ type: "file", filename: "screenshot.png" }),
383 ]);
384 }),
385 ),
386 );
387​
388 it.effect("gives up and aborts the session when a prompt never settles", () =>
389 withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
390 Effect.gen(function* () {
391 const started = yield* Deferred.make<AbortSignal | undefined>();
392 let sessionAborts = 0;
393 runtimeMock.state.onPrompt = (signal) => {
394 Deferred.doneUnsafe(started, Effect.succeed(signal));
395 return new Promise<never>(() => {});
396 };
397 runtimeMock.state.onAbort = () => {
398 sessionAborts += 1;
399 return Promise.reject(new Error("abort observed"));
400 };
401 const fiber = yield* textGeneration
402 .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
403 .pipe(Effect.forkChild);
404 const signal = yield* Deferred.await(started);
405 yield* TestClock.adjust(Duration.minutes(3));
406​
407 const error = yield* Fiber.join(fiber).pipe(Effect.flip);
408 expect(error).toBeInstanceOf(TextGenerationError);
409 expect(error.detail).toBe("OpenCode did not finish generating in time.");
410 expect(signal?.aborted).toBe(true);
411 expect(sessionAborts).toBe(1);
412 }),
413 ),
414 );
415​
416 it.effect("uses an environment-only password for a locally spawned server", () =>
417 withOpenCodeTextGeneration(
418 DEFAULT_OPENCODE_SETTINGS,
419 (textGeneration) =>
420 Effect.gen(function* () {
421 yield* textGeneration.generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT);
422​
423 expect(runtimeMock.state.authHeaders).toEqual([
424 `Basic ${btoa("opencode:environment-password")}`,
425 ]);
426 }),
427 { OPENCODE_SERVER_PASSWORD: "environment-password" },
428 ),
429 );
430​
431 it.effect("returns a typed empty-output error for malformed and blank response parts", () =>
432 withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
433 Effect.gen(function* () {
434 runtimeMock.state.promptResult = {
435 data: {
436 parts: [null, { type: "tool" }, { type: "text", text: " " }],
437 },
438 };
439​
440 const error = yield* textGeneration
441 .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
442 .pipe(Effect.flip);
443​
444 expect(error.message).toContain("OpenCode returned empty output.");
445 expect(error.cause).toMatchObject({
446 _tag: "OpenCodeTextGenerationEmptyOutputError",
447 operation: "generateCommitMessage",
448 cwd: process.cwd(),
449 sessionId: "http://127.0.0.1:4301/session",
450 providerId: "openai",
451 modelId: "gpt-5",
452 responsePartCount: 3,
453 textPartCount: 1,
454 });
455 expect(error.cause).not.toHaveProperty("cause");
456 expect(runtimeMock.state.sessionCalls).toEqual(["delete http://127.0.0.1:4301/session"]);
457 }),
458 ),
459 );
460​
461 it.effect(
462 "maps OpenCode prompt errors to fixed details and keeps provider text in the cause",
463 () =>
464 Effect.forEach(
465 [
466 {
467 error: {
468 name: "APIError",
469 data: {
470 message: "Org quota secret-org exceeded",
471 statusCode: 429,
472 isRetryable: true,
473 },
474 },
475 rawText: "secret-org",
476 detail: "The model provider's usage or rate limit was reached. Try again later.",
477 },
478 {
479 error: {
480 name: "APIError",
481 data: {
482 message: "<none>",
483 statusCode: 503,
484 isRetryable: true,
485 responseBody: "<title>Upstream gateway secret-host</title>",
486 },
487 },
488 rawText: "secret-host",
489 detail: "The model provider failed the request (HTTP 503).",
490 },
491 {
492 error: { name: "UnknownError", data: { message: "Provider stack trace secret-token" } },
493 rawText: "secret-token",
494 detail: "OpenCode could not generate the text.",
495 },
496 ],
497 (testCase) =>
498 withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
499 Effect.gen(function* () {
500 runtimeMock.state.promptResult = {
501 data: { info: { error: testCase.error }, parts: [] },
502 };
503​
504 const error = yield* textGeneration
505 .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
506 .pipe(Effect.flip);
507​
508 expect(error.detail).toBe(testCase.detail);
509 expect(error.message).not.toContain(testCase.rawText);
510 expect(error.cause).toMatchObject({
511 _tag: "OpenCodeTextGenerationPromptResponseError",
512 providerErrorName: testCase.error.name,
513 cause: testCase.error,
514 });
515 expect((error.cause as Error).message).not.toContain(testCase.rawText);
516 }),
517 ),
518 { discard: true },
519 ),
520 );
521​
522 it.effect("deletes the session when the prompt request rejects", () =>
523 withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
524 Effect.gen(function* () {
525 runtimeMock.state.promptRequestError = new Error("prompt transport failed");
526​
527 const error = yield* textGeneration
528 .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
529 .pipe(Effect.flip);
530​
531 expect(error.detail).toBe("OpenCode session.prompt request failed.");
532 expect(runtimeMock.state.sessionCalls).toEqual(["delete http://127.0.0.1:4301/session"]);
533 }),
534 ),
535 );
536​
537 it.effect("parses JSON returned as plain text output", () =>
538 withOpenCodeTextGeneration(DEFAULT_OPENCODE_SETTINGS, (textGeneration) =>
539 Effect.gen(function* () {
540 runtimeMock.state.promptResult = {
541 data: {
542 parts: [
543 {
544 type: "text",
545 text: 'Here is the result:\n{"subject":"Tighten OpenCode parsing","body":"Handle JSON text output locally."}',
546 },
547 ],
548 },
549 };
550​
551 const result = yield* textGeneration.generateCommitMessage({
552 cwd: process.cwd(),
553 branch: "feature/opencode-reuse",
554 stagedSummary: "M README.md",
555 stagedPatch: "diff --git a/README.md b/README.md",
556 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
557 });
558​
559 expect(result).toEqual({
560 subject: "Tighten OpenCode parsing",
561 body: "Handle JSON text output locally.",
562 });
563 }),
564 ),
565 );
566});
567​
568it.layer(layerOpenCodeTextGenerationExistingServerTest)(
569 "OpenCodeTextGeneration with configured server URL",
570 (it) => {
571 it.effect("does not send a local environment password to a configured server", () =>
572 withOpenCodeTextGeneration(
573 EXTERNAL_SERVER_WITHOUT_AUTH_OPENCODE_SETTINGS,
574 (textGeneration) =>
575 Effect.gen(function* () {
576 yield* textGeneration.generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT);
577 expect(runtimeMock.state.authHeaders).toEqual([null]);
578 }),
579 { OPENCODE_SERVER_PASSWORD: "local-secret" },
580 ),
581 );
582​
583 it.effect("does not create a session when the server version is unsupported", () =>
584 withOpenCodeTextGeneration(EXISTING_SERVER_OPENCODE_SETTINGS, (textGeneration) =>
585 Effect.gen(function* () {
586 runtimeMock.state.connectionError = new Error(
587 "OpenCode v1.14.18 is too old. Upgrade to v1.14.19 or newer.",
588 );
589​
590 const error = yield* textGeneration
591 .generateCommitMessage(DEFAULT_COMMIT_MESSAGE_INPUT)
592 .pipe(Effect.flip);
593​
594 expect(error).toBeInstanceOf(TextGenerationError);
595 expect(error.message).toContain("v1.14.18 is too old");
596 expect(runtimeMock.state.sessionCreateCalls).toBe(0);
597 }),
598 ),
599 );
600​
601 it.effect("reuses a configured OpenCode server URL without spawning or applying idle TTL", () =>
602 withOpenCodeTextGeneration(EXISTING_SERVER_OPENCODE_SETTINGS, (textGeneration) =>
603 Effect.gen(function* () {
604 yield* textGeneration.generateCommitMessage({
605 cwd: process.cwd(),
606 branch: "feature/opencode-reuse",
607 stagedSummary: "M README.md",
608 stagedPatch: "diff --git a/README.md b/README.md",
609 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
610 });
611 yield* textGeneration.generateCommitMessage({
612 cwd: process.cwd(),
613 branch: "feature/opencode-reuse",
614 stagedSummary: "M README.md",
615 stagedPatch: "diff --git a/README.md b/README.md",
616 modelSelection: DEFAULT_TEST_MODEL_SELECTION,
617 });
618​
619 expect(runtimeMock.state.startCalls).toEqual([]);
620 expect(runtimeMock.state.sessionCalls).toEqual([
621 "delete http://127.0.0.1:9999/session",
622 "delete http://127.0.0.1:9999/session",
623 ]);
624 expect(runtimeMock.state.promptUrls).toEqual([
625 "http://127.0.0.1:9999",
626 "http://127.0.0.1:9999",
627 ]);
628 expect(runtimeMock.state.authHeaders).toEqual([
629 `Basic ${btoa("opencode:secret-password")}`,
630 `Basic ${btoa("opencode:secret-password")}`,
631 ]);
632​
633 yield* advanceIdleClock;
634​
635 expect(runtimeMock.state.closeCalls).toEqual([]);
636 }),
637 ).pipe(Effect.provide(TestClock.layer())),
638 );
639 },
640);