mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test(cli): add root-v alias regression coverage
This commit is contained in:
@@ -44,6 +44,16 @@ describe("argv helpers", () => {
|
||||
argv: ["node", "openclaw", "acp", "-v"],
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
name: "root -v alias with equals profile",
|
||||
argv: ["node", "openclaw", "--profile=work", "-v"],
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "subcommand path after global root flags should not be treated as version",
|
||||
argv: ["node", "openclaw", "--dev", "skills", "list", "-v"],
|
||||
expected: false,
|
||||
},
|
||||
])("detects help/version flags: $name", ({ argv, expected }) => {
|
||||
expect(hasHelpOrVersion(argv)).toBe(expected);
|
||||
});
|
||||
|
||||
39
src/cli/program/build-program.version-alias.test.ts
Normal file
39
src/cli/program/build-program.version-alias.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import process from "node:process";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { buildProgram } = await import("./build-program.js");
|
||||
|
||||
describe("buildProgram version alias handling", () => {
|
||||
let originalArgv: string[];
|
||||
|
||||
beforeEach(() => {
|
||||
originalArgv = [...process.argv];
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
process.argv = originalArgv;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("exits with version output for root -v", () => {
|
||||
process.argv = ["node", "openclaw", "-v"];
|
||||
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
|
||||
throw new Error(`process.exit:${String(code)}`);
|
||||
}) as typeof process.exit);
|
||||
|
||||
expect(() => buildProgram()).toThrow("process.exit:0");
|
||||
expect(logSpy).toHaveBeenCalledTimes(1);
|
||||
expect(exitSpy).toHaveBeenCalledWith(0);
|
||||
});
|
||||
|
||||
it("does not treat subcommand -v as root version alias", () => {
|
||||
process.argv = ["node", "openclaw", "acp", "-v"];
|
||||
const exitSpy = vi.spyOn(process, "exit").mockImplementation(((code?: number) => {
|
||||
throw new Error(`unexpected process.exit:${String(code)}`);
|
||||
}) as typeof process.exit);
|
||||
|
||||
expect(() => buildProgram()).not.toThrow();
|
||||
expect(exitSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user