From 40a666159732a99e207d7ea054decfe0cda6b9b0 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Tue, 17 Feb 2026 21:31:49 -0500 Subject: [PATCH] test(cli): fix option-collision mock typings --- src/cli/acp-cli.option-collisions.test.ts | 4 +-- ...rowser-cli-state.option-collisions.test.ts | 36 ++++++++++++++++--- .../register-service-commands.test.ts | 12 +++---- .../register.option-collisions.test.ts | 6 ++-- .../gateway-cli/run.option-collisions.test.ts | 10 +++--- src/cli/update-cli.option-collisions.test.ts | 6 ++-- 6 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/cli/acp-cli.option-collisions.test.ts b/src/cli/acp-cli.option-collisions.test.ts index 240ade624..44596d8cf 100644 --- a/src/cli/acp-cli.option-collisions.test.ts +++ b/src/cli/acp-cli.option-collisions.test.ts @@ -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(), diff --git a/src/cli/browser-cli-state.option-collisions.test.ts b/src/cli/browser-cli-state.option-collisions.test.ts index b50b5faa0..2bddcce01 100644 --- a/src/cli/browser-cli-state.option-collisions.test.ts +++ b/src/cli/browser-cli-state.option-collisions.test.ts @@ -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; + 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; + 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 } }; + if (!call) { + throw new Error("Expected callBrowserRequest to be called"); + } + const request = call[1] as { body?: { headers?: Record } }; expect(request.body?.headers).toEqual({ "x-auth": "ok" }); }); }); diff --git a/src/cli/daemon-cli/register-service-commands.test.ts b/src/cli/daemon-cli/register-service-commands.test.ts index 03fcf4138..1b90e1fed 100644 --- a/src/cli/daemon-cli/register-service-commands.test.ts +++ b/src/cli/daemon-cli/register-service-commands.test.ts @@ -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), diff --git a/src/cli/gateway-cli/register.option-collisions.test.ts b/src/cli/gateway-cli/register.option-collisions.test.ts index 77093e206..95a475c46 100644 --- a/src/cli/gateway-cli/register.option-collisions.test.ts +++ b/src/cli/gateway-cli/register.option-collisions.test.ts @@ -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[] = []; diff --git a/src/cli/gateway-cli/run.option-collisions.test.ts b/src/cli/gateway-cli/run.option-collisions.test.ts index a97e9b2fa..339d0220f 100644 --- a/src/cli/gateway-cli/run.option-collisions.test.ts +++ b/src/cli/gateway-cli/run.option-collisions.test.ts @@ -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 }) => { await start(); }); diff --git a/src/cli/update-cli.option-collisions.test.ts b/src/cli/update-cli.option-collisions.test.ts index baa39d640..6503daf4f 100644 --- a/src/cli/update-cli.option-collisions.test.ts +++ b/src/cli/update-cli.option-collisions.test.ts @@ -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(),