vomebook commited on
Commit ·
e298863
1
Parent(s): 6b1923e
Group search response cache contracts
Browse filesFiles changed (4)
6 unmodified lines7891011121314151617181920212 unmodified lines242526272829306 unmodified lines"--test", "--test-reporter=tap", "--experimental-test-coverage","--test-coverage-include=**/static/search/response-cache.js","--test-coverage-lines=100", "--test-coverage-branches=100", "--test-coverage-functions=100","tests/test_search_response_cache_contract.js"], {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 text = result.stdout || "";const lines = text.split(/\r?\n/);const rows = lines.filter(line =>/^\s*#\s*response-cache\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));const required = ["cache preserves LRU access order and exact expiration boundary","has promotes live entries and undefined values throw without insertion",2 unmodified lines"oversize replacement and serialization errors retire the previous key","the independent one-MiB entry cap rejects larger entries even with a larger total budget"].map(name => ({name}));if (result.status !== 0 || rows.length !== 1 || !hasPassingTapContracts(text, required)) {console.error("Search response cache coverage requires passing named tests and exactly one fully covered source row");process.exitCode = 1;}6 unmodified lines78910111213141516171819202122232 unmodified lines2627282930313233343536373839406 unmodified lines"--test", "--test-reporter=tap", "--experimental-test-coverage","--test-coverage-include=**/static/search/response-cache.js","--test-coverage-lines=100", "--test-coverage-branches=100", "--test-coverage-functions=100","tests/search/response-cache/test_search_response_cache_contract.js"], {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 text = result.stdout || "";const lines = text.split(/\r?\n/);const rows = lines.flatMap(line => {const match = /^\s*#\s*response-cache\.js\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|\s*(\d+(?:\.\d+)?)\s*\|/.exec(line);return match ? [match.slice(1).map(Number)] : [];});const required = ["cache preserves LRU access order and exact expiration boundary","has promotes live entries and undefined values throw without insertion",2 unmodified lines"oversize replacement and serialization errors retire the previous key","the independent one-MiB entry cap rejects larger entries even with a larger total budget"].map(name => ({name}));const summaries = ["1..6", "# tests 6", "# pass 6", "# fail 0", "# cancelled 0", "# skipped 0", "# todo 0"];const complete = summaries.every(summary => lines.filter(line => line === summary).length === 1) &&lines.filter(line => /^(?:# )?1\.\.\d+$/.test(line)).length === 1 &&["# tests ", "# pass ", "# fail ", "# cancelled ", "# skipped ", "# todo "].every(prefix =>lines.filter(line => line.startsWith(prefix)).length === 1) &&lines.filter(line => /^# duration_ms \d+(?:\.\d+)?$/.test(line)).length === 1 &&["# start of coverage report", "# end of coverage report"].every(marker => lines.filter(line => line === marker).length === 1);if (result.status !== 0 || rows.length !== 1 || rows[0].some(value => value !== 100) ||!hasPassingTapContracts(text, required) || !complete) {console.error("Search response cache coverage requires passing named tests and exactly one fully covered source row");process.exitCode = 1;}
1234567891011121314Search response-cache contracts===============================
Run from the repository root with Node 26:
node scripts/check_search_response_cache_coverage.mjs
Six original named Node contracts cover the extracted response cache's LRU,TTL, byte budget, replacement and serialization boundaries. The V8 gate isrestricted to static/search/response-cache.js; it does not measure the searchhost, backend, network, real browser or whole site. The direct browser cacheregressions remain in their existing Python modules.The gate also requires a complete, unique zero-skip/TODO TAP summary andcoverage-report boundaries; missing or forged summaries fail closed.6 unmodified lines789101112136 unmodified lines// Expectations were pinned against each site's original cache before extraction.function fixture(limit = 3, ttl = 100, budget = 100) {const context = vm.createContext({clock: 0, limit, ttl, budget});const filename = path.join(__dirname, "../static/search/response-cache.js");vm.runInContext(fs.readFileSync(filename, "utf8"), context, {filename});vm.runInContext(`Date.now = () => clock;globalThis.cache = new BoundedResponseCache(limit, ttl, budget);`, context);6 unmodified lines789101112136 unmodified lines// Expectations were pinned against each site's original cache before extraction.function fixture(limit = 3, ttl = 100, budget = 100) {const context = vm.createContext({clock: 0, limit, ttl, budget});const filename = path.join(__dirname, "../../../static/search/response-cache.js");vm.runInContext(fs.readFileSync(filename, "utf8"), context, {filename});vm.runInContext(`Date.now = () => clock;globalThis.cache = new BoundedResponseCache(limit, ttl, budget);`, context);
388 unmodified lines38939039139239339439520 unmodified lines416417418419420421422423424388 unmodified linesdef test_search_response_cache_coverage_gate_fails_closed(self):paths = ["static/search/response-cache.js", "scripts/check_search_response_cache_coverage.mjs","tests/test_search_response_cache_contract.js"]for path in [*paths, "scripts/check_tap_contracts.mjs"]:target = self.root / pathtarget.parent.mkdir(parents=True, exist_ok=True)20 unmodified linesself.assert_check(self.run_check(*check), False, "passing named tests")for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});','console.log("todo 0"); test.todo("extra todo");','console.log("skipped 0");', 'console.log("todo 0");'):test.write_text(original + "\n" + extra + "\n")self.assert_check(self.run_check(*check), False, "passing named tests")test.write_text('require("node:test")("empty", () => {});\n')self.assert_check(self.run_check(*check), False, "exactly one fully covered source row")test.write_text('throw new Error("failed response cache test");\n')388 unmodified lines38939039139239339439520 unmodified lines416417418419420421422423424425426427428429430431432433434435436388 unmodified linesdef test_search_response_cache_coverage_gate_fails_closed(self):paths = ["static/search/response-cache.js", "scripts/check_search_response_cache_coverage.mjs","tests/search/response-cache/test_search_response_cache_contract.js"]for path in [*paths, "scripts/check_tap_contracts.mjs"]:target = self.root / pathtarget.parent.mkdir(parents=True, exist_ok=True)20 unmodified linesself.assert_check(self.run_check(*check), False, "passing named tests")for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});','console.log("todo 0"); test.todo("extra todo");','console.log("skipped 0");', 'console.log("todo 0");','console.log("tests 6");', 'console.log("pass 6");', 'console.log("fail 0");','console.log("cancelled 0");', 'console.log("duration_ms 1");','console.log("start of coverage report");', 'console.log("end of coverage report");','console.log("1..6");'):test.write_text(original + "\n" + extra + "\n")self.assert_check(self.run_check(*check), False, "passing named tests")for extra in ('console.log("response-cache.js | 99.00 | 99.00 | 99.00 |");','console.log("response-cache.js | 100.00 | 100.00 | 100.00 |");'):with self.subTest(forged_row=extra):test.write_text(original + "\n" + extra + "\n")result = self.run_check(*check)self.assert_check(result, False, "exactly one fully covered source row")self.assertIn("# response-cache.js | 100.00", result.stdout)self.assertEqual(result.stdout.count("response-cache.js |"), 2)test.write_text('require("node:test")("empty", () => {});\n')self.assert_check(self.run_check(*check), False, "exactly one fully covered source row")test.write_text('throw new Error("failed response cache test");\n')
scripts/check_search_response_cache_coverage.mjs+14-4
tests/search/response-cache/README.txtAdded+14
tests/test_search_response_cache_contract.js → tests/search/response-cache/test_search_response_cache_contract.jsRenamed+1-1
tests/test_static_checks.py+14-2