



























@@ -61,6 +61,16 @@ describe("runHeartbeatOnce commitments", () => {
6161};
6262}
636364+function expectCommitmentFields(
65+commitment: CommitmentRecord | undefined,
66+expected: Partial<CommitmentRecord>,
67+) {
68+expect(commitment).toBeDefined();
69+for (const [key, value] of Object.entries(expected)) {
70+expect(commitment?.[key as keyof CommitmentRecord]).toEqual(value);
71+}
72+}
73+6474async function setupCommitmentCase(params?: {
6575replyText?: string;
6676target?: "last" | "none";
@@ -237,7 +247,7 @@ describe("runHeartbeatOnce commitments", () => {
237247238248expect(result.status).toBe("ran");
239249expect(sendTelegram).toHaveBeenCalled();
240-expect(store.commitments[0]).toMatchObject({
250+expectCommitmentFields(store.commitments[0], {
241251id: "cm_interview",
242252status: "pending",
243253attempts: 0,
@@ -314,7 +324,7 @@ describe("runHeartbeatOnce commitments", () => {
314324315325expect(result.status).toBe("ran");
316326expect(sendTelegram).not.toHaveBeenCalled();
317-expect(store.commitments[0]).toMatchObject({
327+expectCommitmentFields(store.commitments[0], {
318328id: "cm_interview",
319329status: "pending",
320330attempts: 0,
@@ -357,13 +367,12 @@ describe("runHeartbeatOnce commitments", () => {
357367runner.stop();
358368359369expect(runOnce).toHaveBeenCalledTimes(1);
360-expect(runOnce).toHaveBeenCalledWith(
361-expect.objectContaining({
362-agentId: "main",
363-heartbeat: expect.objectContaining({ target: "none" }),
364-}),
365-);
366-expect(runOnce.mock.calls[0]?.[0]).not.toHaveProperty("sessionKey", dueSessionKey);
370+const runOptions = runOnce.mock.calls[0]?.[0] as
371+| { agentId?: string; heartbeat?: { target?: string }; sessionKey?: string }
372+| undefined;
373+expect(runOptions?.agentId).toBe("main");
374+expect(runOptions?.heartbeat?.target).toBe("none");
375+expect(runOptions?.sessionKey).not.toBe(dueSessionKey);
367376});
368377});
369378@@ -372,7 +381,7 @@ describe("runHeartbeatOnce commitments", () => {
372381373382expect(result.status).toBe("ran");
374383expect(sendTelegram).toHaveBeenCalled();
375-expect(store.commitments[0]).toMatchObject({
384+expectCommitmentFields(store.commitments[0], {
376385id: "cm_interview",
377386status: "sent",
378387attempts: 1,
@@ -387,7 +396,7 @@ describe("runHeartbeatOnce commitments", () => {
387396388397expect(result.status).toBe("ran");
389398expect(sendTelegram).not.toHaveBeenCalled();
390-expect(store.commitments[0]).toMatchObject({
399+expectCommitmentFields(store.commitments[0], {
391400id: "cm_interview",
392401status: "dismissed",
393402attempts: 1,
@@ -403,7 +412,7 @@ describe("runHeartbeatOnce commitments", () => {
403412404413expect(result.status).toBe("ran");
405414expect(sendTelegram).not.toHaveBeenCalled();
406-expect(store.commitments[0]).toMatchObject({
415+expectCommitmentFields(store.commitments[0], {
407416id: "cm_interview",
408417status: "dismissed",
409418attempts: 1,
@@ -424,7 +433,7 @@ describe("runHeartbeatOnce commitments", () => {
424433425434expect(result.status).toBe("ran");
426435expect(sendTelegram).toHaveBeenCalled();
427-expect(store.commitments[0]).toMatchObject({
436+expectCommitmentFields(store.commitments[0], {
428437id: "cm_interview",
429438status: "sent",
430439attempts: 1,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。