|
| 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