-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRuntimeFoundationCatalogTests.cs
More file actions
227 lines (186 loc) · 8.91 KB
/
RuntimeFoundationCatalogTests.cs
File metadata and controls
227 lines (186 loc) · 8.91 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
namespace DotPilot.Tests;
public class RuntimeFoundationCatalogTests
{
private const string ApprovalPrompt = "Please continue, but stop for approval before changing files.";
private const string BlankPrompt = " ";
private const string CodexCommandName = "codex";
private const string ClaudeCommandName = "claude";
private const string GitHubCommandName = "gh";
private const string DeterministicClientStatusSummary = "Always available for in-repo and CI validation.";
[Test]
public void CatalogGroupsEpicTwelveIntoFourSequencedSlices()
{
var catalog = CreateCatalog();
var snapshot = catalog.GetSnapshot();
snapshot.EpicLabel.Should().Be(RuntimeFoundationIssues.FormatIssueLabel(RuntimeFoundationIssues.EmbeddedAgentRuntimeHostEpic));
snapshot.Slices.Should().HaveCount(4);
snapshot.Slices.Select(slice => slice.IssueNumber).Should().ContainInOrder(
RuntimeFoundationIssues.DomainModel,
RuntimeFoundationIssues.CommunicationContracts,
RuntimeFoundationIssues.EmbeddedOrleansHost,
RuntimeFoundationIssues.AgentFrameworkRuntime);
}
[Test]
public void CatalogAlwaysIncludesTheDeterministicClientForProviderIndependentCoverage()
{
var catalog = CreateCatalog();
var snapshot = catalog.GetSnapshot();
snapshot.Providers.Should().ContainSingle(provider =>
provider.DisplayName == snapshot.DeterministicClientName &&
provider.StatusSummary == DeterministicClientStatusSummary &&
provider.RequiresExternalToolchain == false &&
provider.Status == ProviderConnectionStatus.Available);
}
[Test]
public async Task DeterministicClientReturnsPendingApprovalWhenPromptRequestsApproval()
{
var client = new DeterministicAgentRuntimeClient();
var result = await client.ExecuteAsync(CreateRequest(ApprovalPrompt, AgentExecutionMode.Execute), CancellationToken.None);
var outcome = result.Value!;
result.IsSuccess.Should().BeTrue();
outcome.NextPhase.Should().Be(SessionPhase.Paused);
outcome.ApprovalState.Should().Be(ApprovalState.Pending);
outcome.ProducedArtifacts.Should().ContainSingle(artifact =>
artifact.Name == "runtime-foundation.snapshot.json" &&
artifact.Kind == ArtifactKind.Snapshot);
}
[Test]
public async Task DeterministicClientReturnsPlanArtifactsForPlanMode()
{
var client = new DeterministicAgentRuntimeClient();
var result = await client.ExecuteAsync(CreateRequest("Plan the runtime foundation rollout.", AgentExecutionMode.Plan), CancellationToken.None);
var outcome = result.Value!;
result.IsSuccess.Should().BeTrue();
outcome.NextPhase.Should().Be(SessionPhase.Plan);
outcome.ApprovalState.Should().Be(ApprovalState.NotRequired);
outcome.ProducedArtifacts.Should().ContainSingle(artifact =>
artifact.Name == "runtime-foundation.plan.md" &&
artifact.Kind == ArtifactKind.Plan);
}
[Test]
public async Task DeterministicClientReturnsExecuteResultsWhenApprovalIsNotRequested()
{
var client = new DeterministicAgentRuntimeClient();
var result = await client.ExecuteAsync(CreateRequest("Run the provider-independent runtime flow.", AgentExecutionMode.Execute), CancellationToken.None);
var outcome = result.Value!;
result.IsSuccess.Should().BeTrue();
outcome.NextPhase.Should().Be(SessionPhase.Execute);
outcome.ApprovalState.Should().Be(ApprovalState.NotRequired);
outcome.ProducedArtifacts.Should().ContainSingle(artifact =>
artifact.Name == "runtime-foundation.snapshot.json" &&
artifact.Kind == ArtifactKind.Snapshot);
}
[Test]
public async Task DeterministicClientReturnsValidationProblemForBlankPrompts()
{
var client = new DeterministicAgentRuntimeClient();
var result = await client.ExecuteAsync(CreateRequest(BlankPrompt, AgentExecutionMode.Plan), CancellationToken.None);
var problem = result.Problem!;
result.IsFailed.Should().BeTrue();
result.HasProblem.Should().BeTrue();
problem.HasErrorCode(RuntimeCommunicationProblemCode.PromptRequired).Should().BeTrue();
problem.InvalidField("Prompt").Should().BeTrue();
}
[Test]
public async Task DeterministicClientHonorsCancellationBeforeProcessing()
{
var client = new DeterministicAgentRuntimeClient();
using var cancellationSource = new CancellationTokenSource();
cancellationSource.Cancel();
var action = async () => await client.ExecuteAsync(CreateRequest("Plan the runtime foundation rollout.", AgentExecutionMode.Plan), cancellationSource.Token);
await action.Should().ThrowAsync<OperationCanceledException>();
}
[Test]
public async Task DeterministicClientReturnsApprovedReviewResults()
{
var client = new DeterministicAgentRuntimeClient();
var result = await client.ExecuteAsync(CreateRequest("Review the runtime foundation output.", AgentExecutionMode.Review), CancellationToken.None);
var outcome = result.Value!;
result.IsSuccess.Should().BeTrue();
outcome.NextPhase.Should().Be(SessionPhase.Review);
outcome.ApprovalState.Should().Be(ApprovalState.Approved);
outcome.ProducedArtifacts.Should().ContainSingle(artifact =>
artifact.Name == "runtime-foundation.review.md" &&
artifact.Kind == ArtifactKind.Report);
}
[Test]
public async Task DeterministicClientReturnsProviderUnavailableProblemWhenProviderIsNotReady()
{
var client = new DeterministicAgentRuntimeClient();
var result = await client.ExecuteAsync(
CreateRequest(
"Run the provider-independent runtime flow.",
AgentExecutionMode.Execute,
ProviderConnectionStatus.Unavailable),
CancellationToken.None);
var problem = result.Problem!;
result.IsFailed.Should().BeTrue();
result.HasProblem.Should().BeTrue();
problem.HasErrorCode(RuntimeCommunicationProblemCode.ProviderUnavailable).Should().BeTrue();
problem.StatusCode.Should().Be((int)System.Net.HttpStatusCode.ServiceUnavailable);
}
[TestCase(CodexCommandName)]
[TestCase(ClaudeCommandName)]
[TestCase(GitHubCommandName)]
public void ExternalToolchainVerificationRunsOnlyWhenTheCommandIsAvailable(string commandName)
{
var catalog = CreateCatalog();
var provider = catalog.GetSnapshot().Providers.Single(item => item.CommandName == commandName);
Assume.That(
provider.Status,
Is.EqualTo(ProviderConnectionStatus.Available),
$"The '{commandName}' toolchain is not available in this environment.");
provider.RequiresExternalToolchain.Should().BeTrue();
provider.StatusSummary.Should().Contain("available");
}
[Test]
public void TypedIdentifiersProduceStableNonEmptyRepresentations()
{
IReadOnlyList<string> values =
[
WorkspaceId.New().ToString(),
AgentProfileId.New().ToString(),
SessionId.New().ToString(),
FleetId.New().ToString(),
ProviderId.New().ToString(),
ModelRuntimeId.New().ToString(),
];
values.Should().OnlyContain(value => !string.IsNullOrWhiteSpace(value));
values.Should().OnlyHaveUniqueItems();
}
[Test]
[NonParallelizable]
public void ExternalProvidersBecomeUnavailableWhenPathIsCleared()
{
using var scope = new EnvironmentVariableScope("PATH", string.Empty);
var catalog = CreateCatalog();
var externalProviders = catalog.GetSnapshot().Providers.Where(provider => provider.RequiresExternalToolchain);
externalProviders.Should().OnlyContain(provider => provider.Status == ProviderConnectionStatus.Unavailable);
}
private static RuntimeFoundationCatalog CreateCatalog()
{
return new RuntimeFoundationCatalog();
}
private static AgentTurnRequest CreateRequest(
string prompt,
AgentExecutionMode mode,
ProviderConnectionStatus providerStatus = ProviderConnectionStatus.Available)
{
return new AgentTurnRequest(SessionId.New(), AgentProfileId.New(), prompt, mode, providerStatus);
}
private sealed class EnvironmentVariableScope : IDisposable
{
private readonly string _variableName;
private readonly string? _originalValue;
public EnvironmentVariableScope(string variableName, string? value)
{
_variableName = variableName;
_originalValue = Environment.GetEnvironmentVariable(variableName);
Environment.SetEnvironmentVariable(variableName, value);
}
public void Dispose()
{
Environment.SetEnvironmentVariable(_variableName, _originalValue);
}
}
}