forked from github/copilot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientSessionManagementE2ETests.cs
More file actions
95 lines (75 loc) · 3.1 KB
/
Copy pathClientSessionManagementE2ETests.cs
File metadata and controls
95 lines (75 loc) · 3.1 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
89
90
91
92
93
94
95
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using Xunit;
using Xunit.Abstractions;
namespace GitHub.Copilot.Test.E2E;
public class ClientSessionManagementE2ETests(E2ETestFixture fixture, ITestOutputHelper output)
: E2ETestBase(fixture, "client_api", output)
{
private static async Task<Exception> AssertFailureAsync(Func<Task> action, string expectedMessage)
{
var ex = await Assert.ThrowsAnyAsync<Exception>(action);
Assert.Contains(expectedMessage, ex.ToString(), StringComparison.OrdinalIgnoreCase);
return ex;
}
[Fact]
public async Task Should_Delete_Session_By_Id()
{
var session = await CreateSessionAsync();
var sessionId = session.SessionId;
await session.SendAndWaitAsync(new MessageOptions { Prompt = "Say OK." });
await session.DisposeAsync();
await Client.DeleteSessionAsync(sessionId);
var metadata = await Client.GetSessionMetadataAsync(sessionId);
Assert.Null(metadata);
}
[Fact]
public async Task Should_Report_Error_When_Deleting_Unknown_Session_Id()
{
await Client.StartAsync();
const string UnknownSessionId = "00000000-0000-0000-0000-000000000000";
await AssertFailureAsync(
() => Client.DeleteSessionAsync(UnknownSessionId),
$"Failed to delete session {UnknownSessionId}");
}
[Fact]
public async Task Should_Get_Null_Last_Session_Id_Before_Any_Sessions_Exist()
{
await Client.StartAsync();
// Other tests in this class create sessions, and xUnit doesn't guarantee
// test execution order. Clear any leftover sessions so this test sees a
// genuinely empty state regardless of order.
foreach (var existing in await Client.ListSessionsAsync())
{
await Client.DeleteSessionAsync(existing.SessionId);
}
var result = await Client.GetLastSessionIdAsync();
Assert.Null(result);
}
[Fact]
public async Task Should_Track_Last_Session_Id_After_Session_Created()
{
var session = await CreateSessionAsync();
await session.SendAndWaitAsync(new MessageOptions { Prompt = "Say OK." });
var sessionId = session.SessionId;
await session.DisposeAsync();
var lastId = await Client.GetLastSessionIdAsync();
Assert.Equal(sessionId, lastId);
}
[Fact]
public async Task Should_Get_Null_Foreground_Session_Id_In_Headless_Mode()
{
await Client.StartAsync();
var sessionId = await Client.GetForegroundSessionIdAsync();
Assert.Null(sessionId);
}
[Fact]
public async Task Should_Report_Error_When_Setting_Foreground_Session_In_Headless_Mode()
{
var session = await CreateSessionAsync();
await AssertFailureAsync(
() => Client.SetForegroundSessionIdAsync(session.SessionId),
"Not running in TUI+server mode");
}
}