|
| 1 | +import { describe, expect, it } from "bun:test"; |
| 2 | +import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; |
| 3 | +import { tmpdir } from "node:os"; |
| 4 | +import { join } from "node:path"; |
| 5 | +import { validateSkillMetadata } from "./check-skill-metadata"; |
| 6 | + |
| 7 | +function withSkillsRoot(run: (skillsRoot: string) => void): void { |
| 8 | + const root = mkdtempSync(join(tmpdir(), "skill-metadata-")); |
| 9 | + try { |
| 10 | + const skillsRoot = join(root, "skills"); |
| 11 | + mkdirSync(skillsRoot); |
| 12 | + run(skillsRoot); |
| 13 | + } finally { |
| 14 | + rmSync(root, { recursive: true, force: true }); |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +function writeSkill( |
| 19 | + skillsRoot: string, |
| 20 | + folderName: string, |
| 21 | + frontMatterName: string, |
| 22 | + description = "Test skill", |
| 23 | +) { |
| 24 | + const skillDir = join(skillsRoot, folderName); |
| 25 | + mkdirSync(skillDir, { recursive: true }); |
| 26 | + writeFileSync( |
| 27 | + join(skillDir, "SKILL.md"), |
| 28 | + `---\nname: ${frontMatterName}\ndescription: ${description}\n---\n\n# Test\n`, |
| 29 | + "utf-8", |
| 30 | + ); |
| 31 | +} |
| 32 | + |
| 33 | +function writeOpenAiAgent( |
| 34 | + skillsRoot: string, |
| 35 | + folderName: string, |
| 36 | + displayName: string, |
| 37 | + shortDescription = "Test skill", |
| 38 | +) { |
| 39 | + const agentDir = join(skillsRoot, folderName, "agents"); |
| 40 | + mkdirSync(agentDir, { recursive: true }); |
| 41 | + writeFileSync( |
| 42 | + join(agentDir, "openai.yaml"), |
| 43 | + `interface:\n display_name: "${displayName}"\n short_description: "${shortDescription}"\n default_prompt: "Use this test skill."\n`, |
| 44 | + "utf-8", |
| 45 | + ); |
| 46 | +} |
| 47 | + |
| 48 | +describe("skill metadata validation", () => { |
| 49 | + it("accepts df-prefixed skill folders whose front matter name matches", () => { |
| 50 | + withSkillsRoot((skillsRoot) => { |
| 51 | + writeSkill(skillsRoot, "df-example-skill", "df-example-skill"); |
| 52 | + writeOpenAiAgent(skillsRoot, "df-example-skill", "Example Skill"); |
| 53 | + |
| 54 | + expect(validateSkillMetadata(skillsRoot)).toEqual([]); |
| 55 | + }); |
| 56 | + }); |
| 57 | + |
| 58 | + it("rejects SKILL.md front matter names that do not match the folder", () => { |
| 59 | + withSkillsRoot((skillsRoot) => { |
| 60 | + writeSkill(skillsRoot, "df-example-skill", "different-name"); |
| 61 | + writeOpenAiAgent(skillsRoot, "df-example-skill", "Example Skill"); |
| 62 | + |
| 63 | + expect(validateSkillMetadata(skillsRoot)).toEqual([ |
| 64 | + { |
| 65 | + path: join(skillsRoot, "df-example-skill", "SKILL.md"), |
| 66 | + message: |
| 67 | + 'front matter name "different-name" must match folder "df-example-skill"', |
| 68 | + }, |
| 69 | + ]); |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + it("rejects skill folders that do not start with df-", () => { |
| 74 | + withSkillsRoot((skillsRoot) => { |
| 75 | + writeSkill(skillsRoot, "example-skill", "example-skill"); |
| 76 | + writeOpenAiAgent(skillsRoot, "example-skill", "Example Skill"); |
| 77 | + |
| 78 | + expect(validateSkillMetadata(skillsRoot)).toEqual([ |
| 79 | + { |
| 80 | + path: join(skillsRoot, "example-skill", "SKILL.md"), |
| 81 | + message: 'skill folder "example-skill" must start with "df-"', |
| 82 | + }, |
| 83 | + ]); |
| 84 | + }); |
| 85 | + }); |
| 86 | + |
| 87 | + it("rejects skills without agents/openai.yaml", () => { |
| 88 | + withSkillsRoot((skillsRoot) => { |
| 89 | + writeSkill(skillsRoot, "df-example-skill", "df-example-skill"); |
| 90 | + |
| 91 | + expect(validateSkillMetadata(skillsRoot)).toEqual([ |
| 92 | + { |
| 93 | + path: join(skillsRoot, "df-example-skill", "agents", "openai.yaml"), |
| 94 | + message: "agents/openai.yaml is required", |
| 95 | + }, |
| 96 | + ]); |
| 97 | + }); |
| 98 | + }); |
| 99 | + |
| 100 | + it("rejects display names that are not derived from the folder name", () => { |
| 101 | + withSkillsRoot((skillsRoot) => { |
| 102 | + writeSkill(skillsRoot, "df-example-skill", "df-example-skill"); |
| 103 | + writeOpenAiAgent(skillsRoot, "df-example-skill", "Df Example Skill"); |
| 104 | + |
| 105 | + expect(validateSkillMetadata(skillsRoot)).toEqual([ |
| 106 | + { |
| 107 | + path: join(skillsRoot, "df-example-skill", "agents", "openai.yaml"), |
| 108 | + message: |
| 109 | + 'interface.display_name "Df Example Skill" must be "Example Skill"', |
| 110 | + }, |
| 111 | + ]); |
| 112 | + }); |
| 113 | + }); |
| 114 | + |
| 115 | + it("rejects short descriptions that do not match SKILL.md descriptions", () => { |
| 116 | + withSkillsRoot((skillsRoot) => { |
| 117 | + writeSkill( |
| 118 | + skillsRoot, |
| 119 | + "df-example-skill", |
| 120 | + "df-example-skill", |
| 121 | + "Full SKILL description", |
| 122 | + ); |
| 123 | + writeOpenAiAgent( |
| 124 | + skillsRoot, |
| 125 | + "df-example-skill", |
| 126 | + "Example Skill", |
| 127 | + "Short UI description", |
| 128 | + ); |
| 129 | + |
| 130 | + expect(validateSkillMetadata(skillsRoot)).toEqual([ |
| 131 | + { |
| 132 | + path: join(skillsRoot, "df-example-skill", "agents", "openai.yaml"), |
| 133 | + message: |
| 134 | + 'interface.short_description must exactly match SKILL.md description "Full SKILL description"', |
| 135 | + }, |
| 136 | + ]); |
| 137 | + }); |
| 138 | + }); |
| 139 | +}); |
0 commit comments