fix(pdf): make pdfjs survive bundling + real-PDF font fidelity (live smoke)

Live dispatch smoke against the Turbopack dev server (master's ask,
2026-09-19) caught two things unit tests cannot - they run unbundled:

- Bundling pdfjs-dist broke its node fake-worker: the chunk-relative
  pdf.worker.mjs import 404s inside .next/dev/server/chunks. Fix:
  serverExternalPackages + tracing includes for legacy/ + standard_fonts/
  (next.config.ts - a clearly-marked seam, same precedent as bcdcd51; the
  standalone output now ships the worker and font files, verified).
- Real-world PDFs warned about missing standardFontDataUrl (non-embedded
  standard fonts silently fall back) and flooded the log with JBIG2
  warnings on scanned files. Fix: standardFontsDir() + verbosity 0 in
  both the node ops and the headless canvas shim.

Verified live end-to-end on GEB (802pp, text layer): teacher dispatch,
12-step read with vision renders, brief with accurate page citations,
wake turn folding the resolution (Chapter IX, pp. 268-270) into the
lesson. Scanned/DRM Polya correctly refuses to fabricate citations.
This commit is contained in:
amosblomqvist
2026-09-19 16:23:20 +03:00
parent 31f600a365
commit 2780166904
3 changed files with 28 additions and 3 deletions
+9
View File
@@ -19,8 +19,16 @@ const nextConfig: NextConfig = {
// pi-ai's provider catalog (39 JSON files) vanished from the trace and
// the server 500s on module load. Include the whole data dirs of the
// runtime-loaded engine packages.
// pdfjs-dist (sources v0 live smoke, 2026-09-19): its legacy build loads
// the node fake worker (pdf.worker.mjs) and our standard_fonts dir via
// runtime-resolved paths — invisible to the tracer. Bundling (without
// serverExternalPackages below) additionally breaks the worker's
// import.meta.url resolution inside .next/dev chunks — the live smoke
// caught it; unit tests run unbundled and never see it.
outputFileTracingIncludes: {
"*": [
"node_modules/pdfjs-dist/legacy/**/*",
"node_modules/pdfjs-dist/standard_fonts/**/*",
"node_modules/@earendil-works/pi-ai/dist/providers/data/**/*",
"node_modules/@earendil-works/pi-agent-core/dist/**/*.json",
// onnxruntime-node: the .node binding was traced, but its
@@ -38,6 +46,7 @@ const nextConfig: NextConfig = {
"@earendil-works/pi-ai",
"@earendil-works/pi-agent-core",
"@huggingface/transformers",
"pdfjs-dist", // sources v0: bundling breaks its node fake-worker path
],
};