diff --git a/dotnet/test/E2E/ClientE2ETests.cs b/dotnet/test/E2E/ClientE2ETests.cs index 9dec8d51f..5aa535334 100644 --- a/dotnet/test/E2E/ClientE2ETests.cs +++ b/dotnet/test/E2E/ClientE2ETests.cs @@ -2,6 +2,7 @@ * Copyright (c) Microsoft Corporation. All rights reserved. *--------------------------------------------------------------------------------------------*/ +using GitHub.Copilot.SDK.Test.Harness; using Xunit; namespace GitHub.Copilot.SDK.Test.E2E; @@ -194,9 +195,9 @@ public async Task Should_Allow_ResumeSession_Called_Without_PermissionHandler() { const string connectionToken = "client-e2e-resume-token"; - await using var client = new CopilotClient(new CopilotClientOptions + await using var ctx = await E2ETestContext.CreateAsync(); + await using var client = ctx.CreateClient(useStdio: false, options: new CopilotClientOptions { - UseStdio = false, TcpConnectionToken = connectionToken, }); await using var originalSession = await client.CreateSessionAsync(new SessionConfig()); @@ -204,7 +205,7 @@ public async Task Should_Allow_ResumeSession_Called_Without_PermissionHandler() var port = client.ActualPort ?? throw new InvalidOperationException("Client must be using TCP transport to support multi-client resume."); - await using var resumeClient = new CopilotClient(new CopilotClientOptions + await using var resumeClient = ctx.CreateClient(options: new CopilotClientOptions { CliUrl = $"localhost:{port}", TcpConnectionToken = connectionToken, diff --git a/dotnet/test/E2E/PerSessionAuthE2ETests.cs b/dotnet/test/E2E/PerSessionAuthE2ETests.cs index dbc52156b..f93da300c 100644 --- a/dotnet/test/E2E/PerSessionAuthE2ETests.cs +++ b/dotnet/test/E2E/PerSessionAuthE2ETests.cs @@ -20,11 +20,35 @@ private CopilotClient CreateAuthTestClient() { ["COPILOT_DEBUG_GITHUB_API_URL"] = Ctx.ProxyUrl, }; - // Disable the harness's auto-injected fake GITHUB_TOKEN so the per-session - // auth tests can validate session-scoped tokens (including the no-token case). + // Disable the harness's auto-injected client token so the per-session + // auth tests validate only session-scoped tokens. return Ctx.CreateClient(options: new CopilotClientOptions { Environment = env }, autoInjectGitHubToken: false); } + private CopilotClient CreateNoAuthTestClient() + { + var env = WithoutAuthEnv(Ctx.GetEnvironment()); + env["COPILOT_DEBUG_GITHUB_API_URL"] = Ctx.ProxyUrl; + + return Ctx.CreateClient(options: new CopilotClientOptions + { + Environment = env, + UseLoggedInUser = false, + }, autoInjectGitHubToken: false); + } + + private static Dictionary WithoutAuthEnv(IReadOnlyDictionary env) + { + var result = new Dictionary(env) + { + ["COPILOT_SDK_AUTH_TOKEN"] = "", + ["GH_TOKEN"] = "", + ["GITHUB_TOKEN"] = "", + }; + + return result; + } + private async Task SetupCopilotUsersAsync() { await Ctx.SetCopilotUserByTokenAsync("token-alice", new CopilotUserConfig( @@ -91,15 +115,15 @@ public async Task ShouldIsolateAuthBetweenSessions() [Fact] public async Task ShouldBeUnauthenticatedWithoutToken() { - await using var session = await AuthClient.CreateSessionAsync(new SessionConfig + var noAuthClient = CreateNoAuthTestClient(); + + await using var session = await noAuthClient.CreateSessionAsync(new SessionConfig { OnPermissionRequest = PermissionHandler.ApproveAll, }); var status = await session.Rpc.Auth.GetStatusAsync(); // Without a per-session GitHub token, there is no per-session identity. - // In CI the process-level fake token may still authenticate globally, - // so we check Login rather than IsAuthenticated. Assert.True(string.IsNullOrEmpty(status.Login), $"Expected no per-session login without token, got {status.Login}"); }