fix: preserve discord announce account routing

This commit is contained in:
Peter Steinberger
2026-05-02 12:50:19 +01:00
parent 3ee41deba9
commit cd84e9bfb0
6 changed files with 78 additions and 4 deletions

View File

@@ -3,8 +3,15 @@ import type { CallGatewayOptions } from "../../gateway/call.js";
import { setActivePluginRegistry } from "../../plugins/runtime.js";
import { createSessionConversationTestRegistry } from "../../test-utils/session-conversation-registry.js";
import { runAgentStep } from "./agent-step.js";
import type { SessionListRow } from "./sessions-helpers.js";
import { runSessionsSendA2AFlow, __testing } from "./sessions-send-tool.a2a.js";
const callGatewayMock = vi.hoisted(() => vi.fn());
vi.mock("../../gateway/call.js", () => ({
callGateway: (opts: unknown) => callGatewayMock(opts),
}));
vi.mock("../run-wait.js", () => ({
waitForAgentRun: vi.fn().mockResolvedValue({ status: "ok" }),
readLatestAssistantReply: vi.fn().mockResolvedValue("Test announce reply"),
@@ -16,17 +23,25 @@ vi.mock("./agent-step.js", () => ({
describe("runSessionsSendA2AFlow announce delivery", () => {
let gatewayCalls: CallGatewayOptions[];
let sessionListRows: SessionListRow[];
beforeEach(() => {
setActivePluginRegistry(createSessionConversationTestRegistry());
gatewayCalls = [];
sessionListRows = [];
callGatewayMock.mockReset();
const callGateway = async <T = Record<string, unknown>>(opts: CallGatewayOptions) => {
gatewayCalls.push(opts);
if (opts.method === "sessions.list") {
return { sessions: sessionListRows } as T;
}
return {} as T;
};
callGatewayMock.mockImplementation(callGateway);
vi.clearAllMocks();
vi.mocked(runAgentStep).mockResolvedValue("Test announce reply");
__testing.setDepsForTest({
callGateway: async <T = Record<string, unknown>>(opts: CallGatewayOptions) => {
gatewayCalls.push(opts);
return {} as T;
},
callGateway,
});
});
@@ -70,6 +85,55 @@ describe("runSessionsSendA2AFlow announce delivery", () => {
expect(sendParams.threadId).toBeUndefined();
});
it.each([
{
source: "deliveryContext.accountId",
accountId: "thinker",
session: {
key: "agent:main:discord:channel:target-room",
kind: "group",
channel: "discord",
deliveryContext: {
channel: "discord",
to: "channel:target-room",
accountId: "thinker",
},
} satisfies SessionListRow,
},
{
source: "lastAccountId",
accountId: "scout",
session: {
key: "agent:main:discord:channel:target-room",
kind: "group",
channel: "discord",
lastChannel: "discord",
lastTo: "channel:target-room",
lastAccountId: "scout",
} satisfies SessionListRow,
},
])("uses Discord session $source for announce accountId", async ({ accountId, session }) => {
sessionListRows = [session];
await runSessionsSendA2AFlow({
targetSessionKey: session.key,
displayKey: session.key,
message: "Test message",
announceTimeoutMs: 10_000,
maxPingPongTurns: 0,
roundOneReply: "Worker completed successfully",
});
expect(gatewayCalls.some((call) => call.method === "sessions.list")).toBe(true);
const sendCall = gatewayCalls.find((call) => call.method === "send");
expect(sendCall).toBeDefined();
expect(sendCall?.params).toMatchObject({
channel: "discord",
to: "channel:target-room",
accountId,
});
});
it.each(["NO_REPLY", "HEARTBEAT_OK", "ANNOUNCE_SKIP", "REPLY_SKIP"])(
"does not re-inject exact control reply %s into agent-to-agent flow",
async (roundOneReply) => {

View File

@@ -62,6 +62,7 @@ export function createSessionConversationTestRegistry() {
selectionLabel: "Discord",
docsPath: "/channels/discord",
blurb: "Discord test stub.",
preferSessionLookupForAnnounceTarget: true,
},
capabilities: { chatTypes: ["direct", "channel", "thread"] },
messaging: {