test(perf): reuse cli programs in coverage tests

This commit is contained in:
Peter Steinberger 2026-03-02 12:00:28 +00:00
parent adf2ef88c6
commit bdfd3bae6f
2 changed files with 10 additions and 5 deletions

View File

@ -74,6 +74,7 @@ vi.mock("./progress.js", () => ({
})); }));
const { registerDaemonCli } = await import("./daemon-cli.js"); const { registerDaemonCli } = await import("./daemon-cli.js");
let daemonProgram: Command;
function createDaemonProgram() { function createDaemonProgram() {
const program = new Command(); const program = new Command();
@ -83,8 +84,7 @@ function createDaemonProgram() {
} }
async function runDaemonCommand(args: string[]) { async function runDaemonCommand(args: string[]) {
const program = createDaemonProgram(); await daemonProgram.parseAsync(args, { from: "user" });
await program.parseAsync(args, { from: "user" });
} }
function parseFirstJsonRuntimeLine<T>() { function parseFirstJsonRuntimeLine<T>() {
@ -96,6 +96,7 @@ describe("daemon-cli coverage", () => {
let envSnapshot: ReturnType<typeof captureEnv>; let envSnapshot: ReturnType<typeof captureEnv>;
beforeEach(() => { beforeEach(() => {
daemonProgram = createDaemonProgram();
envSnapshot = captureEnv([ envSnapshot = captureEnv([
"OPENCLAW_STATE_DIR", "OPENCLAW_STATE_DIR",
"OPENCLAW_CONFIG_PATH", "OPENCLAW_CONFIG_PATH",

View File

@ -1,5 +1,5 @@
import { Command } from "commander"; import { Command } from "commander";
import { describe, expect, it, vi } from "vitest"; import { beforeEach, describe, expect, it, vi } from "vitest";
import { withEnvOverride } from "../config/test-helpers.js"; import { withEnvOverride } from "../config/test-helpers.js";
import { createCliRuntimeCapture } from "./test-runtime-capture.js"; import { createCliRuntimeCapture } from "./test-runtime-capture.js";
@ -86,6 +86,7 @@ vi.mock("../commands/gateway-status.js", () => ({
})); }));
const { registerGatewayCli } = await import("./gateway-cli.js"); const { registerGatewayCli } = await import("./gateway-cli.js");
let gatewayProgram: Command;
function createGatewayProgram() { function createGatewayProgram() {
const program = new Command(); const program = new Command();
@ -95,8 +96,7 @@ function createGatewayProgram() {
} }
async function runGatewayCommand(args: string[]) { async function runGatewayCommand(args: string[]) {
const program = createGatewayProgram(); await gatewayProgram.parseAsync(args, { from: "user" });
await program.parseAsync(args, { from: "user" });
} }
async function expectGatewayExit(args: string[]) { async function expectGatewayExit(args: string[]) {
@ -104,6 +104,10 @@ async function expectGatewayExit(args: string[]) {
} }
describe("gateway-cli coverage", () => { describe("gateway-cli coverage", () => {
beforeEach(() => {
gatewayProgram = createGatewayProgram();
});
it("registers call/health commands and routes to callGateway", async () => { it("registers call/health commands and routes to callGateway", async () => {
resetRuntimeCapture(); resetRuntimeCapture();
callGateway.mockClear(); callGateway.mockClear();