-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.ts
More file actions
134 lines (117 loc) · 3.78 KB
/
index.test.ts
File metadata and controls
134 lines (117 loc) · 3.78 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { test, expect, describe } from "bun:test";
import { formatOutput, formatMessage, formatContentBlock } from "./src/format";
import { projectDirToPath } from "./src/data";
import type { MessageEntry, ShowOptions } from "./src/types";
const defaultOptions: ShowOptions = {
noTools: false,
noSystem: false,
compact: false,
};
describe("projectDirToPath", () => {
test("converts dash-separated dir to path", () => {
expect(projectDirToPath("-Users-defrex-code-foo")).toBe(
"/Users/defrex/code/foo"
);
});
test("handles single segment", () => {
expect(projectDirToPath("-tmp")).toBe("/tmp");
});
});
describe("formatOutput", () => {
test("renders YAML frontmatter and body", () => {
const result = formatOutput({ title: "test", count: 5 }, "hello world");
expect(result).toBe("---\ntitle: test\ncount: 5\n---\n\nhello world");
});
test("escapes special characters in YAML values", () => {
const result = formatOutput({ msg: 'has "quotes"' }, "body");
expect(result).toContain('msg: "has \\"quotes\\""');
});
});
describe("formatContentBlock", () => {
test("renders text block", () => {
const result = formatContentBlock(
{ type: "text", text: "hello" },
defaultOptions
);
expect(result).toBe("hello");
});
test("renders tool_use block", () => {
const result = formatContentBlock(
{ type: "tool_use", id: "1", name: "Read", input: { path: "/tmp" } },
defaultOptions
);
expect(result).toContain("**Tool: Read**");
expect(result).toContain('"path": "/tmp"');
});
test("hides tool_use with noTools", () => {
const result = formatContentBlock(
{ type: "tool_use", id: "1", name: "Read", input: {} },
{ ...defaultOptions, noTools: true }
);
expect(result).toBeNull();
});
test("truncates tool_use input in compact mode", () => {
const longInput = { data: "x".repeat(500) };
const result = formatContentBlock(
{ type: "tool_use", id: "1", name: "Read", input: longInput },
{ ...defaultOptions, compact: true }
);
expect(result).toContain("(truncated)");
});
test("renders tool_result as collapsible", () => {
const result = formatContentBlock(
{ type: "tool_result", tool_use_id: "1", content: "output here" },
defaultOptions
);
expect(result).toContain("<details>");
expect(result).toContain("output here");
});
test("hides thinking in compact mode", () => {
const result = formatContentBlock(
{ type: "thinking", thinking: "hmm" },
{ ...defaultOptions, compact: true }
);
expect(result).toBeNull();
});
});
describe("formatMessage", () => {
const userEntry: MessageEntry = {
type: "user",
message: { role: "user", content: "hello" },
};
const assistantEntry: MessageEntry = {
type: "assistant",
message: {
role: "assistant",
content: [{ type: "text", text: "hi there" }],
model: "claude-opus-4-6",
},
};
test("renders user message", () => {
const result = formatMessage(userEntry, defaultOptions);
expect(result).toBe("## User\n\nhello");
});
test("renders assistant message with content blocks", () => {
const result = formatMessage(assistantEntry, defaultOptions);
expect(result).toContain("## Assistant");
expect(result).toContain("hi there");
});
test("filters by type", () => {
const result = formatMessage(userEntry, {
...defaultOptions,
type: "assistant",
});
expect(result).toBeNull();
});
test("hides system with noSystem", () => {
const systemEntry: MessageEntry = {
type: "system" as any,
message: { role: "system", content: "init" },
};
const result = formatMessage(systemEntry, {
...defaultOptions,
noSystem: true,
});
expect(result).toBeNull();
});
});