-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathmessageView.test.ts
More file actions
69 lines (61 loc) · 2.08 KB
/
messageView.test.ts
File metadata and controls
69 lines (61 loc) · 2.08 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
import { test } from "node:test";
import assert from "node:assert/strict";
import { MessageView, parseDiffPreview } from "../ui";
import type { SessionMessage } from "../session";
test("parseDiffPreview removes headers and classifies lines", () => {
const lines = parseDiffPreview(
["--- a/file.txt", "+++ b/file.txt", "@@ -1,1 +1,1 @@", " context", "-old", "+new"].join("\n")
);
assert.deepEqual(lines, [
{ marker: " ", content: "context", kind: "context" },
{ marker: "-", content: "old", kind: "removed" },
{ marker: "+", content: "new", kind: "added" },
]);
});
test("parseDiffPreview keeps nonstandard context lines", () => {
const lines = parseDiffPreview("...\n+added");
assert.deepEqual(lines, [
{ marker: " ", content: "...", kind: "context" },
{ marker: "+", content: "added", kind: "added" },
]);
});
test("MessageView summarizes thinking content across lines", () => {
assert.equal(
getThinkingParams({
content: "Plan:\n\nInspect the code and update tests",
}),
"Plan: Inspect the code and update tests"
);
});
test("MessageView removes a trailing colon from thinking summaries", () => {
assert.equal(getThinkingParams({ content: "Planning:" }), "Planning");
});
test("MessageView falls back to a reasoning placeholder for hidden reasoning content", () => {
assert.equal(
getThinkingParams({
content: "",
messageParams: { reasoning_content: "hidden chain of thought" },
}),
"(reasoning...)"
);
});
function getThinkingParams(overrides: Partial<SessionMessage>): string {
const view = MessageView({ message: buildAssistantMessage(overrides) }) as any;
return view.props.children.props.params;
}
function buildAssistantMessage(overrides: Partial<SessionMessage>): SessionMessage {
return {
id: "message-1",
sessionId: "session-1",
role: "assistant",
content: "",
contentParams: null,
messageParams: null,
compacted: false,
visible: true,
createTime: "2026-01-01T00:00:00.000Z",
updateTime: "2026-01-01T00:00:00.000Z",
meta: { asThinking: true },
...overrides,
};
}