|
| 1 | +import { mkdir, mkdtemp, writeFile } from "node:fs/promises"; |
| 2 | +import { tmpdir } from "node:os"; |
| 3 | +import { join } from "node:path"; |
| 4 | +import { describe, expect, test } from "bun:test"; |
| 5 | + |
| 6 | +import { formatAttachedSkillConstraints } from "./attached-skills.js"; |
| 7 | + |
| 8 | +async function writePluginSkill( |
| 9 | + pluginRoot: string, |
| 10 | + name: string, |
| 11 | + body: string, |
| 12 | +): Promise<void> { |
| 13 | + const dir = join(pluginRoot, "skills", name); |
| 14 | + await mkdir(dir, { recursive: true }); |
| 15 | + await writeFile( |
| 16 | + join(dir, "SKILL.md"), |
| 17 | + `---\nname: ${name}\ndescription: ${name} skill\n---\n\n${body}\n`, |
| 18 | + ); |
| 19 | +} |
| 20 | + |
| 21 | +describe("formatAttachedSkillConstraints", () => { |
| 22 | + test("returns undefined when no names are attached", async () => { |
| 23 | + expect( |
| 24 | + await formatAttachedSkillConstraints({ |
| 25 | + names: [], |
| 26 | + cwd: "/tmp", |
| 27 | + skillDirs: [], |
| 28 | + }), |
| 29 | + ).toBeUndefined(); |
| 30 | + }); |
| 31 | + |
| 32 | + test("injects resolved bodies from plugin skill dirs and notes misses without throwing", async () => { |
| 33 | + const cwd = await mkdtemp(join(tmpdir(), "attached-skills-")); |
| 34 | + const pluginRoot = join(cwd, "plugin"); |
| 35 | + await writePluginSkill(pluginRoot, "style", "Follow the style guide."); |
| 36 | + const section = await formatAttachedSkillConstraints({ |
| 37 | + names: ["style", "philosophy"], |
| 38 | + cwd, |
| 39 | + skillDirs: [pluginRoot], |
| 40 | + }); |
| 41 | + expect(section).toContain("# Attached skill constraints"); |
| 42 | + expect(section).toContain("Do not use_skill them again"); |
| 43 | + expect(section).toContain("do not park, do not ask_director"); |
| 44 | + expect(section).toContain("### style"); |
| 45 | + expect(section).toContain("Follow the style guide."); |
| 46 | + expect(section).toContain( |
| 47 | + 'Attached skill "philosophy" could not be resolved. Proceed under AGENTS.md.', |
| 48 | + ); |
| 49 | + expect(section).not.toContain("### philosophy"); |
| 50 | + }); |
| 51 | + |
| 52 | + test("does not resolve plugin skills when skillDirs is empty", async () => { |
| 53 | + const cwd = await mkdtemp(join(tmpdir(), "attached-skills-empty-")); |
| 54 | + const pluginRoot = join(cwd, "plugin"); |
| 55 | + await writePluginSkill(pluginRoot, "style", "Follow the style guide."); |
| 56 | + const section = await formatAttachedSkillConstraints({ |
| 57 | + names: ["style"], |
| 58 | + cwd, |
| 59 | + skillDirs: [], |
| 60 | + }); |
| 61 | + expect(section).toContain( |
| 62 | + 'Attached skill "style" could not be resolved. Proceed under AGENTS.md.', |
| 63 | + ); |
| 64 | + expect(section).not.toContain("Follow the style guide."); |
| 65 | + }); |
| 66 | +}); |
0 commit comments