test(cli): fix option-collision mock typings

This commit is contained in:
Gustavo Madeira Santana
2026-02-17 21:31:49 -05:00
parent c90b09cb02
commit 40a6661597
6 changed files with 51 additions and 23 deletions

View File

@@ -1,8 +1,8 @@
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
const runAcpClientInteractive = vi.fn(async () => {});
const serveAcpGateway = vi.fn(async () => {});
const runAcpClientInteractive = vi.fn(async (_opts?: unknown) => {});
const serveAcpGateway = vi.fn(async (_opts?: unknown) => {});
const defaultRuntime = {
error: vi.fn(),

View File

@@ -4,8 +4,19 @@ import type { BrowserParentOpts } from "./browser-cli-shared.js";
import { registerBrowserStateCommands } from "./browser-cli-state.js";
const mocks = vi.hoisted(() => ({
callBrowserRequest: vi.fn(async () => ({ ok: true })),
runBrowserResizeWithOutput: vi.fn(async () => {}),
callBrowserRequest: vi.fn(
async (
_opts: BrowserParentOpts,
_params: {
method: "GET" | "POST" | "DELETE";
path: string;
query?: Record<string, string | number | boolean | undefined>;
body?: unknown;
},
_extra?: { timeoutMs?: number; progress?: boolean },
) => ({ ok: true }),
),
runBrowserResizeWithOutput: vi.fn(async (_params: unknown) => {}),
runtime: {
log: vi.fn(),
error: vi.fn(),
@@ -14,7 +25,16 @@ const mocks = vi.hoisted(() => ({
}));
vi.mock("./browser-cli-shared.js", () => ({
callBrowserRequest: (...args: unknown[]) => mocks.callBrowserRequest(...args),
callBrowserRequest: (
opts: BrowserParentOpts,
params: {
method: "GET" | "POST" | "DELETE";
path: string;
query?: Record<string, string | number | boolean | undefined>;
body?: unknown;
},
extra?: { timeoutMs?: number; progress?: boolean },
) => mocks.callBrowserRequest(opts, params, extra),
}));
vi.mock("./browser-cli-resize.js", () => ({
@@ -61,7 +81,10 @@ describe("browser state option collisions", () => {
const call = mocks.callBrowserRequest.mock.calls.at(-1);
expect(call).toBeDefined();
const request = call?.[1] as { body?: { targetId?: string } };
if (!call) {
throw new Error("Expected callBrowserRequest to be called");
}
const request = call[1] as { body?: { targetId?: string } };
expect(request.body?.targetId).toBe("tab-1");
});
@@ -81,7 +104,10 @@ describe("browser state option collisions", () => {
const call = mocks.callBrowserRequest.mock.calls.at(-1);
expect(call).toBeDefined();
const request = call?.[1] as { body?: { headers?: Record<string, string> } };
if (!call) {
throw new Error("Expected callBrowserRequest to be called");
}
const request = call[1] as { body?: { headers?: Record<string, string> } };
expect(request.body?.headers).toEqual({ "x-auth": "ok" });
});
});

View File

@@ -2,12 +2,12 @@ import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { addGatewayServiceCommands } from "./register-service-commands.js";
const runDaemonInstall = vi.fn(async () => {});
const runDaemonRestart = vi.fn(async () => {});
const runDaemonStart = vi.fn(async () => {});
const runDaemonStatus = vi.fn(async () => {});
const runDaemonStop = vi.fn(async () => {});
const runDaemonUninstall = vi.fn(async () => {});
const runDaemonInstall = vi.fn(async (_opts?: unknown) => {});
const runDaemonRestart = vi.fn(async (_opts?: unknown) => {});
const runDaemonStart = vi.fn(async (_opts?: unknown) => {});
const runDaemonStatus = vi.fn(async (_opts?: unknown) => {});
const runDaemonStop = vi.fn(async (_opts?: unknown) => {});
const runDaemonUninstall = vi.fn(async (_opts?: unknown) => {});
vi.mock("./runners.js", () => ({
runDaemonInstall: (opts: unknown) => runDaemonInstall(opts),

View File

@@ -1,8 +1,10 @@
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
const callGatewayCli = vi.fn(async () => ({ ok: true }));
const gatewayStatusCommand = vi.fn(async () => {});
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[] = [];

View File

@@ -1,17 +1,17 @@
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
const startGatewayServer = vi.fn(async () => ({
const startGatewayServer = vi.fn(async (_port: number, _opts?: unknown) => ({
close: vi.fn(async () => {}),
}));
const setGatewayWsLogStyle = vi.fn();
const setVerbose = vi.fn();
const forceFreePortAndWait = vi.fn(async () => ({
const setGatewayWsLogStyle = vi.fn((_style: string) => undefined);
const setVerbose = vi.fn((_enabled: boolean) => undefined);
const forceFreePortAndWait = vi.fn(async (_port: number, _opts: unknown) => ({
killed: [],
waitedMs: 0,
escalatedToSigkill: false,
}));
const ensureDevGatewayConfig = vi.fn(async () => {});
const ensureDevGatewayConfig = vi.fn(async (_opts?: unknown) => {});
const runGatewayLoop = vi.fn(async ({ start }: { start: () => Promise<unknown> }) => {
await start();
});

View File

@@ -1,9 +1,9 @@
import { Command } from "commander";
import { beforeEach, describe, expect, it, vi } from "vitest";
const updateCommand = vi.fn(async () => {});
const updateStatusCommand = vi.fn(async () => {});
const updateWizardCommand = vi.fn(async () => {});
const updateCommand = vi.fn(async (_opts?: unknown) => {});
const updateStatusCommand = vi.fn(async (_opts?: unknown) => {});
const updateWizardCommand = vi.fn(async (_opts?: unknown) => {});
const defaultRuntime = {
log: vi.fn(),