-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathreasoning-history-guard.spec.ts
More file actions
107 lines (97 loc) · 2.9 KB
/
Copy pathreasoning-history-guard.spec.ts
File metadata and controls
107 lines (97 loc) · 2.9 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
// npx vitest run api/providers/utils/__tests__/reasoning-history-guard.spec.ts
import { historyHasToolCallsWithoutReasoning } from "../reasoning-history-guard"
describe("historyHasToolCallsWithoutReasoning", () => {
it("returns false for empty messages", () => {
expect(historyHasToolCallsWithoutReasoning([])).toBe(false)
})
it("returns false when no assistant messages have tool_calls", () => {
const messages = [
{ role: "user", content: "hello" },
{ role: "assistant", content: "hi there" },
]
expect(historyHasToolCallsWithoutReasoning(messages)).toBe(false)
})
it("returns false when assistant messages have tool_calls with reasoning_content", () => {
const messages = [
{
role: "assistant",
content: null,
tool_calls: [{ id: "call_1", function: { name: "test" } }],
reasoning_content: "I should call test because...",
},
]
expect(historyHasToolCallsWithoutReasoning(messages)).toBe(false)
})
it("returns true when assistant messages have tool_calls but no reasoning_content field", () => {
const messages = [
{
role: "assistant",
content: null,
tool_calls: [{ id: "call_1", function: { name: "test" } }],
},
]
expect(historyHasToolCallsWithoutReasoning(messages)).toBe(true)
})
it("returns true when assistant messages have tool_calls with empty reasoning_content", () => {
const messages = [
{
role: "assistant",
content: null,
tool_calls: [{ id: "call_1", function: { name: "test" } }],
reasoning_content: "",
},
]
expect(historyHasToolCallsWithoutReasoning(messages)).toBe(true)
})
it("returns true when assistant messages have empty tool_calls array", () => {
const messages = [
{
role: "assistant",
content: "hello",
tool_calls: [],
},
]
expect(historyHasToolCallsWithoutReasoning(messages)).toBe(false)
})
it("returns false for non-assistant messages with tool_calls", () => {
const messages = [
{
role: "user",
content: "hello",
tool_calls: [{ id: "call_1" }],
},
]
expect(historyHasToolCallsWithoutReasoning(messages)).toBe(false)
})
it("returns true when at least one assistant message is missing reasoning_content despite tool_calls", () => {
const messages = [
{
role: "assistant",
content: "Let me think...",
reasoning_content: "thinking step 1",
},
{
role: "assistant",
content: null,
tool_calls: [{ id: "call_1", function: { name: "read_file" } }],
// no reasoning_content — this is the problematic message
},
{
role: "tool",
content: "file content",
tool_call_id: "call_1",
},
]
expect(historyHasToolCallsWithoutReasoning(messages)).toBe(true)
})
it("handles non-array tool_calls gracefully", () => {
const messages = [
{
role: "assistant",
content: null,
tool_calls: "not-an-array" as unknown as unknown[],
},
]
expect(historyHasToolCallsWithoutReasoning(messages)).toBe(false)
})
})