File size: 2,158 Bytes
816cdba
4d152fb
816cdba
 
 
 
 
 
 
 
 
 
4d152fb
 
816cdba
 
 
 
 
 
 
 
51b6ed5
5413736
 
 
 
 
da9ec8b
51b6ed5
da9ec8b
51b6ed5
816cdba
 
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
import {spawnSync} from "node:child_process";
import {hasPassingTapContracts} from "../check_tap_contracts.mjs";

// Node 26 V8 report, one source only. Measured with the three named tests:
// 100.00% lines, 95.24% branches, 95.12% functions after strict annotations.
// Compare the printed decimals explicitly: Node floors CLI thresholds, and an
// empty report otherwise passes as 100%. This is not whole-Reader coverage.
const minimum = [100, 95.24, 95.12];
const result = spawnSync(process.execPath, [
  "--test", "--test-concurrency=1", "--test-reporter=tap", "--experimental-test-coverage",
  "--test-coverage-include=**/static/reader/core/reader-request-manager.js",
  ...minimum.map((value, index) => `--test-coverage-${["lines", "branches", "functions"][index]}=${value}`),
  "tests/reader/transport/test_reader_request_manager.js", "tests/reader/transport/test_reader_initial_recovery.js",
  "tests/reader/transport/test_reader_request_manager_edges.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 rows = (result.stdout || "").split(/\r?\n/).flatMap(line => {
  const match = /^\s*#\s*reader-request-manager\.js\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 || "";
// Each test logs its completion marker only after its async contract finishes.
const required = [
  ["reader request manager behavior", "reader request manager contracts passed"],
  ["reader initial response recovery", "reader initial response recovery contracts passed"],
  ["reader request manager edge behavior", "reader request manager edge contracts passed"]
].map(([name, marker]) => ({name, marker}));
if (result.status !== 0 || rows.length !== 1 || rows[0].some((value, index) => value < minimum[index]) ||
    !hasPassingTapContracts(text, required)) {
  console.error("Request manager coverage gate requires passing named tests and exactly one source coverage row above each minimum");
  process.exitCode = 1;
}