mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-24 06:19:48 +00:00
108 lines
3.5 KiB
TypeScript
108 lines
3.5 KiB
TypeScript
import { Command } from "commander";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { runRegisteredCli } from "../test-utils/command-runner.js";
|
|
import { registerUpdateCli } from "./update-cli.js";
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
updateCommand: vi.fn(async (_opts: unknown) => {}),
|
|
updateFinalizeCommand: vi.fn(async (_opts: unknown) => {}),
|
|
updateStatusCommand: vi.fn(async (_opts: unknown) => {}),
|
|
updateWizardCommand: vi.fn(async (_opts: unknown) => {}),
|
|
defaultRuntime: {
|
|
log: vi.fn(),
|
|
error: vi.fn(),
|
|
writeStdout: vi.fn(),
|
|
writeJson: vi.fn(),
|
|
exit: vi.fn(),
|
|
},
|
|
}));
|
|
|
|
const {
|
|
updateCommand,
|
|
updateFinalizeCommand,
|
|
updateStatusCommand,
|
|
updateWizardCommand,
|
|
defaultRuntime,
|
|
} = mocks;
|
|
|
|
vi.mock("./update-cli/update-command.js", () => ({
|
|
updateCommand: (opts: unknown) => mocks.updateCommand(opts),
|
|
updateFinalizeCommand: (opts: unknown) => mocks.updateFinalizeCommand(opts),
|
|
}));
|
|
|
|
vi.mock("./update-cli/status.js", () => ({
|
|
updateStatusCommand: (opts: unknown) => mocks.updateStatusCommand(opts),
|
|
}));
|
|
|
|
vi.mock("./update-cli/wizard.js", () => ({
|
|
updateWizardCommand: (opts: unknown) => mocks.updateWizardCommand(opts),
|
|
}));
|
|
|
|
vi.mock("../runtime.js", () => ({
|
|
defaultRuntime: mocks.defaultRuntime,
|
|
}));
|
|
|
|
function firstCallOptions(mock: { mock: { calls: unknown[][] } }) {
|
|
return mock.mock.calls[0]?.[0];
|
|
}
|
|
|
|
describe("update cli option collisions", () => {
|
|
beforeEach(() => {
|
|
updateCommand.mockClear();
|
|
updateFinalizeCommand.mockClear();
|
|
updateStatusCommand.mockClear();
|
|
updateWizardCommand.mockClear();
|
|
defaultRuntime.log.mockClear();
|
|
defaultRuntime.error.mockClear();
|
|
defaultRuntime.writeStdout.mockClear();
|
|
defaultRuntime.writeJson.mockClear();
|
|
defaultRuntime.exit.mockClear();
|
|
});
|
|
|
|
it.each([
|
|
{
|
|
name: "forwards parent-captured --json/--timeout to `update status`",
|
|
argv: ["update", "status", "--json", "--timeout", "9"],
|
|
assert: () => {
|
|
expect(updateStatusCommand).toHaveBeenCalledTimes(1);
|
|
const opts = firstCallOptions(updateStatusCommand);
|
|
expect((opts as { json?: boolean; timeout?: string } | undefined)?.json).toBe(true);
|
|
expect((opts as { json?: boolean; timeout?: string } | undefined)?.timeout).toBe("9");
|
|
},
|
|
},
|
|
{
|
|
name: "forwards parent-captured --json/--timeout to hidden `update finalize`",
|
|
argv: ["update", "finalize", "--json", "--timeout", "17", "--no-restart"],
|
|
assert: () => {
|
|
expect(updateFinalizeCommand).toHaveBeenCalledTimes(1);
|
|
const opts = firstCallOptions(updateFinalizeCommand);
|
|
expect(
|
|
(opts as { json?: boolean; timeout?: string; restart?: boolean } | undefined)?.json,
|
|
).toBe(true);
|
|
expect(
|
|
(opts as { json?: boolean; timeout?: string; restart?: boolean } | undefined)?.timeout,
|
|
).toBe("17");
|
|
expect(
|
|
(opts as { json?: boolean; timeout?: string; restart?: boolean } | undefined)?.restart,
|
|
).toBe(false);
|
|
},
|
|
},
|
|
{
|
|
name: "forwards parent-captured --timeout to `update wizard`",
|
|
argv: ["update", "wizard", "--timeout", "13"],
|
|
assert: () => {
|
|
expect(updateWizardCommand).toHaveBeenCalledTimes(1);
|
|
const opts = firstCallOptions(updateWizardCommand);
|
|
expect((opts as { timeout?: string } | undefined)?.timeout).toBe("13");
|
|
},
|
|
},
|
|
])("$name", async ({ argv, assert }) => {
|
|
await runRegisteredCli({
|
|
register: registerUpdateCli as (program: Command) => void,
|
|
argv,
|
|
});
|
|
|
|
assert();
|
|
});
|
|
});
|