|
| 1 | +// Regression test for bounded HEARTBEAT.md reads. |
| 2 | +import fs from "node:fs/promises"; |
| 3 | +import path from "node:path"; |
| 4 | +import { describe, expect, it, vi } from "vitest"; |
| 5 | +import type { OpenClawConfig } from "../config/types.openclaw.js"; |
| 6 | +import { runHeartbeatOnce } from "./heartbeat-runner.js"; |
| 7 | +import { installHeartbeatRunnerTestRuntime } from "./heartbeat-runner.test-harness.js"; |
| 8 | +import { seedMainSessionStore, withTempHeartbeatSandbox } from "./heartbeat-runner.test-utils.js"; |
| 9 | + |
| 10 | +installHeartbeatRunnerTestRuntime({ includeSlack: true }); |
| 11 | + |
| 12 | +describe("runHeartbeatOnce oversized HEARTBEAT.md", () => { |
| 13 | + it("treats an oversized HEARTBEAT.md like a missing file and continues the run", async () => { |
| 14 | + await withTempHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => { |
| 15 | + const cfg: OpenClawConfig = { |
| 16 | + agents: { |
| 17 | + defaults: { |
| 18 | + workspace: tmpDir, |
| 19 | + heartbeat: { every: "5m", target: "slack", to: "channel:C123" }, |
| 20 | + }, |
| 21 | + }, |
| 22 | + channels: { slack: { heartbeat: { showOk: false } } }, |
| 23 | + session: { store: storePath }, |
| 24 | + }; |
| 25 | + await seedMainSessionStore(storePath, cfg, { |
| 26 | + lastChannel: "slack", |
| 27 | + lastProvider: "slack", |
| 28 | + lastTo: "channel:C123", |
| 29 | + }); |
| 30 | + // Overwrite the default heartbeat file with content larger than the 16 MB cap. |
| 31 | + const oversizedContent = Buffer.alloc(16 * 1024 * 1024 + 1, "x"); |
| 32 | + await fs.writeFile(path.join(tmpDir, "HEARTBEAT.md"), oversizedContent); |
| 33 | + |
| 34 | + replySpy.mockResolvedValue({ text: "needs attention" }); |
| 35 | + const sendSlack = vi.fn().mockResolvedValue({ messageId: "m1", channelId: "C123" }); |
| 36 | + |
| 37 | + const res = await runHeartbeatOnce({ |
| 38 | + cfg, |
| 39 | + deps: { |
| 40 | + getReplyFromConfig: replySpy, |
| 41 | + slack: sendSlack, |
| 42 | + getQueueSize: () => 0, |
| 43 | + nowMs: () => 0, |
| 44 | + }, |
| 45 | + }); |
| 46 | + |
| 47 | + expect(res.status).toBe("ran"); |
| 48 | + expect(sendSlack).toHaveBeenCalledTimes(1); |
| 49 | + }); |
| 50 | + }); |
| 51 | +}); |
0 commit comments