From c2d102b6ee81f55f5d676f995ec30598ca962ec2 Mon Sep 17 00:00:00 2001 From: Shakker Date: Wed, 24 Jun 2026 04:19:31 +0100 Subject: [PATCH] test: scope post-attach sentinel env --- .../server-startup-post-attach.test.ts | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/gateway/server-startup-post-attach.test.ts b/src/gateway/server-startup-post-attach.test.ts index 325364a52be2..af80c89be150 100644 --- a/src/gateway/server-startup-post-attach.test.ts +++ b/src/gateway/server-startup-post-attach.test.ts @@ -563,15 +563,19 @@ describe("startGatewayPostAttachRuntime", () => { it("skips heavy restart sentinel refresh when no sentinel file exists", async () => { const stateDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-no-sentinel-")); - vi.stubEnv("OPENCLAW_STATE_DIR", stateDir); - hoisted.refreshLatestUpdateRestartSentinel.mockClear(); + try { + await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => { + hoisted.refreshLatestUpdateRestartSentinel.mockClear(); - const result = await testing.refreshLatestUpdateRestartSentinelIfPresent(); + const result = await testing.refreshLatestUpdateRestartSentinelIfPresent(); - expect(result).toBeNull(); - expect(hoisted.refreshLatestUpdateRestartSentinel).not.toHaveBeenCalled(); - closeOpenClawStateDatabaseForTest(); - fs.rmSync(stateDir, { recursive: true, force: true }); + expect(result).toBeNull(); + expect(hoisted.refreshLatestUpdateRestartSentinel).not.toHaveBeenCalled(); + }); + } finally { + closeOpenClawStateDatabaseForTest(); + fs.rmSync(stateDir, { recursive: true, force: true }); + } }); it("refreshes the restart sentinel when the sentinel row exists", async () => { @@ -585,15 +589,16 @@ describe("startGatewayPostAttachRuntime", () => { }, { OPENCLAW_STATE_DIR: stateDir } as NodeJS.ProcessEnv, ); - vi.stubEnv("OPENCLAW_STATE_DIR", stateDir); - const sentinel = { kind: "update", status: "ok", ts: 1 } as const; - hoisted.refreshLatestUpdateRestartSentinel.mockClear(); - hoisted.refreshLatestUpdateRestartSentinel.mockResolvedValue(sentinel); + await withEnvAsync({ OPENCLAW_STATE_DIR: stateDir }, async () => { + const sentinel = { kind: "update", status: "ok", ts: 1 } as const; + hoisted.refreshLatestUpdateRestartSentinel.mockClear(); + hoisted.refreshLatestUpdateRestartSentinel.mockResolvedValue(sentinel); - const result = await testing.refreshLatestUpdateRestartSentinelIfPresent(); + const result = await testing.refreshLatestUpdateRestartSentinelIfPresent(); - expect(result).toBe(sentinel); - expect(hoisted.refreshLatestUpdateRestartSentinel).toHaveBeenCalledOnce(); + expect(result).toBe(sentinel); + expect(hoisted.refreshLatestUpdateRestartSentinel).toHaveBeenCalledOnce(); + }); } finally { closeOpenClawStateDatabaseForTest(); fs.rmSync(stateDir, { recursive: true, force: true });