Repository navigation
Expand file tree
/
Copy pathCopilotRequestSessionIdE2ETests.cs
More file actions
120 lines (105 loc) · 4.23 KB
/
Copy pathCopilotRequestSessionIdE2ETests.cs
File metadata and controls
120 lines (105 loc) · 4.23 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
using GitHub.Copilot.Test.Harness;
using Xunit;
using Xunit.Abstractions;
namespace GitHub.Copilot.Test.E2E;
#pragma warning disable GHCP001 // The LLM inference surface is intentionally experimental.
/// <summary>
/// Asserts the runtime threads its session id into the LLM inference callback
/// for BOTH a CAPI session and a BYOK session. The callback alone services
/// every model-layer request — no upstream server, no CAPI proxy acting as the
/// inference endpoint — so the only source of <c>req.SessionId</c> is the
/// runtime's own per-client threading.
/// </summary>
public class CopilotRequestSessionIdE2ETests(E2ETestFixture fixture, ITestOutputHelper output)
: E2ETestBase(fixture, "llm_inference_session_id", output)
{
private CopilotClient CreateClientWith(RecordingRequestHandler provider) =>
Ctx.CreateClient(options: new CopilotClientOptions
{
Connection = RuntimeConnection.ForStdio(),
RequestHandler = provider,
});
[Fact]
[Trait(E2ETestTraits.Backend, E2ETestTraits.CapiOnly)]
public async Task Threads_The_Session_Id_Into_A_Capi_Session_Inference_Request()
{
var provider = new RecordingRequestHandler();
await using var client = CreateClientWith(provider);
await client.StartAsync();
var session = await Ctx.CreateSessionAsync(client, new SessionConfig
{
OnPermissionRequest = PermissionHandler.ApproveAll,
});
var capiSessionId = session.SessionId;
string content;
try
{
var msg = await session.SendAndWaitAsync(new MessageOptions { Prompt = "Say OK." });
content = msg?.Data.Content ?? string.Empty;
}
finally
{
await session.DisposeAsync();
}
var inference = provider.InferenceRequests;
Assert.NotEmpty(inference);
Assert.All(inference, r =>
{
Assert.Equal(capiSessionId, r.SessionId);
AssertAgentMetadata(r);
});
// Validate the final assistant response arrived (guards against truncated captures)
Assert.Contains("OK from the synthetic", content);
}
[Fact]
[Trait(E2ETestTraits.Backend, E2ETestTraits.SelfConfiguredBackend)]
public async Task Threads_The_Session_Id_Into_A_Byok_Session_Inference_Request()
{
var provider = new RecordingRequestHandler();
await using var client = CreateClientWith(provider);
await client.StartAsync();
var session = await Ctx.CreateSessionAsync(client, new SessionConfig
{
OnPermissionRequest = PermissionHandler.ApproveAll,
// BYOK providers require an explicit model id.
Model = "claude-sonnet-5",
Provider = new ProviderConfig
{
Type = "openai",
WireApi = "responses",
BaseUrl = "https://byok.invalid/v1",
ApiKey = "byok-secret",
ModelId = "claude-sonnet-5",
WireModel = "claude-sonnet-5",
},
});
var byokSessionId = session.SessionId;
string content;
try
{
var msg = await session.SendAndWaitAsync(new MessageOptions { Prompt = "Say OK." });
content = msg?.Data.Content ?? string.Empty;
}
finally
{
await session.DisposeAsync();
}
var inference = provider.InferenceRequests;
Assert.NotEmpty(inference);
Assert.All(inference, r =>
{
Assert.Equal(byokSessionId, r.SessionId);
AssertAgentMetadata(r);
});
// Validate the final assistant response arrived (guards against truncated captures)
Assert.Contains("OK from the synthetic", content);
}
private static void AssertAgentMetadata(InterceptedRequest request)
{
Assert.False(string.IsNullOrEmpty(request.AgentId));
Assert.False(string.IsNullOrEmpty(request.InteractionType));
}
}