-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathE2ETestBackend.cs
More file actions
122 lines (107 loc) · 4.5 KB
/
Copy pathE2ETestBackend.cs
File metadata and controls
122 lines (107 loc) · 4.5 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
121
122
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
namespace GitHub.Copilot.Test.Harness;
internal enum E2ETestBackend
{
Capi,
AnthropicMessages,
OpenAIResponses,
OpenAICompletions,
}
internal static class E2ETestBackendConfiguration
{
internal const string EnvironmentVariable = "COPILOT_SDK_E2E_BACKEND";
private const string AnthropicDefaultModel = "claude-sonnet-5";
private const string OpenAIDefaultModel = "gpt-4.1";
private const string FakeCredential = "fake-byok-credential-for-e2e-tests";
internal static E2ETestBackend Current
=> Parse(Environment.GetEnvironmentVariable(EnvironmentVariable));
internal static E2ETestBackend Parse(string? value)
=> value?.Trim().ToLowerInvariant() switch
{
null or "" or "capi" => E2ETestBackend.Capi,
"anthropic-messages" => E2ETestBackend.AnthropicMessages,
"openai-responses" => E2ETestBackend.OpenAIResponses,
"openai-completions" => E2ETestBackend.OpenAICompletions,
_ => throw new ArgumentOutOfRangeException(
nameof(value),
value,
$"Unsupported {EnvironmentVariable} value. Expected capi, anthropic-messages, openai-responses, or openai-completions."),
};
internal static string ToWireName(this E2ETestBackend backend)
=> backend switch
{
E2ETestBackend.Capi => "capi",
E2ETestBackend.AnthropicMessages => "anthropic-messages",
E2ETestBackend.OpenAIResponses => "openai-responses",
E2ETestBackend.OpenAICompletions => "openai-completions",
_ => throw new ArgumentOutOfRangeException(nameof(backend), backend, null),
};
internal static void ApplyProvider(
this E2ETestBackend backend,
SessionConfig config,
string proxyUrl)
{
if (backend == E2ETestBackend.Capi
|| config.Provider is not null
|| config.Providers is not null)
{
return;
}
var model = config.Model ??= backend.GetDefaultModel();
config.Provider = CreateProvider(backend, proxyUrl, model);
}
internal static void ApplyProvider(
this E2ETestBackend backend,
ResumeSessionConfig config,
string proxyUrl)
{
if (backend == E2ETestBackend.Capi || config.Provider is not null)
{
return;
}
var model = config.Model ??= backend.GetDefaultModel();
config.Provider = CreateProvider(backend, proxyUrl, model);
}
private static string GetDefaultModel(this E2ETestBackend backend)
=> backend switch
{
E2ETestBackend.AnthropicMessages => AnthropicDefaultModel,
E2ETestBackend.OpenAIResponses or E2ETestBackend.OpenAICompletions => OpenAIDefaultModel,
_ => throw new ArgumentOutOfRangeException(nameof(backend), backend, null),
};
private static ProviderConfig CreateProvider(
E2ETestBackend backend,
string proxyUrl,
string model)
=> new()
{
BaseUrl = proxyUrl,
Type = backend switch
{
E2ETestBackend.AnthropicMessages => "anthropic",
E2ETestBackend.OpenAIResponses or E2ETestBackend.OpenAICompletions => "openai",
_ => throw new ArgumentOutOfRangeException(nameof(backend), backend, null),
},
WireApi = backend switch
{
E2ETestBackend.AnthropicMessages => null,
E2ETestBackend.OpenAIResponses => "responses",
E2ETestBackend.OpenAICompletions => "completions",
_ => throw new ArgumentOutOfRangeException(nameof(backend), backend, null),
},
BearerToken = FakeCredential,
ModelId = model,
WireModel = model,
};
}
internal static class E2ETestTraits
{
// Trait key used by workflow filters to classify backend compatibility.
internal const string Backend = "E2EBackend";
// Requires the default CAPI backend and is excluded from BYOK legs.
internal const string CapiOnly = "CapiOnly";
// Owns its backend setup and must not inherit the backend selected by the test matrix.
internal const string SelfConfiguredBackend = "SelfConfiguredBackend";
}