Skip to content

Commit 453c049

Browse files
authored
test(telegram): table-drive funnel-parity chunk boundaries for streamed final pagination (#104760)
The behavior fix landed on main in #104608 (fe3884a): draft-stream final pagination now routes markdownSource previews through markdownToTelegramChunks, the same chunker the durable reply funnel uses (delivery.replies.ts buildChunkTextResolver), and the overflow-pagination golden was re-recorded on safe boundaries there. This adds the missing parity regression coverage: table-driven cases for mid-word, mid-entity, mid-tag, and fenced code-block page boundaries assert the streamed pages equal the durable chunker's HTML chunks exactly, and that retained/current page snapshots carry the durable plainText projection so an HTML-parse 400 degrades both funnels identically. Formatting proof: Testbox tbx_01kx9n9q7rksfxgr5baj0esw57 check:changed format lane passed on this diff (local worktree has no node_modules for the hook).
1 parent c059d7d commit 453c049

1 file changed

Lines changed: 68 additions & 25 deletions

File tree

‎extensions/telegram/src/draft-stream.test.ts‎

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,33 +1282,76 @@ describe("createTelegramDraftStream", () => {
12821282
});
12831283
});
12841284

1285-
it("shares durable Markdown chunk boundaries with final draft pagination", async () => {
1286-
const api = createMockDraftApi();
1287-
const text = Array.from(
1288-
{ length: 12 },
1289-
(_, index) =>
1290-
`**${String(index).padStart(2, "0")}** overflow pagination line with filler text`,
1291-
).join("\n");
1292-
const maxChars = 80;
1293-
const expectedChunks = markdownToTelegramChunks(text, maxChars);
1294-
const stream = createDraftStream(api, {
1295-
maxChars,
1296-
renderText: (value) => ({
1297-
text: renderTelegramHtmlText(value),
1298-
parseMode: "HTML",
1299-
markdownSource: { text: value },
1300-
}),
1301-
});
1285+
// Send funnel parity (extensions/telegram/CLAUDE.md): streamed FINAL pages must
1286+
// land on the exact chunk boundaries the durable reply funnel produces
1287+
// (delivery.replies.ts buildChunkTextResolver -> markdownToTelegramChunks), so
1288+
// pagination never splits mid-word, inside an HTML entity, or inside a tag.
1289+
it.each([
1290+
{
1291+
boundary: "mid-word",
1292+
maxChars: 96,
1293+
text: Array.from(
1294+
{ length: 18 },
1295+
(_, index) => `sesquipedalian${index} incontrovertible counterrevolutionaries`,
1296+
).join(" "),
1297+
},
1298+
{
1299+
boundary: "mid-entity",
1300+
maxChars: 96,
1301+
text: Array.from({ length: 24 }, (_, index) => `alpha & beta < gamma > delta ${index}`).join(
1302+
"\n",
1303+
),
1304+
},
1305+
{
1306+
boundary: "mid-tag",
1307+
maxChars: 112,
1308+
text: Array.from(
1309+
{ length: 16 },
1310+
(_, index) =>
1311+
`**bold span ${index}** plus [link ${index}](https://example.com/p${index}) and \`code${index}\``,
1312+
).join("\n"),
1313+
},
1314+
{
1315+
boundary: "code-block",
1316+
maxChars: 128,
1317+
text: [
1318+
"Intro paragraph before the fence.",
1319+
"```ts",
1320+
...Array.from({ length: 20 }, (_, index) => `const value${index} = compute(${index});`),
1321+
"```",
1322+
"Closing paragraph after the fence.",
1323+
].join("\n"),
1324+
},
1325+
])(
1326+
"shares durable chunk boundaries with final draft pagination ($boundary)",
1327+
async ({ maxChars, text }) => {
1328+
const api = createMockDraftApi();
1329+
const expectedChunks = markdownToTelegramChunks(text, maxChars);
1330+
// Guard the table: a case that fits in one page proves nothing about boundaries.
1331+
expect(expectedChunks.length).toBeGreaterThan(1);
1332+
const retainedPageTexts: string[] = [];
1333+
const stream = createDraftStream(api, {
1334+
maxChars,
1335+
onRetainedPage: (page) => retainedPageTexts.push(page.textSnapshot),
1336+
renderText: (value) => ({
1337+
text: renderTelegramHtmlText(value),
1338+
parseMode: "HTML",
1339+
markdownSource: { text: value },
1340+
}),
1341+
});
13021342

1303-
stream.update(text);
1304-
await stream.stop();
1343+
stream.update(text);
1344+
await stream.stop();
13051345

1306-
const pages = api.sendMessage.mock.calls.map((call) => call[1]);
1307-
expect(pages).toEqual(expectedChunks.map((chunk) => chunk.html));
1308-
expect(pages.map(telegramHtmlToPlainTextFallback)).toEqual(
1309-
expectedChunks.map((chunk) => chunk.text),
1310-
);
1311-
});
1346+
const pages = api.sendMessage.mock.calls.map((call) => call[1]);
1347+
expect(pages).toEqual(expectedChunks.map((chunk) => chunk.html));
1348+
// Plain-fallback parity: each page must carry the durable funnel's plainText
1349+
// projection so an HTML-parse 400 degrades both funnels to identical text.
1350+
expect([...retainedPageTexts, stream.currentMessageSnapshot?.()?.text]).toEqual(
1351+
expectedChunks.map((chunk) => chunk.text),
1352+
);
1353+
},
1354+
);
13121355

13131356
it("paginates one rendered rich-code plan without reparsing Markdown tails", async () => {
13141357
const api = createMockDraftApi();

0 commit comments

Comments
 (0)