Skip to content

Commit 6b6bdd4

Browse files
committed
test: qualify native MEAI instructions streaming
1 parent 619eedd commit 6b6bdd4

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

‎CodexSharpSDK.Tests/Integration/RealCodexIntegrationTests.cs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,55 @@
1+
using System.Text;
12
using System.Text.Json.Nodes;
23
using ManagedCode.CodexSharpSDK.Client;
34
using ManagedCode.CodexSharpSDK.Configuration;
5+
using ManagedCode.CodexSharpSDK.Extensions.AI;
46
using ManagedCode.CodexSharpSDK.Models;
57
using ManagedCode.CodexSharpSDK.Tests.Shared;
8+
using Microsoft.Extensions.AI;
69

710
namespace ManagedCode.CodexSharpSDK.Tests.Integration;
811

912
[Property("RequiresCodexAuth", "true")]
1013
public class RealCodexIntegrationTests
1114
{
15+
private const string InstructionsAnswer = "native-meai-instructions-confirmed";
16+
private const string NativeInstructions = "Reply with exactly native-meai-instructions-confirmed. Do not use tools, execute commands or change files.";
17+
private const string NativeUserPrompt = "Return the exact answer specified by your system instructions.";
18+
19+
[Test]
20+
public async Task GetStreamingResponseAsync_WithRealCodexCli_HonorsStandardInstructions()
21+
{
22+
using var settings = RealCodexTestSupport.GetRequiredSettings();
23+
using var client = new CodexChatClient(new CodexChatClientOptions
24+
{
25+
CodexOptions = new CodexOptions { EnvironmentVariables = settings.EnvironmentOverrides },
26+
DefaultModel = settings.Model,
27+
DefaultThreadOptions = new ThreadOptions
28+
{
29+
Model = settings.Model,
30+
WebSearchMode = WebSearchMode.Disabled,
31+
SandboxMode = SandboxMode.ReadOnly,
32+
NetworkAccessEnabled = true,
33+
},
34+
});
35+
using var cancellation = new CancellationTokenSource(TimeSpan.FromMinutes(2));
36+
var text = new StringBuilder();
37+
var hasUsage = false;
38+
var hasTerminal = false;
39+
await foreach (var update in client.GetStreamingResponseAsync(
40+
[new ChatMessage(ChatRole.User, NativeUserPrompt)],
41+
new ChatOptions { Instructions = NativeInstructions },
42+
cancellation.Token))
43+
{
44+
text.Append(update.Text);
45+
hasUsage |= update.Contents.OfType<UsageContent>().Any();
46+
hasTerminal |= update.FinishReason is not null;
47+
}
48+
await Assert.That(text.ToString().Trim()).IsEqualTo(InstructionsAnswer);
49+
await Assert.That(hasUsage).IsTrue();
50+
await Assert.That(hasTerminal).IsTrue();
51+
}
52+
1253
[Test]
1354
public async Task RunAsync_WithRealCodexCli_ReturnsStructuredOutput()
1455
{

0 commit comments

Comments
 (0)