Wait for gateway version during restart

This commit is contained in:
pickaxe
2026-04-27 20:03:13 -07:00
committed by Peter Steinberger
parent f53ec52e7d
commit b46ff081f7
2 changed files with 44 additions and 0 deletions

View File

@@ -572,6 +572,47 @@ describe("inspectGatewayRestart", () => {
expect(sleep).toHaveBeenCalledTimes(185);
});
it("keeps waiting when the expected gateway version is not available yet", async () => {
const service = makeGatewayService({ status: "running", pid: 8000 });
inspectPortUsage
.mockResolvedValueOnce({
port: 18789,
status: "free",
listeners: [],
hints: [],
})
.mockResolvedValueOnce({
port: 18789,
status: "busy",
listeners: [{ pid: 8000, commandLine: "openclaw-gateway" }],
hints: [],
});
probeGateway.mockResolvedValue({
ok: true,
close: null,
server: { version: "2026.4.26", connId: "new" },
});
const { waitForGatewayHealthyRestart } = await import("./restart-health.js");
const snapshot = await waitForGatewayHealthyRestart({
service,
port: 18789,
expectedVersion: "2026.4.26",
attempts: 4,
delayMs: 1_000,
});
expect(snapshot).toMatchObject({
healthy: true,
gatewayVersion: "2026.4.26",
expectedVersion: "2026.4.26",
waitOutcome: "healthy",
elapsedMs: 1_000,
});
expect(snapshot.versionMismatch).toBeUndefined();
expect(sleep).toHaveBeenCalledTimes(1);
});
it("annotates timeout waits when the health loop exhausts all attempts", async () => {
const service = makeGatewayService({ status: "running", pid: 8000 });
inspectPortUsage.mockResolvedValue({

View File

@@ -123,6 +123,9 @@ function applyExpectedVersion(
if (snapshot.gatewayVersion === expectedVersion) {
return { ...snapshot, expectedVersion };
}
if (snapshot.gatewayVersion == null) {
return { ...snapshot, healthy: false, expectedVersion };
}
return {
...snapshot,
healthy: false,