mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
fix(qa): preserve paginated bus events (#111410)
This commit is contained in:
@@ -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)),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user