

























@@ -33,8 +33,22 @@ type DeliveryRequest = DeliveryIntentCallbackParams & {
33333434const cfg = {} as OpenClawConfig;
353536+function requireMockCall(
37+mock: { mock: { calls: unknown[][] } },
38+callIndex: number,
39+label: string,
40+): unknown[] {
41+const call = mock.mock.calls.at(callIndex);
42+if (!call) {
43+throw new Error(`expected ${label} call ${callIndex}`);
44+}
45+return call;
46+}
47+3648function latestDeliveryRequest(): DeliveryRequest {
37-const [request] = deliverOutboundPayloads.mock.calls.at(-1) as unknown as [DeliveryRequest];
49+const [request] = requireMockCall(deliverOutboundPayloads, -1, "delivery request") as [
50+DeliveryRequest,
51+];
3852return request;
3953}
4054@@ -293,7 +307,7 @@ describe("withDurableMessageSendContext", () => {
293307);
294308295309expect(onEditReceipt).toHaveBeenCalledTimes(1);
296-const [editReceiptArg, renderedArg] = onEditReceipt.mock.calls[0] as unknown as [
310+const [editReceiptArg, renderedArg] = requireMockCall(onEditReceipt, 0, "edit receipt") as [
297311unknown,
298312{ payloads?: unknown },
299313];
@@ -353,7 +367,7 @@ describe("withDurableMessageSendContext", () => {
353367expect(result.reason).toBe("no_visible_result");
354368expect(result.deliveryIntent?.id).toBe("intent-2");
355369expect(onCommitReceipt).toHaveBeenCalledTimes(1);
356-const [receiptArg] = onCommitReceipt.mock.calls[0] as unknown as [
370+const [receiptArg] = requireMockCall(onCommitReceipt, 0, "commit receipt") as [
357371{ platformMessageIds?: unknown },
358372];
359373expect(receiptArg.platformMessageIds).toEqual([]);
@@ -388,7 +402,7 @@ describe("withDurableMessageSendContext", () => {
388402hookEffect: { cancelReason: "owned-by-other-agent" },
389403});
390404expect(onCommitReceipt).toHaveBeenCalledTimes(1);
391-const [receiptArg] = onCommitReceipt.mock.calls[0] as unknown as [
405+const [receiptArg] = requireMockCall(onCommitReceipt, 0, "commit receipt") as [
392406{ platformMessageIds?: unknown },
393407];
394408expect(receiptArg.platformMessageIds).toEqual([]);
@@ -420,7 +434,7 @@ describe("withDurableMessageSendContext", () => {
420434reason: "cancelled_by_message_sending_hook",
421435});
422436expect(onPayloadDeliveryOutcome).toHaveBeenCalledTimes(1);
423-const [outcomeArg] = onPayloadDeliveryOutcome.mock.calls[0] as unknown as [
437+const [outcomeArg] = requireMockCall(onPayloadDeliveryOutcome, 0, "payload outcome") as [
424438OutboundPayloadDeliveryOutcome,
425439];
426440expect(outcomeArg.index).toBe(0);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。