/** * 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. `/../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; }