test(perf): stub expensive cli coverage integration paths

This commit is contained in:
Peter Steinberger
2026-03-02 12:41:45 +00:00
parent f94d6fb1f1
commit 7b38e8231e
2 changed files with 26 additions and 2 deletions

View File

@@ -21,6 +21,16 @@ const inspectPortUsage = vi.fn(async (port: number) => ({
listeners: [],
hints: [],
}));
const buildGatewayInstallPlan = vi.fn(
async (params: { port: number; token?: string; env?: NodeJS.ProcessEnv }) => ({
programArguments: ["/bin/node", "cli", "gateway", "--port", String(params.port)],
workingDirectory: process.cwd(),
environment: {
OPENCLAW_GATEWAY_PORT: String(params.port),
...(params.token ? { OPENCLAW_GATEWAY_TOKEN: params.token } : {}),
},
}),
);
const { runtimeLogs, defaultRuntime, resetRuntimeCapture } = createCliRuntimeCapture();
@@ -65,6 +75,11 @@ vi.mock("../runtime.js", () => ({
defaultRuntime,
}));
vi.mock("../commands/daemon-install-helpers.js", () => ({
buildGatewayInstallPlan: (params: { port: number; token?: string; env?: NodeJS.ProcessEnv }) =>
buildGatewayInstallPlan(params),
}));
vi.mock("./deps.js", () => ({
createDefaultDeps: () => {},
}));
@@ -108,6 +123,7 @@ describe("daemon-cli coverage", () => {
delete process.env.OPENCLAW_GATEWAY_PORT;
delete process.env.OPENCLAW_PROFILE;
serviceReadCommand.mockResolvedValue(null);
buildGatewayInstallPlan.mockClear();
});
afterEach(() => {

View File

@@ -1,6 +1,7 @@
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { withEnvOverride } from "../config/test-helpers.js";
import { GatewayLockError } from "../infra/gateway-lock.js";
import { createCliRuntimeCapture } from "./test-runtime-capture.js";
type DiscoveredBeacon = Awaited<
@@ -26,6 +27,8 @@ const discoverGatewayBeacons = vi.fn<(opts: unknown) => Promise<DiscoveredBeacon
async () => [],
);
const gatewayStatusCommand = vi.fn<(opts: unknown) => Promise<void>>(async () => {});
const inspectPortUsage = vi.fn(async (_port: number) => ({ status: "free" as const }));
const formatPortDiagnostics = vi.fn(() => [] as string[]);
const { runtimeLogs, runtimeErrors, defaultRuntime, resetRuntimeCapture } =
createCliRuntimeCapture();
@@ -85,6 +88,11 @@ vi.mock("../commands/gateway-status.js", () => ({
gatewayStatusCommand: (opts: unknown) => gatewayStatusCommand(opts),
}));
vi.mock("../infra/ports.js", () => ({
inspectPortUsage: (port: number) => inspectPortUsage(port),
formatPortDiagnostics: (diagnostics: unknown) => formatPortDiagnostics(diagnostics),
}));
const { registerGatewayCli } = await import("./gateway-cli.js");
let gatewayProgram: Command;
@@ -106,6 +114,8 @@ async function expectGatewayExit(args: string[]) {
describe("gateway-cli coverage", () => {
beforeEach(() => {
gatewayProgram = createGatewayProgram();
inspectPortUsage.mockClear();
formatPortDiagnostics.mockClear();
});
it("registers call/health commands and routes to callGateway", async () => {
@@ -216,8 +226,6 @@ describe("gateway-cli coverage", () => {
it("prints stop hints on GatewayLockError when service is loaded", async () => {
resetRuntimeCapture();
serviceIsLoaded.mockResolvedValue(true);
const { GatewayLockError } = await import("../infra/gateway-lock.js");
startGatewayServer.mockRejectedValueOnce(
new GatewayLockError("another gateway instance is already listening"),
);