11import * as NodeServices from "@effect/platform-node/NodeServices" ;
22import { assert , describe , it } from "@effect/vitest" ;
33import {
4+ EnvironmentId ,
45 MessageId ,
56 NodeId ,
67 ProjectId ,
@@ -12,7 +13,7 @@ import {
1213 ThreadId ,
1314} from "@t3tools/contracts" ;
1415import { pendingBackgroundTurnItems } from "@t3tools/shared/orchestrationV2PendingBackgroundWork" ;
15- import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime" ;
16+ import { resolveSelfInvocation , selfInvocationArgs } from "@t3tools/shared/nodeRuntime" ;
1617import * as Exit from "effect/Exit" ;
1718import * as Fiber from "effect/Fiber" ;
1819import * as DateTime from "effect/DateTime" ;
@@ -1113,6 +1114,136 @@ describe("AcpRegistryAdapterV2", () => {
11131114 } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
11141115 ) ;
11151116
1117+ it . effect ( "gives Copilot T3's MCP server over HTTP when it advertises HTTP" , ( ) =>
1118+ Effect . gen ( function * ( ) {
1119+ const selfInvocation = yield * resolveSelfInvocation ( ) ;
1120+ const mockAgentPath = yield * ( yield * Path . Path ) . fromFileUrl (
1121+ new URL ( "../../../scripts/acp-mock-agent.ts" , import . meta. url ) ,
1122+ ) ;
1123+ const mcpSessions = yield * McpProviderSessions . McpProviderSessions ;
1124+ const endpoint = "http://127.0.0.1:43123/mcp" ;
1125+ const sessionMcpServers = Effect . fn ( "sessionMcpServers" ) ( function * (
1126+ config : Record < string , unknown > ,
1127+ agentEnvironment : Record < string , string > = { } ,
1128+ ) {
1129+ const requests : Array < AcpSessionRuntime . AcpSessionRequestLogEvent > = [ ] ;
1130+ const instanceId = ProviderInstanceId . make ( "acp-registry-mcp-transport" ) ;
1131+ const threadId = ThreadId . make ( "thread-acp-registry-mcp-transport" ) ;
1132+ const mcpSession = {
1133+ environmentId : EnvironmentId . make ( "environment-acp-registry-mcp-transport" ) ,
1134+ threadId,
1135+ providerSessionId : "mcp-session-acp-registry-mcp-transport" ,
1136+ providerInstanceId : instanceId ,
1137+ endpoint,
1138+ browserToolsAvailable : false ,
1139+ } ;
1140+ yield * mcpSessions . set ( { ...mcpSession , authorizationHeader : "Bearer opened-token" } ) ;
1141+ const adapter = yield * makeAcpRegistryAdapterV2 ( {
1142+ selfInvocation,
1143+ instanceId,
1144+ settings : yield * decodeAcpRegistryAdapterSettings ( config ) ,
1145+ environment : { } ,
1146+ nativeLogging : ( ) => ( {
1147+ requestLogger : ( event ) =>
1148+ Effect . sync ( ( ) => {
1149+ if ( event . status === "started" ) requests . push ( event ) ;
1150+ } ) ,
1151+ } ) ,
1152+ } ) . pipe (
1153+ Effect . provide (
1154+ Layer . mock ( AcpRegistrySupport . AcpRegistryCatalog ) ( {
1155+ resolve : ( ) =>
1156+ Effect . succeed ( {
1157+ distribution : "local" as const ,
1158+ spawn : {
1159+ command : process . execPath ,
1160+ args : [ mockAgentPath ] ,
1161+ env : { T3_ACP_SESSION_LIFECYCLE : "1" , ...agentEnvironment } ,
1162+ } ,
1163+ } ) ,
1164+ } ) ,
1165+ ) ,
1166+ ) ;
1167+ const modelSelection = { instanceId, model : "default" } as const ;
1168+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
1169+ runtimeMode : "full-access" ,
1170+ interactionMode : "default" ,
1171+ cwd : process . cwd ( ) ,
1172+ } ) ;
1173+ const runtime = yield * adapter . openSession ( {
1174+ threadId,
1175+ providerSessionId : ProviderSessionId . make ( "provider-session-acp-registry-mcp-transport" ) ,
1176+ modelSelection,
1177+ runtimePolicy,
1178+ } ) ;
1179+ const providerThread = yield * runtime . ensureThread ( {
1180+ threadId,
1181+ modelSelection,
1182+ runtimePolicy,
1183+ } ) ;
1184+ yield * mcpSessions . set ( { ...mcpSession , authorizationHeader : "Bearer rotated-token" } ) ;
1185+ yield * runtime . resumeThread ( {
1186+ providerThread : {
1187+ ...providerThread ,
1188+ nativeThreadRef : {
1189+ driver : ACP_REGISTRY_PROVIDER ,
1190+ nativeId : "mock-session-2" ,
1191+ strength : "strong" ,
1192+ } ,
1193+ } ,
1194+ } ) ;
1195+ const sent = ( method : string ) => {
1196+ const payload = requests . find ( ( event ) => event . method === method ) ?. payload ;
1197+ return typeof payload === "object" && payload !== null
1198+ ? Reflect . get ( payload , "mcpServers" )
1199+ : undefined ;
1200+ } ;
1201+ return { new : sent ( "session/new" ) , load : sent ( "session/load" ) } ;
1202+ } ) ;
1203+ const http = ( authorization : string ) => [
1204+ {
1205+ type : "http" ,
1206+ name : "t3-code" ,
1207+ url : endpoint ,
1208+ headers : [ { name : "Authorization" , value : authorization } ] ,
1209+ } ,
1210+ ] ;
1211+ const stdio = ( authorization : string ) => [
1212+ {
1213+ name : "t3-code" ,
1214+ command : selfInvocation . command ,
1215+ args : [ ...selfInvocationArgs ( selfInvocation , [ "acp-mcp-bridge" ] ) ] ,
1216+ env : [
1217+ { name : "ELECTRON_RUN_AS_NODE" , value : "1" } ,
1218+ { name : "T3_ACP_MCP_ENDPOINT" , value : endpoint } ,
1219+ { name : "T3_ACP_MCP_AUTHORIZATION" , value : authorization } ,
1220+ ] ,
1221+ } ,
1222+ ] ;
1223+
1224+ assert . deepEqual (
1225+ yield * sessionMcpServers ( { agentId : "github-copilot-cli" } , { T3_ACP_MCP_HTTP : "1" } ) ,
1226+ { new : http ( "Bearer opened-token" ) , load : http ( "Bearer rotated-token" ) } ,
1227+ ) ;
1228+ const acp = [ { type : "acp" , name : "t3-code" , serverId : "t3-code" } ] ;
1229+ assert . deepEqual (
1230+ yield * sessionMcpServers (
1231+ { agentId : "github-copilot-cli" } ,
1232+ { T3_ACP_MCP_HTTP : "1" , T3_ACP_MCP_ACP : "1" } ,
1233+ ) ,
1234+ { new : acp , load : acp } ,
1235+ ) ;
1236+ assert . deepEqual ( yield * sessionMcpServers ( { agentId : "github-copilot-cli" } ) , {
1237+ new : stdio ( "Bearer opened-token" ) ,
1238+ load : stdio ( "Bearer rotated-token" ) ,
1239+ } ) ;
1240+ assert . deepEqual ( yield * sessionMcpServers ( { agentId : "gemini" } , { T3_ACP_MCP_HTTP : "1" } ) , {
1241+ new : stdio ( "Bearer opened-token" ) ,
1242+ load : stdio ( "Bearer rotated-token" ) ,
1243+ } ) ;
1244+ } ) . pipe ( Effect . provide ( layerTest ) , Effect . scoped ) ,
1245+ ) ;
1246+
11161247 it . effect . each ( [ "before" , "after" ] as const ) (
11171248 "reconciles a full prompt echo %s acknowledgment" ,
11181249 ( ordering ) =>
0 commit comments