|
| 1 | +using System.Text; |
1 | 2 | using System.Text.Json.Nodes; |
2 | 3 | using ManagedCode.CodexSharpSDK.Client; |
3 | 4 | using ManagedCode.CodexSharpSDK.Configuration; |
| 5 | +using ManagedCode.CodexSharpSDK.Extensions.AI; |
4 | 6 | using ManagedCode.CodexSharpSDK.Models; |
5 | 7 | using ManagedCode.CodexSharpSDK.Tests.Shared; |
| 8 | +using Microsoft.Extensions.AI; |
6 | 9 |
|
7 | 10 | namespace ManagedCode.CodexSharpSDK.Tests.Integration; |
8 | 11 |
|
9 | 12 | [Property("RequiresCodexAuth", "true")] |
10 | 13 | public class RealCodexIntegrationTests |
11 | 14 | { |
| 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 | + |
12 | 53 | [Test] |
13 | 54 | public async Task RunAsync_WithRealCodexCli_ReturnsStructuredOutput() |
14 | 55 | { |
|
0 commit comments