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 NodeCrypto from "@effect/platform-node/NodeCrypto";
8import * as NodeServices from "@effect/platform-node/NodeServices";
9import * as Layer from "effect/Layer";
10import { assert, it } from "@effect/vitest";
11import * as HostProcess from "@t3tools/shared/HostProcess";
12import * as Deferred from "effect/Deferred";
13import * as Effect from "effect/Effect";
14import * as Exit from "effect/Exit";
15import * as Fiber from "effect/Fiber";
16import * as Scope from "effect/Scope";
17import * as Result from "effect/Result";
18import * as Stream from "effect/Stream";
19import { ChildProcessSpawner } from "effect/process";
20import { describe, expect } from "vite-plus/test";
21
22import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
23import { AgentScope } from "@t3tools/shared/AgentScope";
24import * as EffectAcpErrors from "effect-acp/errors";
25
26const __dirname = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
27const mockAgentPath = NodePath.join(__dirname, "../../../scripts/acp-mock-agent.ts");
28const mockAgentCommand = "node";
29const mockAgentArgs = [mockAgentPath];
30const mockRuntimeOptions = {
31 spawn: { command: mockAgentCommand, args: mockAgentArgs },
32 cwd: process.cwd(),
33 clientInfo: { name: "t3-test", version: "0.0.0" },
34 authMethodId: "test",
35} satisfies AcpSessionRuntime.AcpSessionRuntimeOptions;
36
37describe("AcpSessionRuntime", () => {
38 it.effect.each(["session/new", "session/resume"] as const)(
39 "buffers root metadata while %s startup is still pending",
40 (setupMethod) =>
41 Effect.gen(function* () {
42 const setupReplied = yield* Deferred.make<void>();
43 const allowStartup = yield* Deferred.make<void>();
44 const events: Array<AcpSessionRuntime.AcpSessionRuntimeEvent> = [];
45 const runtime = yield* AcpSessionRuntime.make({
46 ...mockRuntimeOptions,
47 ...(setupMethod === "session/resume"
48 ? {
49 spawn: {
50 ...mockRuntimeOptions.spawn,
51 env: { T3_ACP_SESSION_LIFECYCLE: "1" },
52 },
53 resumeSessionId: "mock-session-1",
54 resumeMethod: "resume" as const,
55 }
56 : {}),
57 requestLogger: (event) =>
58 event.method === setupMethod && event.status === "succeeded"
59 ? Deferred.succeed(setupReplied, undefined).pipe(
60 Effect.andThen(Deferred.await(allowStartup)),
61 )
62 : Effect.void,
63 });
64 yield* runtime.getEvents().pipe(
65 Stream.runForEach((event) => {
66 if (event._tag === "EventStreamBarrier") {
67 return Deferred.succeed(event.acknowledge, undefined);
68 }
69 events.push(event);
70 return Effect.void;
71 }),
72 Effect.forkChild,
73 );
74 const startup = yield* runtime.start().pipe(Effect.forkChild);
75 yield* Deferred.await(setupReplied);
76 yield* runtime.request("_test/startup-metadata", {});
77 yield* Deferred.succeed(allowStartup, undefined);
78 yield* Fiber.join(startup);
79 yield* runtime.drainEvents;
80
81 expect(events.map((event) => event._tag)).toEqual([
82 "AvailableCommandsUpdated",
83 "ModeChanged",
84 "ConfigOptionsUpdated",
85 ]);
86 expect(events[0]).toMatchObject({
87 availableCommands: [{ name: "plan", description: "Native command" }],
88 });
89 expect(yield* runtime.getModeState).toMatchObject({ currentModeId: "code" });
90 expect(events[2]).toMatchObject({
91 configOptions: yield* runtime.getConfigOptions,
92 });
93 expect(
94 (yield* runtime.getConfigOptions).find((option) => option.category === "model"),
95 ).toMatchObject({ currentValue: "gpt-5.4" });
96 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
97 );
98
99 it.effect("publishes model changes returned by a config request and live notifications", () =>
100 Effect.gen(function* () {
101 const runtime = yield* AcpSessionRuntime.make(mockRuntimeOptions);
102 yield* runtime.start();
103 const updates = yield* Stream.toPull(
104 runtime.getEvents().pipe(Stream.filter((event) => event._tag === "ConfigOptionsUpdated")),
105 );
106 const selected = yield* runtime.setConfigOption("model", "composer-2");
107 expect((yield* updates)[0]?.configOptions).toEqual(selected.configOptions);
108 yield* runtime.request("_test/startup-metadata", {});
109 expect((yield* updates)[0]?.configOptions).toEqual(yield* runtime.getConfigOptions);
110 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
111 );
112
113 it.effect("waits for native cancellation and drains final updates before another prompt", () =>
114 Effect.gen(function* () {
115 const toolStarted = yield* Deferred.make<void>();
116 const cancelReceived = yield* Deferred.make<void>();
117 const events: Array<AcpSessionRuntime.AcpSessionRuntimeEvent> = [];
118 let promptRequests = 0;
119 const runtime = yield* AcpSessionRuntime.make({
120 ...mockRuntimeOptions,
121 spawn: {
122 ...mockRuntimeOptions.spawn,
123 env: { T3_ACP_COMPLETE_FIRST_PROMPT_ON_CANCEL: "1" },
124 },
125 cancelBehavior: "wait-for-prompt",
126 requestLogger: (event) =>
127 Effect.sync(() => {
128 if (event.method === "session/prompt" && event.status === "started")
129 promptRequests += 1;
130 }),
131 });
132 yield* runtime.getEvents().pipe(
133 Stream.runForEach((event) => {
134 if (event._tag === "EventStreamBarrier") {
135 return Deferred.succeed(event.acknowledge, undefined);
136 }
137 events.push(event);
138 if (event._tag === "ToolCallUpdated" && event.toolCall.status === "inProgress") {
139 return Deferred.succeed(toolStarted, undefined);
140 }
141 if (event._tag === "ThoughtDelta" && event.text === "native-cancel-received") {
142 return Deferred.succeed(cancelReceived, undefined);
143 }
144 return Effect.void;
145 }),
146 Effect.forkChild,
147 );
148 yield* runtime.start();
149 const prompt = yield* runtime
150 .prompt({
151 prompt: [{ type: "text", text: "first" }],
152 })
153 .pipe(Effect.forkChild);
154 yield* Deferred.await(toolStarted);
155 const cancellation = yield* runtime.cancel.pipe(Effect.forkChild);
156 yield* Deferred.await(cancelReceived);
157 const replacement = yield* runtime
158 .prompt({
159 prompt: [{ type: "text", text: "second" }],
160 })
161 .pipe(Effect.forkChild({ startImmediately: true }));
162
163 expect(prompt.pollUnsafe()).toBeUndefined();
164 expect(cancellation.pollUnsafe()).toBeUndefined();
165 expect(promptRequests).toBe(1);
166 yield* runtime.request("_test/finish-cancel", {});
167 yield* Fiber.join(cancellation);
168
169 expect(yield* Fiber.join(prompt)).toEqual({
170 stopReason: "cancelled",
171 _meta: { nativeCancel: true },
172 });
173 expect(
174 events.some(
175 (event) =>
176 event._tag === "ToolCallUpdated" &&
177 event.toolCall.status === "failed" &&
178 event.toolCall.detail === "Cancelled.",
179 ),
180 ).toBe(true);
181 const cancelledDelta = events.find(
182 (event) => event._tag === "ContentDelta" && event.text === "Request cancelled.",
183 );
184 expect(cancelledDelta?._tag).toBe("ContentDelta");
185 if (cancelledDelta?._tag === "ContentDelta") {
186 expect(
187 events.filter(
188 (event) =>
189 event._tag === "AssistantItemCompleted" && event.itemId === cancelledDelta.itemId,
190 ),
191 ).toHaveLength(1);
192 }
193 expect(yield* Fiber.join(replacement)).toMatchObject({ stopReason: "end_turn" });
194 expect(promptRequests).toBe(2);
195 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
196 );
197
198 it.effect("reports an idle child exit and rejects later prompts", () =>
199 Effect.gen(function* () {
200 const stopped = yield* Deferred.make<string>();
201 const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
202 const runtime = yield* AcpSessionRuntime.make(mockRuntimeOptions).pipe(
203 Effect.provideService(
204 ChildProcessSpawner.ChildProcessSpawner,
205 ChildProcessSpawner.make((command) =>
206 spawner.spawn(command).pipe(
207 Effect.map((child) =>
208 ChildProcessSpawner.makeHandle({
209 ...child,
210 // Model an inherited pipe held open until detached work is stopped.
211 stdout: Stream.concat(
212 child.stdout,
213 Stream.fromEffect(Deferred.await(stopped)).pipe(Stream.drain),
214 ),
215 }),
216 ),
217 ),
218 ),
219 ),
220 Effect.provideService(AgentScope, {
221 ...AgentScope.defaultValue(),
222 wrap: ({ command, args }) =>
223 Effect.succeed({ command, args, unit: "t3code-acp-test.scope" }),
224 stop: (unit) => Deferred.succeed(stopped, unit).pipe(Effect.asVoid),
225 }),
226 );
227 yield* runtime.start();
228 expect(yield* Deferred.isDone(stopped)).toBe(false);
229 yield* runtime.notify("_test/exit", {});
230 const events = yield* runtime.getEvents().pipe(Stream.take(1), Stream.runCollect);
231 expect(yield* Deferred.await(stopped)).toBe("t3code-acp-test.scope");
232 const event = events[0];
233 expect(event).toMatchObject({ _tag: "ConnectionTerminated", error: { code: 19 } });
234 if (event?._tag !== "ConnectionTerminated") return;
235 expect(
236 yield* runtime
237 .prompt({
238 prompt: [{ type: "text", text: "must not run" }],
239 })
240 .pipe(Effect.flip),
241 ).toBe(event.error);
242 expect(yield* runtime.start().pipe(Effect.flip)).toBe(event.error);
243 expect(yield* runtime.initialize().pipe(Effect.flip)).toBe(event.error);
244 expect(
245 yield* runtime.request("_test/environment", {}).pipe(
246 Effect.match({
247 onFailure: (error) => error,
248 onSuccess: () => undefined,
249 }),
250 ),
251 ).toBe(event.error);
252 expect(yield* runtime.notify("_test/exit", {}).pipe(Effect.flip)).toBe(event.error);
253 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
254 );
255
256 it.effect("retires a native runtime when its prompt caller is interrupted", () =>
257 Effect.gen(function* () {
258 const dispatched = yield* Deferred.make<void>();
259 const runtime = yield* AcpSessionRuntime.make({
260 ...mockRuntimeOptions,
261 spawn: {
262 ...mockRuntimeOptions.spawn,
263 env: { T3_ACP_COMPLETE_FIRST_PROMPT_ON_CANCEL: "1" },
264 },
265 cancelBehavior: "wait-for-prompt",
266 });
267 yield* runtime.start();
268 const prompt = yield* runtime
269 .prompt(
270 {
271 prompt: [{ type: "text", text: "first" }],
272 },
273 { dispatched },
274 )
275 .pipe(Effect.forkChild);
276 yield* Deferred.await(dispatched);
277 yield* Fiber.interrupt(prompt);
278 const events = yield* runtime.getEvents().pipe(
279 Stream.filter((event) => event._tag === "ConnectionTerminated"),
280 Stream.take(1),
281 Stream.runCollect,
282 );
283 expect(events[0]).toMatchObject({
284 error: { _tag: "AcpTransportError", method: "session/prompt" },
285 });
286 expect(
287 yield* runtime
288 .prompt({
289 prompt: [{ type: "text", text: "must not run" }],
290 })
291 .pipe(Effect.flip),
292 ).toBe(events[0]?.error);
293 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
294 );
295
296 it.effect("fails a pending request when the stderr handler rejects the runtime", () =>
297 Effect.gen(function* () {
298 const failure = new EffectAcpErrors.AcpTransportError({
299 detail: "Sign in before continuing.",
300 cause: undefined,
301 });
302 const runtime = yield* AcpSessionRuntime.make({
303 ...mockRuntimeOptions,
304 spawn: { ...mockRuntimeOptions.spawn, env: { T3_ACP_FLOOD_STDERR: "1" } },
305 onStderr: () => Effect.fail(failure),
306 });
307 expect(yield* runtime.start().pipe(Effect.flip)).toBe(failure);
308 const events = yield* runtime.getEvents().pipe(
309 Stream.filter((event) => event._tag === "ConnectionTerminated"),
310 Stream.take(1),
311 Stream.runCollect,
312 );
313 expect(events[0]?.error).toBe(failure);
314 expect(yield* runtime.initialize().pipe(Effect.flip)).toBe(failure);
315 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
316 );
317
318 it.effect.each([
319 { name: "exit code", terminate: "process.exit(1)", code: 1, signal: undefined },
320 ...(HostProcess.Platform.defaultValue() === "win32"
321 ? []
322 : [
323 {
324 name: "signal",
325 terminate: "process.kill(process.pid, 'SIGTERM')",
326 code: undefined,
327 signal: "SIGTERM",
328 },
329 ]),
330 ])("retains the $name and sanitized stderr when ACP exits before initialize", (testCase) =>
331 Effect.gen(function* () {
332 const runtime = yield* AcpSessionRuntime.make({
333 ...mockRuntimeOptions,
334 spawn: {
335 command: process.execPath,
336 args: [
337 "-e",
338 `process.stderr.write("Invalid project config: Unrecognized key in cli.json\\nAuthorization: Bearer secret-token-value\\n", () => { ${testCase.terminate}; });`,
339 ],
340 },
341 });
342 const error = yield* runtime.start().pipe(Effect.flip);
343 assert.instanceOf(error, EffectAcpErrors.AcpProcessExitedError);
344 expect(error.code).toBe(testCase.code);
345 expect(error.signal).toBe(testCase.signal);
346 expect(error).toMatchObject({
347 pid: expect.any(Number),
348 stderr:
349 "Invalid project config: Unrecognized key in cli.json\nAuthorization: Bearer [redacted]",
350 });
351 expect(error.message).toBe(
352 `${testCase.signal ? "ACP process exited after signal SIGTERM" : "ACP process exited with code 1"}\nInvalid project config: Unrecognized key in cli.json\nAuthorization: Bearer [redacted]`,
353 );
354 if (testCase.signal) {
355 expect(error.cause).toMatchObject({
356 reason: {
357 module: "ChildProcess",
358 method: "exitCode",
359 cause: new Error("Process interrupted due to receipt of signal: 'SIGTERM'"),
360 },
361 });
362 }
363 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
364 );
365
366 it.effect("drains large stderr output and keeps auth-sized logging chunks", () =>
367 Effect.gen(function* () {
368 const lengths: Array<number> = [];
369 for (const logStderr of [false, true]) {
370 yield* Effect.gen(function* () {
371 const runtime = yield* AcpSessionRuntime.make({
372 ...mockRuntimeOptions,
373 spawn: { ...mockRuntimeOptions.spawn, env: { T3_ACP_FLOOD_STDERR: "1" } },
374 ...(logStderr
375 ? {
376 onStderr: (text: string) =>
377 Effect.sync(() => {
378 lengths.push(text.length);
379 }),
380 }
381 : {}),
382 });
383 expect(yield* runtime.initialize()).toMatchObject({ protocolVersion: 2 });
384 }).pipe(Effect.scoped);
385 }
386 expect(lengths.length).toBeGreaterThan(0);
387 expect(Math.max(...lengths)).toBeGreaterThanOrEqual(16_384);
388 expect(Math.max(...lengths)).toBeLessThanOrEqual(32_768);
389 }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
390 );
391
392 it.effect("releases a queued event drain when its runtime scope closes", () =>
393 Effect.gen(function* () {
394 const scope = yield* Effect.acquireRelease(Scope.make(), (scope) =>
395 Scope.close(scope, Exit.void),
396 );
397 const barrierReceived = yield* Deferred.make<void>();
398 const runtime = yield* AcpSessionRuntime.make(mockRuntimeOptions).pipe(
399 Effect.provideService(Scope.Scope, scope),
400 );
401 yield* runtime.start();
402 yield* runtime.getEvents().pipe(
403 Stream.runForEach((event) =>
404 event._tag === "EventStreamBarrier"
405 ? Deferred.succeed(barrierReceived, undefined).pipe(Effect.andThen(Effect.never))
406 : Effect.void,
407 ),
408 Effect.forkIn(scope),
409 );
410 const drain = yield* runtime.drainEvents.pipe(Effect.forkChild);
411 yield* Deferred.await(barrierReceived);
412 yield* Scope.close(scope, Exit.void);
413 yield* Fiber.join(drain);
414 yield* runtime.drainEvents;
415 expect(yield* runtime.initialize().pipe(Effect.flip)).toMatchObject({
416 _tag: "AcpTransportError",
417 detail: "The ACP session runtime is closed.",
418 });
419 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
420 );
421
422 it.effect("does not restore ambient variables to a sanitized child environment", () =>
423 Effect.gen(function* () {
424 yield* Effect.acquireRelease(
425 Effect.sync(() => {
426 const previous = process.env.T3_ACP_RUNTIME_AMBIENT;
427 process.env.T3_ACP_RUNTIME_AMBIENT = "sentinel";
428 return previous;
429 }),
430 (previous) =>
431 Effect.sync(() => {
432 if (previous === undefined) delete process.env.T3_ACP_RUNTIME_AMBIENT;
433 else process.env.T3_ACP_RUNTIME_AMBIENT = previous;
434 }),
435 );
436 const runtime = yield* AcpSessionRuntime.make({
437 ...mockRuntimeOptions,
438 spawn: {
439 command: process.execPath,
440 args: mockAgentArgs,
441 extendEnv: false,
442 env: { T3_ACP_RUNTIME_EXPLICIT: "kept" },
443 },
444 });
445 yield* runtime.initialize();
446 expect(yield* runtime.request("_test/environment", {})).toEqual({
447 inherited: false,
448 explicit: true,
449 });
450 }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
451 );
452
453 it("selects explicit or agent-managed authentication without choosing terminal auth", () => {
454 const methods = [
455 { id: "browser", name: "Browser", type: "terminal" as const },
456 { id: "api-key", name: "API key", type: "agent" as const },
457 ];
458
459 expect(AcpSessionRuntime.selectAcpAgentAuthMethod(methods)?.id).toBe("api-key");
460 expect(AcpSessionRuntime.selectAcpAgentAuthMethod(methods, "browser")?.id).toBe("browser");
461 expect(AcpSessionRuntime.selectAcpAgentAuthMethod(methods, "missing")).toBeUndefined();
462 });
463
464 it.effect("prefers MCP-over-ACP only when the agent advertises that transport", () => {
465 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
466 return Effect.gen(function* () {
467 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
468 yield* runtime.start();
469
470 const created = requestEvents.find(
471 (event) => event.method === "session/new" && event.status === "started",
472 );
473 expect(created?.payload).toMatchObject({
474 mcpServers: [{ type: "acp", name: "t3-code", serverId: "t3-code" }],
475 });
476 }).pipe(
477 Effect.provide(
478 AcpSessionRuntime.layer({
479 spawn: {
480 command: mockAgentCommand,
481 args: mockAgentArgs,
482 env: { T3_ACP_MCP_ACP: "1" },
483 },
484 cwd: process.cwd(),
485 clientInfo: { name: "t3-test", version: "0.0.0" },
486 authMethodId: "test",
487 mcpServers: [{ type: "stdio", name: "t3-code", command: "/usr/bin/node", args: [] }],
488 acpMcpServers: [{ type: "acp", name: "t3-code", serverId: "t3-code" }],
489 requestLogger: (event) =>
490 Effect.sync(() => {
491 requestEvents.push(event);
492 }),
493 }),
494 ),
495 Effect.scoped,
496 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
497 );
498 });
499
500 it.effect("supports v2 session deletion and secret-safe provider management", () => {
501 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
502 return Effect.gen(function* () {
503 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
504 yield* runtime.start();
505
506 yield* runtime.deleteSession("native-session-1");
507 expect((yield* runtime.listProviders).providers[0]).toMatchObject({
508 providerId: "mock-provider",
509 current: null,
510 });
511 yield* runtime.setProvider({
512 providerId: "mock-provider",
513 apiType: "openai",
514 baseUrl: "https://api.example.test/v1",
515 headers: { Authorization: "Bearer top-secret" },
516 });
517 expect((yield* runtime.listProviders).providers[0]?.current).toEqual({
518 apiType: "openai",
519 baseUrl: "https://api.example.test/v1",
520 });
521 yield* runtime.disableProvider("mock-provider");
522 expect((yield* runtime.listProviders).providers[0]?.current).toBeNull();
523
524 const setRequest = requestEvents.find(
525 (event) => event.method === "providers/set" && event.status === "started",
526 );
527 expect(setRequest?.payload).toMatchObject({
528 headers: { Authorization: "[redacted]" },
529 });
530 }).pipe(
531 Effect.provide(
532 AcpSessionRuntime.layer({
533 spawn: {
534 command: mockAgentCommand,
535 args: mockAgentArgs,
536 env: { T3_ACP_V2_MANAGEMENT: "1" },
537 },
538 cwd: process.cwd(),
539 clientInfo: { name: "t3-test", version: "0.0.0" },
540 authMethodId: "test",
541 requestLogger: (event) =>
542 Effect.sync(() => {
543 requestEvents.push(event);
544 }),
545 }),
546 ),
547 Effect.scoped,
548 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
549 );
550 });
551
552 it.effect("authenticates explicitly typed v2 agent methods and retries session creation", () => {
553 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
554 return Effect.gen(function* () {
555 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
556 const started = yield* runtime.start();
557 expect(started.sessionId).toBe("mock-session-1");
558 expect(
559 requestEvents.filter((event) => event.status === "started").map((event) => event.method),
560 ).toEqual(["initialize", "session/new", "authenticate", "session/new"]);
561 expect(
562 requestEvents.filter(
563 (event) => event.method === "session/new" && event.status === "failed",
564 ),
565 ).toHaveLength(1);
566 expect(
567 requestEvents.filter(
568 (event) => event.method === "session/new" && event.status === "succeeded",
569 ),
570 ).toHaveLength(1);
571 }).pipe(
572 Effect.provide(
573 AcpSessionRuntime.layer({
574 authMethodId: "test",
575 spawn: {
576 command: mockAgentCommand,
577 args: mockAgentArgs,
578 env: {
579 T3_ACP_AUTH_METHOD_ID: "test",
580 T3_ACP_REQUIRE_AUTH: "1",
581 },
582 },
583 cwd: process.cwd(),
584 clientInfo: { name: "t3-test", version: "0.0.0" },
585 requestLogger: (event) =>
586 Effect.sync(() => {
587 requestEvents.push(event);
588 }),
589 }),
590 ),
591 Effect.scoped,
592 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
593 );
594 });
595
596 it.effect("can surface auth-required without authenticating during discovery", () => {
597 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
598 let advertisedAuthMethodName: string | undefined;
599 return Effect.gen(function* () {
600 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
601 const result = yield* Effect.result(runtime.start());
602
603 expect(Result.isFailure(result)).toBe(true);
604 expect(advertisedAuthMethodName).toBe("Mock agent authentication");
605 expect(
606 requestEvents.filter((event) => event.status === "started").map((event) => event.method),
607 ).toEqual(["initialize", "session/new"]);
608 }).pipe(
609 Effect.provide(
610 AcpSessionRuntime.layer({
611 authenticateOnAuthRequired: false,
612 authMethodId: "test",
613 spawn: {
614 command: mockAgentCommand,
615 args: mockAgentArgs,
616 env: {
617 T3_ACP_AUTH_METHOD_ID: "test",
618 T3_ACP_REQUIRE_AUTH: "1",
619 },
620 },
621 cwd: process.cwd(),
622 clientInfo: { name: "t3-test", version: "0.0.0" },
623 onInitialized: (initializeResult) =>
624 Effect.sync(() => {
625 advertisedAuthMethodName = initializeResult.authMethods?.[0]?.name;
626 }),
627 requestLogger: (event) =>
628 Effect.sync(() => {
629 requestEvents.push(event);
630 }),
631 }),
632 ),
633 Effect.scoped,
634 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
635 );
636 });
637
638 it.effect("starts a session, prompts, and emits normalized events against the mock agent", () =>
639 Effect.gen(function* () {
640 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
641 const started = yield* runtime.start();
642
643 expect(started.initializeResult).toMatchObject({ protocolVersion: 2 });
644 expect(started.sessionId).toBe("mock-session-1");
645
646 const promptResult = yield* runtime.prompt({
647 prompt: [{ type: "text", text: "hi" }],
648 });
649 expect(promptResult).toMatchObject({ stopReason: "end_turn" });
650
651 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 4)));
652 expect(notes).toHaveLength(4);
653 expect(notes.map((note) => note._tag)).toEqual([
654 "PlanUpdated",
655 "AssistantItemStarted",
656 "ContentDelta",
657 "AssistantItemCompleted",
658 ]);
659 const planUpdate = notes.find((note) => note._tag === "PlanUpdated");
660 expect(planUpdate?._tag).toBe("PlanUpdated");
661 if (planUpdate?._tag === "PlanUpdated") {
662 expect(planUpdate.payload).toMatchObject({
663 nativePlanId: "mock-plan",
664 kind: "items",
665 });
666 if (planUpdate.payload.kind === "items") {
667 expect(planUpdate.payload.plan).toHaveLength(2);
668 }
669 }
670 const assistantStart = notes[1];
671 const assistantDelta = notes[2];
672 if (
673 assistantStart?._tag === "AssistantItemStarted" &&
674 assistantDelta?._tag === "ContentDelta"
675 ) {
676 expect(assistantDelta.itemId).toBe(assistantStart.itemId);
677 }
678 }).pipe(
679 Effect.provide(
680 AcpSessionRuntime.layer({
681 spawn: {
682 command: mockAgentCommand,
683 args: mockAgentArgs,
684 },
685 cwd: process.cwd(),
686 clientInfo: { name: "t3-test", version: "0.0.0" },
687 authMethodId: "test",
688 }),
689 ),
690 Effect.scoped,
691 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
692 ),
693 );
694
695 it.effect("keeps assistant item IDs unique when a provider session restarts", () => {
696 const collectFirstAssistantItemId = Effect.gen(function* () {
697 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
698 const started = yield* runtime.start();
699 expect(started.sessionId).toBe("mock-session-1");
700
701 yield* runtime.prompt({
702 prompt: [{ type: "text", text: "hi" }],
703 });
704
705 const events = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 4)));
706 const assistantStart = events.find((event) => event._tag === "AssistantItemStarted");
707 expect(assistantStart?._tag).toBe("AssistantItemStarted");
708 return assistantStart?._tag === "AssistantItemStarted" ? assistantStart.itemId : "";
709 }).pipe(
710 Effect.provide(
711 AcpSessionRuntime.layer({
712 spawn: {
713 command: mockAgentCommand,
714 args: mockAgentArgs,
715 },
716 cwd: process.cwd(),
717 clientInfo: { name: "t3-test", version: "0.0.0" },
718 authMethodId: "test",
719 }),
720 ),
721 Effect.scoped,
722 );
723
724 return Effect.gen(function* () {
725 const beforeRestart = yield* collectFirstAssistantItemId;
726 const afterRestart = yield* collectFirstAssistantItemId;
727
728 expect(afterRestart).not.toBe(beforeRestart);
729 }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)));
730 });
731
732 it.effect("drops session updates emitted for a child ACP session", () =>
733 Effect.gen(function* () {
734 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
735 yield* runtime.start();
736
737 const promptResult = yield* runtime.prompt({
738 prompt: [{ type: "text", text: "hi" }],
739 });
740 expect(promptResult).toMatchObject({ stopReason: "end_turn" });
741
742 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 4)));
743 expect(notes.map((note) => note._tag)).toEqual([
744 "AssistantItemStarted",
745 "ContentDelta",
746 "ContentDelta",
747 "AssistantItemCompleted",
748 ]);
749 expect(
750 notes
751 .filter((note) => note._tag === "ContentDelta")
752 .map((note) => note.text)
753 .join(""),
754 ).toBe("root before child root after child");
755 expect(notes.some((note) => note._tag === "ToolCallUpdated")).toBe(false);
756 }).pipe(
757 Effect.provide(
758 AcpSessionRuntime.layer({
759 spawn: {
760 command: mockAgentCommand,
761 args: mockAgentArgs,
762 env: {
763 T3_ACP_EMIT_FOREIGN_SESSION_UPDATES: "1",
764 },
765 },
766 cwd: process.cwd(),
767 clientInfo: { name: "t3-test", version: "0.0.0" },
768 authMethodId: "test",
769 }),
770 ),
771 Effect.scoped,
772 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
773 ),
774 );
775
776 it.effect("segments assistant text around ACP tool calls", () =>
777 Effect.gen(function* () {
778 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
779 yield* runtime.start();
780
781 const promptResult = yield* runtime.prompt({
782 prompt: [{ type: "text", text: "hi" }],
783 });
784 expect(promptResult).toMatchObject({ stopReason: "end_turn" });
785
786 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 7)));
787 expect(notes.map((note) => note._tag)).toEqual([
788 "AssistantItemStarted",
789 "ContentDelta",
790 "AssistantItemCompleted",
791 "ToolCallUpdated",
792 "ToolCallUpdated",
793 "AssistantItemStarted",
794 "ContentDelta",
795 ]);
796
797 const firstStarted = notes[0];
798 const firstDelta = notes[1];
799 const firstCompleted = notes[2];
800 const secondStarted = notes[5];
801 const secondDelta = notes[6];
802 expect(firstStarted?._tag).toBe("AssistantItemStarted");
803 expect(firstCompleted?._tag).toBe("AssistantItemCompleted");
804 expect(secondStarted?._tag).toBe("AssistantItemStarted");
805 if (
806 firstStarted?._tag === "AssistantItemStarted" &&
807 firstDelta?._tag === "ContentDelta" &&
808 firstCompleted?._tag === "AssistantItemCompleted" &&
809 secondStarted?._tag === "AssistantItemStarted" &&
810 secondDelta?._tag === "ContentDelta"
811 ) {
812 expect(firstDelta.itemId).toBe(firstStarted.itemId);
813 expect(firstCompleted.itemId).toBe(firstStarted.itemId);
814 expect(secondStarted.itemId).not.toBe(firstStarted.itemId);
815 expect(secondDelta.itemId).toBe(secondStarted.itemId);
816 }
817 }).pipe(
818 Effect.provide(
819 AcpSessionRuntime.layer({
820 spawn: {
821 command: mockAgentCommand,
822 args: mockAgentArgs,
823 env: {
824 T3_ACP_EMIT_INTERLEAVED_ASSISTANT_TOOL_CALLS: "1",
825 },
826 },
827 cwd: process.cwd(),
828 clientInfo: { name: "t3-test", version: "0.0.0" },
829 authMethodId: "test",
830 }),
831 ),
832 Effect.scoped,
833 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
834 ),
835 );
836
837 it.effect("keeps one answer when an earlier tool reports progress mid-stream", () =>
838 Effect.gen(function* () {
839 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
840 yield* runtime.start();
841 yield* runtime.prompt({ prompt: [{ type: "text", text: "hi" }] });
842
843 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 9)));
844 expect(notes.map((note) => note._tag)).toEqual([
845 "ToolCallUpdated",
846 "AssistantItemStarted",
847 "ContentDelta",
848 "ContentDelta",
849 "ToolCallUpdated",
850 "ContentDelta",
851 "ToolCallUpdated",
852 "ContentDelta",
853 "AssistantItemCompleted",
854 ]);
855 const itemIds = new Set(
856 notes.flatMap((note) =>
857 note._tag === "ContentDelta" ||
858 note._tag === "AssistantItemStarted" ||
859 note._tag === "AssistantItemCompleted"
860 ? [note.itemId]
861 : [],
862 ),
863 );
864 expect(itemIds.size).toBe(1);
865 }).pipe(
866 Effect.provide(
867 AcpSessionRuntime.layer({
868 spawn: {
869 command: mockAgentCommand,
870 args: mockAgentArgs,
871 env: { T3_ACP_EMIT_BACKGROUND_TOOL_DURING_ANSWER: "1" },
872 },
873 cwd: process.cwd(),
874 clientInfo: { name: "t3-test", version: "0.0.0" },
875 authMethodId: "test",
876 }),
877 ),
878 Effect.scoped,
879 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
880 ),
881 );
882
883 it.effect("emits status-only tool updates through completion", () =>
884 Effect.gen(function* () {
885 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
886 yield* runtime.start();
887
888 const promptResult = yield* runtime.prompt({
889 prompt: [{ type: "text", text: "hi" }],
890 });
891 expect(promptResult).toMatchObject({ stopReason: "end_turn" });
892
893 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 3)));
894 expect(notes.map((note) => note._tag)).toEqual([
895 "ToolCallUpdated",
896 "ToolCallUpdated",
897 "ToolCallUpdated",
898 ]);
899 const toolCalls = notes.flatMap((note) =>
900 note._tag === "ToolCallUpdated" ? [note.toolCall] : [],
901 );
902 expect(toolCalls.map((toolCall) => toolCall.status)).toEqual([
903 "pending",
904 "inProgress",
905 "completed",
906 ]);
907 for (const toolCall of toolCalls) {
908 expect(toolCall.title).toBe("Read file");
909 }
910 }).pipe(
911 Effect.provide(
912 AcpSessionRuntime.layer({
913 spawn: {
914 command: mockAgentCommand,
915 args: mockAgentArgs,
916 env: {
917 T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1",
918 },
919 },
920 cwd: process.cwd(),
921 clientInfo: { name: "t3-test", version: "0.0.0" },
922 authMethodId: "test",
923 }),
924 ),
925 Effect.scoped,
926 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
927 ),
928 );
929
930 it.effect("supports negotiated ACP session list, fork, resume, and close methods", () => {
931 const requestEvents: Array<AcpSessionRuntime.AcpSessionRequestLogEvent> = [];
932 return Effect.gen(function* () {
933 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
934 const started = yield* runtime.start();
935 expect(started.initializeResult.agentCapabilities?.sessionCapabilities).toMatchObject({
936 list: {},
937 fork: {},
938 resume: {},
939 close: {},
940 });
941 expect(started.initializeResult.agentCapabilities?.auth).toMatchObject({ logout: {} });
942
943 const listed = yield* runtime.listSessions();
944 expect(listed.sessions.map((session) => session.sessionId)).toEqual(["mock-session-1"]);
945
946 const forked = yield* runtime.forkSession(started.sessionId);
947 expect(forked.sessionId).toBe("mock-session-1-fork");
948 yield* runtime.prompt({ prompt: [{ type: "text", text: "on fork" }] });
949
950 const resumed = yield* runtime.resumeSession(started.sessionId);
951 expect(resumed.sessionId).toBe("mock-session-1");
952 yield* runtime.closeSession();
953 yield* runtime.logout;
954
955 expect(
956 requestEvents.find(
957 (event) => event.method === "session/prompt" && event.status === "started",
958 )?.payload,
959 ).toMatchObject({ sessionId: "mock-session-1-fork" });
960 expect(
961 requestEvents.filter((event) => event.status === "started").map((event) => event.method),
962 ).toEqual(
963 expect.arrayContaining([
964 "session/list",
965 "session/fork",
966 "session/resume",
967 "session/close",
968 "logout",
969 ]),
970 );
971 // Omitted roots clear an agent's stored ones, so every activation resends them.
972 for (const method of ["session/new", "session/fork", "session/resume"]) {
973 expect(
974 requestEvents.find((event) => event.method === method && event.status === "started")
975 ?.payload,
976 ).toMatchObject({
977 additionalDirectories: ["/tmp/t3-attachments"],
978 _meta: { negotiated: "0.0.0" },
979 });
980 }
981 }).pipe(
982 Effect.provide(
983 AcpSessionRuntime.layer({
984 authMethodId: "test",
985 spawn: {
986 command: mockAgentCommand,
987 args: mockAgentArgs,
988 env: {
989 T3_ACP_SESSION_LIFECYCLE: "1",
990 },
991 },
992 additionalDirectories: ["/tmp/t3-attachments"],
993 sessionMeta: (initializeResult) => ({
994 negotiated: initializeResult.agentInfo?.version ?? "none",
995 }),
996 cwd: process.cwd(),
997 clientInfo: { name: "t3-test", version: "0.0.0" },
998 requestLogger: (event) =>
999 Effect.sync(() => {
1000 requestEvents.push(event);
1001 }),
1002 }),
1003 ),
1004 Effect.scoped,
1005 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1006 );
1007 });
1008
1009 it.effect("rejects unauthenticated ACP session lifecycle requests", () =>
1010 Effect.gen(function* () {
1011 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
1012 yield* runtime.start();
1013
1014 const listError = yield* runtime.listSessions().pipe(Effect.flip);
1015 expect(listError._tag).toBe("AcpRequestError");
1016 if (listError._tag === "AcpRequestError") {
1017 expect(listError.code).toBe(-32000);
1018 }
1019
1020 const forkError = yield* runtime.forkSession("mock-session-1").pipe(Effect.flip);
1021 expect(forkError._tag).toBe("AcpRequestError");
1022 if (forkError._tag === "AcpRequestError") {
1023 expect(forkError.code).toBe(-32000);
1024 }
1025
1026 const resumeError = yield* runtime.resumeSession("mock-session-1").pipe(Effect.flip);
1027 expect(resumeError._tag).toBe("AcpRequestError");
1028 if (resumeError._tag === "AcpRequestError") {
1029 expect(resumeError.code).toBe(-32000);
1030 }
1031
1032 const closeError = yield* runtime.closeSession().pipe(Effect.flip);
1033 expect(closeError._tag).toBe("AcpRequestError");
1034 if (closeError._tag === "AcpRequestError") {
1035 expect(closeError.code).toBe(-32000);
1036 }
1037 }).pipe(
1038 Effect.provide(
1039 AcpSessionRuntime.layer({
1040 spawn: {
1041 command: mockAgentCommand,
1042 args: mockAgentArgs,
1043 env: {
1044 T3_ACP_REQUIRE_AUTH: "1",
1045 T3_ACP_SESSION_LIFECYCLE: "1",
1046 },
1047 },
1048 cwd: process.cwd(),
1049 resumeSessionId: "mock-session-1",
1050 clientInfo: { name: "t3-test", version: "0.0.0" },
1051 }),
1052 ),
1053 Effect.scoped,
1054 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1055 ),
1056 );
1057
1058 // regression: #3156 harden ACP resume with replay-idle load readiness
1059 it.effect("fails session startup when session/load returns an error", () =>
1060 Effect.gen(function* () {
1061 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
1062 const error = yield* runtime.start().pipe(Effect.flip);
1063
1064 expect(error._tag).toBe("AcpRequestError");
1065 }).pipe(
1066 Effect.provide(
1067 AcpSessionRuntime.layer({
1068 authMethodId: "test",
1069 spawn: {
1070 command: mockAgentCommand,
1071 args: mockAgentArgs,
1072 env: {
1073 T3_ACP_FAIL_LOAD_SESSION: "1",
1074 },
1075 },
1076 cwd: process.cwd(),
1077 resumeSessionId: "stale-session-id",
1078 clientInfo: { name: "t3-test", version: "0.0.0" },
1079 }),
1080 ),
1081 Effect.scoped,
1082 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1083 ),
1084 );
1085
1086 it.effect("keeps active configuration after a candidate session load fails", () =>
1087 Effect.gen(function* () {
1088 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
1089 yield* runtime.start();
1090 const before = yield* runtime.getConfigOptions;
1091
1092 const error = yield* runtime.loadSession("candidate-session").pipe(Effect.flip);
1093
1094 expect(error._tag).toBe("AcpRequestError");
1095 expect(yield* runtime.getConfigOptions).toEqual(before);
1096 expect(before.some((option) => option.id === "candidate-only")).toBe(false);
1097 }).pipe(
1098 Effect.provide(
1099 AcpSessionRuntime.layer({
1100 authMethodId: "test",
1101 spawn: {
1102 command: mockAgentCommand,
1103 args: mockAgentArgs,
1104 env: {
1105 T3_ACP_FAIL_LOAD_SESSION_AFTER_CONFIG_REPLAY: "1",
1106 },
1107 },
1108 cwd: process.cwd(),
1109 clientInfo: { name: "t3-test", version: "0.0.0" },
1110 }),
1111 ),
1112 Effect.scoped,
1113 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1114 ),
1115 );
1116
1117 it.effect("ignores session/update replay notifications during session/load", () =>
1118 Effect.gen(function* () {
1119 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
1120 yield* runtime.start();
1121
1122 yield* runtime.prompt({
1123 prompt: [{ type: "text", text: "hi" }],
1124 });
1125 const notes = Array.from(yield* Stream.runCollect(Stream.take(runtime.getEvents(), 4)));
1126 expect(notes.map((note) => note._tag)).toEqual([
1127 "PlanUpdated",
1128 "AssistantItemStarted",
1129 "ContentDelta",
1130 "AssistantItemCompleted",
1131 ]);
1132 expect(notes.some((note) => note._tag === "ToolCallUpdated")).toBe(false);
1133 }).pipe(
1134 Effect.provide(
1135 AcpSessionRuntime.layer({
1136 authMethodId: "test",
1137 spawn: {
1138 command: mockAgentCommand,
1139 args: mockAgentArgs,
1140 env: {
1141 T3_ACP_EMIT_LOAD_REPLAY: "1",
1142 },
1143 },
1144 cwd: process.cwd(),
1145 resumeSessionId: "mock-session-1",
1146 clientInfo: { name: "t3-test", version: "0.0.0" },
1147 }),
1148 ),
1149 Effect.scoped,
1150 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1151 ),
1152 );
1153
1154 it.effect("rejects invalid config option values before sending session/set_config_option", () => {
1155 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "acp-runtime-"));
1156 const requestLogPath = NodePath.join(tempDir, "requests.ndjson");
1157 return Effect.gen(function* () {
1158 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
1159 yield* runtime.start();
1160
1161 const error = yield* runtime.setModel("composer-2[fast=false]").pipe(Effect.flip);
1162 expect(error._tag).toBe("AcpRequestError");
1163 if (error._tag === "AcpRequestError") {
1164 expect(error.code).toBe(-32602);
1165 expect(error.message).toContain(
1166 'Invalid value "composer-2[fast=false]" for session config option "model"',
1167 );
1168 expect(error.message).toContain("composer-2[fast=true]");
1169 }
1170
1171 const recordedRequests = NodeFS.readFileSync(requestLogPath, "utf8")
1172 .trim()
1173 .split("\n")
1174 .filter((line) => line.length > 0)
1175 .map((line) => JSON.parse(line) as { method?: string; params?: { value?: unknown } });
1176 expect(
1177 recordedRequests.some(
1178 (message) =>
1179 message.method === "session/set_config_option" &&
1180 message.params?.value === "composer-2[fast=false]",
1181 ),
1182 ).toBe(false);
1183 }).pipe(
1184 Effect.provide(
1185 AcpSessionRuntime.layer({
1186 authMethodId: "test",
1187 spawn: {
1188 command: mockAgentCommand,
1189 args: mockAgentArgs,
1190 env: {
1191 T3_ACP_REQUEST_LOG_PATH: requestLogPath,
1192 },
1193 },
1194 cwd: process.cwd(),
1195 clientInfo: { name: "t3-test", version: "0.0.0" },
1196 }),
1197 ),
1198 Effect.scoped,
1199 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1200 Effect.ensuring(Effect.sync(() => NodeFS.rmSync(tempDir, { recursive: true, force: true }))),
1201 );
1202 });
1203
1204 it.effect("sends configured custom models the agent does not advertise", () => {
1205 const tempDir = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "acp-runtime-"));
1206 const requestLogPath = NodePath.join(tempDir, "requests.ndjson");
1207 return Effect.gen(function* () {
1208 const runtime = yield* AcpSessionRuntime.AcpSessionRuntime;
1209 yield* runtime.start();
1210
1211 yield* runtime.setModel("cline-free/custom-model");
1212 const error = yield* runtime.setModel("unconfigured/model").pipe(Effect.flip);
1213 expect(error._tag).toBe("AcpRequestError");
1214
1215 const sentModels = NodeFS.readFileSync(requestLogPath, "utf8")
1216 .trim()
1217 .split("\n")
1218 .filter((line) => line.length > 0)
1219 .map((line) => JSON.parse(line) as { method?: string; params?: { value?: unknown } })
1220 .filter((message) => message.method === "session/set_config_option")
1221 .map((message) => message.params?.value);
1222 expect(sentModels).toEqual(["cline-free/custom-model"]);
1223 }).pipe(
1224 Effect.provide(
1225 AcpSessionRuntime.layer({
1226 ...mockRuntimeOptions,
1227 spawn: {
1228 command: mockAgentCommand,
1229 args: mockAgentArgs,
1230 env: { T3_ACP_REQUEST_LOG_PATH: requestLogPath },
1231 },
1232 customModels: ["cline-free/custom-model"],
1233 }),
1234 ),
1235 Effect.scoped,
1236 Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1237 Effect.ensuring(Effect.sync(() => NodeFS.rmSync(tempDir, { recursive: true, force: true }))),
1238 );
1239 });
1240});