test: trim cli program test bootstrap overhead
This commit is contained in:
@@ -1,8 +1,15 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createIosNodeListResponse } from "./program.nodes-test-helpers.js";
|
||||
import { callGateway, installBaseProgramMocks, runTui, runtime } from "./program.test-mocks.js";
|
||||
import {
|
||||
callGateway,
|
||||
installBaseProgramMocks,
|
||||
installSmokeProgramMocks,
|
||||
runTui,
|
||||
runtime,
|
||||
} from "./program.test-mocks.js";
|
||||
|
||||
installBaseProgramMocks();
|
||||
installSmokeProgramMocks();
|
||||
|
||||
const { buildProgram } = await import("./program.js");
|
||||
|
||||
|
||||
@@ -2,9 +2,16 @@ import * as fs from "node:fs/promises";
|
||||
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { parseCameraSnapPayload, parseCameraClipPayload } from "./nodes-camera.js";
|
||||
import { IOS_NODE, createIosNodeListResponse } from "./program.nodes-test-helpers.js";
|
||||
import { callGateway, installBaseProgramMocks, runTui, runtime } from "./program.test-mocks.js";
|
||||
import {
|
||||
callGateway,
|
||||
installBaseProgramMocks,
|
||||
installSmokeProgramMocks,
|
||||
runTui,
|
||||
runtime,
|
||||
} from "./program.test-mocks.js";
|
||||
|
||||
installBaseProgramMocks();
|
||||
installSmokeProgramMocks();
|
||||
|
||||
function getFirstRuntimeLogLine(): string {
|
||||
const first = runtime.log.mock.calls[0]?.[0];
|
||||
|
||||
@@ -14,6 +14,16 @@ import {
|
||||
installBaseProgramMocks();
|
||||
installSmokeProgramMocks();
|
||||
|
||||
vi.mock("./config-cli.js", () => ({
|
||||
registerConfigCli: (program: {
|
||||
command: (name: string) => { action: (fn: () => unknown) => void };
|
||||
}) => {
|
||||
program.command("config").action(() => configureCommand({}, runtime));
|
||||
},
|
||||
runConfigGet: vi.fn(),
|
||||
runConfigUnset: vi.fn(),
|
||||
}));
|
||||
|
||||
const { buildProgram } = await import("./program.js");
|
||||
|
||||
describe("cli program (smoke)", () => {
|
||||
|
||||
@@ -25,7 +25,7 @@ const { registerSubCliByName, registerSubCliCommands } = await import("./registe
|
||||
|
||||
describe("registerSubCliCommands", () => {
|
||||
const originalArgv = process.argv;
|
||||
const originalEnv = { ...process.env };
|
||||
const originalDisableLazySubcommands = process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS;
|
||||
|
||||
const createRegisteredProgram = (argv: string[], name?: string) => {
|
||||
process.argv = argv;
|
||||
@@ -38,8 +38,11 @@ describe("registerSubCliCommands", () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
process.env = { ...originalEnv };
|
||||
delete process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS;
|
||||
if (originalDisableLazySubcommands === undefined) {
|
||||
delete process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS;
|
||||
} else {
|
||||
process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS = originalDisableLazySubcommands;
|
||||
}
|
||||
registerAcpCli.mockClear();
|
||||
acpAction.mockClear();
|
||||
registerNodesCli.mockClear();
|
||||
@@ -48,7 +51,11 @@ describe("registerSubCliCommands", () => {
|
||||
|
||||
afterEach(() => {
|
||||
process.argv = originalArgv;
|
||||
process.env = { ...originalEnv };
|
||||
if (originalDisableLazySubcommands === undefined) {
|
||||
delete process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS;
|
||||
} else {
|
||||
process.env.OPENCLAW_DISABLE_LAZY_SUBCOMMANDS = originalDisableLazySubcommands;
|
||||
}
|
||||
});
|
||||
|
||||
it("registers only the primary placeholder and dispatches", async () => {
|
||||
@@ -56,7 +63,7 @@ describe("registerSubCliCommands", () => {
|
||||
|
||||
expect(program.commands.map((cmd) => cmd.name())).toEqual(["acp"]);
|
||||
|
||||
await program.parseAsync(process.argv);
|
||||
await program.parseAsync(["acp"], { from: "user" });
|
||||
|
||||
expect(registerAcpCli).toHaveBeenCalledTimes(1);
|
||||
expect(acpAction).toHaveBeenCalledTimes(1);
|
||||
@@ -91,7 +98,7 @@ describe("registerSubCliCommands", () => {
|
||||
const names = program.commands.map((cmd) => cmd.name());
|
||||
expect(names.filter((name) => name === "acp")).toHaveLength(1);
|
||||
|
||||
await program.parseAsync(["node", "openclaw", "acp"], { from: "user" });
|
||||
await program.parseAsync(["acp"], { from: "user" });
|
||||
expect(registerAcpCli).toHaveBeenCalledTimes(1);
|
||||
expect(acpAction).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user