42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { buildWorkspaceSkillSnapshot } from "./skills.js";
|
|
|
|
async function _writeSkill(params: {
|
|
dir: string;
|
|
name: string;
|
|
description: string;
|
|
metadata?: string;
|
|
body?: string;
|
|
}) {
|
|
const { dir, name, description, metadata, body } = params;
|
|
await fs.mkdir(dir, { recursive: true });
|
|
await fs.writeFile(
|
|
path.join(dir, "SKILL.md"),
|
|
`---
|
|
name: ${name}
|
|
description: ${description}${metadata ? `\nmetadata: ${metadata}` : ""}
|
|
---
|
|
|
|
${body ?? `# ${name}\n`}
|
|
`,
|
|
"utf-8",
|
|
);
|
|
}
|
|
|
|
describe("buildWorkspaceSkillSnapshot", () => {
|
|
it("returns an empty snapshot when skills dirs are missing", async () => {
|
|
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-"));
|
|
|
|
const snapshot = buildWorkspaceSkillSnapshot(workspaceDir, {
|
|
managedSkillsDir: path.join(workspaceDir, ".managed"),
|
|
bundledSkillsDir: path.join(workspaceDir, ".bundled"),
|
|
});
|
|
|
|
expect(snapshot.prompt).toBe("");
|
|
expect(snapshot.skills).toEqual([]);
|
|
});
|
|
});
|