refactor(core): dedupe shared config and runtime helpers

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:03 +00:00
parent 544ffbcf7b
commit 04892ee230
68 changed files with 1966 additions and 2018 deletions

View File

@@ -86,6 +86,40 @@ describe("Ghost reminder bug (issue #13317)", () => {
expect(calledCtx?.Body).not.toContain("heartbeat poll");
};
const runCronReminderCase = async (
tmpPrefix: string,
enqueue: (sessionKey: string) => void,
): Promise<{
result: Awaited<ReturnType<typeof runHeartbeatOnce>>;
sendTelegram: ReturnType<typeof vi.fn>;
getReplySpy: ReturnType<typeof vi.spyOn<typeof replyModule, "getReplyFromConfig">>;
}> => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), tmpPrefix));
const sendTelegram = vi.fn().mockResolvedValue({
messageId: "m1",
chatId: "155462274",
});
const getReplySpy = vi
.spyOn(replyModule, "getReplyFromConfig")
.mockResolvedValue({ text: "Relay this reminder now" });
try {
const { cfg, sessionKey } = await createConfig(tmpDir);
enqueue(sessionKey);
const result = await runHeartbeatOnce({
cfg,
agentId: "main",
reason: "cron:reminder-job",
deps: {
sendTelegram,
},
});
return { result, sendTelegram, getReplySpy };
} finally {
await fs.rm(tmpDir, { recursive: true, force: true });
}
};
it("does not use CRON_EVENT_PROMPT when only a HEARTBEAT_OK event is present", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-ghost-"));
const sendTelegram = vi.fn().mockResolvedValue({
@@ -122,68 +156,28 @@ describe("Ghost reminder bug (issue #13317)", () => {
});
it("uses CRON_EVENT_PROMPT when an actionable cron event exists", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-cron-"));
const sendTelegram = vi.fn().mockResolvedValue({
messageId: "m1",
chatId: "155462274",
});
const getReplySpy = vi
.spyOn(replyModule, "getReplyFromConfig")
.mockResolvedValue({ text: "Relay this reminder now" });
try {
const { cfg } = await createConfig(tmpDir);
enqueueSystemEvent("Reminder: Check Base Scout results", {
sessionKey: resolveMainSessionKey(cfg),
});
const result = await runHeartbeatOnce({
cfg,
agentId: "main",
reason: "cron:reminder-job",
deps: {
sendTelegram,
},
});
expect(result.status).toBe("ran");
expectCronEventPrompt(getReplySpy, "Reminder: Check Base Scout results");
expect(sendTelegram).toHaveBeenCalled();
} finally {
await fs.rm(tmpDir, { recursive: true, force: true });
}
const { result, sendTelegram, getReplySpy } = await runCronReminderCase(
"openclaw-cron-",
(sessionKey) => {
enqueueSystemEvent("Reminder: Check Base Scout results", { sessionKey });
},
);
expect(result.status).toBe("ran");
expectCronEventPrompt(getReplySpy, "Reminder: Check Base Scout results");
expect(sendTelegram).toHaveBeenCalled();
});
it("uses CRON_EVENT_PROMPT when cron events are mixed with heartbeat noise", async () => {
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-cron-mixed-"));
const sendTelegram = vi.fn().mockResolvedValue({
messageId: "m1",
chatId: "155462274",
});
const getReplySpy = vi
.spyOn(replyModule, "getReplyFromConfig")
.mockResolvedValue({ text: "Relay this reminder now" });
try {
const { cfg, sessionKey } = await createConfig(tmpDir);
enqueueSystemEvent("HEARTBEAT_OK", { sessionKey });
enqueueSystemEvent("Reminder: Check Base Scout results", { sessionKey });
const result = await runHeartbeatOnce({
cfg,
agentId: "main",
reason: "cron:reminder-job",
deps: {
sendTelegram,
},
});
expect(result.status).toBe("ran");
expectCronEventPrompt(getReplySpy, "Reminder: Check Base Scout results");
expect(sendTelegram).toHaveBeenCalled();
} finally {
await fs.rm(tmpDir, { recursive: true, force: true });
}
const { result, sendTelegram, getReplySpy } = await runCronReminderCase(
"openclaw-cron-mixed-",
(sessionKey) => {
enqueueSystemEvent("HEARTBEAT_OK", { sessionKey });
enqueueSystemEvent("Reminder: Check Base Scout results", { sessionKey });
},
);
expect(result.status).toBe("ran");
expectCronEventPrompt(getReplySpy, "Reminder: Check Base Scout results");
expect(sendTelegram).toHaveBeenCalled();
});
it("uses CRON_EVENT_PROMPT for tagged cron events on interval wake", async () => {