checkchange 0.5.2 → 0.5.4
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/.agents/skills/using-checkchange/SKILL.md +5 -2
- package/README.md +87 -3
- package/dist/attribution.d.ts +1 -1
- package/dist/attribution.js +26 -3
- package/dist/complexity-providers/csharpDescriptorProvider.js +2 -2
- package/dist/coverage-providers/lcovProvider.d.ts +19 -2
- package/dist/coverage-providers/lcovProvider.js +77 -15
- package/dist/coverage.d.ts +21 -1
- package/dist/coverage.js +96 -30
- package/dist/crapCalc.d.ts +1 -1
- package/dist/crapCalc.js +2 -2
- package/dist/evidence.d.ts +8 -1
- package/dist/evidence.js +41 -8
- package/dist/formatters/index.d.ts +4 -0
- package/dist/formatters/sarif.js +23 -2
- package/dist/providers/config.js +13 -2
- package/dist/rules.d.ts +1 -1
- package/dist/rules.js +1 -1
- package/package.json +1 -1
|
@@ -17,7 +17,9 @@ Correct use of `checkchange check`: prevents hallucination, enforces WARN blocks
|
|
|
17
17
|
- Comparing evidence runs with `delta`.
|
|
18
18
|
|
|
19
19
|
# What It Entails
|
|
20
|
-
1.
|
|
20
|
+
1. Generate coverage artifact before check — required before check:
|
|
21
|
+
- vitest/jest: `pnpm vitest run --coverage` → `coverage/coverage-final.json`
|
|
22
|
+
- bun: `bun test --coverage --coverage-reporter=lcov` → `coverage/lcov.info`, check with `--coverage-file coverage/lcov.info`. Bare `bun test --coverage` prints a table + exit 0 but writes NO artifact (default reporter text) → `coverageArtifact: absent`. No converter needed. vitest cannot run `bun:test` suites — don't try it. (checkchange >=0.5.4 detects bun via builtin BUN_RUNNER + `--auto-coverage`.)
|
|
21
23
|
2. `checkchange check [--base <ref>] [--json] [--cache] [--auto-coverage] [--crap-threshold <n>] [--coverage-file <path>] [--format github|junit|sarif] [--provider-config <path>] [--allow-external-config] [--verbose]` — auto-detects base if omitted (origin/HEAD → origin/master/main → master/main)
|
|
22
24
|
3. Read gate + changedFunctions
|
|
23
25
|
|
|
@@ -57,7 +59,8 @@ Correct use of `checkchange check`: prevents hallucination, enforces WARN blocks
|
|
|
57
59
|
- Cache: `--cache` opt-in (default off). Also `CHECKCHANGE_CACHE=1` env.
|
|
58
60
|
- Format: `--format github|junit|sarif` (sidecar, separate from --json). Valid only on `check`. SARIF sidecar emits canonical `$schema` key (`https://json.schemastore.org/sarif-2.1.0.json`) since 0.5.1 — strict SARIF validators accept it.
|
|
59
61
|
- Value flags: inline (`--base=HEAD`) and next-token (`--base HEAD`) both honored; bare or empty-inline (`--base`, `--base=`) errors `<flag> requires a value`; `--crap-threshold abc` errors instead of producing NaN.
|
|
60
|
-
-
|
|
62
|
+
- Bun projects: `bun test --coverage --coverage-reporter=lcov` then `checkchange check --coverage-file coverage/lcov.info --json`. lcov provider reads `DA:` line-hit records, ignores `FN:` (bun emits none).
|
|
63
|
+
- Gate self-disable trap: a diff containing unsupported-extension files (e.g. package-lock.json, reformatted package.json) can make checkchange evaluate 0 functions → gate NOT_EVALUATED with gateReason no-supported-file-extensions. Keep such files out of the diff.
|
|
61
64
|
- Exit codes: FAILED→1, SUCCESS+WARN→1, UNSUPPORTED+NOT_APPLICABLE→0.
|
|
62
65
|
- Malformed artifact: analysisStatus=FAILED, gate=FAILED, completeness=INCOMPLETE.
|
|
63
66
|
- Trace sidecar: `{command:"trace", correlationId, spans:[{stage,durationMs,status}]}`.
|
package/README.md
CHANGED
|
@@ -107,9 +107,8 @@ Those are evidence states, not judgments about whether the software is ultimatel
|
|
|
107
107
|
|
|
108
108
|
# Install
|
|
109
109
|
|
|
110
|
-
The package is published on npm as `checkchange`.
|
|
111
|
-
|
|
112
|
-
Current registry version: **0.4.4**
|
|
110
|
+
The package is published on npm as `checkchange`. Check the current published
|
|
111
|
+
version with `npm view checkchange version`.
|
|
113
112
|
|
|
114
113
|
### npm
|
|
115
114
|
|
|
@@ -149,6 +148,26 @@ pnpm run build
|
|
|
149
148
|
node dist/cli.js check --base main --json
|
|
150
149
|
```
|
|
151
150
|
|
|
151
|
+
### Updating an existing npm install
|
|
152
|
+
|
|
153
|
+
To get the latest released version:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm install -g checkchange@latest # global install
|
|
157
|
+
npm install checkchange@latest # project-local dependency
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Check what you have and what is available:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
checkchange --version
|
|
164
|
+
npm view checkchange version
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
If you need a pinned version for reproducibility, use `checkchange@<version>`
|
|
168
|
+
with the version you want (list available versions with
|
|
169
|
+
`npm view checkchange versions`).
|
|
170
|
+
|
|
152
171
|
---
|
|
153
172
|
|
|
154
173
|
# Requirements
|
|
@@ -384,6 +403,20 @@ of four values:
|
|
|
384
403
|
`no-supported-file-extensions`, `complexity-analysis-failed`, or the coverage
|
|
385
404
|
error reason (`missing` / `malformed` / `failed`).
|
|
386
405
|
|
|
406
|
+
**Explicit-file malformed taxonomy.** When `--coverage-file <path>` points to
|
|
407
|
+
an extension-gated LCOV artifact (`*.info` or `*.lcov`) that parses to an empty
|
|
408
|
+
map and carries neither `SF:` nor `DA:` tokens anywhere in the file, the guard
|
|
409
|
+
classifies it as malformed → `analysisStatus FAILED`, `gate FAILED`,
|
|
410
|
+
`completeness INCOMPLETE`, `coverageErrorReason: "malformed"`, stderr
|
|
411
|
+
`Error: coverage artifact malformed`, exit 1. This catches garbage or
|
|
412
|
+
JSON-renamed-.info/.lcov inputs up front rather than silently treating them as
|
|
413
|
+
valid zero-record artifacts. Lenient boundary preserved: a valid LCOV artifact
|
|
414
|
+
that contains `SF:` (even when it has zero `DA:` lines) continues through as
|
|
415
|
+
lenient SUCCESS/NOT_EVALUATED, since the token proves the artifact originated
|
|
416
|
+
from a real LCOV-producing toolchain. Invalid JSON (all explicit paths), size
|
|
417
|
+
breaches (>100 MB), and unconvertible Python-binary lanes still return `malformed`
|
|
418
|
+
via the existing throw/catch path.
|
|
419
|
+
|
|
387
420
|
Exit codes:
|
|
388
421
|
|
|
389
422
|
| Condition | Exit code |
|
|
@@ -394,6 +427,57 @@ Exit codes:
|
|
|
394
427
|
|
|
395
428
|
---
|
|
396
429
|
|
|
430
|
+
# Diagnostics output
|
|
431
|
+
|
|
432
|
+
`--json` may include an optional top-level `diagnostics` object. Existing fields
|
|
433
|
+
(`lineage`, `quality`, `fingerprints`) carry provenance, quality scores, and
|
|
434
|
+
per-function hashes. A fourth field, `functionCoverage`, is emitted only when
|
|
435
|
+
the coverage artifact is LCOV and contains FN/FNDA records.
|
|
436
|
+
|
|
437
|
+
## `diagnostics.functionCoverage`
|
|
438
|
+
|
|
439
|
+
**What it is:** For each changed function that has an LCOV FN record whose
|
|
440
|
+
declaration line matches the function's `lineStart`, one entry carrying the
|
|
441
|
+
function-hit count observed in the coverage artifact:
|
|
442
|
+
|
|
443
|
+
```json
|
|
444
|
+
{
|
|
445
|
+
"file": "src/adapters/typescript/collector.ts",
|
|
446
|
+
"method": "visit",
|
|
447
|
+
"line": 488,
|
|
448
|
+
"hits": 4166
|
|
449
|
+
}
|
|
450
|
+
```
|
|
451
|
+
|
|
452
|
+
**When present:** `coverageArtifact` is LCOV (`--coverage-file *.info`) AND
|
|
453
|
+
at least one changed function's declaration line appears in an FN record. The
|
|
454
|
+
field is omitted entirely for Istanbul JSON or Cobertura XML — those formats
|
|
455
|
+
carry no per-function hit counts.
|
|
456
|
+
|
|
457
|
+
**When absent:** No LCOV FN data matched any attributed method (including cases
|
|
458
|
+
where only anonymous `(anonymous_N)` FN entries exist — see below), or the
|
|
459
|
+
artifact is not LCOV.
|
|
460
|
+
|
|
461
|
+
**Does NOT affect gate decisions.** Function-hit counts are diagnostic-only.
|
|
462
|
+
CRAP derives from statement + branch coverage only (`coverageNormalization.js:1-9`);
|
|
463
|
+
`changedFunctions` shape (`{file, method, lineStart, ..., crap, coverage, coverageKind}`)
|
|
464
|
+
is unchanged; gate, threshold, and completeness are unaffected. This is a
|
|
465
|
+
YAGNI-boundary decision recorded in the
|
|
466
|
+
[coverage-path-normalization spike](.opencode/scratch/coverage-path-normalization/notes.md
|
|
467
|
+
"Task 7 spike B"): Option A (parallel side-channel, zero gate impact) was chosen
|
|
468
|
+
over Option B (injecting FN spans into attribution, which would break statement
|
|
469
|
+
coverage via single-line synthesized spans).
|
|
470
|
+
|
|
471
|
+
**Anonymous functions.** Bun-produced LCOV emits FN entries named
|
|
472
|
+
`(anonymous_0)`, `(anonymous_1)`, etc. for unnamed arrow/expression functions.
|
|
473
|
+
The core `parseFileMethods` skips these descriptors, so anonymous FN entries
|
|
474
|
+
cannot be matched to changed methods and surface as orphan hits in the raw
|
|
475
|
+
`CoverageResult.functionCoverage` map but do NOT appear in the diagnostics
|
|
476
|
+
array (matching is keyed by `info.file` + `info.lineStart` against attributed
|
|
477
|
+
methods only).
|
|
478
|
+
|
|
479
|
+
---
|
|
480
|
+
|
|
397
481
|
# Why the evidence matters
|
|
398
482
|
|
|
399
483
|
One of the design goals of CheckChange is to distinguish **"we measured it"** from **"we don't have enough evidence."**
|
package/dist/attribution.d.ts
CHANGED
|
@@ -9,4 +9,4 @@ export interface AttributedComplexity {
|
|
|
9
9
|
coveragePercent: number | null;
|
|
10
10
|
coverageKind: string | null;
|
|
11
11
|
}
|
|
12
|
-
export declare function attachCoverage(complexityInfo: ComplexityInfo[], coverageResult: CoverageResult): Promise<AttributedComplexity[]>;
|
|
12
|
+
export declare function attachCoverage(complexityInfo: ComplexityInfo[], coverageResult: CoverageResult, cwd?: string): Promise<AttributedComplexity[]>;
|
package/dist/attribution.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
1
2
|
import { parseFileMethods } from '@barney-media/crap-typescript-core';
|
|
2
3
|
import { coverageForMethods } from '@barney-media/crap-typescript-core';
|
|
3
4
|
import { parsePythonFileMethods } from './complexity-providers/pythonDescriptorProvider.js';
|
|
@@ -15,7 +16,7 @@ import { parsePythonFileMethods } from './complexity-providers/pythonDescriptorP
|
|
|
15
16
|
import { parseCsharpFileMethods } from './complexity-providers/csharpFallbackParser.js';
|
|
16
17
|
// Provenance for the attribution lineage stage: coverageForMethods/parseFileMethods from the core package.
|
|
17
18
|
export const attributionProvenance = { tool: '@barney-media/crap-typescript-core', version: '0.5.0' };
|
|
18
|
-
export async function attachCoverage(complexityInfo, coverageResult) {
|
|
19
|
+
export async function attachCoverage(complexityInfo, coverageResult, cwd) {
|
|
19
20
|
// If coverage is not available or has error, return null for coverage
|
|
20
21
|
if (!coverageResult.available || coverageResult.error) {
|
|
21
22
|
return nullCoverageForAll(complexityInfo);
|
|
@@ -35,7 +36,7 @@ export async function attachCoverage(complexityInfo, coverageResult) {
|
|
|
35
36
|
// Process each file that has coverage
|
|
36
37
|
for (const [filePath, fileCoverage] of coverageResult.coverageMap) {
|
|
37
38
|
// We'll find all complexity files where the absolute coverage path ends with the relative complexity path
|
|
38
|
-
const fileComplexity = matchingComplexityForFile(filePath, complexityByFile);
|
|
39
|
+
const fileComplexity = matchingComplexityForFile(filePath, complexityByFile, cwd);
|
|
39
40
|
if (fileComplexity === undefined) {
|
|
40
41
|
// No exact match or ambiguous -> skip this coverage file (no attribution from it)
|
|
41
42
|
continue;
|
|
@@ -63,8 +64,30 @@ function nullCoverageForAll(complexityInfo) {
|
|
|
63
64
|
// File matching: resolve the complexity entries a coverage file belongs to. Exactly one
|
|
64
65
|
// case-insensitive suffix match wins; zero matches or an ambiguous multi-match declines
|
|
65
66
|
// attribution for that coverage file.
|
|
66
|
-
function matchingComplexityForFile(filePath, complexityByFile) {
|
|
67
|
+
function matchingComplexityForFile(filePath, complexityByFile, cwd) {
|
|
67
68
|
const normalizedFilePath = filePath.replace(/\\/g, '/');
|
|
69
|
+
// cwd provided: prefer an exact absolute-vs-absolute match so suffix-
|
|
70
|
+
// ambiguous rels (`src/helper.ts` vs `helper.ts`) disambiguate. Only
|
|
71
|
+
// fall back to suffix matching below when zero exact matches exist,
|
|
72
|
+
// preserving the ambiguity-decline semantics. cwd omitted: legacy
|
|
73
|
+
// suffix matching, byte-for-byte as before.
|
|
74
|
+
if (cwd !== undefined) {
|
|
75
|
+
const exactMatches = [];
|
|
76
|
+
for (const [rel, list] of complexityByFile.entries()) {
|
|
77
|
+
const absRel = resolve(cwd, rel).replace(/\\/g, '/');
|
|
78
|
+
if (normalizedFilePath.toLowerCase() === absRel.toLowerCase()) {
|
|
79
|
+
exactMatches.push({ rel, list });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (exactMatches.length === 1) {
|
|
83
|
+
return exactMatches[0].list;
|
|
84
|
+
}
|
|
85
|
+
if (exactMatches.length > 1) {
|
|
86
|
+
// Ambiguous exact match: decline attribution for this coverage file
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
// No exact match: fall through to suffix matching below.
|
|
90
|
+
}
|
|
68
91
|
const matches = [];
|
|
69
92
|
for (const [rel, list] of complexityByFile.entries()) {
|
|
70
93
|
const normalizedRel = rel.replace(/\\/g, '/');
|
|
@@ -174,10 +174,10 @@ export function vehicleRejection() {
|
|
|
174
174
|
return lastVehicleRejection;
|
|
175
175
|
}
|
|
176
176
|
// The fallback parser is checkchange's OWN code (./csharpFallbackParser.ts), so
|
|
177
|
-
// its tool is checkchange and its version is the package version — same 0.5.
|
|
177
|
+
// its tool is checkchange and its version is the package version — same 0.5.4
|
|
178
178
|
// the other self-provenance consts hard-code (src/crapCalc.ts:3, src/rules.ts:4).
|
|
179
179
|
const FALLBACK_TOOL = 'checkchange';
|
|
180
|
-
const FALLBACK_TOOL_VERSION = '0.5.
|
|
180
|
+
const FALLBACK_TOOL_VERSION = '0.5.4';
|
|
181
181
|
// The vehicle's INSTALLED version is never probed: the rich path is
|
|
182
182
|
// documented-unreachable (see SPAWN FORM above), so `dotnet-crap --version` is
|
|
183
183
|
// never spawned to learn it, and no version is fabricated here. `unknown` is the
|
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import type { coverageForMethods } from '@barney-media/crap-typescript-core';
|
|
2
2
|
type FileCoverage = NonNullable<Parameters<typeof coverageForMethods>[1]>;
|
|
3
|
+
/** One FN/FNDA record: function name as written in LCOV, its FN line, and FNDA hits. */
|
|
4
|
+
export type FunctionHits = {
|
|
5
|
+
name: string;
|
|
6
|
+
line: number;
|
|
7
|
+
hits: number;
|
|
8
|
+
};
|
|
3
9
|
/**
|
|
4
10
|
* Parse LCOV content and convert it to the same Map shape the core package's
|
|
5
11
|
* parseCoverageReport produces, so coverageForMethods can attribute methods.
|
|
6
12
|
* @param lcovContent The LCOV file content as string
|
|
7
13
|
* @param cwd Current working directory for path normalization
|
|
14
|
+
* @param out Optional side output: when given, FN/FNDA records are collected
|
|
15
|
+
* into `out.functionCoverage` (mutated in place), keyed by the same normalized
|
|
16
|
+
* path the returned Map uses. FNDA hits are matched to FN entries by name
|
|
17
|
+
* (first not-yet-matched entry wins for same-name FNs, which are otherwise
|
|
18
|
+
* kept as separate line-keyed entries); an FNDA with no matching FN is
|
|
19
|
+
* skipped — there is no line to report it at. FN entries with no FNDA keep
|
|
20
|
+
* hits 0. `(anonymous_N)` names are captured as-is, never filtered. When
|
|
21
|
+
* `out` is omitted nothing is collected and the parse is unchanged.
|
|
8
22
|
* @returns Map<filePath, { statements: Array<{ span: { startLine: number, startColumn: number, endLine: number, endColumn: number }, hits: number }>, branches: [], functions: [] }>
|
|
9
|
-
*
|
|
23
|
+
* `functions` is always empty: FN/FNDA data rides the side output only, never
|
|
24
|
+
* the attribution lane. BRDA/BRF branch records are still not parsed.
|
|
10
25
|
*/
|
|
11
|
-
export declare function parseLcovContent(lcovContent: string, cwd: string
|
|
26
|
+
export declare function parseLcovContent(lcovContent: string, cwd: string, out?: {
|
|
27
|
+
functionCoverage: Map<string, FunctionHits[]>;
|
|
28
|
+
}): Map<string, FileCoverage>;
|
|
12
29
|
export {};
|
|
@@ -5,10 +5,19 @@ import * as fs from 'node:fs';
|
|
|
5
5
|
* parseCoverageReport produces, so coverageForMethods can attribute methods.
|
|
6
6
|
* @param lcovContent The LCOV file content as string
|
|
7
7
|
* @param cwd Current working directory for path normalization
|
|
8
|
+
* @param out Optional side output: when given, FN/FNDA records are collected
|
|
9
|
+
* into `out.functionCoverage` (mutated in place), keyed by the same normalized
|
|
10
|
+
* path the returned Map uses. FNDA hits are matched to FN entries by name
|
|
11
|
+
* (first not-yet-matched entry wins for same-name FNs, which are otherwise
|
|
12
|
+
* kept as separate line-keyed entries); an FNDA with no matching FN is
|
|
13
|
+
* skipped — there is no line to report it at. FN entries with no FNDA keep
|
|
14
|
+
* hits 0. `(anonymous_N)` names are captured as-is, never filtered. When
|
|
15
|
+
* `out` is omitted nothing is collected and the parse is unchanged.
|
|
8
16
|
* @returns Map<filePath, { statements: Array<{ span: { startLine: number, startColumn: number, endLine: number, endColumn: number }, hits: number }>, branches: [], functions: [] }>
|
|
9
|
-
*
|
|
17
|
+
* `functions` is always empty: FN/FNDA data rides the side output only, never
|
|
18
|
+
* the attribution lane. BRDA/BRF branch records are still not parsed.
|
|
10
19
|
*/
|
|
11
|
-
export function parseLcovContent(lcovContent, cwd) {
|
|
20
|
+
export function parseLcovContent(lcovContent, cwd, out) {
|
|
12
21
|
// Security: limit LCOV size to prevent OOM
|
|
13
22
|
const MAX_SIZE = 100 * 1024 * 1024; // 100MB
|
|
14
23
|
if (lcovContent.length > MAX_SIZE) {
|
|
@@ -18,6 +27,11 @@ export function parseLcovContent(lcovContent, cwd) {
|
|
|
18
27
|
let currentFile = '';
|
|
19
28
|
// Keyed by LCOV line number so a repeated DA:<line> overwrites, as before.
|
|
20
29
|
const statements = {};
|
|
30
|
+
// FN/FNDA side output, per currentFile. Collected only when `out` is given,
|
|
31
|
+
// so the default path keeps its allocation-free hot loop.
|
|
32
|
+
const fnEntries = [];
|
|
33
|
+
const fnByName = new Map();
|
|
34
|
+
const fndaMatched = new Set();
|
|
21
35
|
const lines = lcovContent.split('\n');
|
|
22
36
|
if (lines.length > 1_000_000) {
|
|
23
37
|
throw new Error('LCOV contains too many lines (over 1,000,000)');
|
|
@@ -26,18 +40,26 @@ export function parseLcovContent(lcovContent, cwd) {
|
|
|
26
40
|
const lineTrimmed = line.trim();
|
|
27
41
|
if (lineTrimmed.startsWith('SF:')) {
|
|
28
42
|
// Before starting a new file, finalize the previous one
|
|
29
|
-
if (currentFile && Object.keys(statements).length > 0) {
|
|
43
|
+
if (currentFile && (Object.keys(statements).length > 0 || fnEntries.length > 0)) {
|
|
30
44
|
const normalized = normalizePath(currentFile, cwd);
|
|
31
45
|
if (normalized !== null) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
46
|
+
if (Object.keys(statements).length > 0) {
|
|
47
|
+
result.set(normalized, {
|
|
48
|
+
statements: Object.values(statements),
|
|
49
|
+
branches: [],
|
|
50
|
+
functions: []
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if (out !== undefined && fnEntries.length > 0) {
|
|
54
|
+
out.functionCoverage.set(normalized, [...fnEntries]);
|
|
55
|
+
}
|
|
37
56
|
}
|
|
38
57
|
// Reset for next file
|
|
39
58
|
Object.keys(statements).forEach(k => delete statements[k]);
|
|
40
59
|
}
|
|
60
|
+
fnEntries.length = 0;
|
|
61
|
+
fnByName.clear();
|
|
62
|
+
fndaMatched.clear();
|
|
41
63
|
// Extract file path (remove leading './' if present)
|
|
42
64
|
const filePath = lineTrimmed.substring(3).trim();
|
|
43
65
|
currentFile = filePath;
|
|
@@ -61,18 +83,58 @@ export function parseLcovContent(lcovContent, cwd) {
|
|
|
61
83
|
}
|
|
62
84
|
}
|
|
63
85
|
}
|
|
64
|
-
|
|
86
|
+
else if (out !== undefined && currentFile && lineTrimmed.startsWith('FN:')) {
|
|
87
|
+
// FN:<line>,<name> — split on the FIRST comma only; names may contain commas.
|
|
88
|
+
const body = lineTrimmed.substring(3);
|
|
89
|
+
const comma = body.indexOf(',');
|
|
90
|
+
if (comma > 0) {
|
|
91
|
+
const lineNum = parseInt(body.substring(0, comma), 10);
|
|
92
|
+
const name = body.substring(comma + 1);
|
|
93
|
+
if (!isNaN(lineNum) && name !== '') {
|
|
94
|
+
const entry = { name, line: lineNum, hits: 0 };
|
|
95
|
+
fnEntries.push(entry);
|
|
96
|
+
const list = fnByName.get(name);
|
|
97
|
+
if (list)
|
|
98
|
+
list.push(entry);
|
|
99
|
+
else
|
|
100
|
+
fnByName.set(name, [entry]);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (out !== undefined && currentFile && lineTrimmed.startsWith('FNDA:')) {
|
|
105
|
+
// FNDA:<hits>,<name> — matched to the first FN entry with this name that
|
|
106
|
+
// has not yet received an FNDA (same-name FNs in one file stay separate
|
|
107
|
+
// line-keyed entries, but FNDA carries no line, so first-unmatched wins).
|
|
108
|
+
// An FNDA with no matching FN is skipped: there is no line to report at.
|
|
109
|
+
const body = lineTrimmed.substring(5);
|
|
110
|
+
const comma = body.indexOf(',');
|
|
111
|
+
if (comma > 0) {
|
|
112
|
+
const hits = parseInt(body.substring(0, comma), 10);
|
|
113
|
+
const name = body.substring(comma + 1);
|
|
114
|
+
const target = fnByName.get(name)?.find((e) => !fndaMatched.has(e));
|
|
115
|
+
if (target !== undefined && !isNaN(hits)) {
|
|
116
|
+
target.hits = hits;
|
|
117
|
+
fndaMatched.add(target);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// We ignore BRDA/BRF for branch coverage for simplicity.
|
|
65
122
|
// If needed, we can extend later.
|
|
66
123
|
}
|
|
67
124
|
// Handle the last file
|
|
68
|
-
if (currentFile && Object.keys(statements).length > 0) {
|
|
125
|
+
if (currentFile && (Object.keys(statements).length > 0 || fnEntries.length > 0)) {
|
|
69
126
|
const normalized = normalizePath(currentFile, cwd);
|
|
70
127
|
if (normalized !== null) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
128
|
+
if (Object.keys(statements).length > 0) {
|
|
129
|
+
result.set(normalized, {
|
|
130
|
+
statements: Object.values(statements),
|
|
131
|
+
branches: [],
|
|
132
|
+
functions: []
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (out !== undefined && fnEntries.length > 0) {
|
|
136
|
+
out.functionCoverage.set(normalized, [...fnEntries]);
|
|
137
|
+
}
|
|
76
138
|
}
|
|
77
139
|
}
|
|
78
140
|
return result;
|
package/dist/coverage.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseCoverageReport } from '@barney-media/crap-typescript-core';
|
|
2
2
|
type CoverageMap = Awaited<ReturnType<typeof parseCoverageReport>>;
|
|
3
|
+
import { type FunctionHits } from './coverage-providers/lcovProvider.js';
|
|
3
4
|
import type { TraceRun } from './execute.js';
|
|
4
5
|
export declare const coverageProvenance: {
|
|
5
6
|
readonly tool: "@barney-media/crap-typescript-core";
|
|
@@ -12,6 +13,12 @@ export interface CoverageResult {
|
|
|
12
13
|
reason?: string;
|
|
13
14
|
/** SHA-256 hex of the coverage artifact bytes as read (present only on a successful read). */
|
|
14
15
|
contentSha256?: string;
|
|
16
|
+
/**
|
|
17
|
+
* FN/FNDA function hits from an LCOV artifact, keyed by the same normalized
|
|
18
|
+
* path as `coverageMap`. Diagnostic only — no attribution, CRAP, or gate
|
|
19
|
+
* path reads it. Only set when an LCOV artifact contributed FN records.
|
|
20
|
+
*/
|
|
21
|
+
functionCoverage?: Map<string, FunctionHits[]>;
|
|
15
22
|
}
|
|
16
23
|
export declare const PYTHON_COVERAGE_FILES: readonly string[];
|
|
17
24
|
/**
|
|
@@ -43,6 +50,14 @@ export declare const PYTHON_COVERAGE_FILES: readonly string[];
|
|
|
43
50
|
* Neither input Map nor its FileCoverage values are mutated.
|
|
44
51
|
*/
|
|
45
52
|
export declare function mergeCoverageMaps(a: CoverageMap, b: CoverageMap): CoverageMap;
|
|
53
|
+
/**
|
|
54
|
+
* Union two `functionCoverage` maps by file path (multi-artifact merge):
|
|
55
|
+
* a path in only one map carries through unchanged; a path in both
|
|
56
|
+
* concatenates its entries. Keys match case-insensitively with the
|
|
57
|
+
* first-seen spelling winning — the same rule as `mergeCoverageMaps`.
|
|
58
|
+
* Neither input Map nor its arrays are mutated.
|
|
59
|
+
*/
|
|
60
|
+
export declare function mergeFunctionCoverageMaps(a: Map<string, FunctionHits[]>, b: Map<string, FunctionHits[]>): Map<string, FunctionHits[]>;
|
|
46
61
|
/**
|
|
47
62
|
* Depth-bounded readdir scan for a `coverage.cobertura.xml` inside any per-run
|
|
48
63
|
* subdirectory of a `TestResults` directory under cwd.
|
|
@@ -110,6 +125,11 @@ export declare function readCoverage(cwd: string, coverageFile?: string, trace?:
|
|
|
110
125
|
* - Python coverage JSON (files key + meta/summary/totals): transformed to Istanbul
|
|
111
126
|
* first, unless alreadyConverted (i.e. convertPythonCoverageToJson already ran).
|
|
112
127
|
* - Otherwise: parsed directly as Istanbul JSON.
|
|
128
|
+
*
|
|
129
|
+
* `out` (optional) collects the LCOV FN/FNDA side output; every other format
|
|
130
|
+
* leaves it empty.
|
|
113
131
|
*/
|
|
114
|
-
export declare function detectCoverageFormat(content: string, actualPath: string, cwd: string, isLcovByExt: boolean, alreadyConverted: boolean
|
|
132
|
+
export declare function detectCoverageFormat(content: string, actualPath: string, cwd: string, isLcovByExt: boolean, alreadyConverted: boolean, out?: {
|
|
133
|
+
functionCoverage: Map<string, FunctionHits[]>;
|
|
134
|
+
}): Promise<CoverageMap>;
|
|
115
135
|
export {};
|
package/dist/coverage.js
CHANGED
|
@@ -251,36 +251,44 @@ async function transformPythonCoverageToIstanbul(pythonJsonPath, cwd) {
|
|
|
251
251
|
function normalizeCoveragePaths(coverageMap, cwd) {
|
|
252
252
|
const normalized = new Map();
|
|
253
253
|
for (const [key, value] of coverageMap.entries()) {
|
|
254
|
-
|
|
255
|
-
|
|
254
|
+
normalized.set(rebaseCoverageKey(key, cwd), value);
|
|
255
|
+
}
|
|
256
|
+
return normalized;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Re-base one absolute coverage key onto `cwd` when its suffix matches a
|
|
260
|
+
* tracked file there (cross-environment artifacts); otherwise return the key
|
|
261
|
+
* unchanged. Shared by statement keys and `functionCoverage` keys so both
|
|
262
|
+
* lanes always carry identical key spelling.
|
|
263
|
+
*/
|
|
264
|
+
function rebaseCoverageKey(key, cwd) {
|
|
265
|
+
if (!path.isAbsolute(key)) {
|
|
266
|
+
return key;
|
|
267
|
+
}
|
|
268
|
+
// Find the longest suffix of `key` that, when resolved against `cwd`,
|
|
269
|
+
// points to an existing file. This re-bases cross-environment absolute
|
|
270
|
+
// paths onto the current checkout.
|
|
271
|
+
// ponytail: resolve against cwd as given (no realpath) so rebased keys
|
|
272
|
+
// keep the caller's path form (macOS /var vs /private/var).
|
|
273
|
+
const segments = key.split(path.sep);
|
|
274
|
+
let rebased = key;
|
|
275
|
+
for (let i = 1; i < segments.length; i++) {
|
|
276
|
+
const candidate = path.join(cwd, ...segments.slice(i));
|
|
277
|
+
// Boundary check: candidate must stay within cwd
|
|
278
|
+
const rel = path.relative(cwd, candidate);
|
|
279
|
+
if (rel.startsWith('..') || path.isAbsolute(rel))
|
|
256
280
|
continue;
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
// ponytail: resolve against cwd as given (no realpath) so rebased keys
|
|
262
|
-
// keep the caller's path form (macOS /var vs /private/var).
|
|
263
|
-
const segments = key.split(path.sep);
|
|
264
|
-
let rebased = key;
|
|
265
|
-
for (let i = 1; i < segments.length; i++) {
|
|
266
|
-
const candidate = path.join(cwd, ...segments.slice(i));
|
|
267
|
-
// Boundary check: candidate must stay within cwd
|
|
268
|
-
const rel = path.relative(cwd, candidate);
|
|
269
|
-
if (rel.startsWith('..') || path.isAbsolute(rel))
|
|
270
|
-
continue;
|
|
271
|
-
try {
|
|
272
|
-
if (fs.existsSync(candidate)) {
|
|
273
|
-
rebased = candidate;
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
catch {
|
|
278
|
-
// ignore and continue
|
|
281
|
+
try {
|
|
282
|
+
if (fs.existsSync(candidate)) {
|
|
283
|
+
rebased = candidate;
|
|
284
|
+
break;
|
|
279
285
|
}
|
|
280
286
|
}
|
|
281
|
-
|
|
287
|
+
catch {
|
|
288
|
+
// ignore and continue
|
|
289
|
+
}
|
|
282
290
|
}
|
|
283
|
-
return
|
|
291
|
+
return rebased;
|
|
284
292
|
}
|
|
285
293
|
/**
|
|
286
294
|
* Union two coverage maps by file path — the seam a Cobertura artifact and an
|
|
@@ -330,6 +338,33 @@ export function mergeCoverageMaps(a, b) {
|
|
|
330
338
|
add(key, value);
|
|
331
339
|
return merged;
|
|
332
340
|
}
|
|
341
|
+
/**
|
|
342
|
+
* Union two `functionCoverage` maps by file path (multi-artifact merge):
|
|
343
|
+
* a path in only one map carries through unchanged; a path in both
|
|
344
|
+
* concatenates its entries. Keys match case-insensitively with the
|
|
345
|
+
* first-seen spelling winning — the same rule as `mergeCoverageMaps`.
|
|
346
|
+
* Neither input Map nor its arrays are mutated.
|
|
347
|
+
*/
|
|
348
|
+
export function mergeFunctionCoverageMaps(a, b) {
|
|
349
|
+
const merged = new Map();
|
|
350
|
+
/** folded key -> the spelling already stored in `merged` */
|
|
351
|
+
const canonical = new Map();
|
|
352
|
+
const add = (key, value) => {
|
|
353
|
+
const folded = key.toLowerCase();
|
|
354
|
+
const seen = canonical.get(folded);
|
|
355
|
+
if (seen === undefined) {
|
|
356
|
+
canonical.set(folded, key);
|
|
357
|
+
merged.set(key, value);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
merged.set(seen, [...merged.get(seen), ...value]);
|
|
361
|
+
};
|
|
362
|
+
for (const [key, value] of a)
|
|
363
|
+
add(key, value);
|
|
364
|
+
for (const [key, value] of b)
|
|
365
|
+
add(key, value);
|
|
366
|
+
return merged;
|
|
367
|
+
}
|
|
333
368
|
function mergeFileCoverage(a, b) {
|
|
334
369
|
// Map preserves first-seen line order; the unit stored for a line is the max-hits one.
|
|
335
370
|
const byLine = new Map();
|
|
@@ -495,6 +530,7 @@ export async function readCoverage(cwd, coverageFile, trace, autoGenerated) {
|
|
|
495
530
|
// the maps are accumulated and reduced at the end (see @lineage above).
|
|
496
531
|
let artifactFound = false;
|
|
497
532
|
let mergedMap = null;
|
|
533
|
+
let mergedFunctionCoverage = null;
|
|
498
534
|
let mergedSha256;
|
|
499
535
|
const registry = providerRegistry();
|
|
500
536
|
const coverageCandidates = registry
|
|
@@ -518,6 +554,11 @@ export async function readCoverage(cwd, coverageFile, trace, autoGenerated) {
|
|
|
518
554
|
if (mergedSha256 === undefined)
|
|
519
555
|
mergedSha256 = result.contentSha256;
|
|
520
556
|
}
|
|
557
|
+
if (result.functionCoverage && result.functionCoverage.size > 0) {
|
|
558
|
+
mergedFunctionCoverage = mergedFunctionCoverage === null
|
|
559
|
+
? result.functionCoverage
|
|
560
|
+
: mergeFunctionCoverageMaps(mergedFunctionCoverage, result.functionCoverage);
|
|
561
|
+
}
|
|
521
562
|
continue;
|
|
522
563
|
}
|
|
523
564
|
// Conversion/read failed - warn and continue to next candidate
|
|
@@ -544,6 +585,8 @@ export async function readCoverage(cwd, coverageFile, trace, autoGenerated) {
|
|
|
544
585
|
const out = { available: true, coverageMap: mergedMap, error: false };
|
|
545
586
|
if (mergedSha256 !== undefined)
|
|
546
587
|
out.contentSha256 = mergedSha256;
|
|
588
|
+
if (mergedFunctionCoverage !== null)
|
|
589
|
+
out.functionCoverage = mergedFunctionCoverage;
|
|
547
590
|
return out;
|
|
548
591
|
}
|
|
549
592
|
// 2b. Scan fallback for Coverlet: `dotnet test --collect:"XPlat Code Coverage"`
|
|
@@ -640,8 +683,11 @@ async function resolveReadableCandidate(cwd, file) {
|
|
|
640
683
|
* - Python coverage JSON (files key + meta/summary/totals): transformed to Istanbul
|
|
641
684
|
* first, unless alreadyConverted (i.e. convertPythonCoverageToJson already ran).
|
|
642
685
|
* - Otherwise: parsed directly as Istanbul JSON.
|
|
686
|
+
*
|
|
687
|
+
* `out` (optional) collects the LCOV FN/FNDA side output; every other format
|
|
688
|
+
* leaves it empty.
|
|
643
689
|
*/
|
|
644
|
-
export async function detectCoverageFormat(content, actualPath, cwd, isLcovByExt, alreadyConverted) {
|
|
690
|
+
export async function detectCoverageFormat(content, actualPath, cwd, isLcovByExt, alreadyConverted, out) {
|
|
645
691
|
// Cobertura first, keyed on basename: a `.cobertura.xml` artifact is Cobertura
|
|
646
692
|
// whether it came from Coverlet or pytest-cov, and it is never Istanbul JSON,
|
|
647
693
|
// so answering before the LCOV and Python-JSON probes below is what keeps it
|
|
@@ -658,7 +704,7 @@ export async function detectCoverageFormat(content, actualPath, cwd, isLcovByExt
|
|
|
658
704
|
}
|
|
659
705
|
if (isLcov) {
|
|
660
706
|
// Security: limit LCOV size - validateAndReadFile already enforces stats.size pre-read
|
|
661
|
-
return parseLcovContent(content, cwd);
|
|
707
|
+
return parseLcovContent(content, cwd, out);
|
|
662
708
|
}
|
|
663
709
|
// Check if this is Python coverage JSON format (has 'files' key + 'meta'/'summary'/'totals')
|
|
664
710
|
// If so, transform to Istanbul format before parsing
|
|
@@ -744,10 +790,30 @@ async function readCoverageFile(coveragePath, cwd, isExplicit, autoGenerated) {
|
|
|
744
790
|
return { available: false, coverageMap: null, error: false };
|
|
745
791
|
return { available: true, coverageMap: null, error: true, reason: 'malformed' };
|
|
746
792
|
}
|
|
747
|
-
const
|
|
793
|
+
const functionCoverage = new Map();
|
|
794
|
+
const coverageMap = await detectCoverageFormat(content, actualPath, cwd, isLcovByExt, alreadyConverted, { functionCoverage });
|
|
795
|
+
// Option (b) garbage guard: explicit LCOV-by-ext file that parsed to an
|
|
796
|
+
// empty map AND carries no SF:/DA: token is not a valid zero-record
|
|
797
|
+
// artifact — it is garbage (or JSON renamed .info/.lcov). Valid LCOV
|
|
798
|
+
// with SF: + zero DA: has a token and stays lenient below. Auto-detect
|
|
799
|
+
// lane is already strict elsewhere; this guard is explicit-file only.
|
|
800
|
+
// Token check uses /(^|\n)(SF:|DA:)/ so first-line SF: counts (the
|
|
801
|
+
// detectCoverageFormat sniff uses '\nSF:' and would miss it).
|
|
802
|
+
if (isExplicit && isLcovByExt && coverageMap.size === 0 && !/(^|\n)(SF:|DA:)/.test(content)) {
|
|
803
|
+
return { available: true, coverageMap: null, error: true, reason: 'malformed' };
|
|
804
|
+
}
|
|
748
805
|
const normalizedCoverageMap = normalizeCoveragePaths(coverageMap, cwd);
|
|
806
|
+
// functionCoverage keys went through the same normalizePath in the LCOV
|
|
807
|
+
// parser; re-base them identically so both lanes carry the same spelling.
|
|
808
|
+
const normalizedFunctionCoverage = new Map();
|
|
809
|
+
for (const [key, value] of functionCoverage) {
|
|
810
|
+
normalizedFunctionCoverage.set(rebaseCoverageKey(key, cwd), value);
|
|
811
|
+
}
|
|
749
812
|
// Lineage input identity: hash of the artifact bytes actually read (in hand, no new reads)
|
|
750
|
-
|
|
813
|
+
const result = { available: true, coverageMap: normalizedCoverageMap, error: false, contentSha256: createHash('sha256').update(content).digest('hex') };
|
|
814
|
+
if (normalizedFunctionCoverage.size > 0)
|
|
815
|
+
result.functionCoverage = normalizedFunctionCoverage;
|
|
816
|
+
return result;
|
|
751
817
|
}
|
|
752
818
|
catch {
|
|
753
819
|
// Malformed or unreadable
|
package/dist/crapCalc.d.ts
CHANGED
package/dist/crapCalc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Provenance for the crapCalc lineage stage. Self tool version tracks package.json
|
|
2
|
-
// (matches existing hard-coded '0.5.
|
|
3
|
-
export const crapCalcProvenance = { tool: 'checkchange', version: '0.5.
|
|
2
|
+
// (matches existing hard-coded '0.5.4' style for the core package).
|
|
3
|
+
export const crapCalcProvenance = { tool: 'checkchange', version: '0.5.4' };
|
|
4
4
|
export function calculateCrap(cc, coveragePercent) {
|
|
5
5
|
if (coveragePercent == null) {
|
|
6
6
|
return null;
|
package/dist/evidence.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface DiagnosticLineageEntry {
|
|
|
31
31
|
}
|
|
32
32
|
export declare const evidenceProvenance: {
|
|
33
33
|
readonly tool: "checkchange";
|
|
34
|
-
readonly version: "0.5.
|
|
34
|
+
readonly version: "0.5.4";
|
|
35
35
|
};
|
|
36
36
|
export interface EvidenceOutput {
|
|
37
37
|
schemaVersion: string;
|
|
@@ -58,8 +58,15 @@ export interface EvidenceOutput {
|
|
|
58
58
|
lineage: DiagnosticLineageEntry[];
|
|
59
59
|
quality: DiagnosticQuality;
|
|
60
60
|
fingerprints?: Record<string, string> | undefined;
|
|
61
|
+
functionCoverage?: FunctionCoverageDiagnosticEntry[];
|
|
61
62
|
};
|
|
62
63
|
}
|
|
64
|
+
export interface FunctionCoverageDiagnosticEntry {
|
|
65
|
+
file: string;
|
|
66
|
+
method: string;
|
|
67
|
+
line: number;
|
|
68
|
+
hits: number;
|
|
69
|
+
}
|
|
63
70
|
export type QualityStage = 'git' | 'complexity' | 'coverage' | 'attribution' | 'rules';
|
|
64
71
|
export interface UncoveredFunction {
|
|
65
72
|
file: string;
|
package/dist/evidence.js
CHANGED
|
@@ -19,8 +19,8 @@ import * as fs from 'fs';
|
|
|
19
19
|
import * as path from 'path';
|
|
20
20
|
import { loadProviderConfig, deriveRegistry, builtinConfig, createGenericCommandProvider } from './providers/index.js';
|
|
21
21
|
const requireFromEvidence = createRequire(import.meta.url);
|
|
22
|
-
// Self provenance; version mirrors package.json (existing codebase style hard-codes '0.5.
|
|
23
|
-
export const evidenceProvenance = { tool: 'checkchange', version: '0.5.
|
|
22
|
+
// Self provenance; version mirrors package.json (existing codebase style hard-codes '0.5.4').
|
|
23
|
+
export const evidenceProvenance = { tool: 'checkchange', version: '0.5.4' };
|
|
24
24
|
function sha256Hex(content) {
|
|
25
25
|
return createHash('sha256').update(content).digest('hex');
|
|
26
26
|
}
|
|
@@ -132,15 +132,45 @@ function buildFingerprints(changedFunctions) {
|
|
|
132
132
|
* behavior). fingerprints emitted only when non-empty. All values deterministic
|
|
133
133
|
* per evidence-contract.md:341.
|
|
134
134
|
*/
|
|
135
|
-
function withDiagnostics(output, lineage, quality, fingerprints) {
|
|
135
|
+
function withDiagnostics(output, lineage, quality, fingerprints, functionCoverage) {
|
|
136
136
|
const fpEntries = fingerprints ? Object.keys(fingerprints).length : 0;
|
|
137
|
+
const fcEntries = functionCoverage ? functionCoverage.length : 0;
|
|
137
138
|
if (lineage.length === 0)
|
|
138
139
|
return output;
|
|
139
140
|
return {
|
|
140
141
|
...output,
|
|
141
|
-
diagnostics: { lineage, quality, ...(fpEntries > 0 ? { fingerprints } : {}) },
|
|
142
|
+
diagnostics: { lineage, quality, ...(fpEntries > 0 ? { fingerprints } : {}), ...(fcEntries > 0 && functionCoverage !== undefined ? { functionCoverage } : {}) },
|
|
142
143
|
};
|
|
143
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Matches CoverageResult.functionCoverage (absolute-path keyed) to attributed
|
|
147
|
+
* methods by file + lineStart, emitting one entry per attributed method that
|
|
148
|
+
* has an FN record at its start line. Key normalization mirrors the
|
|
149
|
+
* attribution seam (attribution.ts matchingComplexityForFile): resolve(cwd,
|
|
150
|
+
* rel), backslashes → slashes, case-insensitive. Returns undefined when the
|
|
151
|
+
* coverage source carried no FN data (Istanbul/Cobertura) or nothing matched,
|
|
152
|
+
* so the diagnostics key stays absent rather than empty.
|
|
153
|
+
*/
|
|
154
|
+
function buildFunctionCoverageDiagnostics(attributedComplexity, coverageResult, cwd) {
|
|
155
|
+
const fc = coverageResult.functionCoverage;
|
|
156
|
+
if (fc === undefined || fc.size === 0)
|
|
157
|
+
return undefined;
|
|
158
|
+
const byAbsPath = new Map();
|
|
159
|
+
for (const [key, entries] of fc)
|
|
160
|
+
byAbsPath.set(key.replace(/\\/g, '/').toLowerCase(), entries);
|
|
161
|
+
const out = [];
|
|
162
|
+
for (const ac of attributedComplexity) {
|
|
163
|
+
const absRel = path.resolve(cwd, ac.info.file).replace(/\\/g, '/').toLowerCase();
|
|
164
|
+
const entries = byAbsPath.get(absRel);
|
|
165
|
+
if (entries === undefined)
|
|
166
|
+
continue;
|
|
167
|
+
const hit = entries.find((e) => e.line === ac.info.lineStart);
|
|
168
|
+
if (hit === undefined)
|
|
169
|
+
continue;
|
|
170
|
+
out.push({ file: ac.info.file, method: ac.info.method, line: hit.line, hits: hit.hits });
|
|
171
|
+
}
|
|
172
|
+
return out.length > 0 ? out : undefined;
|
|
173
|
+
}
|
|
144
174
|
const providers = new Map();
|
|
145
175
|
export function registerProvider(ext, factory) { providers.set(ext, factory); }
|
|
146
176
|
export function getProvider(ext) { return providers.get(ext); }
|
|
@@ -657,10 +687,10 @@ function resolveCoverageFailure(coverageCapability, coverageErrorReason, autoGen
|
|
|
657
687
|
* Returns either the attributed complexity or an early-return output on failure.
|
|
658
688
|
* ponytail: extracted from buildEvidenceOutput to reduce cyclomatic complexity.
|
|
659
689
|
*/
|
|
660
|
-
async function attachCoverageWithTracking(complexityInfo, coverageResult, trace, lineage, base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason) {
|
|
690
|
+
async function attachCoverageWithTracking(complexityInfo, coverageResult, trace, lineage, base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason, cwd) {
|
|
661
691
|
const t0 = Date.now();
|
|
662
692
|
try {
|
|
663
|
-
const attributedComplexity = await attachCoverage(complexityInfo, coverageResult);
|
|
693
|
+
const attributedComplexity = await attachCoverage(complexityInfo, coverageResult, cwd);
|
|
664
694
|
if (trace)
|
|
665
695
|
trace.recordStage('attribution', Date.now() - t0, 'ok');
|
|
666
696
|
lineage.push({
|
|
@@ -832,10 +862,13 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
|
|
|
832
862
|
coverageErrorReason = covRes.coverageErrorReason;
|
|
833
863
|
const analysisStatus = covRes.analysisStatus;
|
|
834
864
|
// Step 3: Attach coverage to complexity info
|
|
835
|
-
const attrResult = await attachCoverageWithTracking(complexityInfo, coverageResult, trace, lineage, base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason);
|
|
865
|
+
const attrResult = await attachCoverageWithTracking(complexityInfo, coverageResult, trace, lineage, base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason, cwd);
|
|
836
866
|
if (attrResult.earlyReturn)
|
|
837
867
|
return attrResult.earlyReturn;
|
|
838
868
|
const attributedComplexity = attrResult.attributedComplexity;
|
|
869
|
+
// FN/FNDA carriage (diagnostic only): match function hits to attributed
|
|
870
|
+
// methods by file + lineStart; undefined when source had no FN data.
|
|
871
|
+
const functionCoverageDiag = buildFunctionCoverageDiagnostics(attributedComplexity, coverageResult, cwd);
|
|
839
872
|
// Step 4+5: Map attributed complexity → MethodEvidence (merged Steps 4+5 via mapToMethodEvidence)
|
|
840
873
|
const t0CrapCalc = Date.now();
|
|
841
874
|
const methodEvidence = mapToMethodEvidence(attributedComplexity);
|
|
@@ -914,7 +947,7 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
|
|
|
914
947
|
attributionComplete: true,
|
|
915
948
|
rulesComplete: true,
|
|
916
949
|
changedFunctions: changedFunctionsWithLanguage
|
|
917
|
-
}), buildFingerprints(changedFunctionsWithLanguage));
|
|
950
|
+
}), buildFingerprints(changedFunctionsWithLanguage), functionCoverageDiag);
|
|
918
951
|
}
|
|
919
952
|
// Helper function to build output when there is a provider failure
|
|
920
953
|
function buildFailedOutput(base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { FunctionCoverageDiagnosticEntry } from '../evidence.js';
|
|
1
2
|
/**
|
|
2
3
|
* Formatters are pure sidecars: (EvidenceOutputShape, opts) => string.
|
|
3
4
|
* They never call engine code and never emit absolute paths — file paths are
|
|
@@ -39,6 +40,9 @@ export interface EvidenceOutputShape {
|
|
|
39
40
|
schemaVersion: string;
|
|
40
41
|
changedFunctions: ChangedFunctionShape[];
|
|
41
42
|
ruleResults: RuleResultShape[];
|
|
43
|
+
diagnostics?: {
|
|
44
|
+
functionCoverage?: FunctionCoverageDiagnosticEntry[];
|
|
45
|
+
};
|
|
42
46
|
}
|
|
43
47
|
export declare const FORMATS: readonly ["github", "junit", "sarif"];
|
|
44
48
|
export type FormatType = (typeof FORMATS)[number];
|
package/dist/formatters/sarif.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** SARIF 2.1.0: one result per WARN with verbatim relative uri + line region. */
|
|
2
2
|
export function formatSARIF(out, opts) {
|
|
3
3
|
void opts;
|
|
4
|
-
const
|
|
4
|
+
const warnResults = out.ruleResults
|
|
5
5
|
.map((r, i) => ({ r, fn: out.changedFunctions[i] }))
|
|
6
6
|
.filter(({ r }) => r.result === 'WARN')
|
|
7
7
|
.map(({ r, fn }) => ({
|
|
@@ -17,6 +17,27 @@ export function formatSARIF(out, opts) {
|
|
|
17
17
|
],
|
|
18
18
|
message: { text: `${r.method} CRAP ${r.crap} > ${r.threshold} (cc ${r.cc}, cov ${r.coverage})` },
|
|
19
19
|
}));
|
|
20
|
+
// FN/FNDA: informational note results when diagnostics carry function coverage.
|
|
21
|
+
const coverageEntries = out.diagnostics?.functionCoverage ?? [];
|
|
22
|
+
const results = [
|
|
23
|
+
...warnResults,
|
|
24
|
+
...coverageEntries.map((entry) => ({
|
|
25
|
+
ruleId: 'function-hit-coverage',
|
|
26
|
+
level: 'note',
|
|
27
|
+
locations: [
|
|
28
|
+
{
|
|
29
|
+
physicalLocation: {
|
|
30
|
+
artifactLocation: { uri: entry.file },
|
|
31
|
+
region: { startLine: entry.line, endLine: entry.line },
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
message: { text: `${entry.method} FN hits ${entry.hits}` },
|
|
36
|
+
})),
|
|
37
|
+
];
|
|
38
|
+
const rules = coverageEntries.length > 0
|
|
39
|
+
? [{ id: 'changed-function-high-crap' }, { id: 'function-hit-coverage' }]
|
|
40
|
+
: [{ id: 'changed-function-high-crap' }];
|
|
20
41
|
return JSON.stringify({
|
|
21
42
|
// SARIF 2.1.0 top-level schema key is `$schema`; the schemastore schema
|
|
22
43
|
// has additionalProperties:false, so `schema` would make the doc invalid.
|
|
@@ -28,7 +49,7 @@ export function formatSARIF(out, opts) {
|
|
|
28
49
|
driver: {
|
|
29
50
|
name: 'checkchange',
|
|
30
51
|
version: out.schemaVersion,
|
|
31
|
-
rules
|
|
52
|
+
rules,
|
|
32
53
|
},
|
|
33
54
|
},
|
|
34
55
|
results,
|
package/dist/providers/config.js
CHANGED
|
@@ -20,6 +20,17 @@ const JEST_RUNNER = {
|
|
|
20
20
|
command: ['npx', 'jest', '--coverage'],
|
|
21
21
|
artifact: 'coverage/coverage-final.json',
|
|
22
22
|
};
|
|
23
|
+
// Probe `bun --version` (spawned as `bun --version --version`), NOT `bun test --version`:
|
|
24
|
+
// measured on bun 1.3.14, the latter prints the banner then RUNS THE SUITE and exits
|
|
25
|
+
// non-zero on no/failing tests — a probe must not execute tests. Bare `bun test
|
|
26
|
+
// --coverage` writes NO artifact (default reporter 'text'); lcov is required.
|
|
27
|
+
const BUN_RUNNER = {
|
|
28
|
+
name: 'bun',
|
|
29
|
+
configFiles: ['bunfig.toml'],
|
|
30
|
+
binaryProbes: ['bun --version'],
|
|
31
|
+
command: ['bun', 'test', '--coverage', '--coverage-reporter=lcov'],
|
|
32
|
+
artifact: 'coverage/lcov.info',
|
|
33
|
+
};
|
|
23
34
|
const PYTEST_RUNNER = {
|
|
24
35
|
name: 'pytest',
|
|
25
36
|
configFiles: ['pyproject.toml', 'pytest.ini', 'setup.cfg', 'requirements.txt'],
|
|
@@ -58,13 +69,13 @@ export function builtinConfig() {
|
|
|
58
69
|
language: 'javascript',
|
|
59
70
|
extensions: ['.js', '.jsx', '.mjs', '.cjs'],
|
|
60
71
|
coverageFiles: ['coverage/coverage-final.json', 'coverage/lcov.info'],
|
|
61
|
-
testRunners: [VITEST_RUNNER, JEST_RUNNER],
|
|
72
|
+
testRunners: [VITEST_RUNNER, JEST_RUNNER, BUN_RUNNER],
|
|
62
73
|
},
|
|
63
74
|
{
|
|
64
75
|
language: 'typescript',
|
|
65
76
|
extensions: ['.ts', '.tsx'],
|
|
66
77
|
coverageFiles: ['coverage/coverage-final.json', 'coverage/lcov.info'],
|
|
67
|
-
testRunners: [VITEST_RUNNER, JEST_RUNNER],
|
|
78
|
+
testRunners: [VITEST_RUNNER, JEST_RUNNER, BUN_RUNNER],
|
|
68
79
|
},
|
|
69
80
|
{
|
|
70
81
|
language: 'python',
|
package/dist/rules.d.ts
CHANGED
package/dist/rules.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Provenance for the rules lineage stage. Self tool version tracks package.json.
|
|
2
|
-
export const rulesProvenance = { tool: 'checkchange', version: '0.5.
|
|
2
|
+
export const rulesProvenance = { tool: 'checkchange', version: '0.5.4' };
|
|
3
3
|
/**
|
|
4
4
|
* Evaluate changed functions against the high-CRAP rule.
|
|
5
5
|
* @param changed Array of changed functions
|