@@ -11,12 +11,29 @@ namespace GitHub.Copilot.Test.E2E;
1111// Other test classes should instead inherit from E2ETestBase
1212public class ClientE2ETests
1313{
14+ // When the run selects the in-process transport
15+ // (COPILOT_SDK_DEFAULT_CONNECTION=inprocess, set by the in-process CI cell),
16+ // these transport-parametrized tests exercise the in-process FFI connection
17+ // instead of spawning a stdio/tcp CLI subprocess. Those subprocesses are
18+ // unproxied and would reach the real Copilot API (e.g. models.list), which is
19+ // unreachable on CI runners; in the in-process cell we run over the host instead.
20+ private static bool IsInProcessMode ( )
21+ => string . Equals (
22+ Environment . GetEnvironmentVariable ( "COPILOT_SDK_DEFAULT_CONNECTION" ) ,
23+ "inprocess" ,
24+ StringComparison . OrdinalIgnoreCase ) ;
25+
26+ private static RuntimeConnection TransportConnection ( bool useStdio )
27+ => IsInProcessMode ( )
28+ ? RuntimeConnection . ForInProcess ( )
29+ : useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) ;
30+
1431 [ Theory ]
1532 [ InlineData ( true ) ] // stdio transport
1633 [ InlineData ( false ) ] // TCP transport
1734 public async Task Should_Start_And_Connect_To_Server ( bool useStdio )
1835 {
19- using var client = new CopilotClient ( new CopilotClientOptions { Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) } ) ;
36+ using var client = new CopilotClient ( new CopilotClientOptions { Connection = TransportConnection ( useStdio ) } ) ;
2037
2138 try
2239 {
@@ -64,7 +81,7 @@ public async Task Should_Start_And_Connect_Over_InProcess_Ffi()
6481 [ InlineData ( false ) ] // TCP transport
6582 public async Task Should_Force_Stop_Without_Cleanup ( bool useStdio )
6683 {
67- using var client = new CopilotClient ( new CopilotClientOptions { Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) } ) ;
84+ using var client = new CopilotClient ( new CopilotClientOptions { Connection = TransportConnection ( useStdio ) } ) ;
6885
6986 await client . CreateSessionAsync ( new SessionConfig { OnPermissionRequest = PermissionHandler . ApproveAll } ) ;
7087 await client . ForceStopAsync ( ) ;
@@ -75,7 +92,7 @@ public async Task Should_Force_Stop_Without_Cleanup(bool useStdio)
7592 [ InlineData ( false ) ] // TCP transport
7693 public async Task Should_Get_Status_With_Version_And_Protocol_Info ( bool useStdio )
7794 {
78- using var client = new CopilotClient ( new CopilotClientOptions { Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) } ) ;
95+ using var client = new CopilotClient ( new CopilotClientOptions { Connection = TransportConnection ( useStdio ) } ) ;
7996
8097 try
8198 {
@@ -99,7 +116,7 @@ public async Task Should_Get_Status_With_Version_And_Protocol_Info(bool useStdio
99116 [ InlineData ( false ) ] // TCP transport
100117 public async Task Should_Get_Auth_Status ( bool useStdio )
101118 {
102- using var client = new CopilotClient ( new CopilotClientOptions { Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) } ) ;
119+ using var client = new CopilotClient ( new CopilotClientOptions { Connection = TransportConnection ( useStdio ) } ) ;
103120
104121 try
105122 {
@@ -126,7 +143,7 @@ public async Task Should_Get_Auth_Status(bool useStdio)
126143 [ InlineData ( false ) ] // TCP transport
127144 public async Task Should_List_Models_When_Authenticated ( bool useStdio )
128145 {
129- using var client = new CopilotClient ( new CopilotClientOptions { Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) } ) ;
146+ using var client = new CopilotClient ( new CopilotClientOptions { Connection = TransportConnection ( useStdio ) } ) ;
130147
131148 try
132149 {
@@ -164,7 +181,7 @@ public async Task Should_List_Models_When_Authenticated(bool useStdio)
164181 [ InlineData ( false ) ] // TCP transport
165182 public async Task Should_Not_Throw_When_Disposing_Session_After_Stopping_Client ( bool useStdio )
166183 {
167- await using var client = new CopilotClient ( new CopilotClientOptions { Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) } ) ;
184+ await using var client = new CopilotClient ( new CopilotClientOptions { Connection = TransportConnection ( useStdio ) } ) ;
168185 await using var session = await client . CreateSessionAsync ( new SessionConfig { OnPermissionRequest = PermissionHandler . ApproveAll } ) ;
169186
170187 await client . StopAsync ( ) ;
@@ -218,7 +235,7 @@ public async Task Should_Report_Error_With_Stderr_When_CLI_Fails_To_Start(bool u
218235 [ InlineData ( false ) ] // TCP transport
219236 public async Task Should_Allow_CreateSession_Called_Without_PermissionHandler ( bool useStdio )
220237 {
221- await using var client = new CopilotClient ( new CopilotClientOptions { Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) } ) ;
238+ await using var client = new CopilotClient ( new CopilotClientOptions { Connection = TransportConnection ( useStdio ) } ) ;
222239 await using var session = await client . CreateSessionAsync ( new SessionConfig ( ) ) ;
223240
224241 Assert . NotNull ( session . SessionId ) ;
@@ -270,7 +287,7 @@ public async Task ListModels_WithCustomHandler_CallsHandler(bool useStdio)
270287 var callCount = 0 ;
271288 await using var client = new CopilotClient ( new CopilotClientOptions
272289 {
273- Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) ,
290+ Connection = TransportConnection ( useStdio ) ,
274291 OnListModels = ( ct ) =>
275292 {
276293 callCount ++ ;
@@ -307,7 +324,7 @@ public async Task ListModels_WithCustomHandler_CachesResults(bool useStdio)
307324 var callCount = 0 ;
308325 await using var client = new CopilotClient ( new CopilotClientOptions
309326 {
310- Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) ,
327+ Connection = TransportConnection ( useStdio ) ,
311328 OnListModels = ( ct ) =>
312329 {
313330 callCount ++ ;
@@ -343,7 +360,7 @@ public async Task ListModels_WithCustomHandler_WorksWithoutStart(bool useStdio)
343360 var callCount = 0 ;
344361 await using var client = new CopilotClient ( new CopilotClientOptions
345362 {
346- Connection = useStdio ? RuntimeConnection . ForStdio ( ) : RuntimeConnection . ForTcp ( ) ,
363+ Connection = TransportConnection ( useStdio ) ,
347364 OnListModels = ( ct ) =>
348365 {
349366 callCount ++ ;
0 commit comments