Skip to content

Commit 6be1f15

Browse files
committed
test: settle gateway health before state guard probes
1 parent 59bcbd1 commit 6be1f15

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

‎src/cli/state-dir-gateway-check.server-fixture.test-support.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ const server = await startGatewayServer(port, {
1010
controlUiEnabled: false,
1111
});
1212
await server.startupSettled;
13+
// Minimal startup skips maintenance, including its initial health refresh. Settle
14+
// that real work before readiness so it cannot starve the next test handshake.
15+
const { refreshGatewayHealthSnapshot } = await import("../gateway/server/health-state.js");
16+
await refreshGatewayHealthSnapshot({ probe: false });
1317
process.send?.({ port });
1418

1519
const close = async () => {

‎src/cli/state-dir-gateway-check.server.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from "node:fs/promises";
33
import os from "node:os";
44
import path from "node:path";
55
import { fileURLToPath } from "node:url";
6-
import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";
6+
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
77
import { getFreePort } from "../test-utils/ports.js";
88
import { checkCliGatewayStateDir } from "./state-dir-gateway-check.js";
99

@@ -69,11 +69,14 @@ describe("state-dir guard with a real token Gateway", () => {
6969
reject(new Error(`Gateway fixture exited early: ${code}\n${childStderr}`));
7070
});
7171
});
72+
}, 120_000);
73+
74+
beforeEach(() => {
7275
vi.stubEnv("HOME", path.join(root, "cli-home"));
7376
setCliStateDir(cliStateDir);
7477
vi.stubEnv("OPENCLAW_GATEWAY_PORT", String(port));
7578
vi.stubEnv("OPENCLAW_SYSTEMD_UNIT", `openclaw-state-dir-server-${process.pid}`);
76-
}, 120_000);
79+
});
7780

7881
afterAll(async () => {
7982
vi.unstubAllEnvs();
@@ -95,7 +98,6 @@ describe("state-dir guard with a real token Gateway", () => {
9598
config: { gateway: { mode: "local", port, auth: { mode: "token", token } } },
9699
}),
97100
).resolves.toEqual({ kind: "allow" });
98-
setCliStateDir(cliStateDir);
99101
});
100102

101103
it("refuses mismatched authenticated hello paths", async () => {

0 commit comments

Comments
 (0)