fix(qa): preserve paginated bus events (#111410)

This commit is contained in:
Peter Steinberger
2026-07-19 06:34:35 -07:00
committed by GitHub
parent 4e008cd713
commit d0f37bd843
2 changed files with 43 additions and 6 deletions
+9 -6
View File
@@ -176,12 +176,15 @@ export function pollQaBusEvents(params: {
requestedCursor: params.input?.cursor,
});
const limit = Math.max(1, Math.min(params.input?.limit ?? 100, 500));
const matches = params.events
.filter((event) => event.accountId === accountId && event.cursor > effectiveStartCursor)
.slice(0, limit)
.map((event) => cloneEvent(event));
const matchingEvents = params.events.filter(
(event) => event.accountId === accountId && event.cursor > effectiveStartCursor,
);
const page = matchingEvents.slice(0, limit);
// A limited page may advance only through events it returns. Jumping to the
// bus-wide cursor would make every remaining account event unreachable.
const nextCursor = matchingEvents.length > page.length ? page.at(-1)?.cursor : params.cursor;
return {
cursor: params.cursor,
events: matches,
cursor: nextCursor ?? params.cursor,
events: page.map((event) => cloneEvent(event)),
};
}
+34
View File
@@ -200,6 +200,40 @@ describe("qa-bus server", () => {
).toEqual([queuedAfterReset.id]);
});
it("paginates a burst without advancing past events omitted by the poll limit", async () => {
const state = createQaBusState();
const bus = await startQaBusServer({ state });
stops.push(bus["stop"]);
for (let index = 1; index <= 101; index += 1) {
state.addInboundMessage({
accountId: "acct-a",
conversation: { id: "burst", kind: "direct" },
senderId: "acct-a-user",
text: `burst event ${index}`,
});
}
const firstPage = await pollQaBus({
baseUrl: bus.baseUrl,
accountId: "acct-a",
cursor: 0,
timeoutMs: 0,
});
expect(firstPage.events).toHaveLength(100);
expect(firstPage.cursor).toBe(100);
const secondPage = await pollQaBus({
baseUrl: bus.baseUrl,
accountId: "acct-a",
cursor: firstPage.cursor,
timeoutMs: 0,
});
expect(secondPage.events).toHaveLength(1);
expect(secondPage.events[0]?.cursor).toBe(101);
expect(secondPage.cursor).toBe(101);
});
it("rejects malformed poll numeric fields before long-polling", async () => {
const state = createQaBusState();
const bus = await startQaBusServer({ state });