Repository navigation
Expand file tree
/
Copy pathtest-has-new-user-content.ts
More file actions
92 lines (85 loc) · 2.17 KB
/
Copy pathtest-has-new-user-content.ts
File metadata and controls
92 lines (85 loc) · 2.17 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
/**
* Unit tests for hasNewUserContent in src/claude-code-language-model.ts.
*/
import { test } from "node:test"
import assert from "node:assert/strict"
import { hasNewUserContent } from "./src/claude-code-language-model.js"
const p = (msgs: any[]) => msgs as any
test("tool-role message with tool-result counts as new content", () => {
assert.equal(
hasNewUserContent(
p([
{ role: "user", content: "go" },
{ role: "assistant", content: [{ type: "text", text: "ok" }] },
{
role: "tool",
content: [
{
type: "tool-result",
toolCallId: "x",
output: { type: "text", value: "done" },
},
],
},
]),
),
true,
)
})
test("assistant-ended prompt still returns false (49345e3 preserved)", () => {
assert.equal(
hasNewUserContent(
p([
{ role: "user", content: "go" },
{ role: "assistant", content: [{ type: "text", text: "ok" }] },
]),
),
false,
)
})
test("empty tool-role content does not falsely return true", () => {
assert.equal(
hasNewUserContent(
p([
{ role: "user", content: "go" },
{ role: "assistant", content: [{ type: "text", text: "ok" }] },
{ role: "tool", content: [] },
]),
),
false,
)
})
test("tool-role without tool-result parts is not new content", () => {
assert.equal(
hasNewUserContent(
p([
{ role: "user", content: "go" },
{ role: "assistant", content: [{ type: "text", text: "ok" }] },
{ role: "tool", content: [{ type: "other" } as any] },
]),
),
false,
)
})
test("trailing user message after tool-result is new content", () => {
assert.equal(
hasNewUserContent(
p([
{ role: "user", content: "go" },
{ role: "assistant", content: [{ type: "text", text: "ok" }] },
{
role: "tool",
content: [
{
type: "tool-result",
toolCallId: "x",
output: { type: "text", value: "done" },
},
],
},
{ role: "user", content: "more" },
]),
),
true,
)
})