Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/architecture/tla/Frontmatter.tla
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
\* Cost: TLC runs in under 1 second. Agent time is not measured.
\* Review: 1 covered (bot thread on double BOM, PR 2455), 0 added, 1 gap.
\* Gap: PR 2456 bot thread on uppercase YAML. The spec models safety only, not false rejects. A test covers it.
\* Gap: a YAML tag such as !!js/function is not a header language. The spec cannot express it. A test covers it.
\* Replay: two BOMs do not run code in gray-matter. It is a false alarm. A test case stays.
\* Skills: the skill caller is the same input domain. The skill path was unguarded before this change.
\* Property test: src/utils/__tests__/safeFrontmatter.spec.ts. Caller tests: SkillsManager.spec.ts, frontmatter-commands.spec.ts.
Expand Down
14 changes: 14 additions & 0 deletions src/services/skills/__tests__/SkillsManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ describe("SkillsManager", () => {
}
})

it.each(["", "yaml", "json"])("accepts data-only %s metadata in skill operations", async (language) => {
mockDirectoryExists.mockImplementation(async (dir: string) => dir === projectSkillsDir)
mockRealpath.mockImplementation(async (value: string) => value)
mockReaddir.mockImplementation(async (dir: string) => (dir === projectSkillsDir ? ["example"] : []))
mockStat.mockResolvedValue({ isDirectory: () => true })
mockFileExists.mockResolvedValue(true)
const metadata =
language === "json" ? '{"name":"example","description":"Example"}' : "name: example\ndescription: Example"
mockReadFile.mockResolvedValue(`---${language}\n${metadata}\n---\nBody`)
await skillsManager.discoverSkills()
expect(skillsManager.getAllSkills()).toHaveLength(1)
expect((await skillsManager.getSkillContent("example"))?.instructions).toBe("Body")
})

describe("discoverSkills", () => {
it("should discover skills from global directory", async () => {
const pdfSkillDir = p(globalSkillsDir, "pdf-processing")
Expand Down
6 changes: 5 additions & 1 deletion src/utils/__tests__/safeFrontmatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("parseFrontmatter", () => {
})
})

it.each(["javascript", "js", "JavaScript", "JS", " javascript ", "toml"])(
it.each(["javascript", "js", "JavaScript", "JS", " javascript ", "toml", "coffee", "__proto__"])(
"rejects %s before executing metadata, including with a BOM",
(language) => {
for (const prefix of ["", "\uFEFF"]) {
Expand Down Expand Up @@ -47,6 +47,10 @@ describe("parseFrontmatter", () => {
})
})

it("rejects executable YAML tags", () => {
expect(() => parseFrontmatter('---\nvalue: !!js/function "function () {}"\n---')).toThrow()
})

it("preserves Markdown without metadata", () => {
expect(parseFrontmatter("# Heading\nBody").content).toBe("# Heading\nBody")
})
Expand Down
Loading