Skip to content

Commit 2de8824

Browse files
authored
test(qa): prove packaged plugin lifecycle transitions (#118973)
1 parent 0287116 commit 2de8824

3 files changed

Lines changed: 128 additions & 21 deletions

File tree

‎qa/scenarios/plugins/plugin-lifecycle-probe.yaml‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ scenario:
44
id: plugin-lifecycle-probe
55
surface: plugins
66
coverage:
7+
primary:
8+
- plugins.activation-runtime
9+
- plugins.docker-lifecycle-suites
10+
- plugins.enable-and-disable-lifecycle
11+
- plugins.lifecycle-package-update
12+
- plugins.lifecycle-update-run
13+
- plugins.smoke-tests-lifecycle
714
secondary:
815
- cli.plugin-validation-and-repair
916
- plugins.plugin-setup
10-
- plugins.smoke-tests-lifecycle
1117
objective: Exercise packaged plugin install, inspect, disable, enable, update, downgrade, and uninstall behavior in a clean Docker runtime.
1218
successCriteria:
1319
- A clean container installs the candidate OpenClaw package and fixture plugin package.
14-
- Runtime inspect reports the installed plugin as enabled and loaded.
15-
- Disable and enable commands persist the expected plugin state.
16-
- Update and downgrade commands replace the installed plugin version while preserving the npm project root.
20+
- Runtime inspect reports the installed plugin as enabled and loaded after install.
21+
- Disable persists the disabled state and runtime inspect reports disabled; re-enable persists the enabled state and runtime inspect reports loaded.
22+
- Upgrade and downgrade update commands both complete successfully.
23+
- After each update, the SQLite install record and installed package.json match the requested version, the npm project root is canonical, and runtime inspect reports loaded.
1724
- Forced uninstall succeeds after installed plugin code is removed and emits a bounded resource summary.
1825
docsRefs:
1926
- docs/plugins/manifest.md

‎test/e2e/qa-lab/plugins/plugin-lifecycle-probe-runtime.ts‎

Lines changed: 90 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,11 @@ function assertNpmProjectRoot(pluginId: string, packageName: string, env: ProbeE
142142
);
143143
}
144144

145-
export function assertInspectLoaded(pluginId: string, inspectPath: string | undefined) {
145+
function assertInspectState(
146+
pluginId: string,
147+
inspectPath: string | undefined,
148+
expected: { enabled: boolean; status: "disabled" | "loaded" },
149+
) {
146150
assertProbe(inspectPath, "inspect JSON path is required");
147151
const inspect = readRequiredJson(inspectPath);
148152
const plugin = inspect.plugin as
@@ -153,13 +157,24 @@ export function assertInspectLoaded(pluginId: string, inspectPath: string | unde
153157
plugin?.id === pluginId,
154158
`expected inspected plugin id ${pluginId}, got ${plugin?.id}`,
155159
);
156-
assertProbe(plugin.enabled === true, `expected ${pluginId} inspect enabled=true`);
157160
assertProbe(
158-
plugin.status === "loaded",
159-
`expected ${pluginId} inspect status loaded, got ${plugin.status}`,
161+
plugin.enabled === expected.enabled,
162+
`expected ${pluginId} inspect enabled=${expected.enabled}`,
163+
);
164+
assertProbe(
165+
plugin.status === expected.status,
166+
`expected ${pluginId} inspect status ${expected.status}, got ${plugin.status}`,
160167
);
161168
}
162169

170+
export function assertInspectLoaded(pluginId: string, inspectPath: string | undefined) {
171+
assertInspectState(pluginId, inspectPath, { enabled: true, status: "loaded" });
172+
}
173+
174+
export function assertInspectDisabled(pluginId: string, inspectPath: string | undefined) {
175+
assertInspectState(pluginId, inspectPath, { enabled: false, status: "disabled" });
176+
}
177+
163178
function assertEnabled(pluginId: string, expected: boolean, env: ProbeEnv = process.env) {
164179
const cfg = config(env) as {
165180
plugins?: { entries?: Record<string, { enabled?: boolean }> };
@@ -493,6 +508,30 @@ async function runMeasured(
493508
);
494509
}
495510

511+
async function runRuntimeInspect(params: {
512+
summaryTsv: string;
513+
phase: string;
514+
entry: string;
515+
pluginId: string;
516+
inspectPath: string;
517+
env: MatrixEnv;
518+
}) {
519+
await runMeasured(
520+
params.summaryTsv,
521+
params.phase,
522+
"bash",
523+
[
524+
"-c",
525+
'node "$1" plugins inspect "$2" --runtime --json >"$3"',
526+
"bash",
527+
params.entry,
528+
params.pluginId,
529+
params.inspectPath,
530+
],
531+
params.env,
532+
);
533+
}
534+
496535
async function runPluginLifecycleMatrix() {
497536
const pluginId = "lifecycle-claw";
498537
const packageName = "@openclaw/lifecycle-claw";
@@ -502,6 +541,10 @@ async function runPluginLifecycleMatrix() {
502541
const tarballV1 = path.join(resourceDir, "lifecycle-claw-1.0.0.tgz");
503542
const tarballV2 = path.join(resourceDir, "lifecycle-claw-2.0.0.tgz");
504543
const inspectV1 = path.join(resourceDir, "plugin-lifecycle-inspect-v1.json");
544+
const inspectDisabled = path.join(resourceDir, "plugin-lifecycle-inspect-disabled.json");
545+
const inspectReenabled = path.join(resourceDir, "plugin-lifecycle-inspect-reenabled.json");
546+
const inspectV2 = path.join(resourceDir, "plugin-lifecycle-inspect-v2.json");
547+
const inspectDowngradeV1 = path.join(resourceDir, "plugin-lifecycle-inspect-downgrade-v1.json");
505548
const summaryTsv = path.join(resourceDir, "resource-summary.tsv");
506549
let registry: RegistryServer | undefined;
507550

@@ -560,20 +603,14 @@ async function runPluginLifecycleMatrix() {
560603
assertVersion(pluginId, "1.0.0", runEnv);
561604
assertNpmProjectRoot(pluginId, packageName, runEnv);
562605

563-
await runMeasured(
606+
await runRuntimeInspect({
564607
summaryTsv,
565-
"inspect-v1",
566-
"bash",
567-
[
568-
"-c",
569-
'node "$1" plugins inspect "$2" --runtime --json >"$3"',
570-
"bash",
571-
entry,
572-
pluginId,
573-
inspectV1,
574-
],
575-
runEnv,
576-
);
608+
phase: "inspect-v1",
609+
entry,
610+
pluginId,
611+
inspectPath: inspectV1,
612+
env: runEnv,
613+
});
577614
assertInspectLoaded(pluginId, inspectV1);
578615

579616
await runMeasured(
@@ -584,9 +621,27 @@ async function runPluginLifecycleMatrix() {
584621
runEnv,
585622
);
586623
assertEnabled(pluginId, false, runEnv);
624+
await runRuntimeInspect({
625+
summaryTsv,
626+
phase: "inspect-disabled",
627+
entry,
628+
pluginId,
629+
inspectPath: inspectDisabled,
630+
env: runEnv,
631+
});
632+
assertInspectDisabled(pluginId, inspectDisabled);
587633

588634
await runMeasured(summaryTsv, "enable", "node", [entry, "plugins", "enable", pluginId], runEnv);
589635
assertEnabled(pluginId, true, runEnv);
636+
await runRuntimeInspect({
637+
summaryTsv,
638+
phase: "inspect-reenabled",
639+
entry,
640+
pluginId,
641+
inspectPath: inspectReenabled,
642+
env: runEnv,
643+
});
644+
assertInspectLoaded(pluginId, inspectReenabled);
590645

591646
await runMeasured(
592647
summaryTsv,
@@ -597,6 +652,15 @@ async function runPluginLifecycleMatrix() {
597652
);
598653
assertVersion(pluginId, "2.0.0", runEnv);
599654
assertNpmProjectRoot(pluginId, packageName, runEnv);
655+
await runRuntimeInspect({
656+
summaryTsv,
657+
phase: "inspect-v2",
658+
entry,
659+
pluginId,
660+
inspectPath: inspectV2,
661+
env: runEnv,
662+
});
663+
assertInspectLoaded(pluginId, inspectV2);
600664

601665
await runMeasured(
602666
summaryTsv,
@@ -607,6 +671,15 @@ async function runPluginLifecycleMatrix() {
607671
);
608672
assertVersion(pluginId, "1.0.0", runEnv);
609673
assertNpmProjectRoot(pluginId, packageName, runEnv);
674+
await runRuntimeInspect({
675+
summaryTsv,
676+
phase: "inspect-downgrade-v1",
677+
entry,
678+
pluginId,
679+
inspectPath: inspectDowngradeV1,
680+
env: runEnv,
681+
});
682+
assertInspectLoaded(pluginId, inspectDowngradeV1);
610683

611684
const installedPath = installPath(pluginId, runEnv);
612685
fs.rmSync(installedPath, { recursive: true, force: true });

‎test/e2e/qa-lab/plugins/plugin-lifecycle-probe.e2e.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";
66
import { resolveWindowsTaskkillPath } from "../../../../scripts/lib/windows-taskkill.mjs";
77
import { createTempDirTracker } from "../../../helpers/temp-dir.js";
88
import {
9+
assertInspectDisabled,
910
assertInspectLoaded,
1011
assertUninstalled,
1112
parseDurationMs,
@@ -75,6 +76,32 @@ describe("plugin lifecycle matrix probe", () => {
7576
expect(() => assertInspectLoaded("lifecycle-claw", inspectPath)).not.toThrow();
7677
});
7778

79+
it("accepts inspect JSON for a disabled plugin", async () => {
80+
const dir = makeTempDir();
81+
const inspectPath = path.join(dir, "inspect.json");
82+
writeFileSync(
83+
inspectPath,
84+
`${JSON.stringify({ plugin: { enabled: false, id: "lifecycle-claw", status: "disabled" } })}\n`,
85+
"utf8",
86+
);
87+
88+
expect(() => assertInspectDisabled("lifecycle-claw", inspectPath)).not.toThrow();
89+
});
90+
91+
it("rejects disabled inspect JSON that still reports a loaded plugin", async () => {
92+
const dir = makeTempDir();
93+
const inspectPath = path.join(dir, "inspect.json");
94+
writeFileSync(
95+
inspectPath,
96+
`${JSON.stringify({ plugin: { enabled: false, id: "lifecycle-claw", status: "loaded" } })}\n`,
97+
"utf8",
98+
);
99+
100+
expect(() => assertInspectDisabled("lifecycle-claw", inspectPath)).toThrow(
101+
"expected lifecycle-claw inspect status disabled, got loaded",
102+
);
103+
});
104+
78105
it("rejects inspect JSON that does not prove the runtime loaded", async () => {
79106
const dir = makeTempDir();
80107
const inspectPath = path.join(dir, "inspect.json");

0 commit comments

Comments
 (0)