diff --git a/src/lib/documents/__tests__/pdfjs-one-runtime-raster-first.test.ts b/src/lib/documents/__tests__/pdfjs-one-runtime-raster-first.test.ts deleted file mode 100644 index 1af8dc44f..000000000 --- a/src/lib/documents/__tests__/pdfjs-one-runtime-raster-first.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { describe, it, vi } from "vitest"; - -/** - * GitHub #1277, rasterization first: a render used to claim the in-process - * pdf.js worker for its own copy, and every later local text read failed - * without a word, leaving the document out of the search index. See - * `pdfjs-one-runtime.ts`. - */ - -vi.mock("@/lib/logging/context", () => ({ annotate: vi.fn() })); -vi.mock("@/lib/logging/signal", () => ({ logCaught: vi.fn() })); - -import { - expectFreshProcess, - expectRaster, - expectTextRead, -} from "./pdfjs-one-runtime"; - -describe("one pdf.js per process (#1277): rasterization first", () => { - it("reads text after a rasterization, and rasterizes again after that", async () => { - expectFreshProcess(); - await expectRaster(); - await expectTextRead(); - await expectRaster(); - }); -}); diff --git a/src/lib/documents/__tests__/pdfjs-one-runtime-text-first.test.ts b/src/lib/documents/__tests__/pdfjs-one-runtime-text-first.test.ts deleted file mode 100644 index 846ec1852..000000000 --- a/src/lib/documents/__tests__/pdfjs-one-runtime-text-first.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { describe, it, vi } from "vitest"; - -/** - * GitHub #1277, text first: a local text read used to claim the in-process - * pdf.js worker for its own copy, and every later rasterization (thumbnails, - * the vision read of a scan) failed until a restart. See - * `pdfjs-one-runtime.ts`. - */ - -vi.mock("@/lib/logging/context", () => ({ annotate: vi.fn() })); -vi.mock("@/lib/logging/signal", () => ({ logCaught: vi.fn() })); - -import { - expectFreshProcess, - expectRaster, - expectTextRead, -} from "./pdfjs-one-runtime"; - -describe("one pdf.js per process (#1277): text read first", () => { - it("rasterizes after a text read, and reads text again after that", async () => { - expectFreshProcess(); - await expectTextRead(); - await expectRaster(); - await expectTextRead(); - }); -}); diff --git a/src/lib/documents/__tests__/pdfjs-one-runtime.ts b/src/lib/documents/__tests__/pdfjs-one-runtime.ts deleted file mode 100644 index d3fb7a672..000000000 --- a/src/lib/documents/__tests__/pdfjs-one-runtime.ts +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Shared steps for the two `pdfjs-one-runtime-*` files (GitHub #1277). - * - * Under Node, pdf.js runs its worker in-process and keeps it on - * `globalThis.pdfjsWorker`. Whichever pdf.js copy opens a document first - * owns that global for the life of the process, and a different copy then - * refuses every document with "The API version … does not match the Worker - * version …". The text reader and the rasterizer once loaded different - * copies, so whichever ran first broke the other until a restart. - * - * Each order needs a fresh process, because the global cannot be taken back - * once claimed; that is why the two orders live in two files (the isolated - * project gives each file its own process) instead of two tests here. - */ -import { readFileSync } from "node:fs"; -import { join } from "node:path"; - -import { expect } from "vitest"; - -import { extractPdfText } from "../local-extract"; -import { rasterizePdf } from "../rasterize-pdf"; - -const FIXTURE = join( - process.cwd(), - "tests", - "fixtures", - "pdf", - "fallback-fonts.pdf", -); - -const pdf = () => readFileSync(FIXTURE); - -/** Nothing in this process has opened a PDF yet. */ -export function expectFreshProcess(): void { - expect( - (globalThis as { pdfjsWorker?: unknown }).pdfjsWorker, - "the file must run in its own process; another file already opened a PDF", - ).toBeUndefined(); -} - -export async function expectTextRead(): Promise { - const result = await extractPdfText(pdf()); - expect(result).toMatchObject({ ok: true, source: "local-pdf" }); - if (result.ok) expect(result.text).toContain("Test Insurance AG"); -} - -export async function expectRaster(): Promise { - const result = await rasterizePdf(pdf(), 1); - expect(result).toMatchObject({ ok: true }); -} 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 298696510..596523e00 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 @@ -21,6 +21,7 @@ import { describe, expect, it, vi } from "vitest"; * `extractPdfText` → the raster step here fails. */ vi.mock("@/lib/logging/context", () => ({ annotate: vi.fn() })); +vi.mock("@/lib/logging/signal", () => ({ logCaught: vi.fn() })); import { extractPdfText } from "../local-extract"; import { rasterizePdf } from "../rasterize-pdf"; @@ -31,6 +32,12 @@ const fixture = readFileSync( describe("one pdfjs for text and raster: text first", () => { it("extracts, rasterises and extracts again in one process", async () => { + // The order only means something in a process that has not opened a PDF. + expect( + (globalThis as { pdfjsWorker?: unknown }).pdfjsWorker, + "this file must run in a process of its own", + ).toBeUndefined(); + const first = await extractPdfText(fixture); expect(first.ok).toBe(true); 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 3389f078e..94b987be7 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 @@ -21,6 +21,7 @@ import { describe, expect, it, vi } from "vitest"; * `extractPdfText` → the text step here fails. */ vi.mock("@/lib/logging/context", () => ({ annotate: vi.fn() })); +vi.mock("@/lib/logging/signal", () => ({ logCaught: vi.fn() })); import { extractPdfText } from "../local-extract"; import { rasterizePdf } from "../rasterize-pdf"; @@ -31,6 +32,12 @@ const fixture = readFileSync( describe("one pdfjs for text and raster: raster first", () => { it("rasterises, extracts and rasterises again in one process", async () => { + // The order only means something in a process that has not opened a PDF. + expect( + (globalThis as { pdfjsWorker?: unknown }).pdfjsWorker, + "this file must run in a process of its own", + ).toBeUndefined(); + const first = await rasterizePdf(fixture, 1); expect(first.ok).toBe(true);