From ba052d80a6a7a4027690d430c36502fcff65ff12 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 10 May 2026 23:58:33 +0100 Subject: [PATCH] test: tighten heartbeat commitment assertions --- .../heartbeat-runner.commitments.test.ts | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/infra/heartbeat-runner.commitments.test.ts b/src/infra/heartbeat-runner.commitments.test.ts index 80b3c5f45c3..0c2c3cae927 100644 --- a/src/infra/heartbeat-runner.commitments.test.ts +++ b/src/infra/heartbeat-runner.commitments.test.ts @@ -61,6 +61,16 @@ describe("runHeartbeatOnce commitments", () => { }; } + function expectCommitmentFields( + commitment: CommitmentRecord | undefined, + expected: Partial, + ) { + expect(commitment).toBeDefined(); + for (const [key, value] of Object.entries(expected)) { + expect(commitment?.[key as keyof CommitmentRecord]).toEqual(value); + } + } + async function setupCommitmentCase(params?: { replyText?: string; target?: "last" | "none"; @@ -237,7 +247,7 @@ describe("runHeartbeatOnce commitments", () => { expect(result.status).toBe("ran"); expect(sendTelegram).toHaveBeenCalled(); - expect(store.commitments[0]).toMatchObject({ + expectCommitmentFields(store.commitments[0], { id: "cm_interview", status: "pending", attempts: 0, @@ -314,7 +324,7 @@ describe("runHeartbeatOnce commitments", () => { expect(result.status).toBe("ran"); expect(sendTelegram).not.toHaveBeenCalled(); - expect(store.commitments[0]).toMatchObject({ + expectCommitmentFields(store.commitments[0], { id: "cm_interview", status: "pending", attempts: 0, @@ -357,13 +367,12 @@ describe("runHeartbeatOnce commitments", () => { runner.stop(); expect(runOnce).toHaveBeenCalledTimes(1); - expect(runOnce).toHaveBeenCalledWith( - expect.objectContaining({ - agentId: "main", - heartbeat: expect.objectContaining({ target: "none" }), - }), - ); - expect(runOnce.mock.calls[0]?.[0]).not.toHaveProperty("sessionKey", dueSessionKey); + const runOptions = runOnce.mock.calls[0]?.[0] as + | { agentId?: string; heartbeat?: { target?: string }; sessionKey?: string } + | undefined; + expect(runOptions?.agentId).toBe("main"); + expect(runOptions?.heartbeat?.target).toBe("none"); + expect(runOptions?.sessionKey).not.toBe(dueSessionKey); }); }); @@ -372,7 +381,7 @@ describe("runHeartbeatOnce commitments", () => { expect(result.status).toBe("ran"); expect(sendTelegram).toHaveBeenCalled(); - expect(store.commitments[0]).toMatchObject({ + expectCommitmentFields(store.commitments[0], { id: "cm_interview", status: "sent", attempts: 1, @@ -387,7 +396,7 @@ describe("runHeartbeatOnce commitments", () => { expect(result.status).toBe("ran"); expect(sendTelegram).not.toHaveBeenCalled(); - expect(store.commitments[0]).toMatchObject({ + expectCommitmentFields(store.commitments[0], { id: "cm_interview", status: "dismissed", attempts: 1, @@ -403,7 +412,7 @@ describe("runHeartbeatOnce commitments", () => { expect(result.status).toBe("ran"); expect(sendTelegram).not.toHaveBeenCalled(); - expect(store.commitments[0]).toMatchObject({ + expectCommitmentFields(store.commitments[0], { id: "cm_interview", status: "dismissed", attempts: 1, @@ -424,7 +433,7 @@ describe("runHeartbeatOnce commitments", () => { expect(result.status).toBe("ran"); expect(sendTelegram).toHaveBeenCalled(); - expect(store.commitments[0]).toMatchObject({ + expectCommitmentFields(store.commitments[0], { id: "cm_interview", status: "sent", attempts: 1,