-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy paththinkingState.test.ts
More file actions
57 lines (51 loc) · 1.95 KB
/
thinkingState.test.ts
File metadata and controls
57 lines (51 loc) · 1.95 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
import { test } from "node:test";
import assert from "node:assert/strict";
import { findExpandedThinkingId } from "../ui";
import type { SessionMessage } from "../session";
function buildMessage(
id: string,
role: SessionMessage["role"],
options: { asThinking?: boolean } = {}
): SessionMessage {
return {
id,
sessionId: "s",
role,
content: "",
contentParams: null,
messageParams: null,
compacted: false,
visible: true,
createTime: "2026-04-28T00:00:00.000Z",
updateTime: "2026-04-28T00:00:00.000Z",
meta: options.asThinking ? { asThinking: true } : undefined,
};
}
test("findExpandedThinkingId returns null on an empty list", () => {
assert.equal(findExpandedThinkingId([]), null);
});
test("findExpandedThinkingId returns the only thinking id when there is no final reply", () => {
const messages = [buildMessage("user", "user"), buildMessage("a-1", "assistant", { asThinking: true })];
assert.equal(findExpandedThinkingId(messages), "a-1");
});
test("findExpandedThinkingId always picks the latest thinking id", () => {
const messages = [
buildMessage("a-1", "assistant", { asThinking: true }),
buildMessage("tool", "tool"),
buildMessage("a-2", "assistant", { asThinking: true }),
];
assert.equal(findExpandedThinkingId(messages), "a-2");
});
test("findExpandedThinkingId returns null after a non-thinking assistant reply", () => {
const messages = [buildMessage("a-1", "assistant", { asThinking: true }), buildMessage("a-final", "assistant")];
assert.equal(findExpandedThinkingId(messages), null);
});
test("findExpandedThinkingId picks the thinking id that follows the last final reply", () => {
const messages = [
buildMessage("a-1", "assistant", { asThinking: true }),
buildMessage("a-final", "assistant"),
buildMessage("a-2", "assistant", { asThinking: true }),
buildMessage("a-3", "assistant", { asThinking: true }),
];
assert.equal(findExpandedThinkingId(messages), "a-3");
});