






















@@ -6,6 +6,7 @@ import { HEARTBEAT_TOKEN } from "../auto-reply/tokens.js";
66import { loadCommitmentStore, saveCommitmentStore } from "../commitments/store.js";
77import type { CommitmentRecord, CommitmentStoreFile } from "../commitments/types.js";
88import type { OpenClawConfig } from "../config/config.js";
9+import { captureEnv, setTestEnvValue } from "../test-utils/env.js";
910import { getLastHeartbeatEvent, resetHeartbeatEventsForTest } from "./heartbeat-events.js";
1011import {
1112runHeartbeatOnce,
@@ -20,12 +21,14 @@ installHeartbeatRunnerTestRuntime();
20212122describe("runHeartbeatOnce commitments", () => {
2223const nowMs = Date.parse("2026-04-29T17:00:00.000Z");
24+const envSnapshot = captureEnv(["OPENCLAW_STATE_DIR"]);
23252426afterEach(() => {
2527resetHeartbeatWakeStateForTests();
2628setHeartbeatsEnabled(true);
2729vi.useRealTimers();
2830vi.unstubAllEnvs();
31+envSnapshot.restore();
2932resetHeartbeatEventsForTest();
3033});
3134@@ -87,7 +90,7 @@ describe("runHeartbeatOnce commitments", () => {
8790visibleReplies?: "automatic" | "message_tool";
8891}) {
8992return await withTempHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
90-vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir);
93+setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir);
9194const sessionKey = "agent:main:telegram:user-155462274";
9295const cfg: OpenClawConfig = {
9396agents: {
@@ -178,7 +181,7 @@ describe("runHeartbeatOnce commitments", () => {
178181it("keeps due heartbeat tasks tool-capable when commitments are also due", async () => {
179182const { result, sendTelegram, store } = await withTempHeartbeatSandbox(
180183async ({ tmpDir, storePath, replySpy }) => {
181-vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir);
184+setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir);
182185const sessionKey = "agent:main:telegram:user-155462274";
183186const cfg: OpenClawConfig = {
184187agents: {
@@ -265,7 +268,7 @@ describe("runHeartbeatOnce commitments", () => {
265268it("does not deliver due commitments when heartbeat target is none", async () => {
266269const { result, sendTelegram, store } = await withTempHeartbeatSandbox(
267270async ({ tmpDir, storePath, replySpy }) => {
268-vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir);
271+setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir);
269272const sessionKey = "agent:main:telegram:user-155462274";
270273const cfg: OpenClawConfig = {
271274agents: {
@@ -344,7 +347,7 @@ describe("runHeartbeatOnce commitments", () => {
344347vi.setSystemTime(nowMs);
345348346349await withTempHeartbeatSandbox(async ({ tmpDir, storePath }) => {
347-vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir);
350+setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir);
348351const dueSessionKey = "agent:main:telegram:user-155462274";
349352const cfg: OpenClawConfig = {
350353agents: {
@@ -399,7 +402,7 @@ describe("runHeartbeatOnce commitments", () => {
399402400403it("does not mark suppressed commitment sends as delivered or duplicate-dismiss their retry", async () => {
401404await withTempHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
402-vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir);
405+setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir);
403406const sessionKey = "agent:main:telegram:user-155462274";
404407const cfg: OpenClawConfig = {
405408agents: {
@@ -559,7 +562,7 @@ describe("runHeartbeatOnce commitments", () => {
559562it("appends HEARTBEAT.md directives to commitment prompt when tasks are configured but none are due", async () => {
560563const { result, sendTelegram, store } = await withTempHeartbeatSandbox(
561564async ({ tmpDir, storePath, replySpy }) => {
562-vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir);
565+setTestEnvValue("OPENCLAW_STATE_DIR", tmpDir);
563566const sessionKey = "agent:main:telegram:user-155462274";
564567const cfg: OpenClawConfig = {
565568agents: {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。