forked from managedcode/CodexSharpSDK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatResponseMapperTests.cs
More file actions
83 lines (72 loc) · 3.26 KB
/
ChatResponseMapperTests.cs
File metadata and controls
83 lines (72 loc) · 3.26 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
using ManagedCode.CodexSharpSDK.Extensions.AI.Content;
using ManagedCode.CodexSharpSDK.Extensions.AI.Internal;
using ManagedCode.CodexSharpSDK.Models;
using Microsoft.Extensions.AI;
namespace ManagedCode.CodexSharpSDK.Extensions.AI.Tests;
public class ChatResponseMapperTests
{
[Test]
public async Task ToChatResponse_BasicResult_MapsCorrectly()
{
var result = new RunResult([], "Hello from Codex", new Usage(100, 10, 50));
var response = ChatResponseMapper.ToChatResponse(result, "thread-123");
await Assert.That(response.Text).Contains("Hello from Codex");
await Assert.That(response.ConversationId).IsEqualTo("thread-123");
await Assert.That(response.Usage).IsNotNull();
await Assert.That(response.Usage!.InputTokenCount).IsEqualTo(100);
await Assert.That(response.Usage!.OutputTokenCount).IsEqualTo(50);
await Assert.That(response.Usage!.TotalTokenCount).IsEqualTo(150);
}
[Test]
public async Task ToChatResponse_NullUsage_NoUsageSet()
{
var result = new RunResult([], "Response", null);
var response = ChatResponseMapper.ToChatResponse(result, null);
await Assert.That(response.Usage).IsNull();
await Assert.That(response.ConversationId).IsNull();
}
[Test]
public async Task ToChatResponse_WithReasoningItem_MapsToTextReasoningContent()
{
var items = new List<ThreadItem>
{
new ReasoningItem("r1", "thinking about this..."),
};
var result = new RunResult(items, "Final answer", null);
var response = ChatResponseMapper.ToChatResponse(result, null);
var contents = response.Messages[0].Contents;
await Assert.That(contents.OfType<TextReasoningContent>().Count()).IsEqualTo(1);
}
[Test]
public async Task ToChatResponse_WithCommandExecution_MapsToCustomContent()
{
var items = new List<ThreadItem>
{
new CommandExecutionItem("c1", "npm test", "all passed", 0, CommandExecutionStatus.Completed),
};
var result = new RunResult(items, "Done", null);
var response = ChatResponseMapper.ToChatResponse(result, null);
var cmdContent = response.Messages[0].Contents.OfType<CommandExecutionContent>().Single();
await Assert.That(cmdContent.Command).IsEqualTo("npm test");
await Assert.That(cmdContent.ExitCode).IsEqualTo(0);
}
[Test]
public async Task ToChatResponse_WithFileChange_MapsToCustomContent()
{
var items = new List<ThreadItem>
{
new FileChangeItem("f1", [new FileUpdateChange("src/app.cs", PatchChangeKind.Update)], PatchApplyStatus.Completed),
};
var result = new RunResult(items, "Fixed", null);
var response = ChatResponseMapper.ToChatResponse(result, null);
var fileContent = response.Messages[0].Contents.OfType<FileChangeContent>().Single();
await Assert.That(fileContent.Changes).Count().IsEqualTo(1);
}
[Test]
public async Task ToChatResponse_CachedTokens_IncludedInUsage()
{
var result = new RunResult([], "Response", new Usage(100, 50, 25));
var response = ChatResponseMapper.ToChatResponse(result, null);
await Assert.That(response.Usage!.CachedInputTokenCount).IsEqualTo(50);
}
}