vomebook commited on
Commit
da9ec8b
·
1 Parent(s): 508c1f3

Share and strictly validate TAP coverage contracts

Browse files
Dockerfile CHANGED
@@ -48,6 +48,7 @@ RUN npx --no-install pyright --project pyrightconfig.json \
48
  && node --test tests/test_search_stable_id_baseline.mjs \
49
  && node scripts/check_search_filter_equality_baseline.mjs \
50
  && node scripts/check_search_folder_merge_baseline.mjs \
 
51
  && printf 'static gate tests passed\n' >/check/static-gate-test-ok
52
 
53
  FROM node:26.11.1-bookworm-slim AS static-assets
 
48
  && node --test tests/test_search_stable_id_baseline.mjs \
49
  && node scripts/check_search_filter_equality_baseline.mjs \
50
  && node scripts/check_search_folder_merge_baseline.mjs \
51
+ && node --test tests/test_tap_contracts.mjs \
52
  && printf 'static gate tests passed\n' >/check/static-gate-test-ok
53
 
54
  FROM node:26.11.1-bookworm-slim AS static-assets
scripts/check_document_loader_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Node 26/V8 scope: only reader-document-loader.mjs and the named tests.
4
  // Baseline after adding failure-path contracts: 100% lines, 94.20% branches,
@@ -18,24 +19,18 @@ const rows = (result.stdout || "").split(/\r?\n/).flatMap(line => {
18
  return match ? [match.slice(1).map(Number)] : [];
19
  });
20
  const text = result.stdout || "";
21
- const lines = text.split(/\r?\n/);
22
  const required = [
23
  "retry policy keeps bounded delay and never retries rate-limited or aborted work",
24
  "proxy fallback respects response ownership, cancellation and bucket routing",
25
  "preloads are single-owner and fall back on failure or mismatched identity",
26
  "document preparation preserves failure and byte-limit ownership",
27
  "script load releases timers, handlers and resources on success, error and close",
28
- "image fallback is not used for budget failures or closed readers",
29
- "tests/test_reader_pdf_rate_outer.mjs"
30
- ];
 
31
  if (result.status !== 0 || rows.length !== 1 || rows[0].some((value, index) => value < minimum[index]) ||
32
- !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) || required.some(name => {
33
- const index = lines.indexOf(`# Subtest: ${name}`);
34
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
35
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "") ||
36
- (name === "tests/test_reader_pdf_rate_outer.mjs" &&
37
- lines[index - 1] !== "# PDF rate-limit retry boundary and generic retry preserved");
38
- })) {
39
  console.error("Document loader coverage requires passing named tests and exactly one source row above each minimum");
40
  process.exitCode = 1;
41
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Node 26/V8 scope: only reader-document-loader.mjs and the named tests.
5
  // Baseline after adding failure-path contracts: 100% lines, 94.20% branches,
 
19
  return match ? [match.slice(1).map(Number)] : [];
20
  });
21
  const text = result.stdout || "";
 
22
  const required = [
23
  "retry policy keeps bounded delay and never retries rate-limited or aborted work",
24
  "proxy fallback respects response ownership, cancellation and bucket routing",
25
  "preloads are single-owner and fall back on failure or mismatched identity",
26
  "document preparation preserves failure and byte-limit ownership",
27
  "script load releases timers, handlers and resources on success, error and close",
28
+ "image fallback is not used for budget failures or closed readers"
29
+ ].map(name => ({name}));
30
+ required.push({name: "tests/test_reader_pdf_rate_outer.mjs",
31
+ marker: "PDF rate-limit retry boundary and generic retry preserved"});
32
  if (result.status !== 0 || rows.length !== 1 || rows[0].some((value, index) => value < minimum[index]) ||
33
+ !hasPassingTapContracts(text, required)) {
 
 
 
 
 
 
34
  console.error("Document loader coverage requires passing named tests and exactly one source row above each minimum");
35
  process.exitCode = 1;
36
  }
scripts/check_reader_core_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import { spawnSync } from "node:child_process";
 
2
 
3
  // Each run includes exactly one own-source file, so Node's aggregate
4
  // thresholds cannot hide a regression in another file or in an empty report.
@@ -29,21 +30,15 @@ for (const gate of gates) {
29
  });
30
  const values = rows.length === 1 ? rows[0].split("|").slice(1,4).map(value=>Number(value.trim())) : [];
31
  const text = result.stdout || "";
32
- const lines = text.split(/\r?\n/);
33
- const skippedOrTodo = !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text);
34
  const expected = {"tests/test_reader_section_virtualizer.js": "reader section virtualizer contracts passed",
35
  "tests/test_reader_chapter_repository.js": "reader chapter repository contracts passed",
36
  "tests/test_reader_chapter_scheduler.js": "reader chapter scheduler contracts passed",
37
  "tests/test_reader_chapter_preload.js": "chapter manifest preload validation, reuse, body deadline and disposal passed",
38
  "tests/test_reader_scroll_anchor.js": "reader scroll anchor contracts passed"};
39
- const missingTests = gate.tests.some(name => {
40
- const index = lines.indexOf(`# Subtest: ${name}`);
41
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
42
- lines[index - 1] !== `# ${expected[name]}` ||
43
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
44
- });
45
  if (result.status !== 0 || rows.length !== 1 ||
46
- values.some((value,index)=>value < [gate.lines,gate.branches,gate.functions][index]) || skippedOrTodo || missingTests) {
47
  console.error(`Reader core coverage gate requires passing named tests and exactly one source coverage row: ${gate.source}`);
48
  process.exitCode = 1;
49
  }
 
1
  import { spawnSync } from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Each run includes exactly one own-source file, so Node's aggregate
5
  // thresholds cannot hide a regression in another file or in an empty report.
 
30
  });
31
  const values = rows.length === 1 ? rows[0].split("|").slice(1,4).map(value=>Number(value.trim())) : [];
32
  const text = result.stdout || "";
 
 
33
  const expected = {"tests/test_reader_section_virtualizer.js": "reader section virtualizer contracts passed",
34
  "tests/test_reader_chapter_repository.js": "reader chapter repository contracts passed",
35
  "tests/test_reader_chapter_scheduler.js": "reader chapter scheduler contracts passed",
36
  "tests/test_reader_chapter_preload.js": "chapter manifest preload validation, reuse, body deadline and disposal passed",
37
  "tests/test_reader_scroll_anchor.js": "reader scroll anchor contracts passed"};
38
+ const missingTests = gate.tests.some(name => typeof expected[name] !== "string") ||
39
+ !hasPassingTapContracts(text, gate.tests.map(name => ({name, marker: expected[name]})));
 
 
 
 
40
  if (result.status !== 0 || rows.length !== 1 ||
41
+ values.some((value,index)=>value < [gate.lines,gate.branches,gate.functions][index]) || missingTests) {
42
  console.error(`Reader core coverage gate requires passing named tests and exactly one source coverage row: ${gate.source}`);
43
  process.exitCode = 1;
44
  }
scripts/check_request_manager_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Node 26 V8 report, one source only. Measured with the three named tests:
4
  // 100.00% lines, 95.24% branches, 95.12% functions after strict annotations.
@@ -20,20 +21,14 @@ const rows = (result.stdout || "").split(/\r?\n/).flatMap(line => {
20
  return match ? [match.slice(1).map(Number)] : [];
21
  });
22
  const text = result.stdout || "";
23
- const lines = text.split(/\r?\n/);
24
  // Each test logs its completion marker only after its async contract finishes.
25
  const required = [
26
  ["reader request manager behavior", "reader request manager contracts passed"],
27
  ["reader initial response recovery", "reader initial response recovery contracts passed"],
28
  ["reader request manager edge behavior", "reader request manager edge contracts passed"]
29
- ];
30
  if (result.status !== 0 || rows.length !== 1 || rows[0].some((value, index) => value < minimum[index]) ||
31
- !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) || required.some(([name, marker]) => {
32
- const index = lines.indexOf(`# Subtest: ${name}`);
33
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
34
- lines[index - 1] !== `# ${marker}` ||
35
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
36
- })) {
37
  console.error("Request manager coverage gate requires passing named tests and exactly one source coverage row above each minimum");
38
  process.exitCode = 1;
39
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Node 26 V8 report, one source only. Measured with the three named tests:
5
  // 100.00% lines, 95.24% branches, 95.12% functions after strict annotations.
 
21
  return match ? [match.slice(1).map(Number)] : [];
22
  });
23
  const text = result.stdout || "";
 
24
  // Each test logs its completion marker only after its async contract finishes.
25
  const required = [
26
  ["reader request manager behavior", "reader request manager contracts passed"],
27
  ["reader initial response recovery", "reader initial response recovery contracts passed"],
28
  ["reader request manager edge behavior", "reader request manager edge contracts passed"]
29
+ ].map(([name, marker]) => ({name, marker}));
30
  if (result.status !== 0 || rows.length !== 1 || rows[0].some((value, index) => value < minimum[index]) ||
31
+ !hasPassingTapContracts(text, required)) {
 
 
 
 
 
32
  console.error("Request manager coverage gate requires passing named tests and exactly one source coverage row above each minimum");
33
  process.exitCode = 1;
34
  }
scripts/check_search_file_types_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Node 26/V8 scope: only the extracted inventory, not the host app.js.
4
  // This data-only source executes on load, so full coverage alone is vacuous:
@@ -14,7 +15,6 @@ if (result.stderr) process.stderr.write(result.stderr);
14
  if (result.error) throw result.error;
15
  const rows = (result.stdout || "").split(/\r?\n/).filter(line =>
16
  /^\s*#\s*file-types\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
17
- const lines = (result.stdout || "").split(/\r?\n/);
18
  const required = [
19
  "all 67 ordered filter extensions are pinned, including case-sensitive lookup",
20
  "all 77 icon mappings and their case-insensitive lookup are pinned",
@@ -22,13 +22,8 @@ const required = [
22
  "original lexical inventories cannot be reassigned or shadowed through global properties",
23
  "const bindings retain their original mutable array and map contents",
24
  "inventory data is isolated between script evaluations"
25
- ];
26
- if (result.status !== 0 || rows.length !== 1 || !/^# skipped 0$/m.test(result.stdout || "") ||
27
- !/^# todo 0$/m.test(result.stdout || "") || required.some(name => {
28
- const index = lines.indexOf(`# Subtest: ${name}`);
29
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
30
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
31
- })) {
32
  console.error("Search file types coverage requires passing named contracts and exactly one fully covered source row");
33
  process.exitCode = 1;
34
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Node 26/V8 scope: only the extracted inventory, not the host app.js.
5
  // This data-only source executes on load, so full coverage alone is vacuous:
 
15
  if (result.error) throw result.error;
16
  const rows = (result.stdout || "").split(/\r?\n/).filter(line =>
17
  /^\s*#\s*file-types\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
 
18
  const required = [
19
  "all 67 ordered filter extensions are pinned, including case-sensitive lookup",
20
  "all 77 icon mappings and their case-insensitive lookup are pinned",
 
22
  "original lexical inventories cannot be reassigned or shadowed through global properties",
23
  "const bindings retain their original mutable array and map contents",
24
  "inventory data is isolated between script evaluations"
25
+ ].map(name => ({name}));
26
+ if (result.status !== 0 || rows.length !== 1 || !hasPassingTapContracts(result.stdout || "", required)) {
 
 
 
 
 
27
  console.error("Search file types coverage requires passing named contracts and exactly one fully covered source row");
28
  process.exitCode = 1;
29
  }
scripts/check_search_filter_equality_baseline.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Require the original inline helper contracts to run, rather than merely load.
4
  const result = spawnSync(process.execPath, [
@@ -8,7 +9,6 @@ if (result.stdout) process.stdout.write(result.stdout);
8
  if (result.stderr) process.stderr.write(result.stderr);
9
  if (result.error) throw result.error;
10
  const text = result.stdout || "";
11
- const lines = text.split(/\r?\n/);
12
  const required = [
13
  "falsy saved values short-circuit before inspecting current",
14
  "length and elements use strict equality in order",
@@ -17,13 +17,8 @@ const required = [
17
  "the current length is re-read after indexed getters mutate it",
18
  "getter exceptions propagate without later property reads",
19
  "the original global function binding remains writable but not deletable"
20
- ];
21
- if (result.status !== 0 || !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) ||
22
- required.some(name => {
23
- const index = lines.indexOf(`# Subtest: ${name}`);
24
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
25
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
26
- })) {
27
  console.error("Search filter equality requires all named baseline contracts with no skips or todos");
28
  process.exitCode = 1;
29
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Require the original inline helper contracts to run, rather than merely load.
5
  const result = spawnSync(process.execPath, [
 
9
  if (result.stderr) process.stderr.write(result.stderr);
10
  if (result.error) throw result.error;
11
  const text = result.stdout || "";
 
12
  const required = [
13
  "falsy saved values short-circuit before inspecting current",
14
  "length and elements use strict equality in order",
 
17
  "the current length is re-read after indexed getters mutate it",
18
  "getter exceptions propagate without later property reads",
19
  "the original global function binding remains writable but not deletable"
20
+ ].map(name => ({name}));
21
+ if (result.status !== 0 || !hasPassingTapContracts(text, required)) {
 
 
 
 
 
22
  console.error("Search filter equality requires all named baseline contracts with no skips or todos");
23
  process.exitCode = 1;
24
  }
scripts/check_search_folder_merge_baseline.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Require every original inline merge contract to finish without skips.
4
  const result = spawnSync(process.execPath, [
@@ -8,7 +9,6 @@ if (result.stdout) process.stdout.write(result.stdout);
8
  if (result.stderr) process.stderr.write(result.stderr);
9
  if (result.error) throw result.error;
10
  const text = result.stdout || "";
11
- const lines = text.split(/\r?\n/);
12
  const required = [
13
  "self paths retain order and duplicates while matching subtree paths are excluded",
14
  "falsy arguments use empty arrays without discarding truthy paths",
@@ -20,13 +20,8 @@ const required = [
20
  "rebound Set receives the original iterable without an intermediate copy",
21
  "custom filter can observe the original callback constructability",
22
  "the original global function binding remains writable but not deletable"
23
- ];
24
- if (result.status !== 0 || !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) ||
25
- required.some(name => {
26
- const index = lines.indexOf(`# Subtest: ${name}`);
27
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
28
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
29
- })) {
30
  console.error("Search folder merge requires all named baseline contracts with no skips or todos");
31
  process.exitCode = 1;
32
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Require every original inline merge contract to finish without skips.
5
  const result = spawnSync(process.execPath, [
 
9
  if (result.stderr) process.stderr.write(result.stderr);
10
  if (result.error) throw result.error;
11
  const text = result.stdout || "";
 
12
  const required = [
13
  "self paths retain order and duplicates while matching subtree paths are excluded",
14
  "falsy arguments use empty arrays without discarding truthy paths",
 
20
  "rebound Set receives the original iterable without an intermediate copy",
21
  "custom filter can observe the original callback constructability",
22
  "the original global function binding remains writable but not deletable"
23
+ ].map(name => ({name}));
24
+ if (result.status !== 0 || !hasPassingTapContracts(text, required)) {
 
 
 
 
 
25
  console.error("Search folder merge requires all named baseline contracts with no skips or todos");
26
  process.exitCode = 1;
27
  }
scripts/check_search_highlight_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Node 26/V8 scope: search/highlight.js and its pinned behavior contracts.
4
  // The unhit branch guards an empty RegExp match, which ordinary escaped terms
@@ -18,19 +19,14 @@ const rows = (result.stdout || "").split(/\r?\n/).flatMap(line => {
18
  return match ? [match.slice(1).map(Number)] : [];
19
  });
20
  const text = result.stdout || "";
21
- const lines = text.split(/\r?\n/);
22
  const required = [
23
  "HTML escaping preserves text and protects attribute and markup delimiters",
24
  "highlighting matches raw text without marking tags or encoded entities",
25
  "highlight regexp is case-insensitive, deduplicated, reusable and literal",
26
  "highlight cache is bounded FIFO and a hit does not change insertion order"
27
- ];
28
  if (result.status !== 0 || rows.length !== 1 || rows[0].some((value, index) => value < minimum[index]) ||
29
- !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) || required.some(name => {
30
- const index = lines.indexOf(`# Subtest: ${name}`);
31
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
32
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
33
- })) {
34
  console.error("Search highlight coverage requires passing named contracts and exactly one source row above each minimum");
35
  process.exitCode = 1;
36
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Node 26/V8 scope: search/highlight.js and its pinned behavior contracts.
5
  // The unhit branch guards an empty RegExp match, which ordinary escaped terms
 
19
  return match ? [match.slice(1).map(Number)] : [];
20
  });
21
  const text = result.stdout || "";
 
22
  const required = [
23
  "HTML escaping preserves text and protects attribute and markup delimiters",
24
  "highlighting matches raw text without marking tags or encoded entities",
25
  "highlight regexp is case-insensitive, deduplicated, reusable and literal",
26
  "highlight cache is bounded FIFO and a hit does not change insertion order"
27
+ ].map(name => ({name}));
28
  if (result.status !== 0 || rows.length !== 1 || rows[0].some((value, index) => value < minimum[index]) ||
29
+ !hasPassingTapContracts(text, required)) {
 
 
 
 
30
  console.error("Search highlight coverage requires passing named contracts and exactly one source row above each minimum");
31
  process.exitCode = 1;
32
  }
scripts/check_search_record_path_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Node 26/V8: only the extracted path module and its compatibility vectors.
4
  // Require a real source row as well as passing tests and full coverage.
@@ -15,12 +16,9 @@ const text = result.stdout || "";
15
  const lines = text.split(/\r?\n/);
16
  const rows = lines.filter(line =>
17
  /^\s*#\s*record-path\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
18
- const name = "tests/test_search_record_path.js";
19
- const index = lines.indexOf(`# Subtest: ${name}`);
20
- if (result.status !== 0 || rows.length !== 1 || !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) ||
21
- index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
22
- lines[index - 1] !== "# search record paths preserve filenames, separators and URL encoding" ||
23
- !/^ok \d+ - tests\/test_search_record_path\.js$/.test(lines[index + 1] || "")) {
24
  console.error("Search record path coverage gate requires passing named tests and exactly one fully covered source row");
25
  process.exitCode = 1;
26
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Node 26/V8: only the extracted path module and its compatibility vectors.
5
  // Require a real source row as well as passing tests and full coverage.
 
16
  const lines = text.split(/\r?\n/);
17
  const rows = lines.filter(line =>
18
  /^\s*#\s*record-path\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
19
+ const required = [{name: "tests/test_search_record_path.js",
20
+ marker: "search record paths preserve filenames, separators and URL encoding"}];
21
+ if (result.status !== 0 || rows.length !== 1 || !hasPassingTapContracts(text, required)) {
 
 
 
22
  console.error("Search record path coverage gate requires passing named tests and exactly one fully covered source row");
23
  process.exitCode = 1;
24
  }
scripts/check_search_response_cache_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Node 26/V8 scope: the extracted response cache and its contract vectors.
4
  // A missing source row or a failed test must never pass as empty coverage.
@@ -22,16 +23,8 @@ const required = [
22
  "replacement resets TTL, byte count and LRU position",
23
  "oversize replacement and serialization errors retire the previous key",
24
  "the independent one-MiB entry cap rejects larger entries even with a larger total budget"
25
- ];
26
- const skipped = lines.filter(line => /^# skipped(?:\s|$)/.test(line));
27
- const todo = lines.filter(line => /^# todo(?:\s|$)/.test(line));
28
- if (result.status !== 0 || rows.length !== 1 || skipped.length !== 1 || skipped[0] !== "# skipped 0" ||
29
- todo.length !== 1 || todo[0] !== "# todo 0" ||
30
- required.some(name => {
31
- const index = lines.indexOf(`# Subtest: ${name}`);
32
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
33
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
34
- })) {
35
  console.error("Search response cache coverage requires passing named tests and exactly one fully covered source row");
36
  process.exitCode = 1;
37
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Node 26/V8 scope: the extracted response cache and its contract vectors.
5
  // A missing source row or a failed test must never pass as empty coverage.
 
23
  "replacement resets TTL, byte count and LRU position",
24
  "oversize replacement and serialization errors retire the previous key",
25
  "the independent one-MiB entry cap rejects larger entries even with a larger total budget"
26
+ ].map(name => ({name}));
27
+ if (result.status !== 0 || rows.length !== 1 || !hasPassingTapContracts(text, required)) {
 
 
 
 
 
 
 
 
28
  console.error("Search response cache coverage requires passing named tests and exactly one fully covered source row");
29
  process.exitCode = 1;
30
  }
scripts/check_search_response_validation_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Node 26/V8 scope: extracted response validator only, excluding the host.
4
  const result = spawnSync(process.execPath, [
@@ -13,20 +14,14 @@ if (result.error) throw result.error;
13
  const text = result.stdout || "";
14
  const rows = text.split(/\r?\n/).filter(line =>
15
  /^\s*#\s*response-validation\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
16
- const lines = text.split(/\r?\n/);
17
  const required = [
18
  "complete, final, empty and past-end pages preserve exact cardinality",
19
  "response shape, safe total and requested page fields are strictly checked",
20
  "record elements accept objects only, preserving sparse-array every semantics",
21
  "legacy boundary values and getter evaluation order remain unchanged",
22
  "host function remains replaceable while forwarding the exact arguments and return value"
23
- ];
24
- if (result.status !== 0 || rows.length !== 1 || !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) ||
25
- required.some(name => {
26
- const index = lines.indexOf(`# Subtest: ${name}`);
27
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
28
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
29
- })) {
30
  console.error("Search response validation coverage requires passing named contracts and exactly one fully covered source row");
31
  process.exitCode = 1;
32
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Node 26/V8 scope: extracted response validator only, excluding the host.
5
  const result = spawnSync(process.execPath, [
 
14
  const text = result.stdout || "";
15
  const rows = text.split(/\r?\n/).filter(line =>
16
  /^\s*#\s*response-validation\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
 
17
  const required = [
18
  "complete, final, empty and past-end pages preserve exact cardinality",
19
  "response shape, safe total and requested page fields are strictly checked",
20
  "record elements accept objects only, preserving sparse-array every semantics",
21
  "legacy boundary values and getter evaluation order remain unchanged",
22
  "host function remains replaceable while forwarding the exact arguments and return value"
23
+ ].map(name => ({name}));
24
+ if (result.status !== 0 || rows.length !== 1 || !hasPassingTapContracts(text, required)) {
 
 
 
 
 
25
  console.error("Search response validation coverage requires passing named contracts and exactly one fully covered source row");
26
  process.exitCode = 1;
27
  }
scripts/check_search_result_identity_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Node 26/V8 scope: extracted identity module only, excluding host and path helper.
4
  const result = spawnSync(process.execPath, [
@@ -13,7 +14,6 @@ if (result.error) throw result.error;
13
  const text = result.stdout || "";
14
  const rows = text.split(/\r?\n/).filter(line =>
15
  /^\s*#\s*result-identity\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
16
- const lines = text.split(/\r?\n/);
17
  const required = [
18
  "non-objects are empty while object fallbacks retain exact path spelling",
19
  "truthy Id precedes id and both retain original String conversion",
@@ -21,13 +21,8 @@ const required = [
21
  "dependency lookup and exceptional values propagate unchanged",
22
  "path lookup remains lazy through early returns and Repo conversion",
23
  "host binding forwards the original result and uncoerced return value"
24
- ];
25
- if (result.status !== 0 || rows.length !== 1 || !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) ||
26
- required.some(name => {
27
- const index = lines.indexOf(`# Subtest: ${name}`);
28
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
29
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
30
- })) {
31
  console.error("Search result identity coverage requires passing named contracts and exactly one fully covered source row");
32
  process.exitCode = 1;
33
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Node 26/V8 scope: extracted identity module only, excluding host and path helper.
5
  const result = spawnSync(process.execPath, [
 
14
  const text = result.stdout || "";
15
  const rows = text.split(/\r?\n/).filter(line =>
16
  /^\s*#\s*result-identity\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
 
17
  const required = [
18
  "non-objects are empty while object fallbacks retain exact path spelling",
19
  "truthy Id precedes id and both retain original String conversion",
 
21
  "dependency lookup and exceptional values propagate unchanged",
22
  "path lookup remains lazy through early returns and Repo conversion",
23
  "host binding forwards the original result and uncoerced return value"
24
+ ].map(name => ({name}));
25
+ if (result.status !== 0 || rows.length !== 1 || !hasPassingTapContracts(text, required)) {
 
 
 
 
 
26
  console.error("Search result identity coverage requires passing named contracts and exactly one fully covered source row");
27
  process.exitCode = 1;
28
  }
scripts/check_search_size_coverage.mjs CHANGED
@@ -1,4 +1,5 @@
1
  import {spawnSync} from "node:child_process";
 
2
 
3
  // Only the extracted size-format module, as exercised by the compatibility
4
  // vectors; an unloaded file must not be accepted as an empty 100% report.
@@ -15,16 +16,12 @@ const text = result.stdout || "";
15
  const lines = text.split(/\r?\n/);
16
  const rows = lines.filter(line =>
17
  /^\s*#\s*size-format\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
18
- const required = ["tests/test_search_size_format.js", "display preserves binary boundaries and historical precision",
19
- "display retains original coercion and empty-value behavior", "display retains prototype and normalized cache behavior"];
20
- if (result.status !== 0 || rows.length !== 1 || !/^# skipped 0$/m.test(text) || !/^# todo 0$/m.test(text) ||
21
- required.some(name => {
22
- const index = lines.indexOf(`# Subtest: ${name}`);
23
- return index < 0 || lines.lastIndexOf(`# Subtest: ${name}`) !== index ||
24
- !new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "") ||
25
- (name === "tests/test_search_size_format.js" &&
26
- lines[index - 1] !== "# search size formatting, parser compatibility and URL round trips passed");
27
- })) {
28
  console.error("Search size coverage gate requires passing named tests and exactly one fully covered source row");
29
  process.exitCode = 1;
30
  }
 
1
  import {spawnSync} from "node:child_process";
2
+ import {hasPassingTapContracts} from "./check_tap_contracts.mjs";
3
 
4
  // Only the extracted size-format module, as exercised by the compatibility
5
  // vectors; an unloaded file must not be accepted as an empty 100% report.
 
16
  const lines = text.split(/\r?\n/);
17
  const rows = lines.filter(line =>
18
  /^\s*#\s*size-format\.js\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|\s*100(?:\.0+)?\s*\|/.test(line));
19
+ const required = [
20
+ {name: "tests/test_search_size_format.js", marker: "search size formatting, parser compatibility and URL round trips passed"},
21
+ ...["display preserves binary boundaries and historical precision", "display retains original coercion and empty-value behavior",
22
+ "display retains prototype and normalized cache behavior"].map(name => ({name}))
23
+ ];
24
+ if (result.status !== 0 || rows.length !== 1 || !hasPassingTapContracts(text, required)) {
 
 
 
 
25
  console.error("Search size coverage gate requires passing named tests and exactly one fully covered source row");
26
  process.exitCode = 1;
27
  }
scripts/check_tap_contracts.mjs ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Shared TAP contract checks for coverage gates; percentages stay gate-owned.
2
+ /** @param {string} text @param {{name: string, marker?: string}[]} required */
3
+ export function hasPassingTapContracts(text, required) {
4
+ const lines = text.split(/\r?\n/);
5
+ const skipped = lines.filter(line => /^# skipped(?:\s|$)/.test(line));
6
+ const todo = lines.filter(line => /^# todo(?:\s|$)/.test(line));
7
+ if (!(skipped.length === 1 && skipped[0] === "# skipped 0" && todo.length === 1 && todo[0] === "# todo 0")) return false;
8
+ if (!Array.isArray(required) || required.length === 0 ||
9
+ required.some(contract => !contract || typeof contract !== "object" || typeof contract.name !== "string" || !contract.name ||
10
+ ("marker" in contract && typeof contract.marker !== "string"))) return false;
11
+ if (new Set(required.map(contract => contract.name)).size !== required.length) return false;
12
+ return required.every(({name, marker}) => {
13
+ const index = lines.indexOf(`# Subtest: ${name}`);
14
+ return index >= 0 && lines.lastIndexOf(`# Subtest: ${name}`) === index &&
15
+ (marker === undefined || lines[index - 1] === `# ${marker}`) &&
16
+ new RegExp(`^ok \\d+ - ${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`).test(lines[index + 1] || "");
17
+ });
18
+ }
tests/test_static_checks.py CHANGED
@@ -220,7 +220,7 @@ class StaticGateTests(unittest.TestCase):
220
  def test_document_loader_coverage_gate_fails_closed(self):
221
  paths = ["static/reader/core/reader-document-loader.mjs", "scripts/check_document_loader_coverage.mjs",
222
  "tests/test_reader_document_loader_contract.mjs", "tests/test_reader_pdf_rate_outer.mjs"]
223
- for path in paths:
224
  target = self.root / path
225
  target.parent.mkdir(parents=True, exist_ok=True)
226
  shutil.copyfile(ROOT / path, target)
@@ -245,6 +245,11 @@ class StaticGateTests(unittest.TestCase):
245
  'test.todo("extra todo");'):
246
  contract.write_text(original + "\n" + extra + "\n")
247
  self.assert_check(self.run_check(*check), False, "passing named tests")
 
 
 
 
 
248
  contract.write_text(original)
249
  rate_test = self.root / paths[3]
250
  rate_source = rate_test.read_text()
@@ -263,10 +268,25 @@ class StaticGateTests(unittest.TestCase):
263
  (self.root / paths[2]).write_text('import "../static/reader/core/reader-document-loader.mjs";\n')
264
  self.assert_check(self.run_check(*check), False, "coverage")
265
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  def test_document_loader_coverage_checks_fractional_minimum(self):
267
  paths = ["static/reader/core/reader-document-loader.mjs", "scripts/check_document_loader_coverage.mjs",
268
  "tests/test_reader_document_loader_contract.mjs", "tests/test_reader_pdf_rate_outer.mjs"]
269
- for path in paths:
270
  target = self.root / path
271
  target.parent.mkdir(parents=True, exist_ok=True)
272
  shutil.copyfile(ROOT / path, target)
@@ -295,7 +315,7 @@ class StaticGateTests(unittest.TestCase):
295
  def test_search_response_cache_coverage_gate_fails_closed(self):
296
  paths = ["static/search/response-cache.js", "scripts/check_search_response_cache_coverage.mjs",
297
  "tests/test_search_response_cache_contract.js"]
298
- for path in paths:
299
  target = self.root / path
300
  target.parent.mkdir(parents=True, exist_ok=True)
301
  shutil.copyfile(ROOT / path, target)
@@ -367,7 +387,7 @@ class StaticGateTests(unittest.TestCase):
367
  def test_search_result_identity_coverage_gate_fails_closed(self):
368
  paths = ["static/search/result-identity.js", "static/search/record-path.js",
369
  "scripts/check_search_result_identity_coverage.mjs", "tests/test_search_stable_id_baseline.mjs", "static/app.js"]
370
- for path in paths:
371
  target = self.root / path
372
  target.parent.mkdir(parents=True, exist_ok=True)
373
  shutil.copyfile(ROOT / path, target)
@@ -381,6 +401,11 @@ class StaticGateTests(unittest.TestCase):
381
  self.assert_check(self.run_check(*check), False, "passing named contracts")
382
  test.write_text(source.replace("test('" + name + "'", "test.skip('" + name + "'"))
383
  self.assert_check(self.run_check(*check), False, "passing named contracts")
 
 
 
 
 
384
  test.write_text(source.replace("test('" + name + "', () => {", "test('" + name + "', () => { throw new Error('identity failure');"))
385
  self.assert_check(self.run_check(*check), False, "identity failure")
386
  test.unlink()
@@ -425,7 +450,7 @@ class StaticGateTests(unittest.TestCase):
425
  def test_search_response_validation_coverage_gate_fails_closed(self):
426
  paths = ["static/search/response-validation.js", "scripts/check_search_response_validation_coverage.mjs",
427
  "tests/test_search_response_validation_baseline.mjs", "static/app.js"]
428
- for path in paths:
429
  target = self.root / path
430
  target.parent.mkdir(parents=True, exist_ok=True)
431
  shutil.copyfile(ROOT / path, target)
@@ -439,6 +464,11 @@ class StaticGateTests(unittest.TestCase):
439
  self.assert_check(self.run_check(*check), False, "passing named contracts")
440
  test.write_text(source.replace("test('" + name + "'", "test.skip('" + name + "'"))
441
  self.assert_check(self.run_check(*check), False, "passing named contracts")
 
 
 
 
 
442
  test.write_text(source.replace("test('" + name + "', () => {",
443
  "test('" + name + "', () => { throw new Error('contract failure');"))
444
  self.assert_check(self.run_check(*check), False, "contract failure")
@@ -495,13 +525,19 @@ class StaticGateTests(unittest.TestCase):
495
  def test_search_file_types_coverage_gate_fails_closed(self):
496
  paths = ["static/search/file-types.js", "scripts/check_search_file_types_coverage.mjs",
497
  "tests/test_search_extension_inventory_baseline.mjs", "static/app.js"]
498
- for path in paths:
499
  target = self.root / path
500
  target.parent.mkdir(parents=True, exist_ok=True)
501
  shutil.copyfile(ROOT / path, target)
502
  check = ["node", "scripts/check_search_file_types_coverage.mjs"]
503
  self.assert_check(self.run_check(*check), True, "file-types.js")
504
  test = self.root / paths[2]
 
 
 
 
 
 
505
  test.write_text('import test from "node:test"; test("empty", () => {});\n')
506
  self.assert_check(self.run_check(*check), False, "exactly one fully covered source row")
507
  test.write_text('throw new Error("failed file types test");\n')
@@ -544,7 +580,7 @@ class StaticGateTests(unittest.TestCase):
544
  def test_search_highlight_coverage_gate_fails_closed(self):
545
  paths = ["static/search/highlight.js", "scripts/check_search_highlight_coverage.mjs",
546
  "tests/test_search_highlight_contract.js"]
547
- for path in paths:
548
  target = self.root / path
549
  target.parent.mkdir(parents=True, exist_ok=True)
550
  shutil.copyfile(ROOT / path, target)
@@ -564,6 +600,11 @@ class StaticGateTests(unittest.TestCase):
564
  self.assert_check(self.run_check(*check), False, "passing named contracts")
565
  test.write_text(source + '\ntest.todo("unfinished contract");\n')
566
  self.assert_check(self.run_check(*check), False, "passing named contracts")
 
 
 
 
 
567
  test.write_text('require("node:test")("empty", () => {});\n')
568
  self.assert_check(self.run_check(*check), False, "exactly one source row")
569
  test.write_text('throw new Error("failed highlight test");\n')
@@ -575,7 +616,7 @@ class StaticGateTests(unittest.TestCase):
575
 
576
  def test_search_highlight_coverage_checks_fractional_minimum(self):
577
  for path in ("static/search/highlight.js", "scripts/check_search_highlight_coverage.mjs",
578
- "tests/test_search_highlight_contract.js"):
579
  target = self.root / path
580
  target.parent.mkdir(parents=True, exist_ok=True)
581
  shutil.copyfile(ROOT / path, target)
@@ -614,7 +655,7 @@ class StaticGateTests(unittest.TestCase):
614
  def test_search_record_path_coverage_gate_fails_closed(self):
615
  paths = ["static/search/record-path.js", "scripts/check_search_record_path_coverage.mjs",
616
  "tests/test_search_record_path.js", "static/app.js"]
617
- for path in paths:
618
  target = self.root / path
619
  target.parent.mkdir(parents=True, exist_ok=True)
620
  shutil.copyfile(ROOT / path, target)
@@ -630,6 +671,11 @@ class StaticGateTests(unittest.TestCase):
630
  'require("node:test").todo("extra todo");'):
631
  test.write_text(original + "\n" + extra + "\n")
632
  self.assert_check(self.run_check(*check), False, "passing named tests")
 
 
 
 
 
633
  test.write_text(original + '\nrequire("node:test")("unexpected failure", () => { throw new Error("path assertion failure"); });\n')
634
  self.assert_check(self.run_check(*check), False, "path assertion failure")
635
  test.write_text('require("node:test")("empty", () => {});\n')
@@ -665,7 +711,7 @@ class StaticGateTests(unittest.TestCase):
665
  def test_search_size_coverage_gate_fails_closed(self):
666
  paths = ["static/search/size-format.js", "scripts/check_search_size_coverage.mjs",
667
  "tests/test_search_size_format.js", "tests/test_search_size_render_contract.js"]
668
- for path in paths:
669
  target = self.root / path
670
  target.parent.mkdir(parents=True, exist_ok=True)
671
  shutil.copyfile(ROOT / path, target)
@@ -686,6 +732,11 @@ class StaticGateTests(unittest.TestCase):
686
  'test.todo("extra todo");'):
687
  render.write_text(original + "\n" + extra + "\n")
688
  self.assert_check(self.run_check(*check), False, "passing named tests")
 
 
 
 
 
689
  render.write_text(original)
690
  formatted = self.root / paths[2]
691
  formatted_source = formatted.read_text()
@@ -728,7 +779,7 @@ class StaticGateTests(unittest.TestCase):
728
  paths = ["static/reader/core/reader-request-manager.js", "scripts/check_request_manager_coverage.mjs",
729
  "tests/test_reader_request_manager.js", "tests/test_reader_initial_recovery.js",
730
  "tests/test_reader_request_manager_edges.js"]
731
- for path in paths:
732
  target = self.root / path
733
  target.parent.mkdir(parents=True, exist_ok=True)
734
  shutil.copyfile(ROOT / path, target)
@@ -744,6 +795,11 @@ class StaticGateTests(unittest.TestCase):
744
  self.assert_check(self.run_check(*check), False, "passing named tests")
745
  source.write_text(original + '\nrequire("node:test").todo("unfinished check");\n')
746
  self.assert_check(self.run_check(*check), False, "passing named tests")
 
 
 
 
 
747
  source.write_text(original + '\nrequire("node:test")("reader request manager behavior", () => {});\n')
748
  self.assert_check(self.run_check(*check), False, "passing named tests")
749
  source.write_text(original)
@@ -802,7 +858,7 @@ class StaticGateTests(unittest.TestCase):
802
  paths = ["static/reader/core/reader-request-manager.js", "scripts/check_request_manager_coverage.mjs",
803
  "tests/test_reader_request_manager.js", "tests/test_reader_initial_recovery.js",
804
  "tests/test_reader_request_manager_edges.js"]
805
- for path in paths:
806
  target = self.root / path
807
  target.parent.mkdir(parents=True, exist_ok=True)
808
  shutil.copyfile(ROOT / path, target)
@@ -975,7 +1031,7 @@ class StaticGateTests(unittest.TestCase):
975
  "tests/test_reader_section_virtualizer.js", "tests/test_reader_chapter_repository.js",
976
  "tests/test_reader_chapter_scheduler.js", "tests/test_reader_chapter_preload.js",
977
  "tests/test_reader_scroll_anchor.js"]
978
- for path in paths:
979
  target = self.root / path
980
  target.parent.mkdir(parents=True, exist_ok=True)
981
  shutil.copyfile(ROOT / path, target)
@@ -996,6 +1052,11 @@ class StaticGateTests(unittest.TestCase):
996
  self.assert_check(self.run_check(*check), False, "passing named tests")
997
  chapter_test.write_text(original_test + '\nrequire("node:test").todo("unfinished check");\n')
998
  self.assert_check(self.run_check(*check), False, "passing named tests")
 
 
 
 
 
999
  chapter_test.write_text(original_test.replace('reader chapter repository contracts passed', 'renamed success marker'))
1000
  self.assert_check(self.run_check(*check), False, "passing named tests")
1001
  chapter_test.write_text(original_test)
@@ -1192,7 +1253,7 @@ class StaticGateTests(unittest.TestCase):
1192
  def test_search_folder_merge_baseline_gate_fails_closed(self):
1193
  paths = ["static/app.js", "scripts/check_search_folder_merge_baseline.mjs",
1194
  "tests/test_search_folder_merge_baseline.mjs"]
1195
- for path in paths:
1196
  target = self.root / path
1197
  target.parent.mkdir(parents=True, exist_ok=True)
1198
  shutil.copyfile(ROOT / path, target)
@@ -1210,6 +1271,11 @@ class StaticGateTests(unittest.TestCase):
1210
  "test.todo('extra todo');"):
1211
  test.write_text(source + "\n" + extra + "\n")
1212
  self.assert_check(self.run_check(*check), False, "all named baseline contracts")
 
 
 
 
 
1213
  test.write_text(source.replace(anchor + ", () => {", anchor + ", () => { throw new Error('folder merge failed');"))
1214
  self.assert_check(self.run_check(*check), False, "folder merge failed")
1215
  test.unlink()
@@ -1222,7 +1288,7 @@ class StaticGateTests(unittest.TestCase):
1222
  def test_search_filter_equality_baseline_gate_fails_closed(self):
1223
  paths = ["static/app.js", "scripts/check_search_filter_equality_baseline.mjs",
1224
  "tests/test_search_filter_equality_baseline.mjs"]
1225
- for path in paths:
1226
  target = self.root / path
1227
  target.parent.mkdir(parents=True, exist_ok=True)
1228
  shutil.copyfile(ROOT / path, target)
@@ -1240,6 +1306,11 @@ class StaticGateTests(unittest.TestCase):
1240
  self.assert_check(self.run_check(*check), False, "all named baseline contracts")
1241
  test.write_text(source + "\ntest.skip('additional skip', () => {});\n")
1242
  self.assert_check(self.run_check(*check), False, "all named baseline contracts")
 
 
 
 
 
1243
  test.write_text(source.replace(anchor + ", () => {", anchor + ", () => { throw new Error('filter baseline failed');"))
1244
  self.assert_check(self.run_check(*check), False, "filter baseline failed")
1245
  test.unlink()
 
220
  def test_document_loader_coverage_gate_fails_closed(self):
221
  paths = ["static/reader/core/reader-document-loader.mjs", "scripts/check_document_loader_coverage.mjs",
222
  "tests/test_reader_document_loader_contract.mjs", "tests/test_reader_pdf_rate_outer.mjs"]
223
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
224
  target = self.root / path
225
  target.parent.mkdir(parents=True, exist_ok=True)
226
  shutil.copyfile(ROOT / path, target)
 
245
  'test.todo("extra todo");'):
246
  contract.write_text(original + "\n" + extra + "\n")
247
  self.assert_check(self.run_check(*check), False, "passing named tests")
248
+ for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});',
249
+ 'console.log("todo 0"); test.todo("extra todo");',
250
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
251
+ contract.write_text(original + "\n" + extra + "\n")
252
+ self.assert_check(self.run_check(*check), False, "passing named tests")
253
  contract.write_text(original)
254
  rate_test = self.root / paths[3]
255
  rate_source = rate_test.read_text()
 
268
  (self.root / paths[2]).write_text('import "../static/reader/core/reader-document-loader.mjs";\n')
269
  self.assert_check(self.run_check(*check), False, "coverage")
270
 
271
+ def test_shared_tap_validator_tests_are_required(self):
272
+ paths = ["scripts/check_tap_contracts.mjs", "tests/test_tap_contracts.mjs"]
273
+ for path in paths:
274
+ target = self.root / path
275
+ target.parent.mkdir(parents=True, exist_ok=True)
276
+ shutil.copyfile(ROOT / path, target)
277
+ check = ["node", "--test", "--test-reporter=tap", paths[1]]
278
+ self.assert_check(self.run_check(*check), True, "# pass 3")
279
+ helper = self.root / paths[0]
280
+ original = helper.read_text()
281
+ anchor = 'todo[0] === "# todo 0"'
282
+ self.assertEqual(original.count(anchor), 1)
283
+ helper.write_text(original.replace(anchor, 'true'))
284
+ self.assert_check(self.run_check(*check), False, "not ok")
285
+
286
  def test_document_loader_coverage_checks_fractional_minimum(self):
287
  paths = ["static/reader/core/reader-document-loader.mjs", "scripts/check_document_loader_coverage.mjs",
288
  "tests/test_reader_document_loader_contract.mjs", "tests/test_reader_pdf_rate_outer.mjs"]
289
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
290
  target = self.root / path
291
  target.parent.mkdir(parents=True, exist_ok=True)
292
  shutil.copyfile(ROOT / path, target)
 
315
  def test_search_response_cache_coverage_gate_fails_closed(self):
316
  paths = ["static/search/response-cache.js", "scripts/check_search_response_cache_coverage.mjs",
317
  "tests/test_search_response_cache_contract.js"]
318
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
319
  target = self.root / path
320
  target.parent.mkdir(parents=True, exist_ok=True)
321
  shutil.copyfile(ROOT / path, target)
 
387
  def test_search_result_identity_coverage_gate_fails_closed(self):
388
  paths = ["static/search/result-identity.js", "static/search/record-path.js",
389
  "scripts/check_search_result_identity_coverage.mjs", "tests/test_search_stable_id_baseline.mjs", "static/app.js"]
390
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
391
  target = self.root / path
392
  target.parent.mkdir(parents=True, exist_ok=True)
393
  shutil.copyfile(ROOT / path, target)
 
401
  self.assert_check(self.run_check(*check), False, "passing named contracts")
402
  test.write_text(source.replace("test('" + name + "'", "test.skip('" + name + "'"))
403
  self.assert_check(self.run_check(*check), False, "passing named contracts")
404
+ for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});',
405
+ 'console.log("todo 0"); test.todo("extra todo");',
406
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
407
+ test.write_text(source + "\n" + extra + "\n")
408
+ self.assert_check(self.run_check(*check), False, "passing named contracts")
409
  test.write_text(source.replace("test('" + name + "', () => {", "test('" + name + "', () => { throw new Error('identity failure');"))
410
  self.assert_check(self.run_check(*check), False, "identity failure")
411
  test.unlink()
 
450
  def test_search_response_validation_coverage_gate_fails_closed(self):
451
  paths = ["static/search/response-validation.js", "scripts/check_search_response_validation_coverage.mjs",
452
  "tests/test_search_response_validation_baseline.mjs", "static/app.js"]
453
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
454
  target = self.root / path
455
  target.parent.mkdir(parents=True, exist_ok=True)
456
  shutil.copyfile(ROOT / path, target)
 
464
  self.assert_check(self.run_check(*check), False, "passing named contracts")
465
  test.write_text(source.replace("test('" + name + "'", "test.skip('" + name + "'"))
466
  self.assert_check(self.run_check(*check), False, "passing named contracts")
467
+ for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});',
468
+ 'console.log("todo 0"); test.todo("extra todo");',
469
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
470
+ test.write_text(source + "\n" + extra + "\n")
471
+ self.assert_check(self.run_check(*check), False, "passing named contracts")
472
  test.write_text(source.replace("test('" + name + "', () => {",
473
  "test('" + name + "', () => { throw new Error('contract failure');"))
474
  self.assert_check(self.run_check(*check), False, "contract failure")
 
525
  def test_search_file_types_coverage_gate_fails_closed(self):
526
  paths = ["static/search/file-types.js", "scripts/check_search_file_types_coverage.mjs",
527
  "tests/test_search_extension_inventory_baseline.mjs", "static/app.js"]
528
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
529
  target = self.root / path
530
  target.parent.mkdir(parents=True, exist_ok=True)
531
  shutil.copyfile(ROOT / path, target)
532
  check = ["node", "scripts/check_search_file_types_coverage.mjs"]
533
  self.assert_check(self.run_check(*check), True, "file-types.js")
534
  test = self.root / paths[2]
535
+ original = test.read_text()
536
+ for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});',
537
+ 'console.log("todo 0"); test.todo("extra todo");',
538
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
539
+ test.write_text(original + "\n" + extra + "\n")
540
+ self.assert_check(self.run_check(*check), False, "passing named contracts")
541
  test.write_text('import test from "node:test"; test("empty", () => {});\n')
542
  self.assert_check(self.run_check(*check), False, "exactly one fully covered source row")
543
  test.write_text('throw new Error("failed file types test");\n')
 
580
  def test_search_highlight_coverage_gate_fails_closed(self):
581
  paths = ["static/search/highlight.js", "scripts/check_search_highlight_coverage.mjs",
582
  "tests/test_search_highlight_contract.js"]
583
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
584
  target = self.root / path
585
  target.parent.mkdir(parents=True, exist_ok=True)
586
  shutil.copyfile(ROOT / path, target)
 
600
  self.assert_check(self.run_check(*check), False, "passing named contracts")
601
  test.write_text(source + '\ntest.todo("unfinished contract");\n')
602
  self.assert_check(self.run_check(*check), False, "passing named contracts")
603
+ for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});',
604
+ 'console.log("todo 0"); test.todo("extra todo");',
605
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
606
+ test.write_text(source + "\n" + extra + "\n")
607
+ self.assert_check(self.run_check(*check), False, "passing named contracts")
608
  test.write_text('require("node:test")("empty", () => {});\n')
609
  self.assert_check(self.run_check(*check), False, "exactly one source row")
610
  test.write_text('throw new Error("failed highlight test");\n')
 
616
 
617
  def test_search_highlight_coverage_checks_fractional_minimum(self):
618
  for path in ("static/search/highlight.js", "scripts/check_search_highlight_coverage.mjs",
619
+ "tests/test_search_highlight_contract.js", "scripts/check_tap_contracts.mjs"):
620
  target = self.root / path
621
  target.parent.mkdir(parents=True, exist_ok=True)
622
  shutil.copyfile(ROOT / path, target)
 
655
  def test_search_record_path_coverage_gate_fails_closed(self):
656
  paths = ["static/search/record-path.js", "scripts/check_search_record_path_coverage.mjs",
657
  "tests/test_search_record_path.js", "static/app.js"]
658
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
659
  target = self.root / path
660
  target.parent.mkdir(parents=True, exist_ok=True)
661
  shutil.copyfile(ROOT / path, target)
 
671
  'require("node:test").todo("extra todo");'):
672
  test.write_text(original + "\n" + extra + "\n")
673
  self.assert_check(self.run_check(*check), False, "passing named tests")
674
+ for extra in ('console.log("skipped 0"); require("node:test").skip("extra skip", () => {});',
675
+ 'console.log("todo 0"); require("node:test").todo("extra todo");',
676
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
677
+ test.write_text(original + "\n" + extra + "\n")
678
+ self.assert_check(self.run_check(*check), False, "passing named tests")
679
  test.write_text(original + '\nrequire("node:test")("unexpected failure", () => { throw new Error("path assertion failure"); });\n')
680
  self.assert_check(self.run_check(*check), False, "path assertion failure")
681
  test.write_text('require("node:test")("empty", () => {});\n')
 
711
  def test_search_size_coverage_gate_fails_closed(self):
712
  paths = ["static/search/size-format.js", "scripts/check_search_size_coverage.mjs",
713
  "tests/test_search_size_format.js", "tests/test_search_size_render_contract.js"]
714
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
715
  target = self.root / path
716
  target.parent.mkdir(parents=True, exist_ok=True)
717
  shutil.copyfile(ROOT / path, target)
 
732
  'test.todo("extra todo");'):
733
  render.write_text(original + "\n" + extra + "\n")
734
  self.assert_check(self.run_check(*check), False, "passing named tests")
735
+ for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});',
736
+ 'console.log("todo 0"); test.todo("extra todo");',
737
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
738
+ render.write_text(original + "\n" + extra + "\n")
739
+ self.assert_check(self.run_check(*check), False, "passing named tests")
740
  render.write_text(original)
741
  formatted = self.root / paths[2]
742
  formatted_source = formatted.read_text()
 
779
  paths = ["static/reader/core/reader-request-manager.js", "scripts/check_request_manager_coverage.mjs",
780
  "tests/test_reader_request_manager.js", "tests/test_reader_initial_recovery.js",
781
  "tests/test_reader_request_manager_edges.js"]
782
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
783
  target = self.root / path
784
  target.parent.mkdir(parents=True, exist_ok=True)
785
  shutil.copyfile(ROOT / path, target)
 
795
  self.assert_check(self.run_check(*check), False, "passing named tests")
796
  source.write_text(original + '\nrequire("node:test").todo("unfinished check");\n')
797
  self.assert_check(self.run_check(*check), False, "passing named tests")
798
+ for extra in ('console.log("skipped 0"); require("node:test").skip("extra skip", () => {});',
799
+ 'console.log("todo 0"); require("node:test").todo("extra todo");',
800
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
801
+ source.write_text(original + "\n" + extra + "\n")
802
+ self.assert_check(self.run_check(*check), False, "passing named tests")
803
  source.write_text(original + '\nrequire("node:test")("reader request manager behavior", () => {});\n')
804
  self.assert_check(self.run_check(*check), False, "passing named tests")
805
  source.write_text(original)
 
858
  paths = ["static/reader/core/reader-request-manager.js", "scripts/check_request_manager_coverage.mjs",
859
  "tests/test_reader_request_manager.js", "tests/test_reader_initial_recovery.js",
860
  "tests/test_reader_request_manager_edges.js"]
861
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
862
  target = self.root / path
863
  target.parent.mkdir(parents=True, exist_ok=True)
864
  shutil.copyfile(ROOT / path, target)
 
1031
  "tests/test_reader_section_virtualizer.js", "tests/test_reader_chapter_repository.js",
1032
  "tests/test_reader_chapter_scheduler.js", "tests/test_reader_chapter_preload.js",
1033
  "tests/test_reader_scroll_anchor.js"]
1034
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
1035
  target = self.root / path
1036
  target.parent.mkdir(parents=True, exist_ok=True)
1037
  shutil.copyfile(ROOT / path, target)
 
1052
  self.assert_check(self.run_check(*check), False, "passing named tests")
1053
  chapter_test.write_text(original_test + '\nrequire("node:test").todo("unfinished check");\n')
1054
  self.assert_check(self.run_check(*check), False, "passing named tests")
1055
+ for extra in ('console.log("skipped 0"); require("node:test").skip("extra skip", () => {});',
1056
+ 'console.log("todo 0"); require("node:test").todo("extra todo");',
1057
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
1058
+ chapter_test.write_text(original_test + "\n" + extra + "\n")
1059
+ self.assert_check(self.run_check(*check), False, "passing named tests")
1060
  chapter_test.write_text(original_test.replace('reader chapter repository contracts passed', 'renamed success marker'))
1061
  self.assert_check(self.run_check(*check), False, "passing named tests")
1062
  chapter_test.write_text(original_test)
 
1253
  def test_search_folder_merge_baseline_gate_fails_closed(self):
1254
  paths = ["static/app.js", "scripts/check_search_folder_merge_baseline.mjs",
1255
  "tests/test_search_folder_merge_baseline.mjs"]
1256
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
1257
  target = self.root / path
1258
  target.parent.mkdir(parents=True, exist_ok=True)
1259
  shutil.copyfile(ROOT / path, target)
 
1271
  "test.todo('extra todo');"):
1272
  test.write_text(source + "\n" + extra + "\n")
1273
  self.assert_check(self.run_check(*check), False, "all named baseline contracts")
1274
+ for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});',
1275
+ 'console.log("todo 0"); test.todo("extra todo");',
1276
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
1277
+ test.write_text(source + "\n" + extra + "\n")
1278
+ self.assert_check(self.run_check(*check), False, "all named baseline contracts")
1279
  test.write_text(source.replace(anchor + ", () => {", anchor + ", () => { throw new Error('folder merge failed');"))
1280
  self.assert_check(self.run_check(*check), False, "folder merge failed")
1281
  test.unlink()
 
1288
  def test_search_filter_equality_baseline_gate_fails_closed(self):
1289
  paths = ["static/app.js", "scripts/check_search_filter_equality_baseline.mjs",
1290
  "tests/test_search_filter_equality_baseline.mjs"]
1291
+ for path in [*paths, "scripts/check_tap_contracts.mjs"]:
1292
  target = self.root / path
1293
  target.parent.mkdir(parents=True, exist_ok=True)
1294
  shutil.copyfile(ROOT / path, target)
 
1306
  self.assert_check(self.run_check(*check), False, "all named baseline contracts")
1307
  test.write_text(source + "\ntest.skip('additional skip', () => {});\n")
1308
  self.assert_check(self.run_check(*check), False, "all named baseline contracts")
1309
+ for extra in ('console.log("skipped 0"); test.skip("extra skip", () => {});',
1310
+ 'console.log("todo 0"); test.todo("extra todo");',
1311
+ 'console.log("skipped 0");', 'console.log("todo 0");'):
1312
+ test.write_text(source + "\n" + extra + "\n")
1313
+ self.assert_check(self.run_check(*check), False, "all named baseline contracts")
1314
  test.write_text(source.replace(anchor + ", () => {", anchor + ", () => { throw new Error('filter baseline failed');"))
1315
  self.assert_check(self.run_check(*check), False, "filter baseline failed")
1316
  test.unlink()
tests/test_static_contract.py CHANGED
@@ -451,6 +451,7 @@ class StaticFrontendContractTests(unittest.TestCase):
451
  self.assertIn("node scripts/check_search_file_types_coverage.mjs", dockerfile)
452
  self.assertIn("node scripts/check_search_response_validation_coverage.mjs", dockerfile)
453
  self.assertIn("node scripts/check_search_result_identity_coverage.mjs", dockerfile)
 
454
  self.assertIn("node scripts/check_search_filter_equality_baseline.mjs", dockerfile)
455
  self.assertIn("node scripts/check_search_folder_merge_baseline.mjs", dockerfile)
456
  self.assertIn("node --test tests/test_search_response_validation_baseline.mjs", dockerfile)
 
451
  self.assertIn("node scripts/check_search_file_types_coverage.mjs", dockerfile)
452
  self.assertIn("node scripts/check_search_response_validation_coverage.mjs", dockerfile)
453
  self.assertIn("node scripts/check_search_result_identity_coverage.mjs", dockerfile)
454
+ self.assertIn("node --test tests/test_tap_contracts.mjs", dockerfile)
455
  self.assertIn("node scripts/check_search_filter_equality_baseline.mjs", dockerfile)
456
  self.assertIn("node scripts/check_search_folder_merge_baseline.mjs", dockerfile)
457
  self.assertIn("node --test tests/test_search_response_validation_baseline.mjs", dockerfile)
tests/test_tap_contracts.mjs ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import {hasPassingTapContracts} from "../scripts/check_tap_contracts.mjs";
4
+
5
+ const required = [{name: "first (contract)"}, {name: "file/a.b", marker: "finished marker"}];
6
+ const valid = ["TAP version 13", "# Subtest: first (contract)", "ok 1 - first (contract)",
7
+ "# finished marker", "# Subtest: file/a.b", "ok 2 - file/a.b", "# skipped 0", "# todo 0", ""].join("\n");
8
+
9
+ test("requires passing named contracts and matching completion markers", () => {
10
+ assert.equal(hasPassingTapContracts(valid, required), true);
11
+ assert.equal(hasPassingTapContracts(valid.replaceAll("\n", "\r\n"), required), true);
12
+ assert.equal(hasPassingTapContracts(valid.replace("# finished marker", "# wrong marker"), required), false);
13
+ assert.equal(hasPassingTapContracts(valid.replace("# finished marker", "# null"),
14
+ [{name: "file/a.b", marker: /** @type {any} */ (null)}]), false);
15
+ assert.equal(hasPassingTapContracts(valid, []), false);
16
+ assert.equal(hasPassingTapContracts(valid, /** @type {any} */ (null)), false);
17
+ assert.equal(hasPassingTapContracts(valid, [/** @type {any} */ (null)]), false);
18
+ assert.equal(hasPassingTapContracts(valid, [/** @type {any} */ (7)]), false);
19
+ function fakeContract() {}
20
+ const forgedFunction = valid + "# Subtest: fakeContract\nok 3 - fakeContract\n";
21
+ assert.equal(hasPassingTapContracts(forgedFunction, [/** @type {any} */ (fakeContract)]), false);
22
+ assert.equal(hasPassingTapContracts(valid + "# Subtest: \nok 3 - \n", [{name: ""}]), false);
23
+ assert.equal(hasPassingTapContracts(valid, [{name: "first (contract)"}, {name: "first (contract)"}]), false);
24
+ const readerFile = [{name: "file/a.b", marker: "finished marker"}];
25
+ assert.equal(hasPassingTapContracts(valid, readerFile), true);
26
+ assert.equal(hasPassingTapContracts(valid.replace("# finished marker", "# undefined"),
27
+ [{name: "file/a.b", marker: /** @type {any} */ (undefined)}]), false);
28
+ assert.equal(hasPassingTapContracts(valid.replace("# Subtest: first (contract)", "# Subtest: renamed"), required), false);
29
+ assert.equal(hasPassingTapContracts(valid.replace("ok 1 - first (contract)", "not ok 1 - first (contract)"), required), false);
30
+ assert.equal(hasPassingTapContracts(valid.replace("ok 2 - file/a.b", "ok 2 - file/aXb"), required), false);
31
+ });
32
+
33
+ test("rejects absent or nonzero skip and todo summaries", () => {
34
+ for (const line of ["# skipped 0", "# todo 0"]) {
35
+ assert.equal(hasPassingTapContracts(valid.replace(line, ""), required), false);
36
+ assert.equal(hasPassingTapContracts(valid.replace(line, line.replace("0", "1")), required), false);
37
+ assert.equal(hasPassingTapContracts(valid.replace(line, line + "0"), required), false);
38
+ assert.equal(hasPassingTapContracts(valid.replace(line, `${line}\n${line.replace("0", "1")}`), required), false);
39
+ assert.equal(hasPassingTapContracts(valid.replace(line, `${line.replace("0", "1")}\n${line}`), required), false);
40
+ assert.equal(hasPassingTapContracts(valid.replace(line, `${line}\n${line}`), required), false);
41
+ }
42
+ });
43
+
44
+ test("rejects duplicate names, directives and incomplete output", () => {
45
+ assert.equal(hasPassingTapContracts(valid + "# Subtest: first (contract)\nok 3 - first (contract)\n", required), false);
46
+ assert.equal(hasPassingTapContracts(valid.replace("ok 1 - first (contract)", "ok 1 - first (contract) # SKIP"), required), false);
47
+ assert.equal(hasPassingTapContracts(valid.replace("ok 2 - file/a.b", "ok 2 - file/a.b # TODO"), required), false);
48
+ assert.equal(hasPassingTapContracts(valid.replace("ok 2 - file/a.b\n", ""), required), false);
49
+ assert.equal(hasPassingTapContracts("# skipped 0\n# todo 0\n# Subtest: first (contract)", required), false);
50
+ });