

















@@ -1,9 +1,14 @@
11import { afterEach, describe, expect, it, vi } from "vitest";
2+import {
3+__testing as sessionBindingServiceTesting,
4+registerSessionBindingAdapter,
5+} from "../infra/outbound/session-binding-service.js";
26import type { AgentInternalEvent } from "./internal-events.js";
37import {
48__testing,
59deliverSubagentAnnouncement,
610extractThreadCompletionFallbackText,
11+resolveSubagentCompletionOrigin,
712} from "./subagent-announce-delivery.js";
813import {
914callGateway as runtimeCallGateway,
@@ -14,6 +19,7 @@ import { resetAnnounceQueuesForTests } from "./subagent-announce-queue.js";
14191520afterEach(() => {
1621resetAnnounceQueuesForTests();
22+sessionBindingServiceTesting.resetSessionBindingAdaptersForTests();
1723__testing.setDepsForTest();
1824});
1925@@ -270,6 +276,77 @@ describe("resolveAnnounceOrigin threaded route targets", () => {
270276});
271277});
272278279+describe("resolveSubagentCompletionOrigin", () => {
280+it("resolves bound completion delivery from the requester session, not the child session", async () => {
281+registerSessionBindingAdapter({
282+channel: "discord",
283+accountId: "bot-alpha",
284+listBySession: (targetSessionKey: string) => {
285+if (targetSessionKey === "agent:worker:subagent:child") {
286+return [
287+{
288+bindingId: "discord:bot-alpha:child-window",
289+ targetSessionKey,
290+targetKind: "subagent",
291+conversation: {
292+channel: "discord",
293+accountId: "bot-alpha",
294+conversationId: "child-window",
295+},
296+status: "active",
297+boundAt: 1,
298+},
299+];
300+}
301+return [];
302+},
303+resolveByConversation: () => null,
304+});
305+registerSessionBindingAdapter({
306+channel: "discord",
307+accountId: "acct-1",
308+listBySession: (targetSessionKey: string) => {
309+if (targetSessionKey === "agent:main:main") {
310+return [
311+{
312+bindingId: "discord:acct-1:parent-main",
313+ targetSessionKey,
314+targetKind: "session",
315+conversation: {
316+channel: "discord",
317+accountId: "acct-1",
318+conversationId: "parent-main",
319+},
320+status: "active",
321+boundAt: 1,
322+},
323+];
324+}
325+return [];
326+},
327+resolveByConversation: () => null,
328+});
329+330+const origin = await resolveSubagentCompletionOrigin({
331+childSessionKey: "agent:worker:subagent:child",
332+requesterSessionKey: "agent:main:main",
333+requesterOrigin: {
334+channel: "discord",
335+accountId: "acct-1",
336+to: "channel:parent-main",
337+},
338+spawnMode: "session",
339+expectsCompletionMessage: true,
340+});
341+342+expect(origin).toEqual({
343+channel: "discord",
344+accountId: "acct-1",
345+to: "channel:parent-main",
346+});
347+});
348+});
349+273350describe("deliverSubagentAnnouncement queued delivery", () => {
274351async function deliverQueuedAnnouncement(params: {
275352requesterOrigin?: {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。