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)
|
- 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: tighten email allowlist matching, typing cleanup, media caps, and onboarding/docs/tests. (#1635) Thanks @iHildy.
|
||||||
- Google Chat: normalize space targets without double `spaces/` prefix.
|
- 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
|
## 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", () => {
|
vi.mock("../infra/dotenv.js", () => ({ loadDotEnv: vi.fn() }));
|
||||||
it("leaves argv unchanged when --update is absent", () => {
|
vi.mock("../infra/env.js", () => ({ normalizeEnv: vi.fn() }));
|
||||||
const argv = ["node", "entry.js", "status"];
|
vi.mock("../infra/path-env.js", () => ({ ensureClawdbotCliOnPath: vi.fn() }));
|
||||||
expect(rewriteUpdateFlagArgv(argv)).toBe(argv);
|
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", () => {
|
it("registers the primary subcommand before parsing", async () => {
|
||||||
expect(rewriteUpdateFlagArgv(["node", "entry.js", "--update"])).toEqual([
|
const argv = ["/usr/bin/node-22", "/opt/clawdbot/entry.js", "gateway", "--port", "18789"];
|
||||||
"node",
|
|
||||||
"entry.js",
|
|
||||||
"update",
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("preserves global flags that appear before --update", () => {
|
await runCli(argv);
|
||||||
expect(rewriteUpdateFlagArgv(["node", "entry.js", "--profile", "p", "--update"])).toEqual([
|
|
||||||
"node",
|
|
||||||
"entry.js",
|
|
||||||
"--profile",
|
|
||||||
"p",
|
|
||||||
"update",
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("keeps update options after the rewritten command", () => {
|
expect(registerSubCliByName).toHaveBeenCalledTimes(1);
|
||||||
expect(rewriteUpdateFlagArgv(["node", "entry.js", "--update", "--json"])).toEqual([
|
expect(registerSubCliByName).toHaveBeenCalledWith(expect.any(Object), "gateway");
|
||||||
"node",
|
expect(parseAsync).toHaveBeenCalledWith(argv);
|
||||||
"entry.js",
|
|
||||||
"update",
|
|
||||||
"--json",
|
|
||||||
]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { assertSupportedRuntime } from "../infra/runtime-guard.js";
|
|||||||
import { formatUncaughtError } from "../infra/errors.js";
|
import { formatUncaughtError } from "../infra/errors.js";
|
||||||
import { installUnhandledRejectionHandler } from "../infra/unhandled-rejections.js";
|
import { installUnhandledRejectionHandler } from "../infra/unhandled-rejections.js";
|
||||||
import { enableConsoleCapture } from "../logging.js";
|
import { enableConsoleCapture } from "../logging.js";
|
||||||
import { getPrimaryCommand, hasHelpOrVersion } from "./argv.js";
|
import { getPrimaryCommand } from "./argv.js";
|
||||||
import { tryRouteCli } from "./route.js";
|
import { tryRouteCli } from "./route.js";
|
||||||
|
|
||||||
export function rewriteUpdateFlagArgv(argv: string[]): string[] {
|
export function rewriteUpdateFlagArgv(argv: string[]): string[] {
|
||||||
@ -50,13 +50,12 @@ export async function runCli(argv: string[] = process.argv) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const parseArgv = rewriteUpdateFlagArgv(normalizedArgv);
|
const parseArgv = rewriteUpdateFlagArgv(normalizedArgv);
|
||||||
if (hasHelpOrVersion(parseArgv)) {
|
// Register the primary subcommand if one exists (for lazy-loading)
|
||||||
const primary = getPrimaryCommand(parseArgv);
|
const primary = getPrimaryCommand(parseArgv);
|
||||||
if (primary) {
|
if (primary) {
|
||||||
const { registerSubCliByName } = await import("./program/register.subclis.js");
|
const { registerSubCliByName } = await import("./program/register.subclis.js");
|
||||||
await registerSubCliByName(program, primary);
|
await registerSubCliByName(program, primary);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
await program.parseAsync(parseArgv);
|
await program.parseAsync(parseArgv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user