perf(cli): speed up help/config paths and route config get/unset

This commit is contained in:
Peter Steinberger
2026-02-14 00:27:30 +00:00
parent 386bb0c618
commit 4d1461011d
8 changed files with 223 additions and 59 deletions

View File

@@ -1,5 +1,9 @@
import { describe, expect, it } from "vitest";
import { rewriteUpdateFlagArgv } from "./run-main.js";
import {
rewriteUpdateFlagArgv,
shouldRegisterPrimarySubcommand,
shouldSkipPluginCommandRegistration,
} from "./run-main.js";
describe("rewriteUpdateFlagArgv", () => {
it("leaves argv unchanged when --update is absent", () => {
@@ -34,3 +38,46 @@ describe("rewriteUpdateFlagArgv", () => {
]);
});
});
describe("shouldRegisterPrimarySubcommand", () => {
it("skips eager primary registration for help/version invocations", () => {
expect(shouldRegisterPrimarySubcommand(["node", "openclaw", "status", "--help"])).toBe(false);
expect(shouldRegisterPrimarySubcommand(["node", "openclaw", "-V"])).toBe(false);
});
it("keeps eager primary registration for regular command runs", () => {
expect(shouldRegisterPrimarySubcommand(["node", "openclaw", "status"])).toBe(true);
});
});
describe("shouldSkipPluginCommandRegistration", () => {
it("skips plugin registration for root help/version", () => {
expect(
shouldSkipPluginCommandRegistration({
argv: ["node", "openclaw", "--help"],
primary: null,
hasBuiltinPrimary: false,
}),
).toBe(true);
});
it("skips plugin registration for builtin subcommand help", () => {
expect(
shouldSkipPluginCommandRegistration({
argv: ["node", "openclaw", "config", "--help"],
primary: "config",
hasBuiltinPrimary: true,
}),
).toBe(true);
});
it("keeps plugin registration for non-builtin help", () => {
expect(
shouldSkipPluginCommandRegistration({
argv: ["node", "openclaw", "voicecall", "--help"],
primary: "voicecall",
hasBuiltinPrimary: false,
}),
).toBe(false);
});
});