diff --git a/src/infra/dotenv.test.ts b/src/infra/dotenv.test.ts index 3e50e2fd13ed..935c4c495195 100644 --- a/src/infra/dotenv.test.ts +++ b/src/infra/dotenv.test.ts @@ -13,6 +13,14 @@ vi.mock("../logging/subsystem.js", () => ({ createSubsystemLogger: vi.fn(() => loggerMocks), })); +function requireFirstWarnCall(): [unknown, unknown] { + const [call] = loggerMocks.warn.mock.calls; + if (!call) { + throw new Error("expected logger warning"); + } + return call as [unknown, unknown]; +} + const CREDENTIAL_AND_GATEWAY_ENV_KEYS = [ "ANTHROPIC_API_KEY", "ANTHROPIC_API_KEY_SECONDARY", @@ -182,7 +190,7 @@ describe("loadDotEnv", () => { expect(process.env.FOO).toBe("from-global"); expect(process.env.BAR).toBe("from-gateway"); expect(loggerMocks.warn).toHaveBeenCalledOnce(); - const [message, metadata] = loggerMocks.warn.mock.calls[0] ?? []; + const [message, metadata] = requireFirstWarnCall(); expect(String(message)).toContain("Conflicting values in"); expect(String((metadata as { ignoredPath?: unknown } | undefined)?.ignoredPath)).toContain( "gateway.env", diff --git a/src/infra/restart.test.ts b/src/infra/restart.test.ts index 7763630f13bd..e7a92f510157 100644 --- a/src/infra/restart.test.ts +++ b/src/infra/restart.test.ts @@ -71,6 +71,14 @@ function setPlatform(platform: NodeJS.Platform): void { }); } +function requireFirstSpawnSyncCall(): [unknown, unknown, unknown] { + const [call] = spawnSyncMock.mock.calls; + if (!call) { + throw new Error("expected spawnSync call"); + } + return call as [unknown, unknown, unknown]; +} + describe.runIf(process.platform !== "win32")("findGatewayPidsOnPortSync", () => { it("parses lsof output and filters non-openclaw/current processes", () => { const gatewayPidA = process.pid + 1000; @@ -168,7 +176,7 @@ describe.runIf(process.platform !== "win32")("cleanStaleGatewayProcessesSync", ( expect(killed).toEqual([stalePid]); expect(resolveGatewayPortMock).not.toHaveBeenCalled(); expect(spawnSyncMock).toHaveBeenCalledTimes(2); - const [command, args, options] = spawnSyncMock.mock.calls[0] ?? []; + const [command, args, options] = requireFirstSpawnSyncCall(); expect(command).toBe("/usr/sbin/lsof"); expect(args).toEqual(["-nP", "-iTCP:19999", "-sTCP:LISTEN", "-Fpc"]); expect((options as { encoding?: unknown; timeout?: unknown } | undefined)?.encoding).toBe( diff --git a/src/infra/update-startup.test.ts b/src/infra/update-startup.test.ts index afa0653ca3fa..73dd62537d51 100644 --- a/src/infra/update-startup.test.ts +++ b/src/infra/update-startup.test.ts @@ -59,6 +59,14 @@ describe("update-startup", () => { let resetUpdateAvailableStateForTest: (typeof import("./update-startup.js"))["resetUpdateAvailableStateForTest"]; let loaded = false; + function requireFirstRunCommandCall(): Parameters { + const [call] = vi.mocked(runCommandWithTimeout).mock.calls; + if (!call) { + throw new Error("expected update command run"); + } + return call; + } + beforeAll(async () => { await suiteRootTracker.setup(); }); @@ -435,7 +443,7 @@ describe("update-startup", () => { } expect(runCommandWithTimeout).toHaveBeenCalledTimes(1); - const [argv, options] = vi.mocked(runCommandWithTimeout).mock.calls[0] ?? []; + const [argv, options] = requireFirstRunCommandCall(); expect(argv).toEqual([ process.execPath, "/opt/openclaw/dist/entry.js",