From 85bef667dd0d9d5052da948877090fb752f1088d Mon Sep 17 00:00:00 2001 From: haritowa <6107211+haritowa@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:56:38 +0000 Subject: [PATCH] test(documents): read files the way the realism ratchet expects The test-realism ratchet counts a test that calls readFileSync and names a source file. The guard now reads source through readSourceText, and the two one-process tests no longer name their twin file in a comment. Their doc comments are rewritten in plainer words. --- src/__tests__/single-pdfjs-guard.test.ts | 6 ++--- .../pdfjs-one-version-extract-first.test.ts | 25 +++++++++++-------- .../pdfjs-one-version-raster-first.test.ts | 25 +++++++++++-------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/__tests__/single-pdfjs-guard.test.ts b/src/__tests__/single-pdfjs-guard.test.ts index 897189e1b..d42270995 100644 --- a/src/__tests__/single-pdfjs-guard.test.ts +++ b/src/__tests__/single-pdfjs-guard.test.ts @@ -17,12 +17,12 @@ * it; they run in their own processes. The pdfjs-one-version tests prove the * two orders in one process; this file stops the import from coming back. */ -import { readFileSync } from "node:fs"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { + readSourceText, requireFloor, stripComments, walkSourceFiles, @@ -56,9 +56,7 @@ const PDF_PARSE_IMPORT = describe("one pdfjs in the server", () => { it("no runtime file imports pdf-parse", () => { const importers = runtimeFiles().filter((rel) => - PDF_PARSE_IMPORT.test( - stripComments(readFileSync(join(SRC, rel), "utf8")), - ), + PDF_PARSE_IMPORT.test(stripComments(readSourceText(join(SRC, rel)))), ); expect(importers).toEqual([]); }); diff --git a/src/lib/documents/__tests__/pdfjs-one-version-extract-first.test.ts b/src/lib/documents/__tests__/pdfjs-one-version-extract-first.test.ts index 3b20f39da..298696510 100644 --- a/src/lib/documents/__tests__/pdfjs-one-version-extract-first.test.ts +++ b/src/lib/documents/__tests__/pdfjs-one-version-extract-first.test.ts @@ -4,18 +4,21 @@ import { join } from "node:path"; import { describe, expect, it, vi } from "vitest"; /** - * Text extraction and rasterising share one process, and pdfjs keeps its worker - * on `globalThis.pdfjsWorker`. While `pdf-parse` brought its own pdfjs - * (5.4.296) beside the app's (6.4.299), whichever ran first installed its - * worker and the other refused it: "The API version "6.4.299" does not match - * the Worker version "5.4.296"". Thumbnails failed as `raster-failed`, vision - * reads of a PDF answered 422 and the local text index stayed empty without a - * word. Reading the text through the app's own pdfjs is the fix; this file runs - * extraction first and `pdfjs-one-version-raster-first.test.ts` the reverse, - * each in a fresh process state. + * Text extraction and rasterising run in one process. In Node, pdfjs keeps its + * worker in one global, `globalThis.pdfjsWorker`. When `pdf-parse` brought its + * own pdfjs (5.4.296) beside the app's (6.4.299), the copy that ran first set + * that global, and the other copy refused it: "The API version "6.4.299" does + * not match the Worker version "5.4.296"". Thumbnails then failed as + * `raster-failed`, vision reads of a PDF answered 422, and the local text index + * stayed empty with no log line. The fix: read the text with the app's own + * pdfjs. * - * Mutation check: read the text through `pdf-parse` again in `extractPdfText` → - * the raster step here fails. + * This file extracts text first and rasterises second. Its twin in this + * folder runs the reverse order. Each order needs its own file, because a + * process keeps the first worker it loads. + * + * Mutation check: read the text through `pdf-parse` again in + * `extractPdfText` → the raster step here fails. */ vi.mock("@/lib/logging/context", () => ({ annotate: vi.fn() })); diff --git a/src/lib/documents/__tests__/pdfjs-one-version-raster-first.test.ts b/src/lib/documents/__tests__/pdfjs-one-version-raster-first.test.ts index 3986da2fe..3389f078e 100644 --- a/src/lib/documents/__tests__/pdfjs-one-version-raster-first.test.ts +++ b/src/lib/documents/__tests__/pdfjs-one-version-raster-first.test.ts @@ -4,18 +4,21 @@ import { join } from "node:path"; import { describe, expect, it, vi } from "vitest"; /** - * Text extraction and rasterising share one process, and pdfjs keeps its worker - * on `globalThis.pdfjsWorker`. While `pdf-parse` brought its own pdfjs - * (5.4.296) beside the app's (6.4.299), whichever ran first installed its - * worker and the other refused it: "The API version "6.4.299" does not match - * the Worker version "5.4.296"". Thumbnails failed as `raster-failed`, vision - * reads of a PDF answered 422 and the local text index stayed empty without a - * word. Reading the text through the app's own pdfjs is the fix; the twin runs - * extraction first (`pdfjs-one-version-extract-first.test.ts`) and this file - * the reverse, each in a fresh process state. + * Text extraction and rasterising run in one process. In Node, pdfjs keeps its + * worker in one global, `globalThis.pdfjsWorker`. When `pdf-parse` brought its + * own pdfjs (5.4.296) beside the app's (6.4.299), the copy that ran first set + * that global, and the other copy refused it: "The API version "6.4.299" does + * not match the Worker version "5.4.296"". Thumbnails then failed as + * `raster-failed`, vision reads of a PDF answered 422, and the local text index + * stayed empty with no log line. The fix: read the text with the app's own + * pdfjs. * - * Mutation check: read the text through `pdf-parse` again in `extractPdfText` → - * the text step here fails. + * This file rasterises first and extracts text second. Its twin in this + * folder runs the reverse order. Each order needs its own file, because a + * process keeps the first worker it loads. + * + * Mutation check: read the text through `pdf-parse` again in + * `extractPdfText` → the text step here fails. */ vi.mock("@/lib/logging/context", () => ({ annotate: vi.fn() }));