Skip to content

Commit 5c7a38e

Browse files
committed
perf(plugins): list from installed metadata
1 parent 86a95b4 commit 5c7a38e

4 files changed

Lines changed: 134 additions & 26 deletions

File tree

‎src/cli/plugins-list-command.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export async function runPluginsListCommand(
4444
runtime: RuntimeEnv = defaultRuntime,
4545
): Promise<void> {
4646
const { buildPluginRegistrySnapshotReport } = await import("../plugins/status-snapshot.js");
47-
const cfg = getRuntimeConfig();
47+
// The inventory projector owns plugin metadata validation from the installed index.
48+
const cfg = getRuntimeConfig({ skipPluginValidation: true });
4849
const report = buildPluginRegistrySnapshotReport({
4950
config: cfg,
5051
...(opts.json ? { logger: quietPluginJsonLogger } : {}),
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// The default plugin inventory route must render manifest facts without executing plugin code.
2+
import fs from "node:fs";
3+
import os from "node:os";
4+
import path from "node:path";
5+
import { afterAll, expect, it, vi } from "vitest";
6+
import type { OpenClawConfig } from "../config/types.openclaw.js";
7+
import {
8+
createColdPluginFixture,
9+
isColdPluginRuntimeLoaded,
10+
} from "../plugins/test-helpers/cold-plugin-fixtures.js";
11+
12+
const testState = vi.hoisted(() => ({
13+
config: {} as OpenClawConfig,
14+
loadedModules: new Set<string>(),
15+
logs: [] as string[],
16+
}));
17+
18+
vi.mock("./command-execution-startup.js", () => ({
19+
applyCliExecutionStartupPresentation: vi.fn(async () => {}),
20+
ensureCliExecutionBootstrap: vi.fn(async () => {}),
21+
resolveCliExecutionStartupContext: vi.fn(() => ({
22+
startupPolicy: { loadPlugins: false, suppressDoctorStdout: true },
23+
})),
24+
}));
25+
26+
vi.mock("../config/config.js", () => ({
27+
getRuntimeConfig: () => testState.config,
28+
}));
29+
30+
vi.mock("../runtime.js", () => ({
31+
defaultRuntime: {
32+
error: vi.fn(),
33+
exit: vi.fn(),
34+
log: (...args: unknown[]) => testState.logs.push(args.map(String).join(" ")),
35+
writeJson: vi.fn(),
36+
writeStdout: vi.fn(),
37+
},
38+
writeRuntimeJson: vi.fn(),
39+
}));
40+
41+
vi.mock("./plugins-cli.js", () => {
42+
testState.loadedModules.add("plugins-cli");
43+
return { registerPluginsCli: vi.fn() };
44+
});
45+
46+
vi.mock("../plugins/loader-module-runtime.js", () => {
47+
testState.loadedModules.add("plugin-module-runtime");
48+
return {};
49+
});
50+
51+
import { tryRouteCli } from "./route.js";
52+
53+
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugins-list-route-"));
54+
55+
afterAll(() => {
56+
fs.rmSync(tempRoot, { recursive: true, force: true });
57+
vi.unstubAllEnvs();
58+
});
59+
60+
it("renders the default list from metadata without loading plugin modules", async () => {
61+
const pluginRoot = path.join(tempRoot, "route-demo");
62+
fs.mkdirSync(pluginRoot, { recursive: true });
63+
const fixture = createColdPluginFixture({
64+
rootDir: pluginRoot,
65+
pluginId: "route-demo",
66+
packageName: "@example/route-demo",
67+
packageVersion: "4.2.0",
68+
manifest: {
69+
name: "Route Demo",
70+
description: "Prepared inventory metadata",
71+
},
72+
});
73+
const bundledRoot = path.join(tempRoot, "bundled");
74+
fs.mkdirSync(bundledRoot, { recursive: true });
75+
vi.stubEnv("OPENCLAW_BUNDLED_PLUGINS_DIR", bundledRoot);
76+
vi.stubEnv("OPENCLAW_DISABLE_BUNDLED_PLUGINS", "1");
77+
vi.stubEnv("OPENCLAW_HOME", path.join(tempRoot, "home"));
78+
vi.stubEnv("OPENCLAW_STATE_DIR", path.join(tempRoot, "state"));
79+
testState.config = {
80+
plugins: {
81+
load: { paths: [pluginRoot] },
82+
entries: { "route-demo": { enabled: true } },
83+
},
84+
};
85+
86+
await expect(tryRouteCli(["node", "openclaw", "plugins", "list"])).resolves.toBe(true);
87+
88+
const output = testState.logs.join("\n");
89+
expect(output).toContain("Route Demo");
90+
expect(output).toContain("route-demo");
91+
expect(output).toContain("Prepared inventory metadata");
92+
expect(output).toContain("4.2.0");
93+
expect(isColdPluginRuntimeLoaded(fixture)).toBe(false);
94+
expect(testState.loadedModules).not.toContain("plugin-module-runtime");
95+
expect(testState.loadedModules).not.toContain("plugins-cli");
96+
});

‎src/cli/program/route-args.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,8 @@ export function parseChannelsStatusRouteArgs(argv: string[]) {
449449
};
450450
}
451451

452-
/** Parse JSON-only `openclaw plugins list` flags for plugin inventory output. */
452+
/** Parse `openclaw plugins list` flags for the metadata-only inventory path. */
453453
export function parsePluginsListRouteArgs(argv: string[]) {
454-
if (!hasFlag(argv, "--json")) {
455-
return null;
456-
}
457454
const positionals = getRoutedCommandPositionals(argv, {
458455
commandPath: ["plugins", "list"],
459456
booleanFlags: ["--json", "--enabled", "--verbose"],
@@ -462,7 +459,7 @@ export function parsePluginsListRouteArgs(argv: string[]) {
462459
return null;
463460
}
464461
return {
465-
json: true as const,
462+
json: hasFlag(argv, "--json"),
466463
enabled: hasFlag(argv, "--enabled"),
467464
verbose: hasFlag(argv, "--verbose"),
468465
};

‎src/cli/program/routes.test.ts‎

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -169,27 +169,41 @@ describe("program routes", () => {
169169
);
170170
});
171171

172-
it("routes plugins list JSON without importing the full plugins CLI", async () => {
173-
const route = expectRoute(["plugins", "list"]);
174-
expect(route.loadPlugins).toBeUndefined();
175-
expect(route.canRun?.(["node", "openclaw", "plugins", "list"])).toBe(false);
176-
177-
await expect(
178-
route.run(["node", "openclaw", "plugins", "list", "--json", "--enabled", "--verbose"]),
179-
).resolves.toBe(true);
180-
181-
expect(runPluginsListCommandMock).toHaveBeenCalledWith(
182-
{ json: true, enabled: true, verbose: true },
183-
defaultRuntime,
184-
);
185-
expect(pluginsCliLoadedMock).not.toHaveBeenCalled();
186-
});
172+
it.each([
173+
{ label: "default", flags: [], options: { json: false, enabled: false, verbose: false } },
174+
{
175+
label: "enabled",
176+
flags: ["--enabled"],
177+
options: { json: false, enabled: true, verbose: false },
178+
},
179+
{
180+
label: "verbose",
181+
flags: ["--verbose"],
182+
options: { json: false, enabled: false, verbose: true },
183+
},
184+
{
185+
label: "JSON",
186+
flags: ["--json", "--enabled", "--verbose"],
187+
options: { json: true, enabled: true, verbose: true },
188+
},
189+
])(
190+
"routes plugins list $label without importing the full plugins CLI",
191+
async ({ flags, options }) => {
192+
const route = expectRoute(["plugins", "list"]);
193+
expect(route.loadPlugins).toBeUndefined();
194+
expect(route.canRun?.(["node", "openclaw", "plugins", "list", ...flags])).toBe(true);
195+
196+
await expect(route.run(["node", "openclaw", "plugins", "list", ...flags])).resolves.toBe(
197+
true,
198+
);
199+
200+
expect(runPluginsListCommandMock).toHaveBeenCalledWith(options, defaultRuntime);
201+
expect(pluginsCliLoadedMock).not.toHaveBeenCalled();
202+
},
203+
);
187204

188-
it("returns false for plugins list JSON route with unsupported arguments", async () => {
189-
await expectRunFalse(
190-
["plugins", "list"],
191-
["node", "openclaw", "plugins", "list", "--json", "--wat"],
192-
);
205+
it("returns false for plugins list route with unsupported arguments", async () => {
206+
await expectRunFalse(["plugins", "list"], ["node", "openclaw", "plugins", "list", "--wat"]);
193207
});
194208

195209
it("matches gateway status route without plugin preload", () => {

0 commit comments

Comments
 (0)