test: guard heartbeat prefix mock call

This commit is contained in:
Peter Steinberger
2026-05-12 03:48:42 +01:00
parent cbc0f68515
commit 3c562dcaa8

View File

@@ -51,6 +51,14 @@ describe("runHeartbeatOnce responsePrefix templates", () => {
});
}
function requireFirstMockCall<T>(mock: { mock: { calls: T[][] } }, label: string): T[] {
const call = mock.mock.calls.at(0);
if (!call) {
throw new Error(`expected ${label} call`);
}
return call;
}
async function runTemplatedHeartbeat(params: { responsePrefix: string; replyText: string }) {
return withTempTelegramHeartbeatSandbox(async ({ tmpDir, storePath, replySpy }) => {
const cfg = createTelegramHeartbeatConfig({
@@ -93,7 +101,7 @@ describe("runHeartbeatOnce responsePrefix templates", () => {
});
expect(sendTelegram).toHaveBeenCalledTimes(1);
const [target, message, options] = sendTelegram.mock.calls[0] ?? [];
const [target, message, options] = requireFirstMockCall(sendTelegram, "telegram send");
expect(target).toBe(TELEGRAM_GROUP);
expect(message).toBe("[openai-codex/gpt-5.4|think:high] Heartbeat alert");
expect(typeof options).toBe("object");