@c9up/helix 0.1.4 → 0.1.5
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/dist/runtime/suite.d.ts +26 -0
- package/dist/runtime/suite.d.ts.map +1 -1
- package/dist/runtime/suite.js +21 -18
- package/dist/runtime/suite.js.map +1 -1
- package/index.darwin-arm64.node +0 -0
- package/index.darwin-x64.node +0 -0
- package/index.linux-arm64-gnu.node +0 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/package.json +2 -2
- package/src/cli/coverage/aggregate.ts +0 -231
- package/src/cli/coverage/collect.ts +0 -63
- package/src/cli/coverage/diff/base.ts +0 -46
- package/src/cli/coverage/diff/index.ts +0 -160
- package/src/cli/coverage/diff/overlay.ts +0 -62
- package/src/cli/coverage/diff/parse.ts +0 -121
- package/src/cli/coverage/diff/reporters.ts +0 -82
- package/src/cli/coverage/diff/types.ts +0 -46
- package/src/cli/coverage/filter.ts +0 -71
- package/src/cli/coverage/glob.ts +0 -0
- package/src/cli/coverage/index.ts +0 -126
- package/src/cli/coverage/reporters/json.ts +0 -40
- package/src/cli/coverage/reporters/lcov.ts +0 -54
- package/src/cli/coverage/reporters/text.ts +0 -48
- package/src/cli/coverage/thresholds.ts +0 -73
- package/src/cli/coverage/types.ts +0 -93
- package/src/cli/discover.ts +0 -174
- package/src/cli/native.ts +0 -104
- package/src/cli/pool.ts +0 -486
- package/src/cli/reporter.ts +0 -155
- package/src/cli/run.ts +0 -440
- package/src/cli/summary.ts +0 -42
- package/src/cli/watch/loop.ts +0 -159
- package/src/cli/watch/types.ts +0 -22
- package/src/cli/watch/watcher.ts +0 -145
- package/src/container/index.ts +0 -16
- package/src/container/override.ts +0 -86
- package/src/container/spy.ts +0 -25
- package/src/index.ts +0 -42
- package/src/runtime/assertion-error.ts +0 -38
- package/src/runtime/cli-worker.ts +0 -140
- package/src/runtime/equals.ts +0 -400
- package/src/runtime/expect.ts +0 -173
- package/src/runtime/index.ts +0 -50
- package/src/runtime/lifecycle.ts +0 -17
- package/src/runtime/matchers.ts +0 -452
- package/src/runtime/run.ts +0 -573
- package/src/runtime/suite.ts +0 -310
- package/src/runtime/test-context.ts +0 -59
- package/src/runtime/vi/fake-timers.ts +0 -410
- package/src/runtime/vi/index.ts +0 -254
- package/src/runtime/vi/spy.ts +0 -224
- package/src/runtime/vi/spyOn.ts +0 -155
- package/src/runtime/vi/system-time.ts +0 -121
- package/src/runtime/worker.ts +0 -239
- package/src/time/freeze.ts +0 -229
- package/src/time/index.ts +0 -16
package/dist/runtime/suite.d.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* collection to one `runTestFile` call via AsyncLocalStorage, so parallel
|
|
7
7
|
* invocations never share state.
|
|
8
8
|
*/
|
|
9
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
10
|
export type TestFn = () => void | Promise<void>;
|
|
10
11
|
export type SuiteFn = () => void;
|
|
11
12
|
export type HookType = "beforeAll" | "afterAll" | "beforeEach" | "afterEach";
|
|
@@ -30,6 +31,31 @@ export interface SuiteNode {
|
|
|
30
31
|
children: Array<SuiteNode | TestNode>;
|
|
31
32
|
hooks: Hook[];
|
|
32
33
|
}
|
|
34
|
+
interface CollectionContext {
|
|
35
|
+
root: SuiteNode;
|
|
36
|
+
stack: SuiteNode[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Collection registry. Holds the `AsyncLocalStorage` scope used per test-file
|
|
40
|
+
* run plus a fallback root for direct DSL use.
|
|
41
|
+
*
|
|
42
|
+
* CRITICAL (H5): this state is pinned to `globalThis`, NOT held as module-local
|
|
43
|
+
* variables. A consumer's test does `import { describe } from '@c9up/helix'`
|
|
44
|
+
* while the runner drives collection via `@c9up/helix/runtime/worker`. If those
|
|
45
|
+
* two specifiers resolve to DISTINCT module instances of this file (src vs dist,
|
|
46
|
+
* or an ESM/CJS dual instance under the tsx loader), a module-local registry
|
|
47
|
+
* means the test's `describe`/`test` register into one instance while the worker
|
|
48
|
+
* opens its collection scope on the other — so the worker collects 0 tests.
|
|
49
|
+
* A single globalThis-backed registry removes that hazard entirely.
|
|
50
|
+
*/
|
|
51
|
+
interface CollectionRegistry {
|
|
52
|
+
storage: AsyncLocalStorage<CollectionContext>;
|
|
53
|
+
fallbackRoot: SuiteNode;
|
|
54
|
+
fallbackStack: SuiteNode[];
|
|
55
|
+
}
|
|
56
|
+
declare global {
|
|
57
|
+
var __helixCollectionRegistry: CollectionRegistry | undefined;
|
|
58
|
+
}
|
|
33
59
|
export declare function resetRoot(): SuiteNode;
|
|
34
60
|
export declare function getRoot(): SuiteNode;
|
|
35
61
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suite.d.ts","sourceRoot":"","sources":["../../src/runtime/suite.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"suite.d.ts","sourceRoot":"","sources":["../../src/runtime/suite.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,MAAM,MAAM,GAAG,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAChD,MAAM,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC;AAEjC,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,UAAU,GAAG,YAAY,GAAG,WAAW,CAAC;AAE7E,MAAM,WAAW,IAAI;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;CACX;AAED,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAEvD,MAAM,WAAW,QAAQ;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,GAAG,SAAS,CAAC;IACvB,IAAI,EAAE,OAAO,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AAgC,CAAC"}
|
package/dist/runtime/suite.js
CHANGED
|
@@ -17,28 +17,31 @@ function makeSuite(name, mode, parent) {
|
|
|
17
17
|
hooks: [],
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
function registry() {
|
|
21
|
+
let r = globalThis.__helixCollectionRegistry;
|
|
22
|
+
if (!r) {
|
|
23
|
+
const root = makeSuite("", "run", undefined);
|
|
24
|
+
r = {
|
|
25
|
+
storage: new AsyncLocalStorage(),
|
|
26
|
+
fallbackRoot: root,
|
|
27
|
+
fallbackStack: [root],
|
|
28
|
+
};
|
|
29
|
+
globalThis.__helixCollectionRegistry = r;
|
|
30
|
+
}
|
|
31
|
+
return r;
|
|
32
|
+
}
|
|
32
33
|
function currentContext() {
|
|
33
|
-
const
|
|
34
|
+
const r = registry();
|
|
35
|
+
const scoped = r.storage.getStore();
|
|
34
36
|
if (scoped)
|
|
35
37
|
return scoped;
|
|
36
|
-
return { root: fallbackRoot, stack: fallbackStack };
|
|
38
|
+
return { root: r.fallbackRoot, stack: r.fallbackStack };
|
|
37
39
|
}
|
|
38
40
|
export function resetRoot() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
const r = registry();
|
|
42
|
+
r.fallbackRoot = makeSuite("", "run", undefined);
|
|
43
|
+
r.fallbackStack = [r.fallbackRoot];
|
|
44
|
+
return r.fallbackRoot;
|
|
42
45
|
}
|
|
43
46
|
export function getRoot() {
|
|
44
47
|
return currentContext().root;
|
|
@@ -50,7 +53,7 @@ export function getRoot() {
|
|
|
50
53
|
export async function withCollection(body) {
|
|
51
54
|
const root = makeSuite("", "run", undefined);
|
|
52
55
|
const ctx = { root, stack: [root] };
|
|
53
|
-
await storage.run(ctx, async () => {
|
|
56
|
+
await registry().storage.run(ctx, async () => {
|
|
54
57
|
await body();
|
|
55
58
|
});
|
|
56
59
|
return root;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suite.js","sourceRoot":"","sources":["../../src/runtime/suite.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAqCrD,SAAS,SAAS,CACjB,IAAY,EACZ,IAAa,EACb,MAA6B;IAE7B,OAAO;QACN,IAAI,EAAE,OAAO;QACb,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;KACT,CAAC;AACH,CAAC;
|
|
1
|
+
{"version":3,"file":"suite.js","sourceRoot":"","sources":["../../src/runtime/suite.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAqCrD,SAAS,SAAS,CACjB,IAAY,EACZ,IAAa,EACb,MAA6B;IAE7B,OAAO;QACN,IAAI,EAAE,OAAO;QACb,IAAI;QACJ,IAAI;QACJ,MAAM;QACN,QAAQ,EAAE,EAAE;QACZ,KAAK,EAAE,EAAE;KACT,CAAC;AACH,CAAC;AA0BD,SAAS,QAAQ;IAChB,IAAI,CAAC,GAAG,UAAU,CAAC,yBAAyB,CAAC;IAC7C,IAAI,CAAC,CAAC,EAAE,CAAC;QACR,MAAM,IAAI,GAAG,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;QAC7C,CAAC,GAAG;YACH,OAAO,EAAE,IAAI,iBAAiB,EAAqB;YACnD,YAAY,EAAE,IAAI;YAClB,aAAa,EAAE,CAAC,IAAI,CAAC;SACrB,CAAC;QACF,UAAU,CAAC,yBAAyB,GAAG,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,CAAC,CAAC;AACV,CAAC;AAED,SAAS,cAAc;IACtB,MAAM,CAAC,GAAG,QAA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AAE,CAAC,CAAC"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c9up/helix",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Helix — framework-agnostic test runtime for the Ream ecosystem (Vitest-compatible runner, spies, container overrides, time-travel). Per-package fakes live in each package's /testing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
},
|
|
43
43
|
"files": [
|
|
44
44
|
"bin",
|
|
45
|
-
"src",
|
|
46
45
|
"dist",
|
|
46
|
+
"index.*.node",
|
|
47
47
|
"README.md",
|
|
48
48
|
"LICENSE"
|
|
49
49
|
],
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Aggregation: merge N raw coverage entries (possibly for the same file
|
|
3
|
-
* from different workers) into a single `CoverageSummary` with per-file
|
|
4
|
-
* and total line / function counts.
|
|
5
|
-
*
|
|
6
|
-
* Range merging strategy mirrors `v8-to-istanbul`:
|
|
7
|
-
* - Walk ranges OUTERMOST-first so inner ranges OVERWRITE the outer
|
|
8
|
-
* count for the lines they cover. A `count: 0` inner range carved
|
|
9
|
-
* out of a `count: 5` outer correctly marks those inner lines as
|
|
10
|
-
* uncovered, matching V8's block-coverage semantics. The previous
|
|
11
|
-
* `Math.max` strategy hid uncovered branches behind their outer
|
|
12
|
-
* function's hit count.
|
|
13
|
-
* - V8 emits BYTE offsets (UTF-8); we convert via Buffer.byteLength
|
|
14
|
-
* so non-ASCII source code maps lines correctly.
|
|
15
|
-
* - When two workers cover the same file:
|
|
16
|
-
* - if their `source` differs (cache-busting query loaded different
|
|
17
|
-
* content), we keep the longer source (best-effort) but emit a
|
|
18
|
-
* warning — offsets are only consistent within one source.
|
|
19
|
-
* - functions are deduplicated by `(name, startOffset)` so the
|
|
20
|
-
* lcov FNF count doesn't double.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import type {
|
|
24
|
-
CoverageSummary,
|
|
25
|
-
FileSummary,
|
|
26
|
-
RawFileCoverage,
|
|
27
|
-
Totals,
|
|
28
|
-
V8Function,
|
|
29
|
-
} from "./types.js";
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Build a function `byteOffset → 1-based line number` over `source`.
|
|
33
|
-
* V8 offsets are UTF-8 byte offsets, so we walk the string code-unit by
|
|
34
|
-
* code-unit and accumulate byte length to keep both indices in sync.
|
|
35
|
-
*
|
|
36
|
-
* Returns `[mapper, totalBytes]`. `totalBytes` is needed so callers can
|
|
37
|
-
* detect offsets pointing past EOF (corrupt input) and clamp.
|
|
38
|
-
*/
|
|
39
|
-
function buildOffsetToLine(
|
|
40
|
-
source: string,
|
|
41
|
-
): [(offset: number) => number, number] {
|
|
42
|
-
const lineStarts: number[] = [0];
|
|
43
|
-
let byteIndex = 0;
|
|
44
|
-
for (let i = 0; i < source.length; i += 1) {
|
|
45
|
-
const code = source.charCodeAt(i);
|
|
46
|
-
// UTF-16 surrogate pair → encodes a single 4-byte UTF-8 char.
|
|
47
|
-
if (code >= 0xd800 && code <= 0xdbff && i + 1 < source.length) {
|
|
48
|
-
const next = source.charCodeAt(i + 1);
|
|
49
|
-
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
50
|
-
byteIndex += 4;
|
|
51
|
-
i += 1;
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// Lone surrogate or BMP char — Buffer.byteLength of one code unit:
|
|
56
|
-
// < 0x80 → 1 byte
|
|
57
|
-
// < 0x800 → 2 bytes
|
|
58
|
-
// else → 3 bytes (BMP non-surrogate)
|
|
59
|
-
if (code < 0x80) {
|
|
60
|
-
byteIndex += 1;
|
|
61
|
-
if (code === 10 /* \n */) lineStarts.push(byteIndex);
|
|
62
|
-
} else if (code < 0x800) {
|
|
63
|
-
byteIndex += 2;
|
|
64
|
-
} else {
|
|
65
|
-
byteIndex += 3;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const totalBytes = byteIndex;
|
|
69
|
-
const mapper = (offset: number): number => {
|
|
70
|
-
const clamped = Math.max(0, Math.min(offset, totalBytes));
|
|
71
|
-
// Binary search for the largest lineStart <= clamped.
|
|
72
|
-
let lo = 0;
|
|
73
|
-
let hi = lineStarts.length - 1;
|
|
74
|
-
while (lo < hi) {
|
|
75
|
-
const mid = (lo + hi + 1) >>> 1;
|
|
76
|
-
if (lineStarts[mid] <= clamped) lo = mid;
|
|
77
|
-
else hi = mid - 1;
|
|
78
|
-
}
|
|
79
|
-
return lo + 1;
|
|
80
|
-
};
|
|
81
|
-
return [mapper, totalBytes];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function computeFileSummary(entry: RawFileCoverage): FileSummary {
|
|
85
|
-
const [offsetToLine] = buildOffsetToLine(entry.source);
|
|
86
|
-
const lineHitsMap = new Map<number, number>();
|
|
87
|
-
const functionHits: FileSummary["functionHits"] = [];
|
|
88
|
-
let fnCovered = 0;
|
|
89
|
-
// Apply ranges across ALL functions in one global pass, sorted by
|
|
90
|
-
// span DESC. The whole-file pseudo-function (largest span) lands
|
|
91
|
-
// first; inner functions and their inner ranges overwrite — so a
|
|
92
|
-
// never-called inner function correctly drops its lines back to
|
|
93
|
-
// count=0 even though the script itself executed at count=1.
|
|
94
|
-
const allRanges: Array<{
|
|
95
|
-
startOffset: number;
|
|
96
|
-
endOffset: number;
|
|
97
|
-
count: number;
|
|
98
|
-
}> = [];
|
|
99
|
-
for (const fn of entry.functions) {
|
|
100
|
-
for (const r of fn.ranges) {
|
|
101
|
-
if (r.endOffset > r.startOffset) allRanges.push(r);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
allRanges.sort((a, b) => {
|
|
105
|
-
const spanA = a.endOffset - a.startOffset;
|
|
106
|
-
const spanB = b.endOffset - b.startOffset;
|
|
107
|
-
if (spanA !== spanB) return spanB - spanA;
|
|
108
|
-
return a.startOffset - b.startOffset;
|
|
109
|
-
});
|
|
110
|
-
for (const r of allRanges) {
|
|
111
|
-
const startLine = offsetToLine(r.startOffset);
|
|
112
|
-
const endLine = offsetToLine(r.endOffset - 1);
|
|
113
|
-
for (let line = startLine; line <= endLine; line += 1) {
|
|
114
|
-
lineHitsMap.set(line, r.count);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
for (const fn of entry.functions) {
|
|
118
|
-
const firstRange = fn.ranges[0];
|
|
119
|
-
// Skip pseudo-functions / synthetic entries with no usable range so
|
|
120
|
-
// reports don't carry `FN:0,name` (lcov rejects line < 1).
|
|
121
|
-
if (!firstRange) continue;
|
|
122
|
-
const fnCount = firstRange.count;
|
|
123
|
-
const fnLine = offsetToLine(firstRange.startOffset);
|
|
124
|
-
if (fnCount > 0) fnCovered += 1;
|
|
125
|
-
functionHits.push({
|
|
126
|
-
name: fn.functionName || "(anonymous)",
|
|
127
|
-
line: Math.max(1, fnLine),
|
|
128
|
-
count: fnCount,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
const lineHits = Array.from(lineHitsMap.entries())
|
|
132
|
-
.map(([line, count]) => ({ line, count }))
|
|
133
|
-
.sort((a, b) => a.line - b.line);
|
|
134
|
-
const linesCovered = lineHits.filter((h) => h.count > 0).length;
|
|
135
|
-
const linesTotal = lineHits.length;
|
|
136
|
-
const fnTotal = functionHits.length;
|
|
137
|
-
return {
|
|
138
|
-
file: entry.file,
|
|
139
|
-
lines: { covered: linesCovered, total: linesTotal },
|
|
140
|
-
// Statements ≈ lines (V8 doesn't expose AST statement boundaries —
|
|
141
|
-
// matches Vitest's v8 provider).
|
|
142
|
-
statements: { covered: linesCovered, total: linesTotal },
|
|
143
|
-
functions: { covered: fnCovered, total: fnTotal },
|
|
144
|
-
// Branches deferred; report 0/0 so reporters / thresholds can still
|
|
145
|
-
// format the field consistently.
|
|
146
|
-
branches: { covered: 0, total: 0 },
|
|
147
|
-
lineHits,
|
|
148
|
-
functionHits,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Merge two raw entries for the same file. Functions are deduplicated by
|
|
154
|
-
* `(name, startOffset)` so concatenation doesn't double FNF in lcov.
|
|
155
|
-
* If `source` differs, we keep the longer one (best effort) and emit a
|
|
156
|
-
* stderr advisory — offsets only line up within one source.
|
|
157
|
-
*/
|
|
158
|
-
function mergeRaw(a: RawFileCoverage, b: RawFileCoverage): RawFileCoverage {
|
|
159
|
-
if (a.source && b.source && a.source !== b.source) {
|
|
160
|
-
process.stderr.write(
|
|
161
|
-
`helix-coverage: ${a.file} has divergent source content across workers — line attribution may be off\n`,
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
const seen = new Set<string>();
|
|
165
|
-
const merged: V8Function[] = [];
|
|
166
|
-
for (const fn of [...a.functions, ...b.functions]) {
|
|
167
|
-
const startOffset = fn.ranges[0]?.startOffset ?? -1;
|
|
168
|
-
const key = `${fn.functionName}@${startOffset}`;
|
|
169
|
-
if (seen.has(key)) continue;
|
|
170
|
-
seen.add(key);
|
|
171
|
-
merged.push(fn);
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
file: a.file,
|
|
175
|
-
source: a.source.length >= b.source.length ? a.source : b.source,
|
|
176
|
-
functions: merged,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function pct(covered: number, total: number): number {
|
|
181
|
-
if (total === 0) return 100;
|
|
182
|
-
return Math.round((covered / total) * 10000) / 100;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
export function aggregate(raw: RawFileCoverage[]): CoverageSummary {
|
|
186
|
-
const byFile = new Map<string, RawFileCoverage>();
|
|
187
|
-
for (const entry of raw) {
|
|
188
|
-
// Skip files we couldn't read source for — emitting a 1-line ghost
|
|
189
|
-
// summary based on collapsed line=1 mapping is worse than omission.
|
|
190
|
-
if (!entry.source) {
|
|
191
|
-
process.stderr.write(
|
|
192
|
-
`helix-coverage: skipping ${entry.file} — source unreadable\n`,
|
|
193
|
-
);
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
const prev = byFile.get(entry.file);
|
|
197
|
-
byFile.set(entry.file, prev ? mergeRaw(prev, entry) : entry);
|
|
198
|
-
}
|
|
199
|
-
const files = Array.from(byFile.values())
|
|
200
|
-
.map(computeFileSummary)
|
|
201
|
-
// Files that ended up with 0 lines / 0 functions (no V8 data) are
|
|
202
|
-
// dropped — they distort per-file averages and clutter the table.
|
|
203
|
-
.filter((f) => f.lines.total > 0 || f.functions.total > 0)
|
|
204
|
-
.sort((a, b) => a.file.localeCompare(b.file));
|
|
205
|
-
|
|
206
|
-
const totals: Totals = {
|
|
207
|
-
lines: { covered: 0, total: 0, pct: 0 },
|
|
208
|
-
statements: { covered: 0, total: 0, pct: 0 },
|
|
209
|
-
functions: { covered: 0, total: 0, pct: 0 },
|
|
210
|
-
branches: { covered: 0, total: 0, pct: 0 },
|
|
211
|
-
};
|
|
212
|
-
for (const f of files) {
|
|
213
|
-
totals.lines.covered += f.lines.covered;
|
|
214
|
-
totals.lines.total += f.lines.total;
|
|
215
|
-
totals.statements.covered += f.statements.covered;
|
|
216
|
-
totals.statements.total += f.statements.total;
|
|
217
|
-
totals.functions.covered += f.functions.covered;
|
|
218
|
-
totals.functions.total += f.functions.total;
|
|
219
|
-
totals.branches.covered += f.branches.covered;
|
|
220
|
-
totals.branches.total += f.branches.total;
|
|
221
|
-
}
|
|
222
|
-
totals.lines.pct = pct(totals.lines.covered, totals.lines.total);
|
|
223
|
-
totals.statements.pct = pct(
|
|
224
|
-
totals.statements.covered,
|
|
225
|
-
totals.statements.total,
|
|
226
|
-
);
|
|
227
|
-
totals.functions.pct = pct(totals.functions.covered, totals.functions.total);
|
|
228
|
-
totals.branches.pct = pct(totals.branches.covered, totals.branches.total);
|
|
229
|
-
|
|
230
|
-
return { files, total: totals };
|
|
231
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reads every `coverage-*.json` produced by the V8 profiler in a given
|
|
3
|
-
* directory, decodes `file://` URLs, and returns a normalised list of
|
|
4
|
-
* `RawFileCoverage` entries (one per unique script URL).
|
|
5
|
-
*
|
|
6
|
-
* Workers write coverage via `NODE_V8_COVERAGE=<dir>` — the orchestrator
|
|
7
|
-
* sets this env var on every spawn and reads the directory after all
|
|
8
|
-
* workers exit. Multiple workers may record the same file; we return ALL
|
|
9
|
-
* entries here and let `aggregate.ts` merge.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { readdir, readFile } from "node:fs/promises";
|
|
13
|
-
import path from "node:path";
|
|
14
|
-
import { fileURLToPath } from "node:url";
|
|
15
|
-
import type { RawFileCoverage, V8CoverageFile } from "./types.js";
|
|
16
|
-
|
|
17
|
-
export async function collect(dir: string): Promise<RawFileCoverage[]> {
|
|
18
|
-
let entries: string[];
|
|
19
|
-
try {
|
|
20
|
-
entries = await readdir(dir);
|
|
21
|
-
} catch {
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
const jsonFiles = entries.filter((e) => e.endsWith(".json"));
|
|
25
|
-
const all: RawFileCoverage[] = [];
|
|
26
|
-
for (const name of jsonFiles) {
|
|
27
|
-
const p = path.join(dir, name);
|
|
28
|
-
let parsed: V8CoverageFile;
|
|
29
|
-
try {
|
|
30
|
-
const raw = await readFile(p, "utf8");
|
|
31
|
-
parsed = JSON.parse(raw) as V8CoverageFile;
|
|
32
|
-
} catch {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
for (const script of parsed.result ?? []) {
|
|
36
|
-
if (!script.url?.startsWith("file://")) continue;
|
|
37
|
-
// V8 sometimes appends `?query` params (our worker uses them as
|
|
38
|
-
// cache-busters) — strip them so the same file from two workers
|
|
39
|
-
// merges correctly.
|
|
40
|
-
const cleanUrl = script.url.split("?")[0];
|
|
41
|
-
let file: string;
|
|
42
|
-
try {
|
|
43
|
-
file = fileURLToPath(cleanUrl);
|
|
44
|
-
} catch {
|
|
45
|
-
continue;
|
|
46
|
-
}
|
|
47
|
-
let source = "";
|
|
48
|
-
try {
|
|
49
|
-
source = await readFile(file, "utf8");
|
|
50
|
-
} catch {
|
|
51
|
-
// Source read may fail for transient temp files or modules that
|
|
52
|
-
// have been GC'd — leave empty; downstream stages fall back to
|
|
53
|
-
// offset-only computation.
|
|
54
|
-
}
|
|
55
|
-
all.push({
|
|
56
|
-
file,
|
|
57
|
-
source,
|
|
58
|
-
functions: script.functions ?? [],
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return all;
|
|
63
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve the default base ref to diff against. Tries, in order:
|
|
3
|
-
* 1. `origin/main`
|
|
4
|
-
* 2. `origin/master`
|
|
5
|
-
* 3. local `main`
|
|
6
|
-
* 4. local `master`
|
|
7
|
-
*
|
|
8
|
-
* Returns `undefined` if none of those exist (so the caller can warn
|
|
9
|
-
* instead of failing the run). Throws when the `git` binary itself is
|
|
10
|
-
* missing — the caller distinguishes "no repo / no ref" (skip
|
|
11
|
-
* gracefully) from "git not installed" (configuration error).
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { spawnSync } from "node:child_process";
|
|
15
|
-
|
|
16
|
-
const CANDIDATES = ["origin/main", "origin/master", "main", "master"];
|
|
17
|
-
|
|
18
|
-
export class GitMissingError extends Error {
|
|
19
|
-
constructor() {
|
|
20
|
-
super("git binary not found on PATH");
|
|
21
|
-
this.name = "GitMissingError";
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function runGit(cwd: string, args: string[]): { ok: boolean } {
|
|
26
|
-
const result = spawnSync("git", args, {
|
|
27
|
-
cwd,
|
|
28
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
29
|
-
});
|
|
30
|
-
const err = result.error as NodeJS.ErrnoException | undefined;
|
|
31
|
-
if (err?.code === "ENOENT") throw new GitMissingError();
|
|
32
|
-
return { ok: result.status === 0 };
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function refExists(cwd: string, ref: string): boolean {
|
|
36
|
-
return runGit(cwd, ["rev-parse", "--verify", "--quiet", `${ref}^{commit}`])
|
|
37
|
-
.ok;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function resolveBaseRef(cwd: string): string | undefined {
|
|
41
|
-
if (!runGit(cwd, ["rev-parse", "--git-dir"]).ok) return undefined;
|
|
42
|
-
for (const cand of CANDIDATES) {
|
|
43
|
-
if (refExists(cwd, cand)) return cand;
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Diff-coverage facade — wires base resolution → git diff → parser →
|
|
3
|
-
* overlay → reporters → thresholds. Called by `run.ts` after the
|
|
4
|
-
* full-tree finalise.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
8
|
-
import path from "node:path";
|
|
9
|
-
import { enforce } from "../thresholds.js";
|
|
10
|
-
import type {
|
|
11
|
-
CoverageSummary,
|
|
12
|
-
Thresholds,
|
|
13
|
-
ThresholdViolation,
|
|
14
|
-
} from "../types.js";
|
|
15
|
-
import { GitMissingError, resolveBaseRef } from "./base.js";
|
|
16
|
-
import { overlay } from "./overlay.js";
|
|
17
|
-
import { parseDiff } from "./parse.js";
|
|
18
|
-
import { diffJson, diffTextSummary } from "./reporters.js";
|
|
19
|
-
import type { DiffOptions, DiffSummary } from "./types.js";
|
|
20
|
-
|
|
21
|
-
export type { DiffOptions, DiffSummary } from "./types.js";
|
|
22
|
-
|
|
23
|
-
export interface DiffFinaliseInput extends DiffOptions {
|
|
24
|
-
root: string;
|
|
25
|
-
coverage: CoverageSummary;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface DiffFinaliseResult {
|
|
29
|
-
summary: DiffSummary;
|
|
30
|
-
violations: ThresholdViolation[];
|
|
31
|
-
textReport: string;
|
|
32
|
-
reportFiles: string[];
|
|
33
|
-
/** When `undefined`, the diff stage was skipped (not in a repo, no
|
|
34
|
-
* base ref, etc.) — callers should print `warning` and move on. */
|
|
35
|
-
warning?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Wrap the diff totals into a `CoverageSummary`-shaped object so we can
|
|
40
|
-
* reuse the full-tree `enforce()` helper. Only `lines`/`statements` are
|
|
41
|
-
* populated; `functions`/`branches` are unsupported in diff mode and are
|
|
42
|
-
* rejected upfront in `validateDiffThresholds`.
|
|
43
|
-
*/
|
|
44
|
-
function toCoverageSummary(diff: DiffSummary): CoverageSummary {
|
|
45
|
-
return {
|
|
46
|
-
files: [],
|
|
47
|
-
total: {
|
|
48
|
-
lines: {
|
|
49
|
-
covered: diff.total.covered,
|
|
50
|
-
total: diff.total.added,
|
|
51
|
-
pct: diff.total.pct,
|
|
52
|
-
},
|
|
53
|
-
statements: {
|
|
54
|
-
covered: diff.total.covered,
|
|
55
|
-
total: diff.total.added,
|
|
56
|
-
pct: diff.total.pct,
|
|
57
|
-
},
|
|
58
|
-
functions: { covered: 0, total: 0, pct: 100 },
|
|
59
|
-
branches: { covered: 0, total: 0, pct: 100 },
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function violationLine(
|
|
65
|
-
metric: keyof Thresholds,
|
|
66
|
-
actual: number,
|
|
67
|
-
threshold: number,
|
|
68
|
-
): string {
|
|
69
|
-
return `coverage-diff: ${metric} ${actual.toFixed(1)} < threshold ${threshold}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Reject `functions`/`branches` thresholds in diff mode — we only track
|
|
74
|
-
* line-level diff coverage today, so silently passing those metrics
|
|
75
|
-
* would let users gate on metrics that always read 100%.
|
|
76
|
-
*/
|
|
77
|
-
function validateDiffThresholds(t: Thresholds | undefined): void {
|
|
78
|
-
if (!t) return;
|
|
79
|
-
const unsupported: string[] = [];
|
|
80
|
-
if (typeof t.functions === "number" && t.functions > 0)
|
|
81
|
-
unsupported.push("functions");
|
|
82
|
-
if (typeof t.branches === "number" && t.branches > 0)
|
|
83
|
-
unsupported.push("branches");
|
|
84
|
-
if (unsupported.length > 0) {
|
|
85
|
-
throw new Error(
|
|
86
|
-
`diff-cov thresholds: ${unsupported.join(", ")} are not supported (line-only). Drop those keys.`,
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export async function finaliseDiff(
|
|
92
|
-
input: DiffFinaliseInput,
|
|
93
|
-
): Promise<DiffFinaliseResult> {
|
|
94
|
-
validateDiffThresholds(input.thresholds);
|
|
95
|
-
|
|
96
|
-
const cwd = input.cwd ?? input.root;
|
|
97
|
-
let base: string | undefined;
|
|
98
|
-
try {
|
|
99
|
-
base = input.base ?? resolveBaseRef(cwd);
|
|
100
|
-
} catch (err) {
|
|
101
|
-
if (err instanceof GitMissingError) {
|
|
102
|
-
return {
|
|
103
|
-
summary: { files: [], total: { added: 0, covered: 0, pct: 100 } },
|
|
104
|
-
violations: [],
|
|
105
|
-
textReport: "",
|
|
106
|
-
reportFiles: [],
|
|
107
|
-
warning: "diff-cov: git binary not found on PATH. Skipping.",
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
throw err;
|
|
111
|
-
}
|
|
112
|
-
if (!base) {
|
|
113
|
-
return {
|
|
114
|
-
summary: { files: [], total: { added: 0, covered: 0, pct: 100 } },
|
|
115
|
-
violations: [],
|
|
116
|
-
textReport: "",
|
|
117
|
-
reportFiles: [],
|
|
118
|
-
warning:
|
|
119
|
-
"diff-cov: no git base ref resolved (origin/main, main, master). Skipping.",
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let diffMap: ReturnType<typeof parseDiff>;
|
|
124
|
-
try {
|
|
125
|
-
diffMap = parseDiff({ cwd, base });
|
|
126
|
-
} catch (err) {
|
|
127
|
-
return {
|
|
128
|
-
summary: { files: [], total: { added: 0, covered: 0, pct: 100 } },
|
|
129
|
-
violations: [],
|
|
130
|
-
textReport: "",
|
|
131
|
-
reportFiles: [],
|
|
132
|
-
warning: `diff-cov: ${err instanceof Error ? err.message : String(err)}`,
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const summary = overlay(input.coverage, diffMap);
|
|
137
|
-
|
|
138
|
-
const reportFiles: string[] = [];
|
|
139
|
-
const outputDir = input.outputDir ?? path.join(input.root, "coverage");
|
|
140
|
-
await mkdir(outputDir, { recursive: true });
|
|
141
|
-
const file = path.join(outputDir, "coverage-diff.json");
|
|
142
|
-
await writeFile(file, diffJson(summary, input.root), "utf8");
|
|
143
|
-
reportFiles.push(file);
|
|
144
|
-
|
|
145
|
-
const textReport = diffTextSummary(summary, input.root);
|
|
146
|
-
|
|
147
|
-
let violations: ThresholdViolation[] = [];
|
|
148
|
-
if (input.thresholds) {
|
|
149
|
-
violations = enforce(toCoverageSummary(summary), input.thresholds);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return { summary, violations, textReport, reportFiles };
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** Reformat threshold violations with the `coverage-diff:` prefix. */
|
|
156
|
-
export function diffViolationSummary(violations: ThresholdViolation[]): string {
|
|
157
|
-
return violations
|
|
158
|
-
.map((v) => violationLine(v.metric, v.actual, v.threshold))
|
|
159
|
-
.join("\n");
|
|
160
|
-
}
|