refactor(agents): share skill plugin fixture writer in tests
This commit is contained in:
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { clearPluginManifestRegistryCache } from "../../plugins/manifest-registry.js";
|
||||
import { writePluginWithSkill } from "../test-helpers/skill-plugin-fixtures.js";
|
||||
import { resolveEmbeddedRunSkillEntries } from "./skills-runtime.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
@@ -20,26 +21,12 @@ async function setupBundledDiffsPlugin() {
|
||||
const workspaceDir = await createTempDir("openclaw-workspace-");
|
||||
const pluginRoot = path.join(bundledPluginsDir, "diffs");
|
||||
|
||||
await fs.mkdir(path.join(pluginRoot, "skills", "diffs"), { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(pluginRoot, "openclaw.plugin.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
id: "diffs",
|
||||
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", "diffs", "SKILL.md"),
|
||||
`---\nname: diffs\ndescription: runtime integration test\n---\n`,
|
||||
"utf-8",
|
||||
);
|
||||
await writePluginWithSkill({
|
||||
pluginRoot,
|
||||
pluginId: "diffs",
|
||||
skillId: "diffs",
|
||||
skillDescription: "runtime integration test",
|
||||
});
|
||||
|
||||
return { bundledPluginsDir, workspaceDir };
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { loadWorkspaceSkillEntries } from "./skills.js";
|
||||
import { writePluginWithSkill } from "./test-helpers/skill-plugin-fixtures.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
@@ -24,26 +25,12 @@ async function setupWorkspaceWithProsePlugin() {
|
||||
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",
|
||||
);
|
||||
await writePluginWithSkill({
|
||||
pluginRoot,
|
||||
pluginId: "open-prose",
|
||||
skillId: "prose",
|
||||
skillDescription: "test",
|
||||
});
|
||||
|
||||
return { workspaceDir, managedDir, bundledDir };
|
||||
}
|
||||
@@ -54,26 +41,12 @@ async function setupWorkspaceWithDiffsPlugin() {
|
||||
const bundledDir = path.join(workspaceDir, ".bundled");
|
||||
const pluginRoot = path.join(workspaceDir, ".openclaw", "extensions", "diffs");
|
||||
|
||||
await fs.mkdir(path.join(pluginRoot, "skills", "diffs"), { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(pluginRoot, "openclaw.plugin.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
id: "diffs",
|
||||
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", "diffs", "SKILL.md"),
|
||||
`---\nname: diffs\ndescription: test\n---\n`,
|
||||
"utf-8",
|
||||
);
|
||||
await writePluginWithSkill({
|
||||
pluginRoot,
|
||||
pluginId: "diffs",
|
||||
skillId: "diffs",
|
||||
skillDescription: "test",
|
||||
});
|
||||
|
||||
return { workspaceDir, managedDir, bundledDir };
|
||||
}
|
||||
|
||||
30
src/agents/test-helpers/skill-plugin-fixtures.ts
Normal file
30
src/agents/test-helpers/skill-plugin-fixtures.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
export async function writePluginWithSkill(params: {
|
||||
pluginRoot: string;
|
||||
pluginId: string;
|
||||
skillId: string;
|
||||
skillDescription: string;
|
||||
}) {
|
||||
await fs.mkdir(path.join(params.pluginRoot, "skills", params.skillId), { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.join(params.pluginRoot, "openclaw.plugin.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
id: params.pluginId,
|
||||
skills: ["./skills"],
|
||||
configSchema: { type: "object", additionalProperties: false, properties: {} },
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf-8",
|
||||
);
|
||||
await fs.writeFile(path.join(params.pluginRoot, "index.ts"), "export {};\n", "utf-8");
|
||||
await fs.writeFile(
|
||||
path.join(params.pluginRoot, "skills", params.skillId, "SKILL.md"),
|
||||
`---\nname: ${params.skillId}\ndescription: ${params.skillDescription}\n---\n`,
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user