fix(cli): respect subcommand version options (#87398) · openclaw/openclaw@b4e5038
Patrick-Eric
·
2026-05-28
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -117,6 +117,10 @@ vi.mock("../../agents/model-auth.js", () => {
|
117 | 117 | }; |
118 | 118 | }); |
119 | 119 | |
| 120 | +vi.mock("../../agents/provider-auth-aliases.js", () => ({ |
| 121 | +resolveProviderIdForAuth: (provider: string) => provider, |
| 122 | +})); |
| 123 | + |
120 | 124 | import { resolveAgentDir, resolveSessionAgentId } from "../../agents/agent-scope.js"; |
121 | 125 | import { |
122 | 126 | clearRuntimeAuthProfileStoreSnapshots, |
@@ -657,7 +661,7 @@ describe("/model chat UX", () => {
|
657 | 661 | expect(reply?.text).not.toContain("[openai] endpoint: default auth: missing"); |
658 | 662 | expect(reply?.text).toContain("via codex runtime / openai-codex"); |
659 | 663 | expect(reply?.text).toContain("openai-codex:patrick@example.test=OAuth"); |
660 | | -}); |
| 664 | +}, 240_000); |
661 | 665 | |
662 | 666 | it("keeps direct provider auth labels when OpenAI API key auth exists", async () => { |
663 | 667 | setAuthProfiles({ |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -165,4 +165,22 @@ describe("configureProgramHelp", () => {
|
165 | 165 | resolveCommitHashMock.mockReturnValue(null); |
166 | 166 | expectVersionExit({ expectedVersion: "OpenClaw 9.9.9-test" }); |
167 | 167 | }); |
| 168 | + |
| 169 | +it("does not treat subcommand --version options as root version requests", () => { |
| 170 | +process.argv = ["node", "openclaw", "skills", "verify", "discrawl", "--version", "1.0.0"]; |
| 171 | +const logSpy = vi.spyOn(console, "log").mockImplementation(() => {}); |
| 172 | +const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number) => { |
| 173 | +throw new Error(`exit:${code ?? ""}`); |
| 174 | +}) as typeof process.exit); |
| 175 | + |
| 176 | +try { |
| 177 | +const program = makeProgramWithCommands(); |
| 178 | +expect(() => configureProgramHelp(program, testProgramContext)).not.toThrow(); |
| 179 | +expect(logSpy).not.toHaveBeenCalled(); |
| 180 | +expect(exitSpy).not.toHaveBeenCalled(); |
| 181 | +} finally { |
| 182 | +logSpy.mockRestore(); |
| 183 | +exitSpy.mockRestore(); |
| 184 | +} |
| 185 | +}); |
168 | 186 | }); |
| Original file line number | Diff line number | Diff line change |
|---|
@@ -3,7 +3,7 @@ import { resolveCommitHash } from "../../infra/git-commit.js";
|
3 | 3 | import { formatDocsLink } from "../../terminal/links.js"; |
4 | 4 | import { isRich, theme } from "../../terminal/theme.js"; |
5 | 5 | import { escapeRegExp } from "../../utils.js"; |
6 | | -import { hasFlag, hasRootVersionAlias } from "../argv.js"; |
| 6 | +import { isRootVersionInvocation } from "../argv.js"; |
7 | 7 | import { formatCliBannerLine, hasEmittedCliBanner } from "../banner.js"; |
8 | 8 | import { replaceCliName, resolveCliName } from "../cli-name.js"; |
9 | 9 | import { CLI_LOG_LEVEL_VALUES, parseCliLogLevelOption } from "../log-level-option.js"; |
@@ -117,11 +117,7 @@ export function configureProgramHelp(
|
117 | 117 | outputError: (str, write) => write(formatCliParseErrorOutput(str, { argv: process.argv })), |
118 | 118 | }); |
119 | 119 | |
120 | | -if ( |
121 | | -hasFlag(process.argv, "-V") || |
122 | | -hasFlag(process.argv, "--version") || |
123 | | -hasRootVersionAlias(process.argv) |
124 | | -) { |
| 120 | +if (isRootVersionInvocation(process.argv)) { |
125 | 121 | const commit = resolveCommitHash({ moduleUrl: import.meta.url }); |
126 | 122 | console.log( |
127 | 123 | commit ? `OpenClaw ${ctx.programVersion} (${commit})` : `OpenClaw ${ctx.programVersion}`, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。