88 lines
2.7 KiB
TypeScript
88 lines
2.7 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { readdirSync, readFileSync } from "node:fs"
|
|
import { join } from "node:path"
|
|
import { validateSkillDoc } from "./check-skill-md.js"
|
|
|
|
const REFERENCE_FILES = ["references/alpha.md", "references/beta.md"]
|
|
|
|
function lines(...rows: string[]): string {
|
|
return rows.join("\n")
|
|
}
|
|
|
|
function cleanSkill(): string {
|
|
return lines(
|
|
"---",
|
|
"name: demo",
|
|
"---",
|
|
"",
|
|
"# Demo Skill",
|
|
"",
|
|
"## Routing",
|
|
"",
|
|
"| Signal | Reference |",
|
|
"| --- | --- |",
|
|
"| first case | `references/alpha.md` |",
|
|
"| second case | `references/beta.md` |"
|
|
)
|
|
}
|
|
|
|
describe("validateSkillDoc", () => {
|
|
test("accepts a well-formed routing hub", () => {
|
|
expect(validateSkillDoc(cleanSkill(), REFERENCE_FILES)).toEqual([])
|
|
})
|
|
|
|
test("flags routing that points at a missing reference file", () => {
|
|
const content = lines(
|
|
"# Demo Skill",
|
|
"",
|
|
"## Routing",
|
|
"",
|
|
"Detailed guide: `references/ghost.md`."
|
|
)
|
|
const issues = validateSkillDoc(content, REFERENCE_FILES)
|
|
const missing = issues.filter((issue) => issue.rule === "skill-reference-exists")
|
|
expect(missing.length).toBe(1)
|
|
expect(missing[0]!.message).toContain("references/ghost.md")
|
|
})
|
|
|
|
test("flags reference files that exist on disk but are never routed", () => {
|
|
const content = lines(
|
|
"# Demo Skill",
|
|
"",
|
|
"## Routing",
|
|
"",
|
|
"Only this: `references/alpha.md`."
|
|
)
|
|
const issues = validateSkillDoc(content, REFERENCE_FILES)
|
|
const unrouted = issues.filter((issue) => issue.rule === "skill-reference-routed")
|
|
expect(unrouted.length).toBe(1)
|
|
expect(unrouted[0]!.message).toContain("references/beta.md")
|
|
})
|
|
|
|
test("flags structure and hygiene problems", () => {
|
|
const content = lines(
|
|
"# Demo Skill",
|
|
"",
|
|
"## Section",
|
|
"",
|
|
"#### Skipped level",
|
|
"",
|
|
"Trailing spaces. "
|
|
)
|
|
const issues = validateSkillDoc(content, REFERENCE_FILES)
|
|
expect(issues.some((issue) => issue.rule === "heading-hierarchy")).toBe(true)
|
|
expect(issues.some((issue) => issue.rule === "trailing-whitespace" && issue.line === 7)).toBe(true)
|
|
})
|
|
|
|
test("the committed skills/seal-use/SKILL.md passes its own charter", () => {
|
|
const root = join(import.meta.dirname, "..")
|
|
const content = readFileSync(join(root, "skills", "seal-use", "SKILL.md"), "utf8")
|
|
const referenceFiles = readdirSync(join(root, "skills", "seal-use", "references"), {
|
|
withFileTypes: true
|
|
})
|
|
.filter((entry) => entry.isFile() && entry.name.endsWith(".md"))
|
|
.map((entry) => `references/${entry.name}`)
|
|
expect(validateSkillDoc(content, referenceFiles)).toEqual([])
|
|
})
|
|
})
|