From 07da843378090f693169b5ea0cd0b2336edef5d6 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 1 Mar 2026 12:06:36 -0800 Subject: [PATCH] CLI argv: test root version fast-path detection --- src/cli/argv.test.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/cli/argv.test.ts b/src/cli/argv.test.ts index 25f04e80a..c46e8e4fa 100644 --- a/src/cli/argv.test.ts +++ b/src/cli/argv.test.ts @@ -8,6 +8,7 @@ import { getVerboseFlag, hasHelpOrVersion, hasFlag, + isRootVersionInvocation, shouldMigrateState, shouldMigrateStateFromPath, } from "./argv.js"; @@ -63,6 +64,36 @@ describe("argv helpers", () => { expect(hasHelpOrVersion(argv)).toBe(expected); }); + it.each([ + { + name: "root --version", + argv: ["node", "openclaw", "--version"], + expected: true, + }, + { + name: "root -V", + argv: ["node", "openclaw", "-V"], + expected: true, + }, + { + name: "root -v alias with profile", + argv: ["node", "openclaw", "--profile", "work", "-v"], + expected: true, + }, + { + name: "subcommand version flag", + argv: ["node", "openclaw", "status", "--version"], + expected: false, + }, + { + name: "unknown root flag with version", + argv: ["node", "openclaw", "--unknown", "--version"], + expected: false, + }, + ])("detects root-only version invocations: $name", ({ argv, expected }) => { + expect(isRootVersionInvocation(argv)).toBe(expected); + }); + it.each([ { name: "single command with trailing flag",