Add AGENTS.md and SKILL.md governance check gates

This commit is contained in:
gitea committed 2026-10-25 17:49:04 +08:00
1 parent 219be61585
commit f5b66be85f
10 files changed
+609 -5

No files matched your search

+104
View File
@@ -0,0 +1,104 @@
import { describe, expect, test } from "bun:test"
import { readdirSync, readFileSync } from "node:fs"
import { join } from "node:path"
import { SKILL_MAX_H2_SECTIONS, SKILL_MAX_LINES, 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("enforces the line budget as a hard error", () => {
const padded = Array.from({ length: SKILL_MAX_LINES }, () => "filler line")
const content = `${cleanSkill()}\n${padded.join("\n")}`
const issues = validateSkillDoc(content, REFERENCE_FILES)
expect(issues.some((issue) => issue.rule === "skill-budget-lines")).toBe(true)
})
test("enforces the H2 section budget as a hard error", () => {
const sections = Array.from(
{ length: SKILL_MAX_H2_SECTIONS + 1 },
(_, index) => `## Section ${index + 1}`
)
const content = `${lines("# Demo Skill", "")}\n${sections.join("\n\n")}`
const issues = validateSkillDoc(content, REFERENCE_FILES)
expect(issues.some((issue) => issue.rule === "skill-budget-h2")).toBe(true)
})
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([])
})
})