30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
import { afterEach, expect, it } from "vitest";
|
|
import { mkdtemp, mkdir, writeFile, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { createSkillLoader, SkillCatalog } from "../src/skills.js";
|
|
let root: string;
|
|
const previous = process.env.AGENT_SKILLS_DIRS;
|
|
afterEach(async () => {
|
|
if (previous === undefined) delete process.env.AGENT_SKILLS_DIRS;
|
|
else process.env.AGENT_SKILLS_DIRS = previous;
|
|
if (root) await rm(root, { recursive: true, force: true });
|
|
});
|
|
it("catalog and execution load the same extra skills and refresh additions", async () => {
|
|
root = await mkdtemp(path.join(tmpdir(), "skill-loader-test-"));
|
|
const extra = path.join(root, "extra");
|
|
await mkdir(extra);
|
|
process.env.AGENT_SKILLS_DIRS = "extra";
|
|
const catalog = new SkillCatalog(root);
|
|
const loader = createSkillLoader(root);
|
|
for (const name of ["first", "second"]) {
|
|
const dir = path.join(extra, name);
|
|
await mkdir(dir);
|
|
await writeFile(path.join(dir, "SKILL.md"), `---\nname: ${name}\ndescription: Test skill\n---\nRead data.`);
|
|
const items = await catalog.reload();
|
|
await loader.reload();
|
|
expect(items.some(s => s.name === name)).toBe(true);
|
|
expect(loader.getSkills().skills.some(s => s.name === name)).toBe(true);
|
|
}
|
|
});
|