@@ -5,8 +5,9 @@ import { describe, expect, it } from "@effect/vitest";
55import * as Deferred from "effect/Deferred" ;
66import * as Effect from "effect/Effect" ;
77import * as Fiber from "effect/Fiber" ;
8+ import { vi } from "vite-plus/test" ;
89
9- import { mcpToolSession , runAcpMcpStdioBridge } from "./AcpMcpStdioBridge.ts" ;
10+ import { mcpToolSession , runAcpMcpCliFastPath , runAcpMcpStdioBridge } from "./AcpMcpStdioBridge.ts" ;
1011
1112function makeHarness ( responder : ( request : Request ) => Promise < Response > | Response ) {
1213 const input = new NodeStream . PassThrough ( ) ;
@@ -38,6 +39,54 @@ function pendingFetch(started: Deferred.Deferred<AbortSignal | undefined>) {
3839}
3940
4041describe ( "AcpMcpStdioBridge" , ( ) => {
42+ it ( "prints structured results once in the terminal while retaining other content and errors" , async ( ) => {
43+ const originalEnvironment = process . env ;
44+ using _environment = {
45+ [ Symbol . dispose ] : ( ) => {
46+ process . env = originalEnvironment ;
47+ } ,
48+ } ;
49+ process . env = {
50+ ...originalEnvironment ,
51+ T3_ACP_MCP_ENDPOINT : "http://127.0.0.1:1/mcp" ,
52+ T3_ACP_MCP_AUTHORIZATION : "Bearer bridge-test" ,
53+ } ;
54+ const structuredContent = { taskId : "task-1" , status : "failed" } ;
55+ const explanation = { type : "text" , text : "The command failed." } ;
56+ const image = { type : "image" , data : "image-data" , mimeType : "image/png" } ;
57+ const result = {
58+ structuredContent,
59+ content : [ { type : "text" , text : JSON . stringify ( structuredContent ) } , explanation , image ] ,
60+ isError : true ,
61+ } ;
62+ using fetch = vi . spyOn ( globalThis , "fetch" ) . mockImplementation ( async ( _url , init ) => {
63+ if ( init ?. method === "DELETE" ) return new Response ( null , { status : 204 } ) ;
64+ const message = JSON . parse ( String ( init ?. body ) ) as { id ?: string ; method : string } ;
65+ if ( message . method === "notifications/initialized" ) {
66+ return new Response ( null , { status : 202 } ) ;
67+ }
68+ return Response . json (
69+ {
70+ jsonrpc : "2.0" ,
71+ id : message . id ,
72+ result : message . method === "initialize" ? { protocolVersion : "2025-06-18" } : result ,
73+ } ,
74+ { headers : { "mcp-session-id" : "session-42" } } ,
75+ ) ;
76+ } ) ;
77+ using output = vi . spyOn ( process . stdout , "write" ) . mockReturnValue ( true ) ;
78+
79+ await runAcpMcpCliFastPath ( "acp-mcp-call" , [ "task_status" , '{"taskId":"task-1"}' ] ) ;
80+
81+ expect ( output ) . toHaveBeenCalledExactlyOnceWith (
82+ `${ JSON . stringify ( { ...result , content : [ explanation , image ] } ) } \n` ,
83+ ) ;
84+ expect ( fetch ) . toHaveBeenLastCalledWith (
85+ "http://127.0.0.1:1/mcp" ,
86+ expect . objectContaining ( { method : "DELETE" } ) ,
87+ ) ;
88+ } ) ;
89+
4190 it . effect ( "forwards requests and replays the session id and protocol version" , ( ) =>
4291 Effect . gen ( function * ( ) {
4392 const { input, written, requests, bridge } = makeHarness ( ( request ) => {
0 commit comments