mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-10 08:41:13 +00:00
test: dedupe plugin bundle and discovery suites
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { captureEnv } from "../test-utils/env.js";
|
||||
import { loadEnabledClaudeBundleCommands } from "./bundle-commands.js";
|
||||
import { createBundleMcpTempHarness } from "./bundle-mcp.test-support.js";
|
||||
import { createBundleMcpTempHarness, withBundleHomeEnv } from "./bundle-mcp.test-support.js";
|
||||
|
||||
const tempHarness = createBundleMcpTempHarness();
|
||||
|
||||
@@ -11,24 +10,6 @@ afterEach(async () => {
|
||||
await tempHarness.cleanup();
|
||||
});
|
||||
|
||||
async function withBundleHomeEnv<T>(
|
||||
prefix: string,
|
||||
run: (params: { homeDir: string; workspaceDir: string }) => Promise<T>,
|
||||
): Promise<T> {
|
||||
const env = captureEnv(["HOME", "USERPROFILE", "OPENCLAW_HOME", "OPENCLAW_STATE_DIR"]);
|
||||
try {
|
||||
const homeDir = await tempHarness.createTempDir(`${prefix}-home-`);
|
||||
const workspaceDir = await tempHarness.createTempDir(`${prefix}-workspace-`);
|
||||
process.env.HOME = homeDir;
|
||||
process.env.USERPROFILE = homeDir;
|
||||
delete process.env.OPENCLAW_HOME;
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
return await run({ homeDir, workspaceDir });
|
||||
} finally {
|
||||
env.restore();
|
||||
}
|
||||
}
|
||||
|
||||
async function writeClaudeBundleCommandFixture(params: {
|
||||
homeDir: string;
|
||||
pluginId: string;
|
||||
@@ -57,65 +38,69 @@ async function writeClaudeBundleCommandFixture(params: {
|
||||
|
||||
describe("loadEnabledClaudeBundleCommands", () => {
|
||||
it("loads enabled Claude bundle markdown commands and skips disabled-model-invocation entries", async () => {
|
||||
await withBundleHomeEnv("openclaw-bundle-commands", async ({ homeDir, workspaceDir }) => {
|
||||
await writeClaudeBundleCommandFixture({
|
||||
homeDir,
|
||||
pluginId: "compound-bundle",
|
||||
commands: [
|
||||
{
|
||||
relativePath: "commands/office-hours.md",
|
||||
contents: [
|
||||
"---",
|
||||
"description: Help with scoping and architecture",
|
||||
"---",
|
||||
"Give direct engineering advice.",
|
||||
],
|
||||
},
|
||||
{
|
||||
relativePath: "commands/workflows/review.md",
|
||||
contents: [
|
||||
"---",
|
||||
"name: workflows:review",
|
||||
"description: Run a structured review",
|
||||
"---",
|
||||
"Review the code. $ARGUMENTS",
|
||||
],
|
||||
},
|
||||
{
|
||||
relativePath: "commands/disabled.md",
|
||||
contents: ["---", "disable-model-invocation: true", "---", "Do not load me."],
|
||||
},
|
||||
],
|
||||
});
|
||||
await withBundleHomeEnv(
|
||||
tempHarness,
|
||||
"openclaw-bundle-commands",
|
||||
async ({ homeDir, workspaceDir }) => {
|
||||
await writeClaudeBundleCommandFixture({
|
||||
homeDir,
|
||||
pluginId: "compound-bundle",
|
||||
commands: [
|
||||
{
|
||||
relativePath: "commands/office-hours.md",
|
||||
contents: [
|
||||
"---",
|
||||
"description: Help with scoping and architecture",
|
||||
"---",
|
||||
"Give direct engineering advice.",
|
||||
],
|
||||
},
|
||||
{
|
||||
relativePath: "commands/workflows/review.md",
|
||||
contents: [
|
||||
"---",
|
||||
"name: workflows:review",
|
||||
"description: Run a structured review",
|
||||
"---",
|
||||
"Review the code. $ARGUMENTS",
|
||||
],
|
||||
},
|
||||
{
|
||||
relativePath: "commands/disabled.md",
|
||||
contents: ["---", "disable-model-invocation: true", "---", "Do not load me."],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const commands = loadEnabledClaudeBundleCommands({
|
||||
workspaceDir,
|
||||
cfg: {
|
||||
plugins: {
|
||||
entries: {
|
||||
"compound-bundle": { enabled: true },
|
||||
const commands = loadEnabledClaudeBundleCommands({
|
||||
workspaceDir,
|
||||
cfg: {
|
||||
plugins: {
|
||||
entries: {
|
||||
"compound-bundle": { enabled: true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
expect(commands).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
pluginId: "compound-bundle",
|
||||
rawName: "office-hours",
|
||||
description: "Help with scoping and architecture",
|
||||
promptTemplate: "Give direct engineering advice.",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
pluginId: "compound-bundle",
|
||||
rawName: "workflows:review",
|
||||
description: "Run a structured review",
|
||||
promptTemplate: "Review the code. $ARGUMENTS",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(commands.some((entry) => entry.rawName === "disabled")).toBe(false);
|
||||
});
|
||||
expect(commands).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
pluginId: "compound-bundle",
|
||||
rawName: "office-hours",
|
||||
description: "Help with scoping and architecture",
|
||||
promptTemplate: "Give direct engineering advice.",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
pluginId: "compound-bundle",
|
||||
rawName: "workflows:review",
|
||||
description: "Run a structured review",
|
||||
promptTemplate: "Review the code. $ARGUMENTS",
|
||||
}),
|
||||
]),
|
||||
);
|
||||
expect(commands.some((entry) => entry.rawName === "disabled")).toBe(false);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user