fix(heartbeat): block dm targets and internalize blocked prompts

This commit is contained in:
Peter Steinberger
2026-02-25 02:02:26 +00:00
parent e0201c2774
commit a805d6b439
9 changed files with 161 additions and 6 deletions

View File

@@ -37,6 +37,7 @@ describe("Ghost reminder bug (issue #13317)", () => {
const createConfig = async (params: {
tmpDir: string;
storePath: string;
target?: "telegram" | "none";
}): Promise<{ cfg: OpenClawConfig; sessionKey: string }> => {
const cfg: OpenClawConfig = {
agents: {
@@ -44,7 +45,7 @@ describe("Ghost reminder bug (issue #13317)", () => {
workspace: params.tmpDir,
heartbeat: {
every: "5m",
target: "telegram",
target: params.target ?? "telegram",
},
},
},
@@ -96,6 +97,7 @@ describe("Ghost reminder bug (issue #13317)", () => {
replyText: string;
reason: string;
enqueue: (sessionKey: string) => void;
target?: "telegram" | "none";
}): Promise<{
result: Awaited<ReturnType<typeof runHeartbeatOnce>>;
sendTelegram: ReturnType<typeof vi.fn>;
@@ -105,7 +107,11 @@ describe("Ghost reminder bug (issue #13317)", () => {
return withTempHeartbeatSandbox(
async ({ tmpDir, storePath }) => {
const { sendTelegram, getReplySpy } = createHeartbeatDeps(params.replyText);
const { cfg, sessionKey } = await createConfig({ tmpDir, storePath });
const { cfg, sessionKey } = await createConfig({
tmpDir,
storePath,
target: params.target,
});
params.enqueue(sessionKey);
const result = await runHeartbeatOnce({
cfg,
@@ -192,4 +198,38 @@ describe("Ghost reminder bug (issue #13317)", () => {
expect(calledCtx?.Body).not.toContain("Read HEARTBEAT.md");
expect(sendTelegram).toHaveBeenCalled();
});
it("uses an internal-only cron prompt when delivery target is none", async () => {
const { result, sendTelegram, calledCtx } = await runHeartbeatCase({
tmpPrefix: "openclaw-cron-internal-",
replyText: "Handled internally",
reason: "cron:reminder-job",
target: "none",
enqueue: (sessionKey) => {
enqueueSystemEvent("Reminder: Rotate API keys", { sessionKey });
},
});
expect(result.status).toBe("ran");
expect(calledCtx?.Provider).toBe("cron-event");
expect(calledCtx?.Body).toContain("Handle this reminder internally");
expect(sendTelegram).not.toHaveBeenCalled();
});
it("uses an internal-only exec prompt when delivery target is none", async () => {
const { result, sendTelegram, calledCtx } = await runHeartbeatCase({
tmpPrefix: "openclaw-exec-internal-",
replyText: "Handled internally",
reason: "exec-event",
target: "none",
enqueue: (sessionKey) => {
enqueueSystemEvent("exec finished: deploy succeeded", { sessionKey });
},
});
expect(result.status).toBe("ran");
expect(calledCtx?.Provider).toBe("exec-event");
expect(calledCtx?.Body).toContain("Handle the result internally");
expect(sendTelegram).not.toHaveBeenCalled();
});
});