mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-09 04:50:59 +00:00
test(documents): keep one pair of one-process order tests
Two pairs of tests ran a text read and a rasterization in one process, one file per order. The pdfjs-one-version pair stays; the other pair and its shared helper go. The kept pair now first asserts that nothing in the process has claimed the pdf.js worker yet, so a file that lands in a shared process fails instead of passing on an order it never ran, and it mocks the failure signal the text read can emit. Refs #1277
This commit is contained in:
1 parent
540c6bfaeb
commit
1fd34e4d74
5 files changed
+14
-102
No files matched your search
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
@@ -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<void> {
|
||||
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<void> {
|
||||
const result = await rasterizePdf(pdf(), 1);
|
||||
expect(result).toMatchObject({ ok: true });
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user