refactor(cli): privatize precomputed help parser (#106692)

This commit is contained in:
Vincent Koc
2026-07-14 05:33:19 +08:00
committed by GitHub
parent d1bb38345e
commit 0f3dc25a3e
4 changed files with 7 additions and 68 deletions
-1
View File
@@ -963,7 +963,6 @@ export const KNIP_UNUSED_EXPORT_BASELINE = [
"src/cli/ports.ts: parseLsofOutput",
"src/cli/ports.ts: PortProcess",
"src/cli/ports.ts: probePortFree",
"src/cli/precomputed-help.ts: resolvePrecomputedSubcommandHelpCommand",
"src/cli/startup-metadata.ts: testing",
"src/cli/tagline.ts: DEFAULT_TAGLINE",
"src/cli/update-cli/progress.ts: inferUpdateFailureHints",
+1 -1
View File
@@ -42,7 +42,7 @@ function isPrecomputedSubcommandHelpName(value: string): value is PrecomputedSub
return PRECOMPUTED_SUBCOMMAND_HELP_COMMANDS.has(value as PrecomputedSubcommandHelpName);
}
export function resolvePrecomputedSubcommandHelpCommand(
function resolvePrecomputedSubcommandHelpCommand(
argv: string[],
): PrecomputedSubcommandHelpName | null {
const args = argv.slice(2);
-65
View File
@@ -2,7 +2,6 @@
import { describe, expect, it } from "vitest";
import type { PluginManifestCommandAliasRegistry } from "../plugins/manifest-command-aliases.js";
import { resolveGatewayRunPreBootstrapOptions } from "./gateway-run-argv.js";
import { resolvePrecomputedSubcommandHelpCommand } from "./precomputed-help.js";
import {
rewriteUpdateFlagArgv,
resolveMissingPluginCommandMessage,
@@ -286,70 +285,6 @@ describe("shouldUseSetupOnboardConfigureHelpFastPath", () => {
});
});
describe("resolvePrecomputedSubcommandHelpCommand", () => {
it("matches only strict allowlisted parent command help", () => {
expect(resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "doctor", "--help"])).toBe(
"doctor",
);
expect(resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "gateway", "-h"])).toBe(
"gateway",
);
expect(
resolvePrecomputedSubcommandHelpCommand([
"node",
"openclaw",
"--profile",
"work",
"--no-color",
"models",
"-h",
]),
).toBe("models");
expect(resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "plugins", "--help"])).toBe(
"plugins",
);
expect(
resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "sessions", "--help"]),
).toBe("sessions");
expect(resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "tasks", "-h"])).toBe(
"tasks",
);
expect(
resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "doctor", "--version"]),
).toBeNull();
expect(
resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "gateway", "-V"]),
).toBeNull();
expect(
resolvePrecomputedSubcommandHelpCommand([
"node",
"openclaw",
"doctor",
"--help",
"--version",
]),
).toBeNull();
expect(
resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "doctor", "--version", "-h"]),
).toBeNull();
expect(
resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "--bogus", "doctor", "--help"]),
).toBeNull();
expect(
resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "doctor", "--help", "--bogus"]),
).toBeNull();
expect(
resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "doctor", "--help", "extra"]),
).toBeNull();
expect(
resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "gateway", "status", "--help"]),
).toBeNull();
expect(
resolvePrecomputedSubcommandHelpCommand(["node", "openclaw", "status", "--help"]),
).toBeNull();
});
});
describe("resolveMissingPluginCommandMessage", () => {
it("explains plugins.allow misses for a bundled plugin command", () => {
expect(
+6 -1
View File
@@ -155,7 +155,7 @@ describe("entry precomputed command help fast path", () => {
expect(outputPrecomputedNodesHelpTextCalls).toBe(1);
});
it.each(["doctor", "sessions", "tasks"])(
it.each(["doctor", "gateway", "plugins", "sessions", "tasks"])(
"renders precomputed %s help from startup metadata without importing the full program",
async (commandName) => {
const outputPrecomputedSubcommandHelpTextCalls: string[] = [];
@@ -196,10 +196,15 @@ describe("entry precomputed command help fast path", () => {
it("keeps subcommand help fast path strict for extra or mixed flags", async () => {
const invocations = [
["node", "openclaw", "doctor", "--version"],
["node", "openclaw", "gateway", "-V"],
["node", "openclaw", "doctor", "--help", "--version"],
["node", "openclaw", "doctor", "--help", "--bogus"],
["node", "openclaw", "doctor", "--help", "extra"],
["node", "openclaw", "doctor", "--version", "-h"],
["node", "openclaw", "--bogus", "doctor", "--help"],
["node", "openclaw", "gateway", "status", "--help"],
["node", "openclaw", "status", "--help"],
];
let outputPrecomputedSubcommandHelpTextCalls = 0;