Compare commits
2 Commits
main
...
fix/cli-su
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50faccaba8 | ||
|
|
4d59d1758c |
@ -34,6 +34,7 @@ Docs: https://docs.clawd.bot
|
||||
- Voice Call: return stream TwiML for outbound conversation calls on initial Twilio webhook. (#1634)
|
||||
- Google Chat: tighten email allowlist matching, typing cleanup, media caps, and onboarding/docs/tests. (#1635) Thanks @iHildy.
|
||||
- Google Chat: normalize space targets without double `spaces/` prefix.
|
||||
- CLI: register lazy subcommands before parse so non-help invocations work. (#1683) Thanks @grrowl.
|
||||
|
||||
## 2026.1.23-1
|
||||
|
||||
|
||||
@ -1,37 +1,36 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { rewriteUpdateFlagArgv } from "./run-main.js";
|
||||
const registerSubCliByName = vi.fn(async () => true);
|
||||
const parseAsync = vi.fn(async () => undefined);
|
||||
const buildProgram = vi.fn(() => ({ parseAsync }));
|
||||
|
||||
describe("rewriteUpdateFlagArgv", () => {
|
||||
it("leaves argv unchanged when --update is absent", () => {
|
||||
const argv = ["node", "entry.js", "status"];
|
||||
expect(rewriteUpdateFlagArgv(argv)).toBe(argv);
|
||||
vi.mock("../infra/dotenv.js", () => ({ loadDotEnv: vi.fn() }));
|
||||
vi.mock("../infra/env.js", () => ({ normalizeEnv: vi.fn() }));
|
||||
vi.mock("../infra/path-env.js", () => ({ ensureClawdbotCliOnPath: vi.fn() }));
|
||||
vi.mock("../infra/runtime-guard.js", () => ({ assertSupportedRuntime: vi.fn() }));
|
||||
vi.mock("../infra/errors.js", () => ({ formatUncaughtError: vi.fn(() => "error") }));
|
||||
vi.mock("../infra/unhandled-rejections.js", () => ({ installUnhandledRejectionHandler: vi.fn() }));
|
||||
vi.mock("../logging.js", () => ({ enableConsoleCapture: vi.fn() }));
|
||||
vi.mock("./program.js", () => ({ buildProgram }));
|
||||
vi.mock("./program/register.subclis.js", () => ({ registerSubCliByName }));
|
||||
vi.mock("./route.js", () => ({ tryRouteCli: vi.fn(async () => false) }));
|
||||
|
||||
const { runCli } = await import("./run-main.js");
|
||||
|
||||
describe("runCli", () => {
|
||||
afterEach(() => {
|
||||
registerSubCliByName.mockClear();
|
||||
parseAsync.mockClear();
|
||||
buildProgram.mockClear();
|
||||
});
|
||||
|
||||
it("rewrites --update into the update command", () => {
|
||||
expect(rewriteUpdateFlagArgv(["node", "entry.js", "--update"])).toEqual([
|
||||
"node",
|
||||
"entry.js",
|
||||
"update",
|
||||
]);
|
||||
});
|
||||
it("registers the primary subcommand before parsing", async () => {
|
||||
const argv = ["/usr/bin/node-22", "/opt/clawdbot/entry.js", "gateway", "--port", "18789"];
|
||||
|
||||
it("preserves global flags that appear before --update", () => {
|
||||
expect(rewriteUpdateFlagArgv(["node", "entry.js", "--profile", "p", "--update"])).toEqual([
|
||||
"node",
|
||||
"entry.js",
|
||||
"--profile",
|
||||
"p",
|
||||
"update",
|
||||
]);
|
||||
});
|
||||
await runCli(argv);
|
||||
|
||||
it("keeps update options after the rewritten command", () => {
|
||||
expect(rewriteUpdateFlagArgv(["node", "entry.js", "--update", "--json"])).toEqual([
|
||||
"node",
|
||||
"entry.js",
|
||||
"update",
|
||||
"--json",
|
||||
]);
|
||||
expect(registerSubCliByName).toHaveBeenCalledTimes(1);
|
||||
expect(registerSubCliByName).toHaveBeenCalledWith(expect.any(Object), "gateway");
|
||||
expect(parseAsync).toHaveBeenCalledWith(argv);
|
||||
});
|
||||
});
|
||||
|
||||
@ -11,7 +11,7 @@ import { assertSupportedRuntime } from "../infra/runtime-guard.js";
|
||||
import { formatUncaughtError } from "../infra/errors.js";
|
||||
import { installUnhandledRejectionHandler } from "../infra/unhandled-rejections.js";
|
||||
import { enableConsoleCapture } from "../logging.js";
|
||||
import { getPrimaryCommand, hasHelpOrVersion } from "./argv.js";
|
||||
import { getPrimaryCommand } from "./argv.js";
|
||||
import { tryRouteCli } from "./route.js";
|
||||
|
||||
export function rewriteUpdateFlagArgv(argv: string[]): string[] {
|
||||
@ -50,12 +50,11 @@ export async function runCli(argv: string[] = process.argv) {
|
||||
});
|
||||
|
||||
const parseArgv = rewriteUpdateFlagArgv(normalizedArgv);
|
||||
if (hasHelpOrVersion(parseArgv)) {
|
||||
const primary = getPrimaryCommand(parseArgv);
|
||||
if (primary) {
|
||||
const { registerSubCliByName } = await import("./program/register.subclis.js");
|
||||
await registerSubCliByName(program, primary);
|
||||
}
|
||||
// Register the primary subcommand if one exists (for lazy-loading)
|
||||
const primary = getPrimaryCommand(parseArgv);
|
||||
if (primary) {
|
||||
const { registerSubCliByName } = await import("./program/register.subclis.js");
|
||||
await registerSubCliByName(program, primary);
|
||||
}
|
||||
await program.parseAsync(parseArgv);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user