File size: 6,867 Bytes
7aef9ca 2db6cf4 7aef9ca 2db6cf4 262c3c2 7aef9ca 2db6cf4 7aef9ca dac2ca2 46a7000 dac2ca2 7ffc398 dac2ca2 d3655e4 dac2ca2 aeb21e9 d14cbd1 dac2ca2 7aef9ca c7f0235 2db6cf4 da9ec8b 7aef9ca da9ec8b c7f0235 7aef9ca | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | import { spawnSync } from "node:child_process";
import {hasPassingTapContracts} from "../check_tap_contracts.mjs";
// Each run includes exactly one own-source file, so Node's aggregate
// thresholds cannot hide a regression in another file or in an empty report.
// Baseline measured 2026-11-03 on Node v26.11.1, using the named tests only.
const gates = [
{ source:"reader-section-virtualizer.js", directory:"formats", lines:100, branches:100, functions:100,
tests:["tests/reader/layout/test_reader_section_virtualizer.js"] },
// Scheduler-only branch baseline after retiring the repository (Node v26.13.1).
{ source:"reader-chapter-repository.js", directory:"formats", lines:100, branches:95.92, functions:100,
tests:["tests/reader/chapters/test_reader_chapter_scheduler.js", "tests/reader/chapters/test_reader_chapter_preload.js"] },
{ source:"reader-scroll-anchor.js", directory:"ui", lines:100, branches:89.61, functions:100,
tests:["tests/reader/layout/test_reader_scroll_anchor.js"] }
];
// Run boundary regressions separately so they cannot change the coverage gates below.
const boundaryTests = [
{file: "tests/reader/pdf-search/test_native_pdf_progress.mjs", names: [
"native PDF publishes final search progress once with the complete first page",
"native PDF distinguishes a completed no-match search from absent text",
"native PDF does not publish twice after cancellation during the final yield"]},
{file: "tests/reader/test_reader_bookmark_handoff.mjs", names: [
"bookmark handoff only cleans matching navigation and preserves other state"]},
{file: "tests/reader/chapters/test_chapter_format_validation.mjs", names: ["tests/reader/chapters/test_chapter_format_validation.mjs"], marker: "chapter metadata validation and prefetch sizes passed"},
{file: "tests/reader/chapters/test_reader_chapter_format_types.mjs", names: [
"chapter search metadata requires the exact path, numeric size and hash",
"optional chapter fields are consumed only as their supported types"]},
{file: "tests/reader/core/test_pdf_text_context.js", names: ["tests/reader/core/test_pdf_text_context.js"]},
{file: "tests/reader/core/test_reader_contract_pdf_document.js", names: ["tests/reader/core/test_reader_contract_pdf_document.js"]},
{file: "tests/reader/core/test_reader_format_controller_boundary.mjs", names: [
"DjVu loader remains a separate module at the HF runtime URL",
"resolution ignores non-string extensions and preserves the existing extension",
"explicit PDF and page-manifest modes follow the resolved extension",
"resolution retains string and legacy DJVU semantics",
"classification is narrowed at the fail boundary without coercion",
"dynamic lifecycle code remains uncoerced and is narrowed by the controller",
"image fallback only accepts a string original extension"]},
{file: "tests/reader/core/test_reader_source_boundary.mjs", names: [
"HF source and download endpoints retain relative URLs",
"download validates unknown JSON and preserves server messages",
"download handles null, primitive and abort errors without losing cleanup",
"a derived text preview still downloads the original VCF with its exact filename",
"normal and early resolution validate metadata while retaining extra fields",
"non-record metadata is rejected before use in both resolution paths and application",
"optional nulls and mixed folders survive resolution and application",
"reapplying committed metadata preserves its identity and refreshes OCR precedence",
"early lookup retries timeout and rethrows null rejection",
"lookup retries share the same delay and attempt budget after cleanup"]},
{file: "tests/reader/security/test_pdf_ocr_runtime_boundary.mjs", names: ["tests/reader/security/test_pdf_ocr_runtime_boundary.mjs"]},
{file: "tests/reader/security/test_reader_security_boundary.js", names: ["tests/reader/security/test_reader_security_boundary.js"]}
];
for (const {file, names, marker} of boundaryTests) {
const result = spawnSync(process.execPath, ["--test", "--test-concurrency=1", "--test-reporter=tap", file], {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 lines = (result.stdout || "").split(/\r?\n/);
const summaries = [`1..${names.length}`, `# tests ${names.length}`, `# pass ${names.length}`,
"# fail 0", "# cancelled 0", "# skipped 0", "# todo 0"];
if (result.status !== 0 || !hasPassingTapContracts(result.stdout || "", names.map(name => marker ? {name, marker} : {name})) ||
!summaries.every(line => lines.filter(item => item === line).length === 1)) {
console.error(`Reader boundary gate requires all named tests to pass: ${file}`);
process.exitCode = 1;
}
}
for (const gate of gates) {
const result = spawnSync(process.execPath, [
"--test", "--test-concurrency=1", "--test-reporter=tap", "--experimental-test-coverage",
`--test-coverage-include=**/static/reader/${gate.directory}/${gate.source}`,
`--test-coverage-lines=${gate.lines}`, `--test-coverage-branches=${gate.branches}`,
`--test-coverage-functions=${gate.functions}`, ...gate.tests
], { 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/).filter(line => {
const columns = line.split("|").map(value => value.trim());
return columns[0].replace(/^#\s*/, "") === gate.source && columns.length >= 4 &&
columns.slice(1,4).every(value => /^\d+(?:\.\d+)?$/.test(value));
});
const values = rows.length === 1 ? rows[0].split("|").slice(1,4).map(value=>Number(value.trim())) : [];
const text = result.stdout || "";
const expected = {"tests/reader/layout/test_reader_section_virtualizer.js": "reader section virtualizer contracts passed",
"tests/reader/chapters/test_reader_chapter_scheduler.js": "reader chapter scheduler contracts passed",
"tests/reader/chapters/test_reader_chapter_preload.js": "chapter manifest preload validation, reuse, body deadline and disposal passed",
"tests/reader/layout/test_reader_scroll_anchor.js": "reader scroll anchor contracts passed"};
const missingTests = gate.tests.some(name => typeof expected[name] !== "string") ||
!hasPassingTapContracts(text, gate.tests.map(name => ({name, marker: expected[name]})));
if (result.status !== 0 || rows.length !== 1 ||
values.some((value,index)=>value < [gate.lines,gate.branches,gate.functions][index]) || missingTests) {
console.error(`Reader core coverage gate requires passing named tests and exactly one source coverage row: ${gate.source}`);
process.exitCode = 1;
}
}
|