Open History to see the last commit
1// @effect-diagnostics nodeBuiltinImport:off
2import * as NodePath from "node:path";
3import * as NodeOS from "node:os";
4import * as NodeURL from "node:url";
5import * as NodeFS from "node:fs";
6
7import * as NodeServices from "@effect/platform-node/NodeServices";
8import { it } from "@effect/vitest";
9import * as Effect from "effect/Effect";
10import * as Fiber from "effect/Fiber";
11import * as Option from "effect/Option";
12import * as TestClock from "effect/testing/TestClock";
13import * as Stream from "effect/Stream";
14import { describe, expect } from "vite-plus/test";
15
16import * as AcpSessionRuntime from "./AcpSessionRuntime.ts";
17import type * as EffectAcpProtocol from "effect-acp/protocol";
18
19const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
20const mockAgentPath = NodePath.join(__dirname, "../../../scripts/acp-mock-agent.ts");
21const mockAgentCommand = "node";
22const mockAgentArgs = [mockAgentPath];
23
24describe("AcpSessionRuntime", () => {
25 it("selects explicit or agent-managed authentication without choosing terminal auth", () => {
26 const methods = [
27 { id: "browser", name: "Browser", type: "terminal" as const },
28 { id: "api-key", name: "API key" },
29 ];
30
31 expect(AcpSessionRuntime.selectAcpAgentAuthMethod(methods)?.id).toBe("api-key");
32 expect(AcpSessionRuntime.selectAcpAgentAuthMethod(methods, "browser")?.id).toBe("browser");
33 expect(AcpSessionRuntime.selectAcpAgentAuthMethod(methods, "missing")).toBeUndefined();
34 });
35
36 it.effect("merges custom initialize client capabilities into the ACP handshake", () => {
37 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
38 return Effect.gen(function* () {
39 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
40 yield* runtime.start();
41
42 const initializeStarted = requestEvents.find(
43 (event) => event.method === "initialize" && event.status === "started",
44 );
45 expect(initializeStarted?.payload).toMatchObject({
46 protocolVersion: 1,
47 clientCapabilities: {
48 fs: { readTextFile: false, writeTextFile: false },
49 terminal: false,
50 _meta: { parameterizedModelPicker: true },
51 },
52 });
53 }).pipe(
54 Effect.provide(
55 AcpSessionRuntime.layer({
56 spawn: {
57 command: mockAgentCommand,
58 args: mockAgentArgs,
59 },
60 cwd: process.cwd(),
61 clientCapabilities: {
62 _meta: {
63 parameterizedModelPicker: true,
64 },
65 },
66 clientInfo: { name: "t3-test", version: "0.0.0" },
67 authMethodId: "test",
68 requestLogger: (event) =>
69 Effect.sync(() => {
70 requestEvents.push(event);
71 }),
72 }),
73 ),
74 Effect.scoped,
75 Effect.provide(NodeServices.layer),
76 );
77 });
78
79 it.effect("does not authenticate when an advertised method is not required", () => {
80 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
81 return Effect.gen(function* () {
82 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
83 yield* runtime.start();
84
85 expect(
86 requestEvents.filter((event) => event.status === "started").map((event) => event.method),
87 ).toEqual(["initialize", "session/new"]);
88 }).pipe(
89 Effect.provide(
90 AcpSessionRuntime.layer({
91 authMethodId: "test",
92 spawn: {
93 command: mockAgentCommand,
94 args: mockAgentArgs,
95 env: { T3_ACP_AUTH_METHOD_ID: "test" },
96 },
97 cwd: process.cwd(),
98 clientInfo: { name: "t3-test", version: "0.0.0" },
99 requestLogger: (event) =>
100 Effect.sync(() => {
101 requestEvents.push(event);
102 }),
103 }),
104 ),
105 Effect.scoped,
106 Effect.provide(NodeServices.layer),
107 );
108 });
109
110 it.effect("authenticates and retries once after session creation returns auth_required", () => {
111 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
112 return Effect.gen(function* () {
113 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
114 const started = yield* runtime.start();
115
116 expect(started.sessionId).toBe("mock-session-1");
117 expect(
118 requestEvents.filter((event) => event.status === "started").map((event) => event.method),
119 ).toEqual(["initialize", "session/new", "authenticate", "session/new"]);
120 expect(
121 requestEvents.filter(
122 (event) => event.method === "session/new" && event.status === "failed",
123 ),
124 ).toHaveLength(1);
125 expect(
126 requestEvents.filter(
127 (event) => event.method === "session/new" && event.status === "succeeded",
128 ),
129 ).toHaveLength(1);
130 }).pipe(
131 Effect.provide(
132 AcpSessionRuntime.layer({
133 authMethodId: "test",
134 spawn: {
135 command: mockAgentCommand,
136 args: mockAgentArgs,
137 env: {
138 T3_ACP_AUTH_METHOD_ID: "test",
139 T3_ACP_REQUIRE_AUTH: "1",
140 },
141 },
142 cwd: process.cwd(),
143 clientInfo: { name: "t3-test", version: "0.0.0" },
144 requestLogger: (event) =>
145 Effect.sync(() => {
146 requestEvents.push(event);
147 }),
148 }),
149 ),
150 Effect.scoped,
151 Effect.provide(NodeServices.layer),
152 );
153 });
154
155 it.effect("starts a session, prompts, and emits normalized events against the mock agent", () =>
156 Effect.gen(function* () {
157 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
158 const started = yield* runtime.start();
159
160 expect(started.initializeResult).toMatchObject({ protocolVersion: 1 });
161 expect(started.sessionId).toBe("mock-session-1");
162
163 const promptResult = yield* runtime.prompt({
164 prompt: [{ type: "text", text: "hi" }],
165 });
166 expect(promptResult).toMatchObject({ stopReason: "end_turn" });
167
168 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 4)));
169 expect(notes).toHaveLength(4);
170 expect(notes.map((note) => note._tag)).toEqual([
171 "PlanUpdated",
172 "AssistantItemStarted",
173 "ContentDelta",
174 "AssistantItemCompleted",
175 ]);
176 const planUpdate = notes.find((note) => note._tag === "PlanUpdated");
177 expect(planUpdate?._tag).toBe("PlanUpdated");
178 if (planUpdate?._tag === "PlanUpdated") {
179 expect(planUpdate.payload.plan).toHaveLength(2);
180 }
181 const assistantStart = notes[1];
182 const assistantDelta = notes[2];
183 if (
184 assistantStart?._tag === "AssistantItemStarted" &&
185 assistantDelta?._tag === "ContentDelta"
186 ) {
187 expect(assistantDelta.itemId).toBe(assistantStart.itemId);
188 }
189 }).pipe(
190 Effect.provide(
191 AcpSessionRuntime.layer({
192 spawn: {
193 command: mockAgentCommand,
194 args: mockAgentArgs,
195 },
196 cwd: process.cwd(),
197 clientInfo: { name: "t3-test", version: "0.0.0" },
198 authMethodId: "test",
199 }),
200 ),
201 Effect.scoped,
202 Effect.provide(NodeServices.layer),
203 ),
204 );
205
206 it.effect("drops session updates emitted for a child ACP session", () =>
207 Effect.gen(function* () {
208 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
209 yield* runtime.start();
210
211 const promptResult = yield* runtime.prompt({
212 prompt: [{ type: "text", text: "hi" }],
213 });
214 expect(promptResult).toMatchObject({ stopReason: "end_turn" });
215
216 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 4)));
217 expect(notes.map((note) => note._tag)).toEqual([
218 "AssistantItemStarted",
219 "ContentDelta",
220 "ContentDelta",
221 "AssistantItemCompleted",
222 ]);
223 expect(
224 notes
225 .filter((note) => note._tag === "ContentDelta")
226 .map((note) => note.text)
227 .join(""),
228 ).toBe("root before child root after child");
229 expect(notes.some((note) => note._tag === "ToolCallUpdated")).toBe(false);
230 }).pipe(
231 Effect.provide(
232 AcpSessionRuntime.layer({
233 spawn: {
234 command: mockAgentCommand,
235 args: mockAgentArgs,
236 env: {
237 T3_ACP_EMIT_FOREIGN_SESSION_UPDATES: "1",
238 },
239 },
240 cwd: process.cwd(),
241 clientInfo: { name: "t3-test", version: "0.0.0" },
242 authMethodId: "test",
243 }),
244 ),
245 Effect.scoped,
246 Effect.provide(NodeServices.layer),
247 ),
248 );
249
250 it.effect("supports successive standard ACP prompts", () =>
251 Effect.gen(function* () {
252 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
253 yield* runtime.start();
254
255 const firstPromptResult = yield* runtime.prompt({
256 prompt: [{ type: "text", text: "first" }],
257 });
258 const secondPromptResult = yield* runtime.prompt({
259 prompt: [{ type: "text", text: "second" }],
260 });
261
262 expect(firstPromptResult).toMatchObject({ stopReason: "end_turn" });
263 expect(secondPromptResult).toMatchObject({ stopReason: "end_turn" });
264 }).pipe(
265 Effect.provide(
266 AcpSessionRuntime.layer({
267 spawn: {
268 command: mockAgentCommand,
269 args: mockAgentArgs,
270 },
271 cwd: process.cwd(),
272 clientInfo: { name: "t3-test", version: "0.0.0" },
273 authMethodId: "test",
274 }),
275 ),
276 Effect.scoped,
277 Effect.provide(NodeServices.layer),
278 ),
279 );
280
281 it.effect("releases a fully silent prompt when session/cancel is requested", () =>
282 Effect.gen(function* () {
283 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
284 yield* runtime.start();
285
286 const promptFiber = yield* runtime
287 .prompt({
288 prompt: [{ type: "text", text: "hang forever" }],
289 })
290 .pipe(Effect.forkChild({ startImmediately: true }));
291
292 yield* TestClock.adjust("500 millis");
293 yield* runtime.cancel;
294
295 const firstPromptResult = yield* Fiber.join(promptFiber);
296 expect(firstPromptResult).toMatchObject({ stopReason: "cancelled" });
297
298 const secondPromptResult = yield* runtime.prompt({
299 prompt: [{ type: "text", text: "second" }],
300 });
301 expect(secondPromptResult).toMatchObject({ stopReason: "end_turn" });
302 }).pipe(
303 Effect.provide(
304 AcpSessionRuntime.layer({
305 spawn: {
306 command: mockAgentCommand,
307 args: mockAgentArgs,
308 env: {
309 T3_ACP_HANG_FIRST_PROMPT_FOREVER: "1",
310 },
311 },
312 cwd: process.cwd(),
313 clientInfo: { name: "t3-test", version: "0.0.0" },
314 authMethodId: "test",
315 }),
316 ),
317 Effect.scoped,
318 Effect.provide(NodeServices.layer),
319 ),
320 );
321
322 it.effect("segments assistant text around ACP tool calls", () =>
323 Effect.gen(function* () {
324 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
325 yield* runtime.start();
326
327 const promptResult = yield* runtime.prompt({
328 prompt: [{ type: "text", text: "hi" }],
329 });
330 expect(promptResult).toMatchObject({ stopReason: "end_turn" });
331
332 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 7)));
333 expect(notes.map((note) => note._tag)).toEqual([
334 "AssistantItemStarted",
335 "ContentDelta",
336 "AssistantItemCompleted",
337 "ToolCallUpdated",
338 "ToolCallUpdated",
339 "AssistantItemStarted",
340 "ContentDelta",
341 ]);
342
343 const firstStarted = notes[0];
344 const firstDelta = notes[1];
345 const firstCompleted = notes[2];
346 const secondStarted = notes[5];
347 const secondDelta = notes[6];
348 expect(firstStarted?._tag).toBe("AssistantItemStarted");
349 expect(firstCompleted?._tag).toBe("AssistantItemCompleted");
350 expect(secondStarted?._tag).toBe("AssistantItemStarted");
351 if (
352 firstStarted?._tag === "AssistantItemStarted" &&
353 firstDelta?._tag === "ContentDelta" &&
354 firstCompleted?._tag === "AssistantItemCompleted" &&
355 secondStarted?._tag === "AssistantItemStarted" &&
356 secondDelta?._tag === "ContentDelta"
357 ) {
358 expect(firstDelta.itemId).toBe(firstStarted.itemId);
359 expect(firstCompleted.itemId).toBe(firstStarted.itemId);
360 expect(secondStarted.itemId).not.toBe(firstStarted.itemId);
361 expect(secondDelta.itemId).toBe(secondStarted.itemId);
362 }
363 }).pipe(
364 Effect.provide(
365 AcpSessionRuntime.layer({
366 spawn: {
367 command: mockAgentCommand,
368 args: mockAgentArgs,
369 env: {
370 T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS: "1",
371 },
372 },
373 cwd: process.cwd(),
374 clientInfo: { name: "t3-test", version: "0.0.0" },
375 authMethodId: "test",
376 }),
377 ),
378 Effect.scoped,
379 Effect.provide(NodeServices.layer),
380 ),
381 );
382
383 it.effect("suppresses generic placeholder tool updates until completion", () =>
384 Effect.gen(function* () {
385 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
386 yield* runtime.start();
387
388 const promptResult = yield* runtime.prompt({
389 prompt: [{ type: "text", text: "hi" }],
390 });
391 expect(promptResult).toMatchObject({ stopReason: "end_turn" });
392
393 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 1)));
394 expect(notes.map((note) => note._tag)).toEqual(["ToolCallUpdated"]);
395 const toolCall = notes[0];
396 expect(toolCall?._tag).toBe("ToolCallUpdated");
397 if (toolCall?._tag === "ToolCallUpdated") {
398 expect(toolCall.toolCall.status).toBe("completed");
399 expect(toolCall.toolCall.title).toBe("Read file");
400 }
401 }).pipe(
402 Effect.provide(
403 AcpSessionRuntime.layer({
404 spawn: {
405 command: mockAgentCommand,
406 args: mockAgentArgs,
407 env: {
408 T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1",
409 },
410 },
411 cwd: process.cwd(),
412 clientInfo: { name: "t3-test", version: "0.0.0" },
413 authMethodId: "test",
414 }),
415 ),
416 Effect.scoped,
417 Effect.provide(NodeServices.layer),
418 ),
419 );
420
421 it.effect("logs ACP requests from the shared runtime", () => {
422 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
423 return Effect.gen(function* () {
424 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
425 yield* runtime.start();
426
427 yield* runtime.setModel("composer-2");
428 yield* runtime.prompt({
429 prompt: [{ type: "text", text: "hi" }],
430 });
431
432 expect(
433 requestEvents.some(
434 (event) => event.method === "session/set_config_option" && event.status === "started",
435 ),
436 ).toBe(true);
437 expect(
438 requestEvents.some(
439 (event) => event.method === "session/set_config_option" && event.status === "succeeded",
440 ),
441 ).toBe(true);
442 expect(
443 requestEvents.some(
444 (event) => event.method === "session/prompt" && event.status === "started",
445 ),
446 ).toBe(true);
447 expect(
448 requestEvents.some(
449 (event) => event.method === "session/prompt" && event.status === "succeeded",
450 ),
451 ).toBe(true);
452 }).pipe(
453 Effect.provide(
454 AcpSessionRuntime.layer({
455 authMethodId: "test",
456 spawn: {
457 command: mockAgentCommand,
458 args: mockAgentArgs,
459 },
460 cwd: process.cwd(),
461 clientInfo: { name: "t3-test", version: "0.0.0" },
462 requestLogger: (event) =>
463 Effect.sync(() => {
464 requestEvents.push(event);
465 }),
466 }),
467 ),
468 Effect.scoped,
469 Effect.provide(NodeServices.layer),
470 );
471 });
472
473 it.effect("supports negotiated ACP session list, fork, resume, and close methods", () => {
474 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
475 return Effect.gen(function* () {
476 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
477 const started = yield* runtime.start();
478 expect(started.initializeResult.agentCapabilities?.sessionCapabilities).toMatchObject({
479 list: {},
480 fork: {},
481 resume: {},
482 close: {},
483 });
484
485 const listed = yield* runtime.listSessions();
486 expect(listed.sessions.map((session) => session.sessionId)).toEqual(["mock-session-1"]);
487
488 const forked = yield* runtime.forkSession(started.sessionId);
489 expect(forked.sessionId).toBe("mock-session-1-fork");
490 yield* runtime.prompt({ prompt: [{ type: "text", text: "on fork" }] });
491
492 const resumed = yield* runtime.resumeSession(started.sessionId);
493 expect(resumed.sessionId).toBe("mock-session-1");
494 yield* runtime.closeSession();
495
496 expect(
497 requestEvents.find(
498 (event) => event.method === "session/prompt" && event.status === "started",
499 )?.payload,
500 ).toMatchObject({ sessionId: "mock-session-1-fork" });
501 expect(
502 requestEvents.filter((event) => event.status === "started").map((event) => event.method),
503 ).toEqual(
504 expect.arrayContaining(["session/list", "session/fork", "session/resume", "session/close"]),
505 );
506 }).pipe(
507 Effect.provide(
508 AcpSessionRuntime.layer({
509 authMethodId: "test",
510 spawn: {
511 command: mockAgentCommand,
512 args: mockAgentArgs,
513 env: {
514 T3_ACP_SESSION_LIFECYCLE: "1",
515 },
516 },
517 cwd: process.cwd(),
518 clientInfo: { name: "t3-test", version: "0.0.0" },
519 requestLogger: (event) =>
520 Effect.sync(() => {
521 requestEvents.push(event);
522 }),
523 }),
524 ),
525 Effect.scoped,
526 Effect.provide(NodeServices.layer),
527 );
528 });
529
530 it.effect("skips no-op session config writes when the requested value is already active", () => {
531 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
532 return Effect.gen(function* () {
533 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
534 yield* runtime.start();
535
536 yield* runtime.setConfigOption("model", "default");
537 yield* runtime.setMode("ask");
538
539 expect(
540 requestEvents.some(
541 (event) => event.method === "session/set_config_option" && event.status === "started",
542 ),
543 ).toBe(false);
544 }).pipe(
545 Effect.provide(
546 AcpSessionRuntime.layer({
547 authMethodId: "test",
548 spawn: {
549 command: mockAgentCommand,
550 args: mockAgentArgs,
551 },
552 cwd: process.cwd(),
553 clientInfo: { name: "t3-test", version: "0.0.0" },
554 requestLogger: (event) =>
555 Effect.sync(() => {
556 requestEvents.push(event);
557 }),
558 }),
559 ),
560 Effect.scoped,
561 Effect.provide(NodeServices.layer),
562 );
563 });
564
565 it.effect("emits low-level ACP protocol logs for raw and decoded messages", () => {
566 const protocolEvents: Array<EffectAcpProtocol.AcpProtocolLogEvent> = [];
567 return Effect.gen(function* () {
568 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
569 yield* runtime.start();
570
571 yield* runtime.prompt({
572 prompt: [{ type: "text", text: "hi" }],
573 });
574
575 expect(
576 protocolEvents.some((event) => event.direction === "outgoing" && event.stage === "raw"),
577 ).toBe(true);
578 expect(
579 protocolEvents.some((event) => event.direction === "outgoing" && event.stage === "decoded"),
580 ).toBe(true);
581 expect(
582 protocolEvents.some((event) => event.direction === "incoming" && event.stage === "raw"),
583 ).toBe(true);
584 expect(
585 protocolEvents.some((event) => event.direction === "incoming" && event.stage === "decoded"),
586 ).toBe(true);
587 }).pipe(
588 Effect.provide(
589 AcpSessionRuntime.layer({
590 authMethodId: "test",
591 spawn: {
592 command: mockAgentCommand,
593 args: mockAgentArgs,
594 },
595 cwd: process.cwd(),
596 clientInfo: { name: "t3-test", version: "0.0.0" },
597 protocolLogging: {
598 logIncoming: true,
599 logOutgoing: true,
600 logger: (event) =>
601 Effect.sync(() => {
602 protocolEvents.push(event);
603 }),
604 },
605 }),
606 ),
607 Effect.scoped,
608 Effect.provide(NodeServices.layer),
609 );
610 });
611
612 it.effect("fails session startup when session/load returns an error", () =>
613 Effect.gen(function* () {
614 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
615 const error = yield* runtime.start().pipe(Effect.flip);
616
617 expect(error._tag).toBe("AcpRequestError");
618 }).pipe(
619 Effect.provide(
620 AcpSessionRuntime.layer({
621 authMethodId: "test",
622 spawn: {
623 command: mockAgentCommand,
624 args: mockAgentArgs,
625 env: {
626 T3_ACP_FAIL_LOAD_SESSION: "1",
627 },
628 },
629 cwd: process.cwd(),
630 resumeSessionId: "stale-session-id",
631 clientInfo: { name: "t3-test", version: "0.0.0" },
632 }),
633 ),
634 Effect.scoped,
635 Effect.provide(NodeServices.layer),
636 ),
637 );
638
639 it.effect("ignores session/update replay notifications during session/load", () =>
640 Effect.gen(function* () {
641 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
642 yield* runtime.start();
643
644 yield* runtime.prompt({
645 prompt: [{ type: "text", text: "hi" }],
646 });
647 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 4)));
648 expect(notes.map((note) => note._tag)).toEqual([
649 "PlanUpdated",
650 "AssistantItemStarted",
651 "ContentDelta",
652 "AssistantItemCompleted",
653 ]);
654 expect(notes.some((note) => note._tag === "ToolCallUpdated")).toBe(false);
655 }).pipe(
656 Effect.provide(
657 AcpSessionRuntime.layer({
658 authMethodId: "test",
659 spawn: {
660 command: mockAgentCommand,
661 args: mockAgentArgs,
662 env: {
663 T3_ACP_EMIT_LOAD_REPLAY: "1",
664 },
665 },
666 cwd: process.cwd(),
667 resumeSessionId: "mock-session-1",
668 clientInfo: { name: "t3-test", version: "0.0.0" },
669 }),
670 ),
671 Effect.scoped,
672 Effect.provide(NodeServices.layer),
673 ),
674 );
675
676 it.effect("completes session/load after replay becomes idle while its RPC stays pending", () =>
677 Effect.gen(function* () {
678 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
679 const started = yield* runtime.start().pipe(Effect.timeout("2 seconds"));
680
681 expect(started.sessionId).toBe("mock-session-1");
682 expect(started.sessionSetupResult._meta).toMatchObject({
683 t3SessionLoadReady: "replay_idle",
684 });
685
686 const unexpectedReplayEvent = yield* Stream.runHead(runtime.getEvents()).pipe(
687 Effect.timeoutOption("100 millis"),
688 );
689 expect(Option.isNone(unexpectedReplayEvent)).toBe(true);
690 }).pipe(
691 Effect.provide(
692 AcpSessionRuntime.layer({
693 authMethodId: "test",
694 spawn: {
695 command: mockAgentCommand,
696 args: mockAgentArgs,
697 env: {
698 T3_ACP_HANG_LOAD_SESSION_AFTER_REPLAY: "1",
699 T3_ACP_LOAD_SESSION_DELAY_MS: "10000",
700 },
701 },
702 cwd: process.cwd(),
703 resumeSessionId: "mock-session-1",
704 sessionLoadReplayIdleGap: "50 millis",
705 sessionLoadTimeout: "1 second",
706 clientInfo: { name: "t3-test", version: "0.0.0" },
707 }),
708 ),
709 Effect.scoped,
710 Effect.provide(NodeServices.layer),
711 TestClock.withLive,
712 ),
713 );
714
715 it.effect("rejects invalid config option values before sending session/set_config_option", () => {
716 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "acp-runtime-"));
717 const requestLogPath = NodePath.join(tempDir, "requests.ndjson");
718 return Effect.gen(function* () {
719 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
720 yield* runtime.start();
721
722 const error = yield* runtime.setModel("composer-2[fast=false]").pipe(Effect.flip);
723 expect(error._tag).toBe("AcpRequestError");
724 if (error._tag === "AcpRequestError") {
725 expect(error.code).toBe(-32602);
726 expect(error.message).toContain(
727 'Invalid value "composer-2[fast=false]" for session config option "model"',
728 );
729 expect(error.message).toContain("composer-2[fast=true]");
730 }
731
732 const recordedRequests = NodeFS.readFileSync(requestLogPath, "utf8")
733 .trim()
734 .split("\n")
735 .filter((line) => line.length > 0)
736 .map((line) => JSON.parse(line) as { method?: string; params?: { value?: unknown } });
737 expect(
738 recordedRequests.some(
739 (message) =>
740 message.method === "session/set_config_option" &&
741 message.params?.value === "composer-2[fast=false]",
742 ),
743 ).toBe(false);
744 }).pipe(
745 Effect.provide(
746 AcpSessionRuntime.layer({
747 authMethodId: "test",
748 spawn: {
749 command: mockAgentCommand,
750 args: mockAgentArgs,
751 env: {
752 T3_ACP_REQUEST_LOG_PATH: requestLogPath,
753 },
754 },
755 cwd: process.cwd(),
756 clientInfo: { name: "t3-test", version: "0.0.0" },
757 }),
758 ),
759 Effect.scoped,
760 Effect.provide(NodeServices.layer),
761 Effect.ensuring(Effect.sync(() => NodeFS.rmSync(tempDir, { recursive: true, force: true }))),
762 );
763 });
764});