From 70fdab6e9587bc0f53ed68576dfe86c61a1c9712 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 18:56:51 +0000 Subject: [PATCH] test(agents): add coverage for shared skill writer helper --- src/agents/skills.e2e-test-helpers.test.ts | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 src/agents/skills.e2e-test-helpers.test.ts diff --git a/src/agents/skills.e2e-test-helpers.test.ts b/src/agents/skills.e2e-test-helpers.test.ts new file mode 100644 index 00000000000..22cd6e7496c --- /dev/null +++ b/src/agents/skills.e2e-test-helpers.test.ts @@ -0,0 +1,52 @@ +import fs from "node:fs/promises"; +import os from "node:os"; +import path from "node:path"; +import { afterEach, describe, expect, it } from "vitest"; +import { writeSkill } from "./skills.e2e-test-helpers.js"; + +const tempDirs: string[] = []; + +afterEach(async () => { + await Promise.all( + tempDirs.splice(0, tempDirs.length).map((dir) => fs.rm(dir, { recursive: true, force: true })), + ); +}); + +describe("writeSkill", () => { + it("writes SKILL.md with required fields", async () => { + const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-skill-helper-")); + tempDirs.push(root); + const skillDir = path.join(root, "demo-skill"); + + await writeSkill({ + dir: skillDir, + name: "demo-skill", + description: "Demo", + }); + + const content = await fs.readFile(path.join(skillDir, "SKILL.md"), "utf-8"); + expect(content).toContain("name: demo-skill"); + expect(content).toContain("description: Demo"); + expect(content).toContain("# demo-skill"); + }); + + it("includes optional metadata, body, and frontmatterExtra", async () => { + const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-skill-helper-")); + tempDirs.push(root); + const skillDir = path.join(root, "custom-skill"); + + await writeSkill({ + dir: skillDir, + name: "custom-skill", + description: "Custom", + metadata: '{"openclaw":{"always":true}}', + frontmatterExtra: "user-invocable: false", + body: "# Custom Body\n", + }); + + const content = await fs.readFile(path.join(skillDir, "SKILL.md"), "utf-8"); + expect(content).toContain('metadata: {"openclaw":{"always":true}}'); + expect(content).toContain("user-invocable: false"); + expect(content).toContain("# Custom Body"); + }); +});