test: guard infra process mock calls · openclaw/openclaw@36a4ed5
steipete
·
2026-05-12
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,14 @@ vi.mock("../logging/subsystem.js", () => ({
|
13 | 13 | createSubsystemLogger: vi.fn(() => loggerMocks), |
14 | 14 | })); |
15 | 15 | |
| 16 | +function requireFirstWarnCall(): [unknown, unknown] { |
| 17 | +const [call] = loggerMocks.warn.mock.calls; |
| 18 | +if (!call) { |
| 19 | +throw new Error("expected logger warning"); |
| 20 | +} |
| 21 | +return call as [unknown, unknown]; |
| 22 | +} |
| 23 | + |
16 | 24 | const CREDENTIAL_AND_GATEWAY_ENV_KEYS = [ |
17 | 25 | "ANTHROPIC_API_KEY", |
18 | 26 | "ANTHROPIC_API_KEY_SECONDARY", |
@@ -182,7 +190,7 @@ describe("loadDotEnv", () => {
|
182 | 190 | expect(process.env.FOO).toBe("from-global"); |
183 | 191 | expect(process.env.BAR).toBe("from-gateway"); |
184 | 192 | expect(loggerMocks.warn).toHaveBeenCalledOnce(); |
185 | | -const [message, metadata] = loggerMocks.warn.mock.calls[0] ?? []; |
| 193 | +const [message, metadata] = requireFirstWarnCall(); |
186 | 194 | expect(String(message)).toContain("Conflicting values in"); |
187 | 195 | expect(String((metadata as { ignoredPath?: unknown } | undefined)?.ignoredPath)).toContain( |
188 | 196 | "gateway.env", |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -71,6 +71,14 @@ function setPlatform(platform: NodeJS.Platform): void {
|
71 | 71 | }); |
72 | 72 | } |
73 | 73 | |
| 74 | +function requireFirstSpawnSyncCall(): [unknown, unknown, unknown] { |
| 75 | +const [call] = spawnSyncMock.mock.calls; |
| 76 | +if (!call) { |
| 77 | +throw new Error("expected spawnSync call"); |
| 78 | +} |
| 79 | +return call as [unknown, unknown, unknown]; |
| 80 | +} |
| 81 | + |
74 | 82 | describe.runIf(process.platform !== "win32")("findGatewayPidsOnPortSync", () => { |
75 | 83 | it("parses lsof output and filters non-openclaw/current processes", () => { |
76 | 84 | const gatewayPidA = process.pid + 1000; |
@@ -168,7 +176,7 @@ describe.runIf(process.platform !== "win32")("cleanStaleGatewayProcessesSync", (
|
168 | 176 | expect(killed).toEqual([stalePid]); |
169 | 177 | expect(resolveGatewayPortMock).not.toHaveBeenCalled(); |
170 | 178 | expect(spawnSyncMock).toHaveBeenCalledTimes(2); |
171 | | -const [command, args, options] = spawnSyncMock.mock.calls[0] ?? []; |
| 179 | +const [command, args, options] = requireFirstSpawnSyncCall(); |
172 | 180 | expect(command).toBe("/usr/sbin/lsof"); |
173 | 181 | expect(args).toEqual(["-nP", "-iTCP:19999", "-sTCP:LISTEN", "-Fpc"]); |
174 | 182 | expect((options as { encoding?: unknown; timeout?: unknown } | undefined)?.encoding).toBe( |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -59,6 +59,14 @@ describe("update-startup", () => {
|
59 | 59 | let resetUpdateAvailableStateForTest: (typeof import("./update-startup.js"))["resetUpdateAvailableStateForTest"]; |
60 | 60 | let loaded = false; |
61 | 61 | |
| 62 | +function requireFirstRunCommandCall(): Parameters<typeof runCommandWithTimeout> { |
| 63 | +const [call] = vi.mocked(runCommandWithTimeout).mock.calls; |
| 64 | +if (!call) { |
| 65 | +throw new Error("expected update command run"); |
| 66 | +} |
| 67 | +return call; |
| 68 | +} |
| 69 | + |
62 | 70 | beforeAll(async () => { |
63 | 71 | await suiteRootTracker.setup(); |
64 | 72 | }); |
@@ -435,7 +443,7 @@ describe("update-startup", () => {
|
435 | 443 | } |
436 | 444 | |
437 | 445 | expect(runCommandWithTimeout).toHaveBeenCalledTimes(1); |
438 | | -const [argv, options] = vi.mocked(runCommandWithTimeout).mock.calls[0] ?? []; |
| 446 | +const [argv, options] = requireFirstRunCommandCall(); |
439 | 447 | expect(argv).toEqual([ |
440 | 448 | process.execPath, |
441 | 449 | "/opt/openclaw/dist/entry.js", |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。