test(frontend): guard wasm shipping at build time, drop CI-fragile pixel test
The in-browser pixel-render fixture test was green locally but flaky in CI: the real pdf.js worker could not fetch /pdfjs-wasm/ in the CI Chromium container, so the CCITT canvas stayed blank (0 sampled pixels) and failed the suite — green locally, red in CI, root cause not locally reproducible. A flaky gate is worse than none. This bug is a build/serve parity failure, so guard it deterministically where it actually breaks: a postbuild assertion that jbig2.wasm and openjpeg.wasm shipped into build/client/pdfjs-wasm/ (non-empty). It runs after `npm run build` — including the Docker build stage — and fails the build loudly if a future pdfjs bump makes the static-copy glob match nothing. Combined with the getDocument(wasmUrl) unit guard and the negative-path render test, the regression is covered without CI flake. Addresses re-review: Tobias (no automated parity check), Sara (pixel test not pinned). Render-decode correctness verified manually via `node build` serving /pdfjs-wasm/jbig2.wasm as application/wasm. Refs #708 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
29
frontend/scripts/assert-pdfjs-wasm.mjs
Normal file
29
frontend/scripts/assert-pdfjs-wasm.mjs
Normal file
@@ -0,0 +1,29 @@
|
||||
// Build-time guard for issue #708. The pdf.js wasm image decoders are copied
|
||||
// into build/client/pdfjs-wasm/ by vite-plugin-static-copy. If a future
|
||||
// pdfjs-dist bump moves or renames the wasm, the glob could silently copy
|
||||
// nothing — and CCITT/JBIG2/JPEG2000 scans would render blank in production
|
||||
// again with no test catching it (the bug is invisible to unit tests). Fail
|
||||
// the build loudly instead. Runs after `npm run build` (incl. the Docker
|
||||
// build stage) via the `postbuild` npm script.
|
||||
import { existsSync, statSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
|
||||
const dir = join(process.cwd(), 'build', 'client', 'pdfjs-wasm');
|
||||
// jbig2.wasm decodes JBIG2 + CCITTFax; openjpeg.wasm decodes JPEG2000.
|
||||
const required = ['jbig2.wasm', 'openjpeg.wasm'];
|
||||
|
||||
const missing = required.filter((f) => {
|
||||
const p = join(dir, f);
|
||||
return !existsSync(p) || statSync(p).size === 0;
|
||||
});
|
||||
|
||||
if (missing.length > 0) {
|
||||
console.error(
|
||||
`\n[assert-pdfjs-wasm] MISSING from build output: ${missing.join(', ')}\n` +
|
||||
`Expected non-empty files in ${dir}.\n` +
|
||||
`The pdf.js wasm decoders did not ship — scanned PDFs would render blank.\n` +
|
||||
`Check the vite-plugin-static-copy target in vite.config.ts and that\n` +
|
||||
`node_modules/pdfjs-dist/wasm/ still contains these files. See issue #708.\n`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
Reference in New Issue
Block a user