refactor(test): dedupe loadWorkspaceSkillEntries plugin setup

This commit is contained in:
Peter Steinberger
2026-02-15 00:00:00 +00:00
parent 7b3e5ce0d1
commit 20abab7c4f

View File

@@ -26,6 +26,36 @@ ${body ?? `# ${name}\n`}
);
}
async function setupWorkspaceWithProsePlugin() {
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-"));
const managedDir = path.join(workspaceDir, ".managed");
const bundledDir = path.join(workspaceDir, ".bundled");
const pluginRoot = path.join(workspaceDir, ".openclaw", "extensions", "open-prose");
await fs.mkdir(path.join(pluginRoot, "skills", "prose"), { recursive: true });
await fs.writeFile(
path.join(pluginRoot, "openclaw.plugin.json"),
JSON.stringify(
{
id: "open-prose",
skills: ["./skills"],
configSchema: { type: "object", additionalProperties: false, properties: {} },
},
null,
2,
),
"utf-8",
);
await fs.writeFile(path.join(pluginRoot, "index.ts"), "export {};\n", "utf-8");
await fs.writeFile(
path.join(pluginRoot, "skills", "prose", "SKILL.md"),
`---\nname: prose\ndescription: test\n---\n`,
"utf-8",
);
return { workspaceDir, managedDir, bundledDir };
}
describe("loadWorkspaceSkillEntries", () => {
it("handles an empty managed skills dir without throwing", async () => {
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-"));
@@ -41,31 +71,7 @@ describe("loadWorkspaceSkillEntries", () => {
});
it("includes plugin-shipped skills when the plugin is enabled", async () => {
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-"));
const managedDir = path.join(workspaceDir, ".managed");
const bundledDir = path.join(workspaceDir, ".bundled");
const pluginRoot = path.join(workspaceDir, ".openclaw", "extensions", "open-prose");
await fs.mkdir(path.join(pluginRoot, "skills", "prose"), { recursive: true });
await fs.writeFile(
path.join(pluginRoot, "openclaw.plugin.json"),
JSON.stringify(
{
id: "open-prose",
skills: ["./skills"],
configSchema: { type: "object", additionalProperties: false, properties: {} },
},
null,
2,
),
"utf-8",
);
await fs.writeFile(path.join(pluginRoot, "index.ts"), "export {};\n", "utf-8");
await fs.writeFile(
path.join(pluginRoot, "skills", "prose", "SKILL.md"),
`---\nname: prose\ndescription: test\n---\n`,
"utf-8",
);
const { workspaceDir, managedDir, bundledDir } = await setupWorkspaceWithProsePlugin();
const entries = loadWorkspaceSkillEntries(workspaceDir, {
config: {
@@ -81,31 +87,7 @@ describe("loadWorkspaceSkillEntries", () => {
});
it("excludes plugin-shipped skills when the plugin is not allowed", async () => {
const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-"));
const managedDir = path.join(workspaceDir, ".managed");
const bundledDir = path.join(workspaceDir, ".bundled");
const pluginRoot = path.join(workspaceDir, ".openclaw", "extensions", "open-prose");
await fs.mkdir(path.join(pluginRoot, "skills", "prose"), { recursive: true });
await fs.writeFile(
path.join(pluginRoot, "openclaw.plugin.json"),
JSON.stringify(
{
id: "open-prose",
skills: ["./skills"],
configSchema: { type: "object", additionalProperties: false, properties: {} },
},
null,
2,
),
"utf-8",
);
await fs.writeFile(path.join(pluginRoot, "index.ts"), "export {};\n", "utf-8");
await fs.writeFile(
path.join(pluginRoot, "skills", "prose", "SKILL.md"),
`---\nname: prose\ndescription: test\n---\n`,
"utf-8",
);
const { workspaceDir, managedDir, bundledDir } = await setupWorkspaceWithProsePlugin();
const entries = loadWorkspaceSkillEntries(workspaceDir, {
config: {