




















@@ -12,6 +12,41 @@ const mocks = vi.hoisted(() => ({
1212resolveOutboundTarget: vi.fn(() => ({ ok: true as const, to: "+15551234567" })),
1313}));
141415+type DeliveryCall = {
16+accountId?: string;
17+session?: {
18+agentId?: string;
19+key?: string;
20+};
21+};
22+23+type ResolveTargetCall = {
24+accountId?: string;
25+channel?: string;
26+mode?: string;
27+to?: string;
28+};
29+30+function readDeliveryCall(): DeliveryCall {
31+expect(mocks.deliverOutboundPayloads).toHaveBeenCalledOnce();
32+const calls = mocks.deliverOutboundPayloads.mock.calls as unknown as Array<[unknown]>;
33+const call = calls[0]?.[0];
34+if (!call) {
35+throw new Error("Expected delivery call");
36+}
37+return call as DeliveryCall;
38+}
39+40+function readResolveTargetCall(): ResolveTargetCall {
41+expect(mocks.resolveOutboundTarget).toHaveBeenCalledOnce();
42+const calls = mocks.resolveOutboundTarget.mock.calls as unknown as Array<[unknown]>;
43+const call = calls[0]?.[0];
44+if (!call) {
45+throw new Error("Expected resolve target call");
46+}
47+return call as ResolveTargetCall;
48+}
49+1550vi.mock("../channels/plugins/index.js", () => ({
1651getChannelPlugin: mocks.getChannelPlugin,
1752getLoadedChannelPlugin: mocks.getChannelPlugin,
@@ -99,9 +134,7 @@ describe("deliverAgentCommandResult", () => {
99134} as SessionEntry,
100135});
101136102-expect(mocks.deliverOutboundPayloads).toHaveBeenCalledWith(
103-expect.objectContaining({ accountId: "kev" }),
104-);
137+expect(readDeliveryCall().accountId).toBe("kev");
105138});
106139107140it("falls back to session accountId for implicit delivery", async () => {
@@ -117,9 +150,7 @@ describe("deliverAgentCommandResult", () => {
117150} as SessionEntry,
118151});
119152120-expect(mocks.deliverOutboundPayloads).toHaveBeenCalledWith(
121-expect.objectContaining({ accountId: "legacy" }),
122-);
153+expect(readDeliveryCall().accountId).toBe("legacy");
123154});
124155125156it("does not infer accountId for explicit delivery targets", async () => {
@@ -136,12 +167,10 @@ describe("deliverAgentCommandResult", () => {
136167} as SessionEntry,
137168});
138169139-expect(mocks.resolveOutboundTarget).toHaveBeenCalledWith(
140-expect.objectContaining({ accountId: undefined, mode: "explicit" }),
141-);
142-expect(mocks.deliverOutboundPayloads).toHaveBeenCalledWith(
143-expect.objectContaining({ accountId: undefined }),
144-);
170+const targetCall = readResolveTargetCall();
171+expect(targetCall.accountId).toBeUndefined();
172+expect(targetCall.mode).toBe("explicit");
173+expect(readDeliveryCall().accountId).toBeUndefined();
145174});
146175147176it("skips session accountId when channel differs", async () => {
@@ -157,9 +186,9 @@ describe("deliverAgentCommandResult", () => {
157186} as SessionEntry,
158187});
159188160-expect(mocks.resolveOutboundTarget).toHaveBeenCalledWith(
161- expect.objectContaining({ accountId: undefined, channel: "whatsapp" }),
162-);
189+const targetCall = readResolveTargetCall();
190+expect(targetCall.accountId).toBeUndefined();
191+expect(targetCall.channel).toBe("whatsapp");
163192});
164193165194it("uses session last channel when none is provided", async () => {
@@ -174,9 +203,9 @@ describe("deliverAgentCommandResult", () => {
174203} as SessionEntry,
175204});
176205177-expect(mocks.resolveOutboundTarget).toHaveBeenCalledWith(
178- expect.objectContaining({ channel: "telegram", to: "123" }),
179-);
206+const targetCall = readResolveTargetCall();
207+expect(targetCall.channel).toBe("telegram");
208+expect(targetCall.to).toBe("123");
180209});
181210182211it("uses reply overrides for delivery routing", async () => {
@@ -196,9 +225,10 @@ describe("deliverAgentCommandResult", () => {
196225} as SessionEntry,
197226});
198227199-expect(mocks.resolveOutboundTarget).toHaveBeenCalledWith(
200-expect.objectContaining({ channel: "slack", to: "#reports", accountId: "ops" }),
201-);
228+const targetCall = readResolveTargetCall();
229+expect(targetCall.channel).toBe("slack");
230+expect(targetCall.to).toBe("#reports");
231+expect(targetCall.accountId).toBe("ops");
202232});
203233204234it("stays silent for intentional empty payloads", async () => {
@@ -234,9 +264,10 @@ describe("deliverAgentCommandResult", () => {
234264} as SessionEntry,
235265});
236266237-expect(mocks.resolveOutboundTarget).toHaveBeenCalledWith(
238-expect.objectContaining({ channel: "whatsapp", to: "+15559876543", accountId: "work" }),
239-);
267+const targetCall = readResolveTargetCall();
268+expect(targetCall.channel).toBe("whatsapp");
269+expect(targetCall.to).toBe("+15559876543");
270+expect(targetCall.accountId).toBe("work");
240271});
241272242273it("does not reuse session lastTo when runContext source omits currentChannelId", async () => {
@@ -254,9 +285,9 @@ describe("deliverAgentCommandResult", () => {
254285} as SessionEntry,
255286});
256287257-expect(mocks.resolveOutboundTarget).toHaveBeenCalledWith(
258- expect.objectContaining({ channel: "whatsapp", to: undefined }),
259-);
288+const targetCall = readResolveTargetCall();
289+expect(targetCall.channel).toBe("whatsapp");
290+expect(targetCall.to).toBeUndefined();
260291});
261292262293it("uses caller-provided outbound session context when opts.sessionKey is absent", async () => {
@@ -273,14 +304,9 @@ describe("deliverAgentCommandResult", () => {
273304},
274305});
275306276-expect(mocks.deliverOutboundPayloads).toHaveBeenCalledWith(
277-expect.objectContaining({
278-session: expect.objectContaining({
279-key: "agent:exec:hook:gmail:thread-1",
280-agentId: "exec",
281-}),
282-}),
283-);
307+const deliveryCall = readDeliveryCall();
308+expect(deliveryCall.session?.key).toBe("agent:exec:hook:gmail:thread-1");
309+expect(deliveryCall.session?.agentId).toBe("exec");
284310});
285311286312it("prefixes nested agent outputs with context", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。