Skip to content

Commit 490c645

Browse files
authored
fix(cli): skip routed command bootstrap for help (#129112)
1 parent 1010a53 commit 490c645

2 files changed

Lines changed: 33 additions & 12 deletions

File tree

‎src/cli/run-main.exit.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ describe("runCli exit behavior", () => {
614614
});
615615

616616
it("does not load inactive provider cleanup modules for cold help", async () => {
617-
tryRouteCliMock.mockResolvedValueOnce(false);
618617
const parseAsync = vi.fn().mockResolvedValueOnce(undefined);
619618
buildProgramMock.mockReturnValueOnce({
620619
commands: [{ name: () => "nodes", aliases: () => [] }],
@@ -2279,6 +2278,26 @@ describe("runCli exit behavior", () => {
22792278
expect(closeActiveMemorySearchManagersMock).not.toHaveBeenCalled();
22802279
});
22812280

2281+
it.each([
2282+
["plugins install", ["plugins", "install", "--help"]],
2283+
["plugins list", ["plugins", "list", "--help"]],
2284+
["gateway status", ["gateway", "status", "--help"]],
2285+
])("renders %s help without importing the command router", async (_name, args) => {
2286+
const argv = ["node", "openclaw", ...args];
2287+
const parseAsync = vi.fn().mockResolvedValueOnce(undefined);
2288+
const program = {
2289+
commands: [{ name: () => args[0], aliases: () => [] }],
2290+
parseAsync,
2291+
};
2292+
buildProgramMock.mockReturnValueOnce(program);
2293+
2294+
await runCli(argv);
2295+
2296+
expect(tryRouteCliMock).not.toHaveBeenCalled();
2297+
expect(registerSubCliByNameMock).toHaveBeenCalledWith(program, args[0], argv);
2298+
expect(parseAsync).toHaveBeenCalledWith(argv);
2299+
});
2300+
22822301
it("propagates precomputed help metadata failures", async () => {
22832302
outputPrecomputedSecretsHelpTextMock.mockImplementationOnce(() => {
22842303
throw new Error("startup metadata failed");

‎src/cli/run-main.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,17 +1497,19 @@ async function runCliWithPreparedOutputMode(
14971497
return;
14981498
}
14991499

1500-
const { tryRouteCli } = await startupTrace.measure("route-import", () => import("./route.js"));
1501-
const routed = await startupTrace.measure(
1502-
"route",
1503-
() =>
1504-
options.builtInMachineOutput
1505-
? tryRouteCli(normalizedArgv, { machineOutput: true })
1506-
: tryRouteCli(normalizedArgv),
1507-
{ timeline: false },
1508-
);
1509-
if (routed) {
1510-
return;
1500+
if (!isHelpOrVersionInvocation) {
1501+
const route = await startupTrace.measure("route-import", () => import("./route.js"));
1502+
const routed = await startupTrace.measure(
1503+
"route",
1504+
() =>
1505+
options.builtInMachineOutput
1506+
? route.tryRouteCli(normalizedArgv, { machineOutput: true })
1507+
: route.tryRouteCli(normalizedArgv),
1508+
{ timeline: false },
1509+
);
1510+
if (routed) {
1511+
return;
1512+
}
15111513
}
15121514

15131515
let parseArgv = normalizeGeneratedHelpCommandArgv(normalizedArgv);

0 commit comments

Comments
 (0)