Skip to content

Commit 35fd9d2

Browse files
Update tests to use bundled CLI
1 parent eb92e08 commit 35fd9d2

2 files changed

Lines changed: 10 additions & 42 deletions

File tree

dotnet/test/ClientTests.cs

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,12 @@ namespace GitHub.Copilot.SDK.Test;
88

99
// These tests bypass E2ETestBase because they are about how the CLI subprocess is started
1010
// Other test classes should instead inherit from E2ETestBase
11-
public class ClientTests : IAsyncLifetime
11+
public class ClientTests
1212
{
13-
private string _cliPath = null!;
14-
15-
public Task InitializeAsync()
16-
{
17-
_cliPath = GetCliPath();
18-
return Task.CompletedTask;
19-
}
20-
21-
public Task DisposeAsync() => Task.CompletedTask;
22-
23-
private static string GetCliPath()
24-
{
25-
var envPath = Environment.GetEnvironmentVariable("COPILOT_CLI_PATH");
26-
if (!string.IsNullOrEmpty(envPath)) return envPath;
27-
28-
var dir = new DirectoryInfo(AppContext.BaseDirectory);
29-
while (dir != null)
30-
{
31-
var path = Path.Combine(dir.FullName, "nodejs/node_modules/@github/copilot/index.js");
32-
if (File.Exists(path)) return path;
33-
dir = dir.Parent;
34-
}
35-
throw new InvalidOperationException("CLI not found. Run 'npm install' in the nodejs directory first.");
36-
}
37-
3813
[Fact]
3914
public async Task Should_Start_And_Connect_To_Server_Using_Stdio()
4015
{
41-
using var client = new CopilotClient(new CopilotClientOptions { CliPath = _cliPath, UseStdio = true });
16+
using var client = new CopilotClient(new CopilotClientOptions { UseStdio = true });
4217

4318
try
4419
{
@@ -61,7 +36,7 @@ public async Task Should_Start_And_Connect_To_Server_Using_Stdio()
6136
[Fact]
6237
public async Task Should_Start_And_Connect_To_Server_Using_Tcp()
6338
{
64-
using var client = new CopilotClient(new CopilotClientOptions { CliPath = _cliPath, UseStdio = false });
39+
using var client = new CopilotClient(new CopilotClientOptions { UseStdio = false });
6540

6641
try
6742
{
@@ -82,7 +57,7 @@ public async Task Should_Start_And_Connect_To_Server_Using_Tcp()
8257
[Fact]
8358
public async Task Should_Force_Stop_Without_Cleanup()
8459
{
85-
using var client = new CopilotClient(new CopilotClientOptions { CliPath = _cliPath });
60+
using var client = new CopilotClient(new CopilotClientOptions());
8661

8762
await client.CreateSessionAsync();
8863
await client.ForceStopAsync();
@@ -93,7 +68,7 @@ public async Task Should_Force_Stop_Without_Cleanup()
9368
[Fact]
9469
public async Task Should_Get_Status_With_Version_And_Protocol_Info()
9570
{
96-
using var client = new CopilotClient(new CopilotClientOptions { CliPath = _cliPath, UseStdio = true });
71+
using var client = new CopilotClient(new CopilotClientOptions { UseStdio = true });
9772

9873
try
9974
{
@@ -115,7 +90,7 @@ public async Task Should_Get_Status_With_Version_And_Protocol_Info()
11590
[Fact]
11691
public async Task Should_Get_Auth_Status()
11792
{
118-
using var client = new CopilotClient(new CopilotClientOptions { CliPath = _cliPath, UseStdio = true });
93+
using var client = new CopilotClient(new CopilotClientOptions { UseStdio = true });
11994

12095
try
12196
{
@@ -140,7 +115,7 @@ public async Task Should_Get_Auth_Status()
140115
[Fact]
141116
public async Task Should_List_Models_When_Authenticated()
142117
{
143-
using var client = new CopilotClient(new CopilotClientOptions { CliPath = _cliPath, UseStdio = true });
118+
using var client = new CopilotClient(new CopilotClientOptions { UseStdio = true });
144119

145120
try
146121
{
@@ -178,7 +153,6 @@ public void Should_Accept_GithubToken_Option()
178153
{
179154
var options = new CopilotClientOptions
180155
{
181-
CliPath = _cliPath,
182156
GithubToken = "gho_test_token"
183157
};
184158

@@ -188,7 +162,7 @@ public void Should_Accept_GithubToken_Option()
188162
[Fact]
189163
public void Should_Default_UseLoggedInUser_To_Null()
190164
{
191-
var options = new CopilotClientOptions { CliPath = _cliPath };
165+
var options = new CopilotClientOptions();
192166

193167
Assert.Null(options.UseLoggedInUser);
194168
}
@@ -198,7 +172,6 @@ public void Should_Allow_Explicit_UseLoggedInUser_False()
198172
{
199173
var options = new CopilotClientOptions
200174
{
201-
CliPath = _cliPath,
202175
UseLoggedInUser = false
203176
};
204177

@@ -210,7 +183,6 @@ public void Should_Allow_Explicit_UseLoggedInUser_True_With_GithubToken()
210183
{
211184
var options = new CopilotClientOptions
212185
{
213-
CliPath = _cliPath,
214186
GithubToken = "gho_test_token",
215187
UseLoggedInUser = true
216188
};

dotnet/test/Harness/E2ETestContext.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ namespace GitHub.Copilot.SDK.Test.Harness;
99

1010
public class E2ETestContext : IAsyncDisposable
1111
{
12-
public string CliPath { get; }
1312
public string HomeDir { get; }
1413
public string WorkDir { get; }
1514
public string ProxyUrl { get; }
1615

1716
private readonly CapiProxy _proxy;
1817
private readonly string _repoRoot;
1918

20-
private E2ETestContext(string cliPath, string homeDir, string workDir, string proxyUrl, CapiProxy proxy, string repoRoot)
19+
private E2ETestContext(string homeDir, string workDir, string proxyUrl, CapiProxy proxy, string repoRoot)
2120
{
22-
CliPath = cliPath;
2321
HomeDir = homeDir;
2422
WorkDir = workDir;
2523
ProxyUrl = proxyUrl;
@@ -30,7 +28,6 @@ private E2ETestContext(string cliPath, string homeDir, string workDir, string pr
3028
public static async Task<E2ETestContext> CreateAsync()
3129
{
3230
var repoRoot = FindRepoRoot();
33-
var cliPath = GetCliPath(repoRoot);
3431

3532
var homeDir = Path.Combine(Path.GetTempPath(), $"copilot-test-config-{Guid.NewGuid()}");
3633
var workDir = Path.Combine(Path.GetTempPath(), $"copilot-test-work-{Guid.NewGuid()}");
@@ -41,7 +38,7 @@ public static async Task<E2ETestContext> CreateAsync()
4138
var proxy = new CapiProxy();
4239
var proxyUrl = await proxy.StartAsync();
4340

44-
return new E2ETestContext(cliPath, homeDir, workDir, proxyUrl, proxy, repoRoot);
41+
return new E2ETestContext(homeDir, workDir, proxyUrl, proxy, repoRoot);
4542
}
4643

4744
private static string FindRepoRoot()
@@ -94,7 +91,6 @@ public IReadOnlyDictionary<string, string> GetEnvironment()
9491

9592
public CopilotClient CreateClient() => new(new CopilotClientOptions
9693
{
97-
CliPath = CliPath,
9894
Cwd = WorkDir,
9995
Environment = GetEnvironment(),
10096
GithubToken = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI")) ? "fake-token-for-e2e-tests" : null,

0 commit comments

Comments
 (0)