From d25549f14207674e7ee17096d6ca082cb7247091 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 21 Jun 2026 10:56:46 +0200 Subject: [PATCH] test(scripts): route plugin fixture commands --- scripts/test-projects.test-support.mjs | 7 +- test/scripts/fixture-plugin-commands.test.ts | 87 ++++++++++++++++++++ test/scripts/test-projects.test.ts | 7 +- 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 test/scripts/fixture-plugin-commands.test.ts diff --git a/scripts/test-projects.test-support.mjs b/scripts/test-projects.test-support.mjs index 4f90c26a24fa..9c7a2befaf1e 100644 --- a/scripts/test-projects.test-support.mjs +++ b/scripts/test-projects.test-support.mjs @@ -1552,10 +1552,15 @@ const TOOLING_SOURCE_TEST_TARGETS = new Map([ ], [ "scripts/e2e/lib/fixture.mjs", - ["test/scripts/fixture-config.test.ts", "test/scripts/fixtures-workspace.test.ts"], + [ + "test/scripts/fixture-config.test.ts", + "test/scripts/fixtures-workspace.test.ts", + "test/scripts/fixture-plugin-commands.test.ts", + ], ], ["scripts/e2e/lib/fixtures/config.mjs", ["test/scripts/fixture-config.test.ts"]], ["scripts/e2e/lib/fixtures/mock-openai-config.mjs", ["test/scripts/mock-openai-config.test.ts"]], + ["scripts/e2e/lib/fixtures/plugins.mjs", ["test/scripts/fixture-plugin-commands.test.ts"]], [ "scripts/e2e/lib/incremental-line-reader.mjs", [ diff --git a/test/scripts/fixture-plugin-commands.test.ts b/test/scripts/fixture-plugin-commands.test.ts new file mode 100644 index 000000000000..71b8c2022a0c --- /dev/null +++ b/test/scripts/fixture-plugin-commands.test.ts @@ -0,0 +1,87 @@ +// Fixture Plugin Commands tests cover shared E2E plugin fixture writers. +import { spawnSync } from "node:child_process"; +import { readFileSync } from "node:fs"; +import path from "node:path"; +import { afterEach, describe, expect, it } from "vitest"; +import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js"; + +const FIXTURE_SCRIPT = "scripts/e2e/lib/fixture.mjs"; +const tempDirs: string[] = []; + +afterEach(() => { + cleanupTempDirs(tempDirs); +}); + +function runFixture(command: string, args: string[]) { + return spawnSync(process.execPath, [FIXTURE_SCRIPT, command, ...args], { + encoding: "utf8", + env: { ...process.env }, + }); +} + +function readJson(file: string) { + return JSON.parse(readFileSync(file, "utf8")); +} + +describe("plugin fixture commands", () => { + it("writes plugin fixtures with manifest and package metadata", () => { + const root = makeTempDir(tempDirs, "openclaw-fixture-plugin-"); + const pluginRoot = path.join(root, "demo"); + + const result = runFixture("plugin", [ + pluginRoot, + "demo-plugin", + "0.1.0", + "demo.ping", + "Demo Plugin", + ]); + + expect(result.status).toBe(0); + expect(readJson(path.join(pluginRoot, "package.json"))).toMatchObject({ + name: "@openclaw/demo-plugin", + version: "0.1.0", + openclaw: { extensions: ["./index.js"] }, + }); + expect(readJson(path.join(pluginRoot, "openclaw.plugin.json"))).toMatchObject({ + id: "demo-plugin", + configSchema: { type: "object", properties: {} }, + }); + expect(readFileSync(path.join(pluginRoot, "index.js"), "utf8")).toContain("demo.ping"); + }); + + it("writes CLI plugin fixtures with local dependency metadata", () => { + const root = makeTempDir(tempDirs, "openclaw-fixture-plugin-cli-"); + const pluginRoot = path.join(root, "cli-demo"); + + const result = runFixture("plugin-cli", [ + pluginRoot, + "demo-cli", + "0.2.0", + "demo.cli", + "Demo CLI", + "demo-cli", + "demo-cli:pong", + ]); + + expect(result.status).toBe(0); + expect(readJson(path.join(pluginRoot, "package.json"))).toMatchObject({ + dependencies: { "is-number": "file:./deps/is-number" }, + }); + expect(readJson(path.join(pluginRoot, "deps", "is-number", "package.json"))).toMatchObject({ + name: "is-number", + version: "7.0.0", + }); + const source = readFileSync(path.join(pluginRoot, "index.js"), "utf8"); + expect(source).toContain("demo-cli:pong"); + expect(source).toContain("registerCli"); + }); + + it("rejects plugin fixture commands with missing required args", () => { + const root = makeTempDir(tempDirs, "openclaw-fixture-plugin-missing-"); + + const result = runFixture("plugin", [path.join(root, "missing"), "demo-plugin"]); + + expect(result.status).not.toBe(0); + expect(result.stderr).toContain("version is required"); + }); +}); diff --git a/test/scripts/test-projects.test.ts b/test/scripts/test-projects.test.ts index 85fd530f181d..9cd38a451292 100644 --- a/test/scripts/test-projects.test.ts +++ b/test/scripts/test-projects.test.ts @@ -493,13 +493,18 @@ describe("scripts/test-projects changed-target routing", () => { ], [ "scripts/e2e/lib/fixture.mjs", - ["test/scripts/fixture-config.test.ts", "test/scripts/fixtures-workspace.test.ts"], + [ + "test/scripts/fixture-config.test.ts", + "test/scripts/fixtures-workspace.test.ts", + "test/scripts/fixture-plugin-commands.test.ts", + ], ], ["scripts/e2e/lib/fixtures/config.mjs", ["test/scripts/fixture-config.test.ts"]], [ "scripts/e2e/lib/fixtures/mock-openai-config.mjs", ["test/scripts/mock-openai-config.test.ts"], ], + ["scripts/e2e/lib/fixtures/plugins.mjs", ["test/scripts/fixture-plugin-commands.test.ts"]], [ "scripts/e2e/lib/incremental-line-reader.mjs", [