diff --git a/src/infra/heartbeat-runner.commitments.test.ts b/src/infra/heartbeat-runner.commitments.test.ts index d30a60916510..916446ecf40f 100644 --- a/src/infra/heartbeat-runner.commitments.test.ts +++ b/src/infra/heartbeat-runner.commitments.test.ts @@ -6,6 +6,7 @@ import { HEARTBEAT_TOKEN } from "../auto-reply/tokens.js"; import { loadCommitmentStore, saveCommitmentStore } from "../commitments/store.js"; import type { CommitmentRecord, CommitmentStoreFile } from "../commitments/types.js"; import type { OpenClawConfig } from "../config/config.js"; +import { captureEnv, setTestEnvValue } from "../test-utils/env.js"; import { getLastHeartbeatEvent, resetHeartbeatEventsForTest } from "./heartbeat-events.js"; import { runHeartbeatOnce, @@ -20,12 +21,14 @@ installHeartbeatRunnerTestRuntime(); describe("runHeartbeatOnce commitments", () => { const nowMs = Date.parse("2026-04-29T17:00:00.000Z"); + const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]); afterEach(() => { resetHeartbeatWakeStateForTests(); setHeartbeatsEnabled(true); vi.useRealTimers(); vi.unstubAllEnvs(); + envSnapshot.restore(); resetHeartbeatEventsForTest(); }); @@ -87,7 +90,7 @@ describe("runHeartbeatOnce commitments", () => { visibleReplies?: "automatic" | "message_tool"; }) { return await withTempHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => { - vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir); + setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir); const sessionKey = "agent:main:telegram:user-155462274"; const cfg: OpenClawConfig = { agents: { @@ -178,7 +181,7 @@ describe("runHeartbeatOnce commitments", () => { it("keeps due heartbeat tasks tool-capable when commitments are also due", async () => { const { result, sendTelegram, store } = await withTempHeartbeatSandbox( async ({ tmpDir, storePath, replySpy }) => { - vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir); + setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir); const sessionKey = "agent:main:telegram:user-155462274"; const cfg: OpenClawConfig = { agents: { @@ -265,7 +268,7 @@ describe("runHeartbeatOnce commitments", () => { it("does not deliver due commitments when heartbeat target is none", async () => { const { result, sendTelegram, store } = await withTempHeartbeatSandbox( async ({ tmpDir, storePath, replySpy }) => { - vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir); + setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir); const sessionKey = "agent:main:telegram:user-155462274"; const cfg: OpenClawConfig = { agents: { @@ -344,7 +347,7 @@ describe("runHeartbeatOnce commitments", () => { vi.setSystemTime(nowMs); await withTempHeartbeatSandbox(async ({ tmpDir, storePath }) => { - vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir); + setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir); const dueSessionKey = "agent:main:telegram:user-155462274"; const cfg: OpenClawConfig = { agents: { @@ -399,7 +402,7 @@ describe("runHeartbeatOnce commitments", () => { it("does not mark suppressed commitment sends as delivered or duplicate-dismiss their retry", async () => { await withTempHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => { - vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir); + setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir); const sessionKey = "agent:main:telegram:user-155462274"; const cfg: OpenClawConfig = { agents: { @@ -559,7 +562,7 @@ describe("runHeartbeatOnce commitments", () => { it("appends HEARTBEAT.md directives to commitment prompt when tasks are configured but none are due", async () => { const { result, sendTelegram, store } = await withTempHeartbeatSandbox( async ({ tmpDir, storePath, replySpy }) => { - vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir); + setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir); const sessionKey = "agent:main:telegram:user-155462274"; const cfg: OpenClawConfig = { agents: {