




















@@ -3,8 +3,15 @@ import type { CallGatewayOptions } from "../../gateway/call.js";
33import { setActivePluginRegistry } from "../../plugins/runtime.js";
44import { createSessionConversationTestRegistry } from "../../test-utils/session-conversation-registry.js";
55import { runAgentStep } from "./agent-step.js";
6+import type { SessionListRow } from "./sessions-helpers.js";
67import { runSessionsSendA2AFlow, __testing } from "./sessions-send-tool.a2a.js";
789+const callGatewayMock = vi.hoisted(() => vi.fn());
10+11+vi.mock("../../gateway/call.js", () => ({
12+callGateway: (opts: unknown) => callGatewayMock(opts),
13+}));
14+815vi.mock("../run-wait.js", () => ({
916waitForAgentRun: vi.fn().mockResolvedValue({ status: "ok" }),
1017readLatestAssistantReply: vi.fn().mockResolvedValue("Test announce reply"),
@@ -16,17 +23,25 @@ vi.mock("./agent-step.js", () => ({
16231724describe("runSessionsSendA2AFlow announce delivery", () => {
1825let gatewayCalls: CallGatewayOptions[];
26+let sessionListRows: SessionListRow[];
19272028beforeEach(() => {
2129setActivePluginRegistry(createSessionConversationTestRegistry());
2230gatewayCalls = [];
31+sessionListRows = [];
32+callGatewayMock.mockReset();
33+const callGateway = async <T = Record<string, unknown>>(opts: CallGatewayOptions) => {
34+gatewayCalls.push(opts);
35+if (opts.method === "sessions.list") {
36+return { sessions: sessionListRows } as T;
37+}
38+return {} as T;
39+};
40+callGatewayMock.mockImplementation(callGateway);
2341vi.clearAllMocks();
2442vi.mocked(runAgentStep).mockResolvedValue("Test announce reply");
2543__testing.setDepsForTest({
26-callGateway: async <T = Record<string, unknown>>(opts: CallGatewayOptions) => {
27-gatewayCalls.push(opts);
28-return {} as T;
29-},
44+ callGateway,
3045});
3146});
3247@@ -70,6 +85,55 @@ describe("runSessionsSendA2AFlow announce delivery", () => {
7085expect(sendParams.threadId).toBeUndefined();
7186});
728788+it.each([
89+{
90+source: "deliveryContext.accountId",
91+accountId: "thinker",
92+session: {
93+key: "agent:main:discord:channel:target-room",
94+kind: "group",
95+channel: "discord",
96+deliveryContext: {
97+channel: "discord",
98+to: "channel:target-room",
99+accountId: "thinker",
100+},
101+} satisfies SessionListRow,
102+},
103+{
104+source: "lastAccountId",
105+accountId: "scout",
106+session: {
107+key: "agent:main:discord:channel:target-room",
108+kind: "group",
109+channel: "discord",
110+lastChannel: "discord",
111+lastTo: "channel:target-room",
112+lastAccountId: "scout",
113+} satisfies SessionListRow,
114+},
115+])("uses Discord session $source for announce accountId", async ({ accountId, session }) => {
116+sessionListRows = [session];
117+118+await runSessionsSendA2AFlow({
119+targetSessionKey: session.key,
120+displayKey: session.key,
121+message: "Test message",
122+announceTimeoutMs: 10_000,
123+maxPingPongTurns: 0,
124+roundOneReply: "Worker completed successfully",
125+});
126+127+expect(gatewayCalls.some((call) => call.method === "sessions.list")).toBe(true);
128+const sendCall = gatewayCalls.find((call) => call.method === "send");
129+expect(sendCall).toBeDefined();
130+expect(sendCall?.params).toMatchObject({
131+channel: "discord",
132+to: "channel:target-room",
133+ accountId,
134+});
135+});
136+73137it.each(["NO_REPLY", "HEARTBEAT_OK", "ANNOUNCE_SKIP", "REPLY_SKIP"])(
74138"does not re-inject exact control reply %s into agent-to-agent flow",
75139async (roundOneReply) => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。