vomebook commited on
Commit ·
f29eabe
1
Parent(s): 9432cbb
Require document loader coverage contracts
Browse filesFiles changed (2)
16 unmodified lines1718192021222316 unmodified linesconst match = /^\s*#\s*reader-document-loader\.mjs\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|/.exec(line);return match ? [match.slice(1).map(Number)] : [];});if (result.status !== 0 || rows.length !== 1 || rows[0].some((value, index) => value < minimum[index])) {console.error("Document loader coverage requires passing tests and exactly one source row above each minimum");process.exitCode = 1;}16 unmodified lines1718192021222324252627282930313233343536373839404116 unmodified linesconst match = /^\s*#\s*reader-document-loader\.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/);const required = ["retry policy keeps bounded delay and never retries rate-limited or aborted work","proxy fallback respects response ownership, cancellation and bucket routing","preloads are single-owner and fall back on failure or mismatched identity","document preparation preserves failure and byte-limit ownership","script load releases timers, handlers and resources on success, error and close","image fallback is not used for budget failures or closed readers","tests/test_reader_pdf_rate_outer.mjs"];if (result.status !== 0 || rows.length !== 1 || rows[0].some((value, index) => value < minimum[index]) ||!/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) || required.some(name => {const index = lines.indexOf(`# Subtest: ${name}`);return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||!new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "") ||(name === "tests/test_reader_pdf_rate_outer.mjs" &&lines[index - 1] !== "# PDF rate-limit retry boundary and generic retry preserved");})) {console.error("Document loader coverage requires passing named tests and exactly one source row above each minimum");process.exitCode = 1;}
198 unmodified lines199200201202203204198 unmodified linesshutil.copyfile(ROOT / path, target)check = ["node", "scripts/check_document_loader_coverage.mjs"]self.assert_check(self.run_check(*check), True, "reader-document-loader.mjs")for path in paths[2:]:(self.root / path).write_text('import {test} from "node:test"; test("empty", () => {});\n')self.assert_check(self.run_check(*check), False, "exactly one source row")198 unmodified lines199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233198 unmodified linesshutil.copyfile(ROOT / path, target)check = ["node", "scripts/check_document_loader_coverage.mjs"]self.assert_check(self.run_check(*check), True, "reader-document-loader.mjs")contract = self.root / paths[2]original = contract.read_text()names = ["retry policy keeps bounded delay and never retries rate-limited or aborted work","proxy fallback respects response ownership, cancellation and bucket routing","preloads are single-owner and fall back on failure or mismatched identity","document preparation preserves failure and byte-limit ownership","script load releases timers, handlers and resources on success, error and close","image fallback is not used for budget failures or closed readers"]for name in names:anchor = 'test("' + name + '"'self.assertEqual(original.count(anchor), 1)for replacement in ('test("renamed contract"', 'test.skip("' + name + '"', 'test.todo("' + name + '"'):contract.write_text(original.replace(anchor, replacement))self.assert_check(self.run_check(*check), False, "passing named tests")name = names[2]for extra in ('test("' + name + '", () => {});', 'test.skip("extra skip", () => {});','test.todo("extra todo");'):contract.write_text(original + "\n" + extra + "\n")self.assert_check(self.run_check(*check), False, "passing named tests")contract.write_text(original)rate_test = self.root / paths[3]rate_source = rate_test.read_text()marker = 'PDF rate-limit retry boundary and generic retry preserved'self.assertEqual(rate_source.count(marker), 1)rate_test.write_text(rate_source.replace(marker, 'missing rate completion marker'))self.assert_check(self.run_check(*check), False, "passing named tests")rate_test.write_text('import "../static/reader/core/reader-document-loader.mjs";\n')self.assert_check(self.run_check(*check), False, "passing named tests")rate_test.write_text(rate_source)for path in paths[2:]:(self.root / path).write_text('import {test} from "node:test"; test("empty", () => {});\n')self.assert_check(self.run_check(*check), False, "exactly one source row")
scripts/check_document_loader_coverage.mjs+20-2
tests/test_static_checks.py+29