From 2f6842fdf4d926756de325b3419204d9c241ba61 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 18 Jan 2026 07:16:08 +0000 Subject: [PATCH] fix: stabilize gateway test env cleanup (#1148) (thanks @TSavo) --- CHANGELOG.md | 1 + src/gateway/server.channels.test.ts | 6 +++--- src/gateway/server.config-apply.test.ts | 26 ++++++------------------- test/setup.ts | 1 + 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e928c80cb..7ead09908 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Docs: https://docs.clawd.bot ### Fixes - Tools: return a companion-app-required message when node exec is requested with no paired node. - Streaming: emit assistant deltas for OpenAI-compatible SSE chunks. (#1147) — thanks @alauppe. +- Tests: clean up gateway env stubs and assert config.apply sentinel writes. (#1148) — thanks @TSavo. ## 2026.1.18-2 diff --git a/src/gateway/server.channels.test.ts b/src/gateway/server.channels.test.ts index 4d0a969ce..ee49ea9b1 100644 --- a/src/gateway/server.channels.test.ts +++ b/src/gateway/server.channels.test.ts @@ -30,7 +30,7 @@ describe("gateway server channels", () => { vi.stubEnv("TELEGRAM_BOT_TOKEN", undefined); const result = await startServerWithClient(); servers.push(result); - const { server, ws } = result; + const { ws } = result; await connectOk(ws); const res = await rpcReq<{ @@ -61,7 +61,7 @@ describe("gateway server channels", () => { test("channels.logout reports no session when missing", async () => { const result = await startServerWithClient(); servers.push(result); - const { server, ws } = result; + const { ws } = result; await connectOk(ws); const res = await rpcReq<{ cleared?: boolean; channel?: string }>(ws, "channels.logout", { @@ -86,7 +86,7 @@ describe("gateway server channels", () => { const result = await startServerWithClient(); servers.push(result); - const { server, ws } = result; + const { ws } = result; await connectOk(ws); const res = await rpcReq<{ diff --git a/src/gateway/server.config-apply.test.ts b/src/gateway/server.config-apply.test.ts index af159ea18..19942a905 100644 --- a/src/gateway/server.config-apply.test.ts +++ b/src/gateway/server.config-apply.test.ts @@ -1,7 +1,5 @@ -import fs from "node:fs/promises"; -import os from "node:os"; -import path from "node:path"; -import { afterEach, describe, expect, it, vi } from "vitest"; +import { readRestartSentinel } from "../infra/restart-sentinel.js"; +import { afterEach, describe, expect, it } from "vitest"; import { connectOk, @@ -31,7 +29,7 @@ describe("gateway config.apply", () => { it("writes config, stores sentinel, and schedules restart", async () => { const result = await startServerWithClient(); servers.push(result); - const { server, ws } = result; + const { ws } = result; await connectOk(ws); const id = "req-1"; @@ -53,26 +51,14 @@ describe("gateway config.apply", () => { ); expect(res.ok).toBe(true); - // Verify sentinel file was created (restart was scheduled) - const sentinelPath = path.join(os.homedir(), ".clawdbot", "restart-sentinel.json"); - - // Wait for file to be written - await new Promise((resolve) => setTimeout(resolve, 100)); - - try { - const raw = await fs.readFile(sentinelPath, "utf-8"); - const parsed = JSON.parse(raw) as { payload?: { kind?: string } }; - expect(parsed.payload?.kind).toBe("config-apply"); - } catch (err) { - // File may not exist if signal delivery is mocked, verify response was ok instead - expect(res.ok).toBe(true); - } + const sentinel = await readRestartSentinel(); + expect(sentinel?.payload.kind).toBe("config-apply"); }); it("rejects invalid raw config", async () => { const result = await startServerWithClient(); servers.push(result); - const { server, ws } = result; + const { ws } = result; await connectOk(ws); const id = "req-2"; diff --git a/test/setup.ts b/test/setup.ts index 7e4fea9dc..d9672c90b 100644 --- a/test/setup.ts +++ b/test/setup.ts @@ -7,4 +7,5 @@ process.on("exit", cleanup); afterEach(() => { // Guard against leaked fake timers across test files/workers. vi.useRealTimers(); + vi.unstubAllEnvs(); });