mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-09 03:22:40 +00:00
test: guard infra process mock calls
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -59,6 +59,14 @@ describe("update-startup", () => {
|
||||
let resetUpdateAvailableStateForTest: (typeof import("./update-startup.js"))["resetUpdateAvailableStateForTest"];
|
||||
let loaded = false;
|
||||
|
||||
function requireFirstRunCommandCall(): Parameters<typeof runCommandWithTimeout> {
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user