diff --git a/src/commitments/commitments-full-chain.integration.test.ts b/src/commitments/commitments-full-chain.integration.test.ts index 944dd2ef818..97401227a60 100644 --- a/src/commitments/commitments-full-chain.integration.test.ts +++ b/src/commitments/commitments-full-chain.integration.test.ts @@ -61,23 +61,29 @@ describe("commitments full-chain integration", () => { }: { items: CommitmentExtractionItem[]; }): Promise => ({ - candidates: [ - { - itemId: items[0]?.itemId ?? "", - kind: "event_check_in", - sensitivity: "routine", - source: "inferred_user_context", - reason: "The user mentioned an interview happening today.", - suggestedText: "How did the interview go?", - dedupeKey: "interview:2026-04-29", - confidence: 0.93, - dueWindow: { - earliest: new Date(dueMs).toISOString(), - latest: new Date(dueMs + 60 * 60_000).toISOString(), - timezone: "America/Los_Angeles", + candidates: (() => { + const [firstItem] = items; + if (!firstItem) { + throw new Error("Expected commitment extraction item"); + } + return [ + { + itemId: firstItem.itemId, + kind: "event_check_in", + sensitivity: "routine", + source: "inferred_user_context", + reason: "The user mentioned an interview happening today.", + suggestedText: "How did the interview go?", + dedupeKey: "interview:2026-04-29", + confidence: 0.93, + dueWindow: { + earliest: new Date(dueMs).toISOString(), + latest: new Date(dueMs + 60 * 60_000).toISOString(), + timezone: "America/Los_Angeles", + }, }, - }, - ], + ]; + })(), }), ), setTimer: () => ({ unref() {} }) as ReturnType, @@ -102,7 +108,11 @@ describe("commitments full-chain integration", () => { const pendingStore = await loadCommitmentStore(); expect(pendingStore.commitments).toHaveLength(1); - expect(pendingStore.commitments[0]).toMatchObject({ + const [pendingCommitment] = pendingStore.commitments; + if (!pendingCommitment) { + throw new Error("Expected pending commitment"); + } + expect(pendingCommitment).toMatchObject({ status: "pending", agentId: "main", sessionKey, @@ -110,9 +120,9 @@ describe("commitments full-chain integration", () => { to: "155462274", suggestedText: "How did the interview go?", }); - expect(pendingStore.commitments[0]?.dueWindow.earliestMs).toBe(dueMs); - expect(pendingStore.commitments[0]).not.toHaveProperty("sourceUserText"); - expect(pendingStore.commitments[0]).not.toHaveProperty("sourceAssistantText"); + expect(pendingCommitment.dueWindow.earliestMs).toBe(dueMs); + expect(pendingCommitment).not.toHaveProperty("sourceUserText"); + expect(pendingCommitment).not.toHaveProperty("sourceAssistantText"); vi.setSystemTime(dueMs + 60_000); const sendTelegram = vi.fn().mockResolvedValue({ @@ -124,13 +134,16 @@ describe("commitments full-chain integration", () => { ctx: { Body?: string; OriginatingChannel?: string; OriginatingTo?: string }, opts?: { disableTools?: boolean }, ) => { + if (!opts) { + throw new Error("Expected commitment heartbeat reply options"); + } expect(ctx.Body).toContain("Due inferred follow-up commitments"); expect(ctx.Body).toContain("How did the interview go?"); expect(ctx.Body).not.toContain("I have an interview later today."); expect(ctx.Body).not.toContain("Good luck, I hope it goes well."); expect(ctx.OriginatingChannel).toBe("telegram"); expect(ctx.OriginatingTo).toBe("155462274"); - expect(opts?.disableTools).toBe(true); + expect(opts.disableTools).toBe(true); return { text: "How did the interview go?" }; }, ); @@ -154,7 +167,11 @@ describe("commitments full-chain integration", () => { expect.objectContaining({ accountId: "primary" }), ); const deliveredStore = await loadCommitmentStore(); - expect(deliveredStore.commitments[0]).toMatchObject({ + const [deliveredCommitment] = deliveredStore.commitments; + if (!deliveredCommitment) { + throw new Error("Expected delivered commitment"); + } + expect(deliveredCommitment).toMatchObject({ status: "sent", attempts: 1, sentAtMs: dueMs + 60_000,