




















1+// Fixture Plugin Commands tests cover shared E2E plugin fixture writers.
2+import { spawnSync } from "node:child_process";
3+import { readFileSync } from "node:fs";
4+import path from "node:path";
5+import { afterEach, describe, expect, it } from "vitest";
6+import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
7+8+const FIXTURE_SCRIPT = "scripts/e2e/lib/fixture.mjs";
9+const tempDirs: string[] = [];
10+11+afterEach(() => {
12+cleanupTempDirs(tempDirs);
13+});
14+15+function runFixture(command: string, args: string[]) {
16+return spawnSync(process.execPath, [FIXTURE_SCRIPT, command, ...args], {
17+encoding: "utf8",
18+env: { ...process.env },
19+});
20+}
21+22+function readJson(file: string) {
23+return JSON.parse(readFileSync(file, "utf8"));
24+}
25+26+describe("plugin fixture commands", () => {
27+it("writes plugin fixtures with manifest and package metadata", () => {
28+const root = makeTempDir(tempDirs, "openclaw-fixture-plugin-");
29+const pluginRoot = path.join(root, "demo");
30+31+const result = runFixture("plugin", [
32+pluginRoot,
33+"demo-plugin",
34+"0.1.0",
35+"demo.ping",
36+"Demo Plugin",
37+]);
38+39+expect(result.status).toBe(0);
40+expect(readJson(path.join(pluginRoot, "package.json"))).toMatchObject({
41+name: "@openclaw/demo-plugin",
42+version: "0.1.0",
43+openclaw: { extensions: ["./index.js"] },
44+});
45+expect(readJson(path.join(pluginRoot, "openclaw.plugin.json"))).toMatchObject({
46+id: "demo-plugin",
47+configSchema: { type: "object", properties: {} },
48+});
49+expect(readFileSync(path.join(pluginRoot, "index.js"), "utf8")).toContain("demo.ping");
50+});
51+52+it("writes CLI plugin fixtures with local dependency metadata", () => {
53+const root = makeTempDir(tempDirs, "openclaw-fixture-plugin-cli-");
54+const pluginRoot = path.join(root, "cli-demo");
55+56+const result = runFixture("plugin-cli", [
57+pluginRoot,
58+"demo-cli",
59+"0.2.0",
60+"demo.cli",
61+"Demo CLI",
62+"demo-cli",
63+"demo-cli:pong",
64+]);
65+66+expect(result.status).toBe(0);
67+expect(readJson(path.join(pluginRoot, "package.json"))).toMatchObject({
68+dependencies: { "is-number": "file:./deps/is-number" },
69+});
70+expect(readJson(path.join(pluginRoot, "deps", "is-number", "package.json"))).toMatchObject({
71+name: "is-number",
72+version: "7.0.0",
73+});
74+const source = readFileSync(path.join(pluginRoot, "index.js"), "utf8");
75+expect(source).toContain("demo-cli:pong");
76+expect(source).toContain("registerCli");
77+});
78+79+it("rejects plugin fixture commands with missing required args", () => {
80+const root = makeTempDir(tempDirs, "openclaw-fixture-plugin-missing-");
81+82+const result = runFixture("plugin", [path.join(root, "missing"), "demo-plugin"]);
83+84+expect(result.status).not.toBe(0);
85+expect(result.stderr).toContain("version is required");
86+});
87+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。