

























@@ -69,6 +69,50 @@ function visibleAgentResponse(runId = "run-main") {
6969};
7070}
717172+function expectInputProvenance(
73+params: Record<string, unknown> | undefined,
74+sourceSessionKey: string,
75+) {
76+const inputProvenance = params?.inputProvenance;
77+expect(inputProvenance).toBeTruthy();
78+if (!inputProvenance || typeof inputProvenance !== "object") {
79+throw new Error("Expected input provenance");
80+}
81+const provenance = inputProvenance as Record<string, unknown>;
82+expect(provenance.kind).toBe("inter_session");
83+expect(provenance.sourceSessionKey).toBe(sourceSessionKey);
84+expect(provenance.sourceTool).toBe("subagent_announce");
85+}
86+87+function getAgentCall(index = 0): AgentCallRequest {
88+const call = agentSpy.mock.calls[index]?.[0];
89+expect(call).toBeDefined();
90+if (!call) {
91+throw new Error(`Expected agent call at index ${index}`);
92+}
93+return call;
94+}
95+96+function expectAgentCallFields(
97+call: AgentCallRequest,
98+expected: {
99+channel?: string;
100+deliver?: boolean;
101+sessionKey: string;
102+to?: string;
103+},
104+) {
105+expect(call.method).toBe("agent");
106+expect(call.params?.sessionKey).toBe(expected.sessionKey);
107+expect(call.params?.deliver).toBe(expected.deliver);
108+if ("channel" in expected) {
109+expect(call.params?.channel).toBe(expected.channel);
110+}
111+if ("to" in expected) {
112+expect(call.params?.to).toBe(expected.to);
113+}
114+}
115+72116const agentSpy = vi.fn(async (_req: AgentCallRequest) => visibleAgentResponse());
73117const sendSpy = vi.fn(async (_req: AgentCallRequest) => ({ runId: "send-main", status: "ok" }));
74118const sessionsDeleteSpy = vi.fn((_req: AgentCallRequest) => undefined);
@@ -695,11 +739,7 @@ describe("subagent announce formatting", () => {
695739expect(call?.params?.channel).toBe("discord");
696740expect(call?.params?.to).toBe("channel:12345");
697741expect(call?.params?.sessionKey).toBe("agent:main:main");
698-expect(call?.params?.inputProvenance).toMatchObject({
699-kind: "inter_session",
700-sourceSessionKey: "agent:main:subagent:test",
701-sourceTool: "subagent_announce",
702-});
742+expectInputProvenance(call?.params, "agent:main:subagent:test");
703743expect(msg).toContain("final answer: 2");
704744expect(msg).not.toContain("✅ Subagent");
705745});
@@ -1171,9 +1211,8 @@ describe("subagent announce formatting", () => {
11711211const directTargets = agentSpy.mock.calls.map(
11721212(call) => (call?.[0] as { params?: { to?: string } })?.params?.to,
11731213);
1174-expect(directTargets).toEqual(
1175-expect.arrayContaining(["channel:thread-child-a", "channel:thread-child-b"]),
1176-);
1214+expect(directTargets).toContain("channel:thread-child-a");
1215+expect(directTargets).toContain("channel:thread-child-b");
11771216expect(directTargets).not.toContain("channel:main-parent-channel");
11781217});
11791218@@ -1859,12 +1898,9 @@ describe("subagent announce formatting", () => {
18591898expect(didAnnounce).toBe(true);
18601899expect(sendSpy).toHaveBeenCalledTimes(0);
18611900expect(agentSpy).toHaveBeenCalledTimes(1);
1862-expect(agentSpy.mock.calls[0]?.[0]).toMatchObject({
1863-method: "agent",
1864-params: {
1865-sessionKey: "agent:main:main",
1866-deliver: false,
1867-},
1901+expectAgentCallFields(getAgentCall(), {
1902+sessionKey: "agent:main:main",
1903+deliver: false,
18681904});
18691905});
18701906@@ -1888,14 +1924,11 @@ describe("subagent announce formatting", () => {
18881924expect(didAnnounce).toBe(true);
18891925expect(sendSpy).not.toHaveBeenCalled();
18901926expect(agentSpy).toHaveBeenCalledTimes(1);
1891-expect(agentSpy.mock.calls[0]?.[0]).toMatchObject({
1892-method: "agent",
1893-params: {
1894-sessionKey: "agent:main:main",
1895-channel: "discord",
1896-to: "channel:12345",
1897-deliver: true,
1898-},
1927+expectAgentCallFields(getAgentCall(), {
1928+sessionKey: "agent:main:main",
1929+channel: "discord",
1930+to: "channel:12345",
1931+deliver: true,
18991932});
19001933});
19011934@@ -2118,7 +2151,8 @@ describe("subagent announce formatting", () => {
21182151const accountIds = agentSpy.mock.calls.map(
21192152(call) => (call?.[0] as { params?: { accountId?: string } })?.params?.accountId,
21202153);
2121-expect(accountIds).toEqual(expect.arrayContaining(["acct-a", "acct-b"]));
2154+expect(accountIds).toContain("acct-a");
2155+expect(accountIds).toContain("acct-b");
21222156});
2123215721242158it.each([
@@ -2206,11 +2240,7 @@ describe("subagent announce formatting", () => {
22062240expect(call?.params?.channel).toBeUndefined();
22072241expect(call?.params?.to).toBeUndefined();
22082242expect((call?.params as { role?: unknown } | undefined)?.role).toBeUndefined();
2209-expect(call?.params?.inputProvenance).toMatchObject({
2210-kind: "inter_session",
2211-sourceSessionKey: "agent:main:subagent:worker",
2212-sourceTool: "subagent_announce",
2213-});
2243+expectInputProvenance(call?.params, "agent:main:subagent:worker");
22142244});
2215224522162246it("keeps completion-mode announce internal for nested requester subagent sessions", async () => {
@@ -2234,11 +2264,7 @@ describe("subagent announce formatting", () => {
22342264expect(call?.params?.deliver).toBe(false);
22352265expect(call?.params?.channel).toBeUndefined();
22362266expect(call?.params?.to).toBeUndefined();
2237-expect(call?.params?.inputProvenance).toMatchObject({
2238-kind: "inter_session",
2239-sourceSessionKey: "agent:main:subagent:orchestrator:subagent:worker",
2240-sourceTool: "subagent_announce",
2241-});
2267+expectInputProvenance(call?.params, "agent:main:subagent:orchestrator:subagent:worker");
22422268const message = typeof call?.params?.message === "string" ? call.params.message : "";
22432269expect(message).toContain(
22442270"Convert this completion into a concise internal orchestration update for your parent agent",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。