fix(pdf-server): detached-buffer on range re-request + stale e2e assertion (#561)

* fix(pdf-server): slice bytes before onDataRange to avoid detached buffer

PDF.js transfers the ArrayBuffer to its worker via postMessage, detaching
it in the main thread. When the same range is re-requested (common on
iOS/WKWebView under memory pressure during scroll/zoom/navigate), the
cached Uint8Array now wraps a detached buffer and onDataRange throws
'Buffer is already detached'.

Fix: pass result.bytes.slice() so the rangeCache entry stays valid.

* test(e2e): update pdf-annotations assertion for new display_pdf prompt text

The 91880a6d prompt rewrite changed the interact-enabled result text from
'Displaying PDF (viewUUID: ...)' to 'PDF opened. viewUUID: ...'. The e2e
test was still asserting the old string.
This commit is contained in:
Olivier Chafik 2026-03-23 20:17:25 +00:00 • committed by GitHub
commit e8a4ea5f89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -50,7 +50,7 @@ async function extractViewUUID(page: Page): Promise<string> {
const resultText = (await resultContent.textContent()) ?? "";
// Extract viewUUID from the JSON result
// The text content includes: "Displaying PDF (viewUUID: <uuid>): ..."
// The text content includes: "PDF opened. viewUUID: <uuid>"
const match = resultText.match(/viewUUID["\s:]+([a-f0-9-]{36})/);
if (!match) {
throw new Error(
@ -107,7 +107,7 @@ test.describe("PDF Server - Annotations", () => {
// (interact action list lives in the tool description, not the runtime result).
expect(resultText).toContain("viewUUID");
expect(resultText).toContain("interactEnabled");
expect(resultText).toContain("Displaying PDF");
expect(resultText).toContain("PDF opened");
});
test("interact tool is available in tool dropdown", async ({ page }) => {