forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorHandlingTests.cs
More file actions
88 lines (74 loc) · 2.94 KB
/
Copy pathErrorHandlingTests.cs
File metadata and controls
88 lines (74 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using GitHub.Copilot.SDK;
using Microsoft.Extensions.Logging;
using Xunit;
namespace GitHub.Copilot.SDK.Test;
/// <summary>
/// Tests for error handling and diagnostics improvements.
/// </summary>
public class ErrorHandlingTests
{
[Fact]
public async Task Should_Provide_Helpful_Error_When_CLI_Not_Found()
{
// Arrange: Use a non-existent CLI path
var client = new CopilotClient(new CopilotClientOptions
{
CliPath = "/nonexistent/path/to/copilot",
AutoStart = true
});
// Act & Assert: Should throw with helpful error message
var exception = await Assert.ThrowsAsync<InvalidOperationException>(
async () => await client.CreateSessionAsync());
Assert.Contains("Failed to start Copilot CLI process", exception.Message);
Assert.Contains("Please ensure the Copilot CLI is installed", exception.Message);
}
[Fact]
public async Task Should_Detect_Immediate_Process_Exit()
{
// Arrange: Use an executable that exits immediately
// Platform-specific command that exits with non-zero code
string exitCommand;
if (OperatingSystem.IsWindows())
{
exitCommand = "cmd";
}
else
{
exitCommand = "false"; // Unix command that exits immediately with code 1
}
var clientOptions = new CopilotClientOptions
{
AutoStart = true
};
if (OperatingSystem.IsWindows())
{
clientOptions.CliPath = exitCommand;
clientOptions.CliArgs = ["/c", "exit", "1"]; // Exit with code 1
}
else
{
clientOptions.CliPath = exitCommand;
}
var client = new CopilotClient(clientOptions);
// Act & Assert: Should detect the immediate exit
var exception = await Assert.ThrowsAsync<InvalidOperationException>(
async () => await client.CreateSessionAsync());
// Should mention the process exited immediately
Assert.Contains("exited immediately", exception.Message);
}
[Fact]
public async Task Should_Provide_Clear_Error_For_Connection_Issues()
{
// Verify that ConnectionLostException is handled and wrapped properly
// by checking that the InvokeRpcAsync method has proper exception handling
// This is a minimal test that verifies the structure exists
// More comprehensive testing would require integration tests with a real CLI
var method = typeof(CopilotClient).GetMethod(
"InvokeRpcAsync",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
Assert.NotNull(method);
}
}