import { spawnSync } from "node:child_process"; // Node 26/V8: preserve the old aggregate floors, and separately protect each // extracted module. These are PDF network contracts, not the whole Reader. // Extraction changes individual denominators; floors are measured separately. const aggregateMinimum = [96.26, 84.70, 87.16]; const minimum = [97.60, 86.74, 87.25]; const cacheMinimum = [100, 98.48, 100]; const hintsMinimum = [98.50, 90.45, 100]; const result = spawnSync(process.execPath, [ "--test", "--test-concurrency=1", "--test-reporter=tap", "--experimental-test-coverage", "--test-coverage-include=**/static/reader/pdf/reader-pdf-network.mjs", "--test-coverage-include=**/static/reader/pdf/reader-pdf-range-cache.mjs", "--test-coverage-include=**/static/reader/pdf/reader-pdf-range-hints.mjs", ...aggregateMinimum.map((value,index)=>`--test-coverage-${["lines","branches","functions"][index]}=${value}`), "tests/reader/pdf-network/test_reader_pdf_backpressure.mjs", "tests/reader/pdf-network/test_reader_pdf_range_transport.mjs", "tests/reader/pdf-network/test_reader_pdf_network_contract.mjs", "tests/reader/pdf-network/test_pdf_range_hints_contract.mjs" ], { encoding: "utf8" }); if (result.stdout) process.stdout.write(result.stdout); if (result.stderr) process.stderr.write(result.stderr); if (result.error) throw result.error; const rows = (result.stdout || "").split(/\r?\n/).flatMap(line => { const match = /^\s*#\s*reader-pdf-network\.mjs\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|/.exec(line); return match ? [match.slice(1).map(Number)] : []; }); const cacheRows = (result.stdout || "").split(/\r?\n/).flatMap(line => { const match = /^\s*#\s*reader-pdf-range-cache\.mjs\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|/.exec(line); return match ? [match.slice(1).map(Number)] : []; }); const hintsRows = (result.stdout || "").split(/\r?\n/).flatMap(line => { const match = /^\s*#\s*reader-pdf-range-hints\.mjs\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|/.exec(line); return match ? [match.slice(1).map(Number)] : []; }); const text = result.stdout || ""; const lines = text.split(/\r?\n/); // Node truncates fractional CLI floors; also check the reported aggregate. const aggregateRows = lines.flatMap(line => { const match = /^\s*#\s*all files\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|/.exec(line); return match ? [match.slice(1).map(Number)] : []; }); const skipped = lines.filter(line => /^# skipped(?:\s|$)/.test(line)); const todo = lines.filter(line => /^# todo(?:\s|$)/.test(line)); const required = [ ["tests/reader/pdf-network/test_reader_pdf_backpressure.mjs", "429 feedback, shared spacing, bounded retry, version consistency and cancellation passed"], ["tests/reader/pdf-network/test_reader_pdf_network_contract.mjs", "PDF network contracts: cache identity, safe revalidation and live cancellation passed"], ["tests/reader/pdf-network/test_pdf_range_hints_contract.mjs", "PDF range hints: bounded scheduling and malformed inputs passed"], ["tests/reader/pdf-network/test_reader_pdf_range_transport.mjs", "PDF range transport: exact demand, optional demand admission, bounded opening hint, restoration scope, weak fallback, validation and cancellation passed"] ]; if (result.status !== 0 || aggregateRows.length !== 1 || aggregateRows[0].some((value,index)=>value < aggregateMinimum[index]) || rows.length !== 1 || rows[0].some((value,index)=>value < minimum[index]) || cacheRows.length !== 1 || cacheRows[0].some((value,index)=>value < cacheMinimum[index]) || hintsRows.length !== 1 || hintsRows[0].some((value,index)=>value < hintsMinimum[index]) || skipped.length !== 1 || skipped[0] !== "# skipped 0" || todo.length !== 1 || todo[0] !== "# todo 0" || required.some(([name, marker]) => { const index = lines.indexOf(`# Subtest: ${name}`); return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index || lines[index - 1] !== `# ${marker}` || !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || ""); })) { console.error("PDF network coverage gate requires passing named tests and exactly one source coverage row per module"); process.exitCode = 1; }