-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.test.ts
More file actions
86 lines (74 loc) · 2.68 KB
/
index.test.ts
File metadata and controls
86 lines (74 loc) · 2.68 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
import { describe, it } from "node:test"
import assert from "node:assert/strict"
import { truncate, extractTextFromParts } from "../src/index"
import { buildPayload } from "../src/payload"
describe("truncate", () => {
it("returns string unchanged when under maxLen", () => {
assert.strictEqual(truncate("hello", 10), "hello")
})
it("returns string unchanged when exactly maxLen", () => {
assert.strictEqual(truncate("hello", 5), "hello")
})
it("truncates and adds ellipsis when over maxLen", () => {
assert.strictEqual(truncate("hello world", 8), "hello...")
})
it("handles maxLen of 3 (minimum for ellipsis)", () => {
assert.strictEqual(truncate("hello", 3), "...")
})
it("handles empty string", () => {
assert.strictEqual(truncate("", 10), "")
})
})
describe("extractTextFromParts", () => {
it("extracts text from text parts", () => {
const parts = [
{ type: "text" as const, text: "hello" },
{ type: "text" as const, text: "world" },
]
assert.strictEqual(extractTextFromParts(parts), "hello world")
})
it("skips non-text parts", () => {
const parts = [
{ type: "text" as const, text: "hello" },
{ type: "tool_use" as const, id: "1", name: "bash", input: {} },
{ type: "text" as const, text: "world" },
] as any[]
assert.strictEqual(extractTextFromParts(parts), "hello world")
})
it("skips text parts with empty text", () => {
const parts = [
{ type: "text" as const, text: "" },
{ type: "text" as const, text: "hello" },
]
assert.strictEqual(extractTextFromParts(parts), "hello")
})
it("returns empty string for no parts", () => {
assert.strictEqual(extractTextFromParts([]), "")
})
it("returns empty string when all parts are non-text", () => {
const parts = [
{ type: "tool_use" as const, id: "1", name: "bash", input: {} },
] as any[]
assert.strictEqual(extractTextFromParts(parts), "")
})
})
describe("PLUGIN_VERSION", () => {
it("resolves to a valid semver string from package.json", async () => {
const pkg = await import("../package.json", { with: { type: "json" } })
const version = pkg.default.version
assert.ok(typeof version === "string", "version should be a string")
assert.match(version, /^\d+\.\d+\.\d+/, "version should be semver")
})
})
describe("question_asked event", () => {
it("builds a valid question_asked payload", () => {
const payload = JSON.parse(
buildPayload("question_asked", "s1", "/tmp/proj", {
tool_name: "question",
}),
)
assert.strictEqual(payload.event, "question_asked")
assert.strictEqual(payload.tool_name, "question")
assert.strictEqual(payload.session_id, "s1")
})
})