Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/plugin-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,17 @@ export async function handlePluginRender(req: http.IncomingMessage, res: http.Se
const coveredSeqs = new Set<number>();
const anchors: { pos: number; msg: BiliMessage }[] = [];
for (const block of activeBlocks) {
const blockSeqs: number[] = [];
let maxCover: number | undefined;
for (const id of block.effectiveMessageIds) {
const seq = idToSeq.get(id);
if (seq !== undefined) blockSeqs.push(seq);
if (seq !== undefined) {
coveredSeqs.add(seq);
maxCover = maxCover === undefined ? seq : Math.max(maxCover, seq);
}
}
if (blockSeqs.length === 0) continue;
for (const s of blockSeqs) coveredSeqs.add(s);
const maxCover = Math.max(...blockSeqs);
const pos = viewRows.findIndex((r) => r.seq > maxCover);
if (maxCover === undefined) continue;
const lastCoveredSeq = maxCover;
const pos = viewRows.findIndex((r) => r.seq > lastCoveredSeq);
// #4732: pos === -1 means the fold reaches the END of the window — the
// covered rows are suppressed below, so the anchor MUST still land
// (at the tail) or the rendered prefix silently drops the whole fold
Expand Down
35 changes: 34 additions & 1 deletion tests/plugin-render-endpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { startServer } from "../src/server.ts";
import type { ProxyOptions } from "../src/config.ts";
import { SessionStore, _setStoreForTest } from "../src/persist.ts";
import { _resetPluginStateForTest } from "../src/plugin.ts";
import { _resetSessionsForTest } from "../src/session.ts";
import { getSession, _resetSessionsForTest } from "../src/session.ts";
import type { MessageRow } from "../src/storage/store.ts";
import { _setForTest } from "../src/registry.ts";
import { resetToolRingForTest } from "../src/tool-ring.ts";
import { __resetIncrementalLaneForTests } from "../src/incremental-lane.js";
Expand Down Expand Up @@ -263,3 +264,35 @@ test("S5 guard rails: poison msgids hard-fail; count mismatch degrades silently"
await h.close();
}
});

test("render handles a fold covering 150000 rows without a function-argument limit", async (t) => {
const h = await harness(true);
try {
const count = 150_000;
const conv = "large-render";
let rows: MessageRow[] = Array.from({ length: count + 1 }, (_, i) => ({
seq: i * 2, msgId: `raw-${i}`, ref: null, refNum: null, role: "user", kind: "message",
content: JSON.stringify({ id: `raw-${i}`, role: "user", contentType: "text", text: i === count ? "uncovered tail" : `covered ${i}` }),
}));
t.mock.method(h.store, "unifiedTailViewRows", () => rows);
t.mock.method(h.store, "unifiedTailSeqs", () => rows.map((row) => row.seq));
const session = getSession(conv);
(session.state.blocks as unknown[]).push({
blockId: "large", active: true,
effectiveMessageIds: [...rows.slice(0, count).map((row) => row.msgId).reverse(), "outside-view"],
});
const rendered = await h.render({ conversationId: conv, untilSeq: count + 1 });
assert.equal(rendered.status, 200, JSON.stringify(rendered.body));
const output = rendered.body as { appliedSeq: number; messages: { content: { type: string; text?: string }[] }[] };
assert.equal(output.appliedSeq, count + 1);
assert.deepEqual(output.messages.flatMap((message) => message.content.map((part) => part.text)), ["", "uncovered tail"]);

rows = [{ ...rows[count]!, seq: 0 }];
const unresolved = await h.render({ conversationId: conv, untilSeq: 1 });
assert.equal(unresolved.status, 200);
const unchanged = unresolved.body as { messages: { content: { text?: string }[] }[] };
assert.deepEqual(unchanged.messages.flatMap((message) => message.content.map((part) => part.text)), ["uncovered tail"]);
} finally {
await h.close();
}
});
Loading