
























@@ -0,0 +1,74 @@
1+import { spawnSync } from "node:child_process";
2+import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
3+import { tmpdir } from "node:os";
4+import path from "node:path";
5+import { afterEach, describe, expect, it } from "vitest";
6+7+const probePath = "scripts/e2e/lib/plugin-lifecycle-matrix/probe.mjs";
8+const tempDirs: string[] = [];
9+10+function makeTempDir(): string {
11+const dir = mkdtempSync(path.join(tmpdir(), "openclaw-plugin-lifecycle-probe-"));
12+tempDirs.push(dir);
13+return dir;
14+}
15+16+function runProbe(args: string[], home = makeTempDir()) {
17+return spawnSync(process.execPath, [probePath, ...args], {
18+cwd: process.cwd(),
19+encoding: "utf8",
20+env: {
21+ ...process.env,
22+HOME: home,
23+OPENCLAW_CONFIG_PATH: path.join(home, ".openclaw", "openclaw.json"),
24+USERPROFILE: home,
25+},
26+});
27+}
28+29+afterEach(() => {
30+for (const dir of tempDirs.splice(0)) {
31+rmSync(dir, { recursive: true, force: true });
32+}
33+});
34+35+describe("plugin lifecycle matrix probe", () => {
36+it("accepts inspect JSON for an enabled loaded plugin", () => {
37+const dir = makeTempDir();
38+const inspectPath = path.join(dir, "inspect.json");
39+writeFileSync(
40+inspectPath,
41+`${JSON.stringify({ plugin: { enabled: true, id: "lifecycle-claw", status: "loaded" } })}\n`,
42+"utf8",
43+);
44+45+const result = runProbe(["assert-inspect-loaded", "lifecycle-claw", inspectPath], dir);
46+47+expect(result.status, result.stderr).toBe(0);
48+});
49+50+it("rejects inspect JSON that does not prove the runtime loaded", () => {
51+const dir = makeTempDir();
52+const inspectPath = path.join(dir, "inspect.json");
53+writeFileSync(
54+inspectPath,
55+`${JSON.stringify({ plugin: { enabled: true, id: "lifecycle-claw", status: "pending" } })}\n`,
56+"utf8",
57+);
58+59+const result = runProbe(["assert-inspect-loaded", "lifecycle-claw", inspectPath], dir);
60+61+expect(result.status).not.toBe(0);
62+expect(result.stderr).toContain("expected lifecycle-claw inspect status loaded, got pending");
63+});
64+65+it("rejects missing inspect JSON instead of treating it as an empty object", () => {
66+const dir = makeTempDir();
67+const inspectPath = path.join(dir, "missing.json");
68+69+const result = runProbe(["assert-inspect-loaded", "lifecycle-claw", inspectPath], dir);
70+71+expect(result.status).not.toBe(0);
72+expect(result.stderr).toContain(`failed to read JSON from ${inspectPath}`);
73+});
74+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。