pi-spine 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/scripts/coverage-parse.mjs +70 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-spine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Orchestration spine for long-running pi development",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"bin/",
|
|
49
49
|
"extensions/",
|
|
50
50
|
"skills/",
|
|
51
|
+
"scripts/coverage-parse.mjs",
|
|
51
52
|
"src/",
|
|
52
53
|
"templates/"
|
|
53
54
|
],
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parse Node test runner coverage summary output.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} output Combined stdout/stderr from a coverage test run.
|
|
9
|
+
* @returns {number | null} Aggregate line coverage percent, or null if not found.
|
|
10
|
+
*/
|
|
11
|
+
export function parseAggregateLineCoverage(output) {
|
|
12
|
+
const tableMatch = output.match(/^\s*[^\s]*\s*all files\s+\|\s+([\d.]+)\s+\|/m);
|
|
13
|
+
if (tableMatch) {
|
|
14
|
+
const value = Number.parseFloat(tableMatch[1]);
|
|
15
|
+
if (Number.isFinite(value)) {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const summaryMatch = output.match(/Line coverage \(in-scope\):\s*([\d.]+)%/);
|
|
21
|
+
if (summaryMatch) {
|
|
22
|
+
const value = Number.parseFloat(summaryMatch[1]);
|
|
23
|
+
if (Number.isFinite(value)) {
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {string} output Combined stdout/stderr from a coverage test run.
|
|
33
|
+
* @returns {Map<string, number>} Repo-relative path → line coverage percent.
|
|
34
|
+
*/
|
|
35
|
+
export function parsePerFileLineCoverage(output) {
|
|
36
|
+
/** @type {Map<string, number>} */
|
|
37
|
+
const byFile = new Map();
|
|
38
|
+
const rowRe = /^\s*(?:[^\s]*\s+)?([^\s|]+\.(?:mjs|ts))\s+\|\s+([\d.]+)\s+\|/gm;
|
|
39
|
+
for (const match of output.matchAll(rowRe)) {
|
|
40
|
+
const filePath = match[1];
|
|
41
|
+
const linePct = Number.parseFloat(match[2]);
|
|
42
|
+
if (filePath === "all" || filePath === "files" || !Number.isFinite(linePct)) {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
byFile.set(filePath, linePct);
|
|
46
|
+
}
|
|
47
|
+
return byFile;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {string} output
|
|
52
|
+
* @param {Record<string, number>} thresholds
|
|
53
|
+
* @returns {Array<{ path: string, actual: number | null, required: number }>}
|
|
54
|
+
*/
|
|
55
|
+
export function findFileCoverageFailures(output, thresholds) {
|
|
56
|
+
const byFile = parsePerFileLineCoverage(output);
|
|
57
|
+
/** @type {Array<{ path: string, actual: number | null, required: number }>} */
|
|
58
|
+
const failures = [];
|
|
59
|
+
for (const [filePath, required] of Object.entries(thresholds)) {
|
|
60
|
+
const basename = path.basename(filePath);
|
|
61
|
+
let actual = byFile.get(filePath) ?? null;
|
|
62
|
+
if (actual === null) {
|
|
63
|
+
actual = byFile.get(basename) ?? null;
|
|
64
|
+
}
|
|
65
|
+
if (actual === null || actual < required) {
|
|
66
|
+
failures.push({ path: filePath, actual, required });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return failures;
|
|
70
|
+
}
|