Skip to content

Commit d5025f2

Browse files
committed
test(gateway): cover hook account replay scope
1 parent 9e041cd commit d5025f2

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

‎src/gateway/server.hooks-session-mode.test.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ async function waitForCronRuns(count: number): Promise<void> {
4747

4848
function cronRunCall(index = 0): {
4949
sessionKey?: string;
50-
job?: { sessionTarget?: string };
50+
job?: { sessionTarget?: string; delivery?: { accountId?: string } };
5151
} {
5252
const call = cronIsolatedRun.mock.calls.at(index)?.[0];
5353
if (!call || typeof call !== "object") {
@@ -244,4 +244,38 @@ describe("gateway hook session mode", () => {
244244
expect(cronRunCall(1).job?.sessionTarget).toBe("session:hook:mode:42");
245245
});
246246
});
247+
248+
test("keeps account id in the idempotency dispatch scope", async () => {
249+
testState.hooksConfig = {
250+
enabled: true,
251+
token: HOOK_TOKEN,
252+
};
253+
await withGatewayServer(async ({ port }) => {
254+
mockRunsOk();
255+
const headers = { "Idempotency-Key": "hook-idem-account-id" };
256+
const basePayload = {
257+
message: "Do it",
258+
channel: "discord",
259+
to: "channel-1",
260+
};
261+
const work = await postHook(
262+
port,
263+
"/hooks/agent",
264+
{ ...basePayload, accountId: "work" },
265+
headers,
266+
);
267+
expect(work.status).toBe(200);
268+
const personal = await postHook(
269+
port,
270+
"/hooks/agent",
271+
{ ...basePayload, accountId: "personal" },
272+
headers,
273+
);
274+
expect(personal.status).toBe(200);
275+
await waitForCronRuns(2);
276+
277+
expect(cronRunCall(0).job?.delivery?.accountId).toBe("work");
278+
expect(cronRunCall(1).job?.delivery?.accountId).toBe("personal");
279+
});
280+
});
247281
});

0 commit comments

Comments
 (0)