feat(pdf): extract standalone PDF ingest package (ESRC-WP-0001)
Bootstrap evidence-source from the citation-evidence src/source PDF slice. - Headless core (src/pdf): ingest/extract/fingerprint, importing domain contracts from @citation-evidence/engine/shared (no local copies) - Browser upload helpers isolated under src/browser behind a ./browser entry point, with an eslint boundary keeping the core browser-free - pnpm/TS/vitest/eslint scaffold; 52 tests (contract + determinism) - Fixtures resolved from the sibling citation-evidence checkout, not duplicated (real PII) — see docs/ADR-0002; suites skip when absent - Boundary + fixture decisions recorded as docs/ADR-0001 / ADR-0002 - README/SCOPE rewritten; capability.infotech.pdf-evidence-ingest registered, NO_CAPABILITIES removed - Follow-on workplans ESRC-WP-0002..0004 queued; ESRC-WP-0001 finished Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
2fd715ba45
commit
cb93c322c0
31 changed files with 5066 additions and 105 deletions
51
tests/fixtures.ts
Normal file
51
tests/fixtures.ts
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Fixture corpus access for evidence-source tests.
|
||||
*
|
||||
* The corpus is owned by the sibling `citation-evidence` checkout (ADR-0002);
|
||||
* it is not duplicated into this repo. Resolution order:
|
||||
* 1. `EVIDENCE_SOURCE_FIXTURE_DIR` env var, if set.
|
||||
* 2. `<repo>/../citation-evidence/fixtures/pdfs` (sibling-checkout default).
|
||||
*
|
||||
* When the corpus is unavailable, `fixtureCorpusAvailable()` returns false so
|
||||
* fixture-driven suites can skip cleanly instead of failing.
|
||||
*/
|
||||
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export const FIXTURE_DIR = process.env.EVIDENCE_SOURCE_FIXTURE_DIR
|
||||
? resolve(process.env.EVIDENCE_SOURCE_FIXTURE_DIR)
|
||||
: resolve(__dirname, "../../citation-evidence/fixtures/pdfs");
|
||||
|
||||
export interface Fixture {
|
||||
readonly id: string;
|
||||
readonly filename: string;
|
||||
readonly page_count: number;
|
||||
readonly known_good_quote: string;
|
||||
readonly known_good_quote_page: number;
|
||||
}
|
||||
|
||||
interface Manifest {
|
||||
readonly fixtures: readonly Fixture[];
|
||||
}
|
||||
|
||||
export function fixturePath(filename: string): string {
|
||||
return resolve(FIXTURE_DIR, filename);
|
||||
}
|
||||
|
||||
export function fixtureBytes(filename: string): Uint8Array {
|
||||
return new Uint8Array(readFileSync(fixturePath(filename)));
|
||||
}
|
||||
|
||||
export function fixtureCorpusAvailable(): boolean {
|
||||
return existsSync(resolve(FIXTURE_DIR, "manifest.json"));
|
||||
}
|
||||
|
||||
export function loadFixtures(): readonly Fixture[] {
|
||||
const manifestPath = resolve(FIXTURE_DIR, "manifest.json");
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, "utf8")) as Manifest;
|
||||
return manifest.fixtures;
|
||||
}
|
||||
17
tests/setup-pdf-worker.ts
Normal file
17
tests/setup-pdf-worker.ts
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Vitest setup: point PDF.js at its legacy worker bundle for Node runs.
|
||||
*
|
||||
* `extractPdf` deliberately does no worker setup (so the same module loads in
|
||||
* browsers and Node). In Node tests we configure `GlobalWorkerOptions.workerSrc`
|
||||
* here, once per test file, before any extraction runs. The legacy bundle ships
|
||||
* as plain JS and works through PDF.js's fake-worker fallback when no real
|
||||
* Worker is available.
|
||||
*/
|
||||
|
||||
import { createRequire } from "node:module";
|
||||
import * as pdfjs from "pdfjs-dist";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = require.resolve(
|
||||
"pdfjs-dist/legacy/build/pdf.worker.mjs",
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue