test(cli): dedupe runtime capture fixtures across command specs

This commit is contained in:
Peter Steinberger
2026-02-18 13:27:07 +00:00
parent 3af9f704c8
commit 8f866d51c4
7 changed files with 59 additions and 90 deletions

View File

@@ -1,20 +1,13 @@
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createCliRuntimeCapture } from "../test-runtime-capture.js";
const callGatewayCli = vi.fn(async (_method: string, _opts: unknown, _params?: unknown) => ({
ok: true,
}));
const gatewayStatusCommand = vi.fn(async (_opts: unknown, _runtime: unknown) => {});
const runtimeLogs: string[] = [];
const runtimeErrors: string[] = [];
const defaultRuntime = {
log: (msg: string) => runtimeLogs.push(msg),
error: (msg: string) => runtimeErrors.push(msg),
exit: (code: number) => {
throw new Error(`__exit__:${code}`);
},
};
const { defaultRuntime, resetRuntimeCapture } = createCliRuntimeCapture();
vi.mock("../cli-utils.js", () => ({
runCommandWithRuntime: async (
@@ -119,8 +112,7 @@ vi.mock("./discover.js", () => ({
describe("gateway register option collisions", () => {
beforeEach(() => {
runtimeLogs.length = 0;
runtimeErrors.length = 0;
resetRuntimeCapture();
callGatewayCli.mockClear();
gatewayStatusCommand.mockClear();
});

View File

@@ -1,5 +1,6 @@
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createCliRuntimeCapture } from "../test-runtime-capture.js";
const startGatewayServer = vi.fn(async (_port: number, _opts?: unknown) => ({
close: vi.fn(async () => {}),
@@ -16,15 +17,7 @@ const runGatewayLoop = vi.fn(async ({ start }: { start: () => Promise<unknown> }
await start();
});
const runtimeLogs: string[] = [];
const runtimeErrors: string[] = [];
const defaultRuntime = {
log: (msg: string) => runtimeLogs.push(msg),
error: (msg: string) => runtimeErrors.push(msg),
exit: (code: number) => {
throw new Error(`__exit__:${code}`);
},
};
const { defaultRuntime, resetRuntimeCapture } = createCliRuntimeCapture();
vi.mock("../../config/config.js", () => ({
getConfigPath: () => "/tmp/openclaw-test-missing-config.json",
@@ -99,8 +92,7 @@ vi.mock("./run-loop.js", () => ({
describe("gateway run option collisions", () => {
beforeEach(() => {
runtimeLogs.length = 0;
runtimeErrors.length = 0;
resetRuntimeCapture();
startGatewayServer.mockClear();
setGatewayWsLogStyle.mockClear();
setVerbose.mockClear();