Skip to content

Commit bb13e28

Browse files
committed
test: command hints + skill formatting — template parsing and output rendering
Command.hints() and Skill.fmt() are user-facing pure functions with zero test coverage. These 9 tests prevent regressions in command argument hint extraction and skill listing output (both verbose XML and markdown formats). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]> https://claude.ai/code/session_011MEvdFUnKtEEi18HBQcJz5
1 parent 966f43c commit bb13e28

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { describe, test, expect } from "bun:test"
2+
import { Command } from "../../src/command/index"
3+
4+
describe("Command.hints: template placeholder extraction", () => {
5+
test("returns empty array for template with no placeholders", () => {
6+
expect(Command.hints("Run the tests and report results")).toEqual([])
7+
expect(Command.hints("")).toEqual([])
8+
})
9+
10+
test("extracts numbered placeholders in sorted order", () => {
11+
expect(Command.hints("Review $2 and compare with $1")).toEqual(["$1", "$2"])
12+
})
13+
14+
test("deduplicates repeated placeholder occurrences", () => {
15+
expect(Command.hints("Use $1 then use $1 again and $2")).toEqual(["$1", "$2"])
16+
})
17+
18+
test("appends $ARGUMENTS when present", () => {
19+
expect(Command.hints("Do something with $ARGUMENTS")).toEqual(["$ARGUMENTS"])
20+
})
21+
22+
test("multi-digit placeholders sort lexicographically", () => {
23+
// $10 sorts before $2 in lexicographic order — this is the actual behavior
24+
// since the code uses [...new Set(numbered)].sort() which is string sort
25+
const result = Command.hints("Map $1 to $2 and also $10")
26+
expect(result).toEqual(["$1", "$10", "$2"])
27+
})
28+
})
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { describe, test, expect } from "bun:test"
2+
import { Skill } from "../../src/skill/skill"
3+
4+
function skill(overrides: Partial<Skill.Info> = {}): Skill.Info {
5+
return {
6+
name: overrides.name ?? "test-skill",
7+
description: overrides.description ?? "A test skill",
8+
location: overrides.location ?? "/home/user/skills/test-skill/SKILL.md",
9+
content: overrides.content ?? "# Test\nDo the thing.",
10+
}
11+
}
12+
13+
describe("Skill.fmt: skill list formatting", () => {
14+
test("returns 'No skills' message for empty list", () => {
15+
expect(Skill.fmt([], { verbose: false })).toBe("No skills are currently available.")
16+
expect(Skill.fmt([], { verbose: true })).toBe("No skills are currently available.")
17+
})
18+
19+
test("verbose mode returns XML with skill tags", () => {
20+
const skills = [
21+
skill({ name: "analyze", description: "Analyze code", location: "/path/to/analyze/SKILL.md" }),
22+
skill({ name: "deploy", description: "Deploy app", location: "/path/to/deploy/SKILL.md" }),
23+
]
24+
const output = Skill.fmt(skills, { verbose: true })
25+
expect(output).toContain("<available_skills>")
26+
expect(output).toContain("</available_skills>")
27+
expect(output).toContain("<name>analyze</name>")
28+
expect(output).toContain("<description>Analyze code</description>")
29+
expect(output).toContain("<name>deploy</name>")
30+
expect(output).toContain("<description>Deploy app</description>")
31+
// File paths get converted to file:// URLs
32+
expect(output).toContain("file:///path/to/analyze/SKILL.md")
33+
})
34+
35+
test("non-verbose returns markdown with bullet points", () => {
36+
const skills = [
37+
skill({ name: "lint", description: "Lint the code" }),
38+
skill({ name: "format", description: "Format files" }),
39+
]
40+
const output = Skill.fmt(skills, { verbose: false })
41+
expect(output).toContain("## Available Skills")
42+
expect(output).toContain("- **lint**: Lint the code")
43+
expect(output).toContain("- **format**: Format files")
44+
})
45+
46+
test("verbose mode preserves builtin: protocol without file:// conversion", () => {
47+
const skills = [
48+
skill({ name: "builtin-skill", description: "Built in", location: "builtin:my-skill/SKILL.md" }),
49+
]
50+
const output = Skill.fmt(skills, { verbose: true })
51+
expect(output).toContain("<location>builtin:my-skill/SKILL.md</location>")
52+
// Should NOT contain file:// for builtin: paths
53+
expect(output).not.toContain("file://")
54+
})
55+
})

0 commit comments

Comments
 (0)