fix: strip frontmatter from injected skill content and share parser from src
This commit is contained in:
1 parent
023e012eda
commit
d301ef5a62
7 files changed
+108
-43
No files matched your search
+46
-11
@@ -11,12 +11,14 @@ import {
|
||||
updateDocMatrix,
|
||||
type ClassificationEntry,
|
||||
} from "../scripts/generate.ts"
|
||||
import { isUserInvoked, parseFrontmatter } from "../scripts/frontmatter.ts"
|
||||
import { isUserInvoked, parseFrontmatter } from "../src/frontmatter.ts"
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..")
|
||||
|
||||
test("parseFrontmatter: plain, quoted with escapes and colons, DMI, nested blocks skipped", () => {
|
||||
const plain = parseFrontmatter("---\nname: tdd\ndescription: Test-driven development\n---\nBody\n")
|
||||
const plain = parseFrontmatter(
|
||||
"---\nname: tdd\ndescription: Test-driven development\n---\nBody\n",
|
||||
)
|
||||
assert.equal(plain.frontmatter.name, "tdd")
|
||||
assert.equal(plain.frontmatter.description, "Test-driven development")
|
||||
assert.equal(plain.body, "Body\n")
|
||||
@@ -38,7 +40,12 @@ test("parseFrontmatter: plain, quoted with escapes and colons, DMI, nested block
|
||||
assert.deepEqual(none.frontmatter, {})
|
||||
})
|
||||
|
||||
function fixtureSkill(upstream: string, bucket: string, name: string, opts: { dmi?: boolean } = {}) {
|
||||
function fixtureSkill(
|
||||
upstream: string,
|
||||
bucket: string,
|
||||
name: string,
|
||||
opts: { dmi?: boolean } = {},
|
||||
) {
|
||||
const dir = path.join(upstream, bucket, name)
|
||||
mkdirSync(path.join(dir, "agents"), { recursive: true })
|
||||
writeFileSync(
|
||||
@@ -76,14 +83,30 @@ test("buildSkills copies verbatim minus agents/, builds manifest, honors exclusi
|
||||
const out = path.join(dir, "skills")
|
||||
const manifest = buildSkills({
|
||||
upstreamSkills: upstream,
|
||||
entries: [entry("tdd", "engineering"), entry("to-spec", "engineering"), entry("beta", "in-progress", { artifacts: ["excluded"] })],
|
||||
entries: [
|
||||
entry("tdd", "engineering"),
|
||||
entry("to-spec", "engineering"),
|
||||
entry("beta", "in-progress", { artifacts: ["excluded"] }),
|
||||
],
|
||||
skillsOut: out,
|
||||
})
|
||||
assert.deepEqual(
|
||||
manifest,
|
||||
[
|
||||
{ id: "tdd", name: "tdd", description: "The tdd skill", autoinvoke: true, path: "skills/tdd/SKILL.md" },
|
||||
{ id: "to-spec", name: "to-spec", description: "The to-spec skill", autoinvoke: false, path: "skills/to-spec/SKILL.md" },
|
||||
{
|
||||
id: "tdd",
|
||||
name: "tdd",
|
||||
description: "The tdd skill",
|
||||
autoinvoke: true,
|
||||
path: "skills/tdd/SKILL.md",
|
||||
},
|
||||
{
|
||||
id: "to-spec",
|
||||
name: "to-spec",
|
||||
description: "The to-spec skill",
|
||||
autoinvoke: false,
|
||||
path: "skills/to-spec/SKILL.md",
|
||||
},
|
||||
].sort((a, b) => a.id.localeCompare(b.id)),
|
||||
)
|
||||
assert.ok(existsSync(path.join(out, "tdd/SKILL.md")))
|
||||
@@ -101,7 +124,8 @@ test("buildSkills throws on unclassified upstream skills and missing classified
|
||||
const upstream = path.join(dir, "upstream")
|
||||
fixtureSkill(upstream, "engineering", "mystery")
|
||||
assert.throws(
|
||||
() => buildSkills({ upstreamSkills: upstream, entries: [], skillsOut: path.join(dir, "out") }),
|
||||
() =>
|
||||
buildSkills({ upstreamSkills: upstream, entries: [], skillsOut: path.join(dir, "out") }),
|
||||
/unclassified upstream skill: engineering\/mystery/,
|
||||
)
|
||||
assert.throws(
|
||||
@@ -124,7 +148,10 @@ test("updateDocMatrix replaces only the marked section", () => {
|
||||
const doc = path.join(dir, "doc.md")
|
||||
writeFileSync(doc, "prose\n<!-- matrix:start -->\nold\n<!-- matrix:end -->\nmore prose\n")
|
||||
updateDocMatrix(doc, "NEW TABLE")
|
||||
assert.equal(readFileSync(doc, "utf8"), "prose\n<!-- matrix:start -->\n\nNEW TABLE\n\n<!-- matrix:end -->\nmore prose\n")
|
||||
assert.equal(
|
||||
readFileSync(doc, "utf8"),
|
||||
"prose\n<!-- matrix:start -->\n\nNEW TABLE\n\n<!-- matrix:end -->\nmore prose\n",
|
||||
)
|
||||
assert.throws(() => updateDocMatrix(doc.replace("doc", "x"), "t"), /ENOENT/)
|
||||
writeFileSync(path.join(dir, "bad.md"), "no markers")
|
||||
assert.throws(() => updateDocMatrix(path.join(dir, "bad.md"), "t"), /missing matrix markers/)
|
||||
@@ -134,11 +161,16 @@ test("updateDocMatrix replaces only the marked section", () => {
|
||||
})
|
||||
|
||||
test("renderMatrix: one row per entry with escaped cells", () => {
|
||||
const md = renderMatrix([entry("tdd", "engineering", { depends_on: ["codebase-design"], rationale: "a | b" })])
|
||||
const md = renderMatrix([
|
||||
entry("tdd", "engineering", { depends_on: ["codebase-design"], rationale: "a | b" }),
|
||||
])
|
||||
const [header, sep, row] = md.split("\n")
|
||||
assert.match(header, /^\| Upstream skill \| Bucket \| DMI \|/)
|
||||
assert.match(sep, /^\| --- \|/)
|
||||
assert.equal(row, "| tdd | eng | | skill | skill:verbatim | codebase-design | analyzed | a \\| b |")
|
||||
assert.equal(
|
||||
row,
|
||||
"| tdd | eng | | skill | skill:verbatim | codebase-design | analyzed | a \\| b |",
|
||||
)
|
||||
})
|
||||
|
||||
// Regression against the real vendored snapshot: every classified-verbatim skill must parse,
|
||||
@@ -162,7 +194,10 @@ test("real snapshot: all vendored skills parse and DMI flags match classificatio
|
||||
)
|
||||
const m = manifest.find((x: { id: string }) => x.id === e.name)
|
||||
assert.equal(m.autoinvoke, !e.user_invoked, `${e.name}: manifest autoinvoke`)
|
||||
assert.ok(!existsSync(path.join(root, "skills", e.name, "agents")), `${e.name}: openai.yaml stripped`)
|
||||
assert.ok(
|
||||
!existsSync(path.join(root, "skills", e.name, "agents")),
|
||||
`${e.name}: openai.yaml stripped`,
|
||||
)
|
||||
}
|
||||
assert.equal(manifest.filter((m: { autoinvoke: boolean }) => !m.autoinvoke).length, 16)
|
||||
})
|
||||
Reference in new issue
Block a user