mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-14 11:30:41 +00:00
fix(cli): correct --verbose / -v option syntax in acp commands (#21303)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 20d058dcf5
Co-authored-by: adhitShet <131381638+adhitShet@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
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