checkchange 0.5.5 → 0.5.7
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 +4 -2
- package/README.md +32 -4
- package/dist/complexity-providers/csharpDescriptorProvider.js +2 -2
- package/dist/crapCalc.d.ts +1 -1
- package/dist/crapCalc.js +2 -2
- package/dist/evidence.d.ts +4 -1
- package/dist/evidence.js +40 -22
- package/dist/generated-filter.d.ts +21 -0
- package/dist/generated-filter.js +120 -0
- package/dist/providers/config.d.ts +2 -0
- package/dist/providers/config.js +15 -2
- package/dist/rules.d.ts +1 -1
- package/dist/rules.js +1 -1
- package/package.json +1 -1
|
@@ -19,7 +19,7 @@ Correct use of `checkchange check`: prevents hallucination, enforces WARN blocks
|
|
|
19
19
|
# What It Entails
|
|
20
20
|
1. Generate coverage artifact before check — required before check:
|
|
21
21
|
- vitest/jest: `pnpm vitest run --coverage` → `coverage/coverage-final.json`
|
|
22
|
-
- bun: `bun test --coverage --coverage-reporter=lcov` → `coverage/lcov.info
|
|
22
|
+
- bun (checkchange >=0.5.4): `checkchange check --auto-coverage` detects bun (bunfig.toml or `bun --version` probe, and the repo must contain at least one source file matching a provider extension: `.ts/.tsx/.js/.jsx/.mjs/.cjs`) and runs `bun test --coverage --coverage-reporter=lcov` itself → `coverage/lcov.info`. Manual recipe when not using --auto-coverage: run that command, then 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.
|
|
23
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)
|
|
24
24
|
3. Read gate + changedFunctions
|
|
25
25
|
|
|
@@ -43,7 +43,8 @@ Correct use of `checkchange check`: prevents hallucination, enforces WARN blocks
|
|
|
43
43
|
"diagnostics?": {
|
|
44
44
|
"lineage": [{"stage","tool","version","inputs"}],
|
|
45
45
|
"quality": {"coverage":"DIRECT|UNAVAILABLE","complexity":"NATIVE|UNAVAILABLE","score":0-100|null,"stageComplete":{...},"uncoveredFunctions?":[{file,method,lineStart,lineEnd}]},
|
|
46
|
-
"fingerprints?": {"file:method:lineStart": "sha256hex"}
|
|
46
|
+
"fingerprints?": {"file:method:lineStart": "sha256hex"},
|
|
47
|
+
"excludedGeneratedFiles?": [{"file","reason"}]
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
```
|
|
@@ -61,6 +62,7 @@ Correct use of `checkchange check`: prevents hallucination, enforces WARN blocks
|
|
|
61
62
|
- 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.
|
|
62
63
|
- 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
64
|
- 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.
|
|
65
|
+
- Generated-file filter (default ON): minified bundles (`.min.js`), source-map sidecars/raw maps (`.js.map`/`.map`), generated-header files, and core-delegated path segments (`dist/`, `node_modules/`, …) are excluded before complexity collection; test files (`.test.`/`.spec.`) carry their own reason. Exclusions surface in `diagnostics.excludedGeneratedFiles` as `[{file, reason}]`; an all-excluded diff is `NOT_EVALUATED` with `gateReason: 'all-files-generated'` (test-only → `'test-files-excluded'`). Re-include path substrings via top-level `generatedIgnorePatterns` in provider config (schema 1 or 2).
|
|
64
66
|
- Exit codes: FAILED→1, SUCCESS+WARN→1, UNSUPPORTED+NOT_APPLICABLE→0.
|
|
65
67
|
- Malformed artifact: analysisStatus=FAILED, gate=FAILED, completeness=INCOMPLETE.
|
|
66
68
|
- Trace sidecar: `{command:"trace", correlationId, spans:[{stage,durationMs,status}]}`.
|
package/README.md
CHANGED
|
@@ -411,8 +411,10 @@ of four values:
|
|
|
411
411
|
| `FAILED` | Analysis could not complete (coverage missing/malformed, complexity failed). |
|
|
412
412
|
|
|
413
413
|
`gateReason` (optional) explains why a non-PASS gate was emitted, e.g.
|
|
414
|
-
`no-supported-file-extensions`, `complexity-analysis-failed`,
|
|
415
|
-
error reason (`missing` / `malformed` / `failed`)
|
|
414
|
+
`no-supported-file-extensions`, `complexity-analysis-failed`, the coverage
|
|
415
|
+
error reason (`missing` / `malformed` / `failed`), or a generated-file
|
|
416
|
+
exclusion: `all-files-generated` when every changed file is excluded, or
|
|
417
|
+
`test-files-excluded` when only test files are.
|
|
416
418
|
|
|
417
419
|
**Explicit-file malformed taxonomy.** When `--coverage-file <path>` points to
|
|
418
420
|
an extension-gated LCOV artifact (`*.info` or `*.lcov`) that parses to an empty
|
|
@@ -442,8 +444,9 @@ Exit codes:
|
|
|
442
444
|
|
|
443
445
|
`--json` may include an optional top-level `diagnostics` object. Existing fields
|
|
444
446
|
(`lineage`, `quality`, `fingerprints`) carry provenance, quality scores, and
|
|
445
|
-
per-function hashes.
|
|
446
|
-
|
|
447
|
+
per-function hashes. `functionCoverage` is emitted only when the coverage
|
|
448
|
+
artifact is LCOV and contains FN/FNDA records. `excludedGeneratedFiles` lists
|
|
449
|
+
every changed file skipped by the generated-file filter.
|
|
447
450
|
|
|
448
451
|
## `diagnostics.functionCoverage`
|
|
449
452
|
|
|
@@ -489,6 +492,31 @@ methods only).
|
|
|
489
492
|
|
|
490
493
|
---
|
|
491
494
|
|
|
495
|
+
## `diagnostics.excludedGeneratedFiles`
|
|
496
|
+
|
|
497
|
+
**What it is:** Machine-generated changed files are excluded from CRAP analysis
|
|
498
|
+
by default. The filter runs on every changed file before complexity collection:
|
|
499
|
+
minified bundles (`*.min.js`), source-map sidecars (`*.js.map`), raw source maps
|
|
500
|
+
(`*.map`), files whose first 8 KB carry a generated header marker, and files
|
|
501
|
+
under core-delegated path segments (`/dist/`, `/node_modules/`, …) are skipped,
|
|
502
|
+
as are test files (`*.test.*`, `*.spec.*`) under their own reason. Each
|
|
503
|
+
exclusion is recorded as `{ "file": ..., "reason": ... }`; the array is empty
|
|
504
|
+
when nothing was excluded.
|
|
505
|
+
|
|
506
|
+
When every changed file is excluded the gate returns `NOT_EVALUATED` with
|
|
507
|
+
`gateReason: 'all-files-generated'` (or `'test-files-excluded'` when only test
|
|
508
|
+
files were), never a vacuous `PASS`.
|
|
509
|
+
|
|
510
|
+
To re-include a generated-looking file, list path substrings in top-level
|
|
511
|
+
`generatedIgnorePatterns` in the provider config (`checkchange.providers.json`;
|
|
512
|
+
schema version 1 or 2, an absent version treated as 1):
|
|
513
|
+
|
|
514
|
+
```json
|
|
515
|
+
{ "version": 2, "generatedIgnorePatterns": ["src/legacy/gen.js"] }
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
---
|
|
519
|
+
|
|
492
520
|
# Why the evidence matters
|
|
493
521
|
|
|
494
522
|
One of the design goals of CheckChange is to distinguish **"we measured it"** from **"we don't have enough evidence."**
|
|
@@ -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.7
|
|
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.7';
|
|
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
|
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.7' style for the core package).
|
|
3
|
+
export const crapCalcProvenance = { tool: 'checkchange', version: '0.5.7' };
|
|
4
4
|
export function calculateCrap(cc, coveragePercent) {
|
|
5
5
|
if (coveragePercent == null) {
|
|
6
6
|
return null;
|
package/dist/evidence.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { type ComplexityInfo } from './complexity.js';
|
|
|
5
5
|
import { type TraceRun } from './execute.js';
|
|
6
6
|
import { type MethodEvidence } from './crap.js';
|
|
7
7
|
import { type ResolvedProvider, type ProviderConfig } from './providers/index.js';
|
|
8
|
+
import { type ExcludedGeneratedFile } from './generated-filter.js';
|
|
8
9
|
/** Capabilities passed to buildOutput / buildEvidenceOutput. */
|
|
9
10
|
export interface Capabilities {
|
|
10
11
|
git: string;
|
|
@@ -31,7 +32,7 @@ export interface DiagnosticLineageEntry {
|
|
|
31
32
|
}
|
|
32
33
|
export declare const evidenceProvenance: {
|
|
33
34
|
readonly tool: "checkchange";
|
|
34
|
-
readonly version: "0.5.
|
|
35
|
+
readonly version: "0.5.7";
|
|
35
36
|
};
|
|
36
37
|
export interface EvidenceOutput {
|
|
37
38
|
schemaVersion: string;
|
|
@@ -59,6 +60,8 @@ export interface EvidenceOutput {
|
|
|
59
60
|
quality: DiagnosticQuality;
|
|
60
61
|
fingerprints?: Record<string, string> | undefined;
|
|
61
62
|
functionCoverage?: FunctionCoverageDiagnosticEntry[];
|
|
63
|
+
/** Generated/minified files excluded at Seam A (plan task 3). Absent when none. */
|
|
64
|
+
excludedGeneratedFiles?: ExcludedGeneratedFile[];
|
|
62
65
|
};
|
|
63
66
|
}
|
|
64
67
|
export interface FunctionCoverageDiagnosticEntry {
|
package/dist/evidence.js
CHANGED
|
@@ -18,9 +18,10 @@ import { createRequire } from 'node:module';
|
|
|
18
18
|
import * as fs from 'fs';
|
|
19
19
|
import * as path from 'path';
|
|
20
20
|
import { loadProviderConfig, deriveRegistry, builtinConfig, createGenericCommandProvider } from './providers/index.js';
|
|
21
|
+
import { filterDiffedFiles } from './generated-filter.js';
|
|
21
22
|
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.
|
|
23
|
+
// Self provenance; version mirrors package.json (existing codebase style hard-codes '0.5.7').
|
|
24
|
+
export const evidenceProvenance = { tool: 'checkchange', version: '0.5.7' };
|
|
24
25
|
function sha256Hex(content) {
|
|
25
26
|
return createHash('sha256').update(content).digest('hex');
|
|
26
27
|
}
|
|
@@ -132,14 +133,14 @@ function buildFingerprints(changedFunctions) {
|
|
|
132
133
|
* behavior). fingerprints emitted only when non-empty. All values deterministic
|
|
133
134
|
* per evidence-contract.md:341.
|
|
134
135
|
*/
|
|
135
|
-
function withDiagnostics(output, lineage, quality, fingerprints, functionCoverage) {
|
|
136
|
+
function withDiagnostics(output, lineage, quality, fingerprints, functionCoverage, excludedGeneratedFiles) {
|
|
136
137
|
const fpEntries = fingerprints ? Object.keys(fingerprints).length : 0;
|
|
137
138
|
const fcEntries = functionCoverage ? functionCoverage.length : 0;
|
|
138
139
|
if (lineage.length === 0)
|
|
139
140
|
return output;
|
|
140
141
|
return {
|
|
141
142
|
...output,
|
|
142
|
-
diagnostics: { lineage, quality, ...(fpEntries > 0 ? { fingerprints } : {}), ...(fcEntries > 0 && functionCoverage !== undefined ? { functionCoverage } : {}) },
|
|
143
|
+
diagnostics: { lineage, quality, ...(fpEntries > 0 ? { fingerprints } : {}), ...(fcEntries > 0 && functionCoverage !== undefined ? { functionCoverage } : {}), ...(excludedGeneratedFiles !== undefined ? { excludedGeneratedFiles } : {}) },
|
|
143
144
|
};
|
|
144
145
|
}
|
|
145
146
|
/**
|
|
@@ -534,9 +535,11 @@ export async function readCoverageWithProvider(detectedExtension, cwd, coverageF
|
|
|
534
535
|
return { result, capability, errorReason, elapsed: Date.now() - t0 };
|
|
535
536
|
}
|
|
536
537
|
// ponytail: extracted from buildEvidenceOutput to reduce cyclomatic complexity.
|
|
537
|
-
//
|
|
538
|
-
//
|
|
539
|
-
|
|
538
|
+
// Shared early return for empty intervals AND all-files-generated (plan task 3):
|
|
539
|
+
// coverage read + lineage push happen BEFORE returning, so MISSING≠MALFORMED and no
|
|
540
|
+
// vacuous PASS is possible (vacuous-PASS ban §5, reviewer C2). Defaults preserve the
|
|
541
|
+
// historical 'no-changed-lines' call sites unchanged.
|
|
542
|
+
async function emptyIntervalsReturn(base, threshold, detectedExtension, cwd, coverageFile, trace, autoGenerated, gitCapability, lineage, gateReason = 'no-changed-lines', excludedGeneratedFiles) {
|
|
540
543
|
const t0CovEarly = Date.now();
|
|
541
544
|
const covEarly = await readCoverageWithProvider(detectedExtension, cwd, coverageFile, trace, autoGenerated);
|
|
542
545
|
if (trace)
|
|
@@ -562,9 +565,9 @@ async function emptyIntervalsReturn(base, threshold, detectedExtension, cwd, cov
|
|
|
562
565
|
analysisStatus: 'UNSUPPORTED',
|
|
563
566
|
gate: 'NOT_EVALUATED',
|
|
564
567
|
completeness: 'INCOMPLETE',
|
|
565
|
-
gateReason
|
|
568
|
+
gateReason,
|
|
566
569
|
...(covEarly.errorReason !== undefined ? { coverageErrorReason: covEarly.errorReason } : {})
|
|
567
|
-
}, lineage, buildQuality({ complexityCapability: 'unavailable', coverageUsable: false }));
|
|
570
|
+
}, lineage, buildQuality({ complexityCapability: 'unavailable', coverageUsable: false }), undefined, undefined, excludedGeneratedFiles);
|
|
568
571
|
}
|
|
569
572
|
// ponytail: extracted from buildEvidenceOutput to reduce cyclomatic complexity.
|
|
570
573
|
// §5 vacuous-PASS ban: coverage absent + needs coverage → NOT_EVALUATED gate.
|
|
@@ -663,7 +666,7 @@ export function buildOutput(base, changed, threshold = 30, capabilities = { git:
|
|
|
663
666
|
* output when analysis should stop, or null to continue.
|
|
664
667
|
* ponytail: extracted from buildEvidenceOutput to reduce cyclomatic complexity.
|
|
665
668
|
*/
|
|
666
|
-
function resolveCoverageFailure(coverageCapability, coverageErrorReason, autoGenerated, base, gitCapability, complexityCapability, threshold, lineage, complexityCapabilityForQuality, complexityQuality) {
|
|
669
|
+
function resolveCoverageFailure(coverageCapability, coverageErrorReason, autoGenerated, base, gitCapability, complexityCapability, threshold, lineage, complexityCapabilityForQuality, complexityQuality, excludedGeneratedFiles) {
|
|
667
670
|
let analysisStatus = 'SUCCESS';
|
|
668
671
|
let gate = '';
|
|
669
672
|
let completeness = 'COMPLETE';
|
|
@@ -675,7 +678,7 @@ function resolveCoverageFailure(coverageCapability, coverageErrorReason, autoGen
|
|
|
675
678
|
analysisStatus = 'FAILED';
|
|
676
679
|
completeness = 'INCOMPLETE';
|
|
677
680
|
return {
|
|
678
|
-
earlyReturn: withDiagnostics(buildFailedOutput(base, gitCapability, complexityCapability, 'failed', threshold, coverageErrorReason), lineage, buildQuality({ complexityCapability: complexityCapabilityForQuality, complexityQuality, coverageUsable: false })),
|
|
681
|
+
earlyReturn: withDiagnostics(buildFailedOutput(base, gitCapability, complexityCapability, 'failed', threshold, coverageErrorReason), lineage, buildQuality({ complexityCapability: complexityCapabilityForQuality, complexityQuality, coverageUsable: false }), undefined, undefined, excludedGeneratedFiles),
|
|
679
682
|
coverageCapability: 'failed', coverageErrorReason, analysisStatus, gate, completeness
|
|
680
683
|
};
|
|
681
684
|
}
|
|
@@ -687,7 +690,7 @@ function resolveCoverageFailure(coverageCapability, coverageErrorReason, autoGen
|
|
|
687
690
|
* Returns either the attributed complexity or an early-return output on failure.
|
|
688
691
|
* ponytail: extracted from buildEvidenceOutput to reduce cyclomatic complexity.
|
|
689
692
|
*/
|
|
690
|
-
async function attachCoverageWithTracking(complexityInfo, coverageResult, trace, lineage, base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason, cwd) {
|
|
693
|
+
async function attachCoverageWithTracking(complexityInfo, coverageResult, trace, lineage, base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason, cwd, excludedGeneratedFiles) {
|
|
691
694
|
const t0 = Date.now();
|
|
692
695
|
try {
|
|
693
696
|
const attributedComplexity = await attachCoverage(complexityInfo, coverageResult, cwd);
|
|
@@ -708,7 +711,7 @@ async function attachCoverageWithTracking(complexityInfo, coverageResult, trace,
|
|
|
708
711
|
trace.recordStage('attribution', Date.now() - t0, 'error');
|
|
709
712
|
return {
|
|
710
713
|
attributedComplexity: [],
|
|
711
|
-
earlyReturn: withDiagnostics(buildFailedOutput(base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason), lineage, buildQuality({ complexityCapability, complexityQuality: measurementQuality(complexityInfo), coverageUsable: !coverageResult.error && coverageResult.available === true }))
|
|
714
|
+
earlyReturn: withDiagnostics(buildFailedOutput(base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason), lineage, buildQuality({ complexityCapability, complexityQuality: measurementQuality(complexityInfo), coverageUsable: !coverageResult.error && coverageResult.available === true }), undefined, undefined, excludedGeneratedFiles)
|
|
712
715
|
};
|
|
713
716
|
}
|
|
714
717
|
}
|
|
@@ -739,14 +742,29 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
|
|
|
739
742
|
});
|
|
740
743
|
// Step 1: Collect complexity
|
|
741
744
|
const detectedExtension = detectExtension(intervals);
|
|
742
|
-
|
|
745
|
+
// Seam A (plan task 3): exclude generated/minified/bundled files BEFORE any
|
|
746
|
+
// complexity collection; exclusions surface via diagnostics.excludedGeneratedFiles.
|
|
747
|
+
// Config first (plan task 4): the loaded config's generatedIgnorePatterns force
|
|
748
|
+
// re-includes, so the same config that selects providers must drive the filter.
|
|
749
|
+
if (_providerRegistry === null) {
|
|
750
|
+
initProviderConfig();
|
|
751
|
+
}
|
|
752
|
+
const { filtered, excluded } = filterDiffedFiles(intervals, {
|
|
753
|
+
generatedIgnorePatterns: _providerConfig?.generatedIgnorePatterns,
|
|
754
|
+
});
|
|
755
|
+
if (intervals.size > 0 && filtered.size === 0) {
|
|
756
|
+
// Fix unit 8 (M1): a test-only exclusion is reported honestly as
|
|
757
|
+
// 'test-files-excluded', never as the generated-bucket 'all-files-generated'.
|
|
758
|
+
const gateReason = excluded.length > 0 && excluded.every((entry) => entry.reason === 'test file')
|
|
759
|
+
? 'test-files-excluded'
|
|
760
|
+
: 'all-files-generated';
|
|
761
|
+
return emptyIntervalsReturn(base, threshold, detectedExtension, cwd, coverageFile, trace, autoGenerated, gitCapability, lineage, gateReason, excluded);
|
|
762
|
+
}
|
|
763
|
+
const changedFiles = new Set(filtered.keys());
|
|
743
764
|
const t0Complexity = Date.now();
|
|
744
765
|
let complexityInfo;
|
|
745
766
|
let complexityCapability = 'available';
|
|
746
767
|
try {
|
|
747
|
-
if (_providerRegistry === null) {
|
|
748
|
-
initProviderConfig();
|
|
749
|
-
}
|
|
750
768
|
const provider = getProvider(detectedExtension);
|
|
751
769
|
if (provider) {
|
|
752
770
|
complexityInfo = await provider.collectComplexity(cwd, trace, changedFiles);
|
|
@@ -814,7 +832,7 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
|
|
|
814
832
|
gate: 'NOT_EVALUATED',
|
|
815
833
|
completeness: 'INCOMPLETE',
|
|
816
834
|
gateReason: 'no-supported-file-extensions'
|
|
817
|
-
}, lineage, buildQuality({ complexityCapability, complexityQuality: measurementQuality(complexityInfo), coverageUsable: false }));
|
|
835
|
+
}, lineage, buildQuality({ complexityCapability, complexityQuality: measurementQuality(complexityInfo), coverageUsable: false }), undefined, undefined, excluded);
|
|
818
836
|
}
|
|
819
837
|
// Step 2: Read coverage
|
|
820
838
|
const t0Coverage = Date.now();
|
|
@@ -851,18 +869,18 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
|
|
|
851
869
|
gate: 'NOT_EVALUATED',
|
|
852
870
|
completeness: 'NOT_APPLICABLE',
|
|
853
871
|
gateReason: 'complexity-analysis-failed'
|
|
854
|
-
}, lineage, buildQuality({ complexityCapability, complexityQuality: measurementQuality(complexityInfo), coverageUsable: false }));
|
|
872
|
+
}, lineage, buildQuality({ complexityCapability, complexityQuality: measurementQuality(complexityInfo), coverageUsable: false }), undefined, undefined, excluded);
|
|
855
873
|
return earlyReturn;
|
|
856
874
|
}
|
|
857
875
|
// If coverage provider failed (malformed)
|
|
858
|
-
const covRes = resolveCoverageFailure(coverageCapability, coverageErrorReason, autoGenerated, base, gitCapability, complexityCapability, threshold, lineage, complexityCapability, measurementQuality(complexityInfo));
|
|
876
|
+
const covRes = resolveCoverageFailure(coverageCapability, coverageErrorReason, autoGenerated, base, gitCapability, complexityCapability, threshold, lineage, complexityCapability, measurementQuality(complexityInfo), excluded);
|
|
859
877
|
if (covRes.earlyReturn)
|
|
860
878
|
return covRes.earlyReturn;
|
|
861
879
|
coverageCapability = covRes.coverageCapability;
|
|
862
880
|
coverageErrorReason = covRes.coverageErrorReason;
|
|
863
881
|
const analysisStatus = covRes.analysisStatus;
|
|
864
882
|
// Step 3: Attach coverage to complexity info
|
|
865
|
-
const attrResult = await attachCoverageWithTracking(complexityInfo, coverageResult, trace, lineage, base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason, cwd);
|
|
883
|
+
const attrResult = await attachCoverageWithTracking(complexityInfo, coverageResult, trace, lineage, base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason, cwd, excluded);
|
|
866
884
|
if (attrResult.earlyReturn)
|
|
867
885
|
return attrResult.earlyReturn;
|
|
868
886
|
const attributedComplexity = attrResult.attributedComplexity;
|
|
@@ -947,7 +965,7 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
|
|
|
947
965
|
attributionComplete: true,
|
|
948
966
|
rulesComplete: true,
|
|
949
967
|
changedFunctions: changedFunctionsWithLanguage
|
|
950
|
-
}), buildFingerprints(changedFunctionsWithLanguage), functionCoverageDiag);
|
|
968
|
+
}), buildFingerprints(changedFunctionsWithLanguage), functionCoverageDiag, excluded);
|
|
951
969
|
}
|
|
952
970
|
// Helper function to build output when there is a provider failure
|
|
953
971
|
function buildFailedOutput(base, gitCapability, complexityCapability, coverageCapability, threshold, coverageErrorReason) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface GeneratedFilterConfig {
|
|
2
|
+
/** Re-include patterns: force a generated-looking file back into analysis. */
|
|
3
|
+
generatedIgnorePatterns?: string[] | undefined;
|
|
4
|
+
}
|
|
5
|
+
export interface ExcludedGeneratedFile {
|
|
6
|
+
file: string;
|
|
7
|
+
reason: string;
|
|
8
|
+
}
|
|
9
|
+
export interface DiffInterval {
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
}
|
|
13
|
+
export declare function isGenerated(filePath: string, config?: GeneratedFilterConfig): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Partitions diffed intervals into analyzable files vs generated exclusions.
|
|
16
|
+
* Input map is never mutated; key order of kept files is preserved.
|
|
17
|
+
*/
|
|
18
|
+
export declare function filterDiffedFiles(intervals: Map<string, DiffInterval[]>, config?: GeneratedFilterConfig): {
|
|
19
|
+
filtered: Map<string, DiffInterval[]>;
|
|
20
|
+
excluded: ExcludedGeneratedFile[];
|
|
21
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated-file policy module (plan task 3).
|
|
3
|
+
*
|
|
4
|
+
* Single policy seam: `isGenerated()` decides whether a changed file is
|
|
5
|
+
* machine-generated / minified / bundled and therefore excluded from CRAP
|
|
6
|
+
* analysis. Core heuristics are delegated to crap-typescript-core
|
|
7
|
+
* `isAnalyzableFile()`; thin additions cover what the core's SYNC API lacks
|
|
8
|
+
* (task-2 empirical finding: core scans @generated markers / *.generated globs
|
|
9
|
+
* only in the async filterSourceFiles, never in isAnalyzableFile).
|
|
10
|
+
*
|
|
11
|
+
* Config escape hatch: `generatedIgnorePatterns` force re-includes a file
|
|
12
|
+
* (Q4 safety valve). Patterns are matched as normalized path substrings.
|
|
13
|
+
*/
|
|
14
|
+
import * as fs from 'node:fs';
|
|
15
|
+
import { isAnalyzableFile } from '@barney-media/crap-typescript-core';
|
|
16
|
+
// Same analyzable-extension set as core ANALYZABLE_EXTENSIONS
|
|
17
|
+
// (crap-typescript-core/dist/fileSelection.js:5). Guard keeps non-code diffs
|
|
18
|
+
// (e.g. README.md) out of the generated bucket: they are already unsupported.
|
|
19
|
+
const CODE_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs'];
|
|
20
|
+
// Fix unit 8: test files are excluded under their OWN reason ('test file'),
|
|
21
|
+
// never the core-segment fallthrough label.
|
|
22
|
+
const TEST_FILE_MARKERS = ['.test.', '.spec.'];
|
|
23
|
+
// Mirror of core DEFAULT_GENERATED_MARKERS (sourceExclusions.js:19-27), applied
|
|
24
|
+
// synchronously because isAnalyzableFile() does not scan file headers.
|
|
25
|
+
const GENERATED_MARKERS = [
|
|
26
|
+
'@generated',
|
|
27
|
+
'@auto-generated',
|
|
28
|
+
'AUTO-GENERATED',
|
|
29
|
+
'This file was generated',
|
|
30
|
+
'Do not edit',
|
|
31
|
+
'DO NOT EDIT',
|
|
32
|
+
];
|
|
33
|
+
const HEADER_BYTES = 8192;
|
|
34
|
+
function normalized(filePath) {
|
|
35
|
+
return filePath.split('\\').join('/');
|
|
36
|
+
}
|
|
37
|
+
function hasCodeExtension(filePath) {
|
|
38
|
+
const lower = normalized(filePath).toLowerCase();
|
|
39
|
+
return CODE_EXTENSIONS.some((ext) => lower.endsWith(ext));
|
|
40
|
+
}
|
|
41
|
+
function isReIncluded(filePath, config) {
|
|
42
|
+
const rel = normalized(filePath);
|
|
43
|
+
return (config?.generatedIgnorePatterns ?? []).some((pattern) => rel.includes(normalized(pattern)));
|
|
44
|
+
}
|
|
45
|
+
function hasTestFileMarker(filePath) {
|
|
46
|
+
const base = normalized(filePath).split('/').pop() ?? '';
|
|
47
|
+
return TEST_FILE_MARKERS.some((marker) => base.includes(marker));
|
|
48
|
+
}
|
|
49
|
+
function hasSourceMapExtension(filePath) {
|
|
50
|
+
return normalized(filePath).toLowerCase().endsWith('.map');
|
|
51
|
+
}
|
|
52
|
+
function hasMinJsSuffix(filePath) {
|
|
53
|
+
return normalized(filePath).toLowerCase().endsWith('.min.js');
|
|
54
|
+
}
|
|
55
|
+
function hasSourceMapSidecar(filePath) {
|
|
56
|
+
return fs.existsSync(`${filePath}.map`);
|
|
57
|
+
}
|
|
58
|
+
/** First 8KB only: minified bundles are huge, never read whole file. */
|
|
59
|
+
function hasGeneratedHeader(filePath) {
|
|
60
|
+
try {
|
|
61
|
+
const fd = fs.openSync(filePath, 'r');
|
|
62
|
+
try {
|
|
63
|
+
const buffer = Buffer.alloc(HEADER_BYTES);
|
|
64
|
+
const bytesRead = fs.readSync(fd, buffer, 0, HEADER_BYTES, 0);
|
|
65
|
+
const header = buffer.subarray(0, bytesRead).toString('utf8');
|
|
66
|
+
return GENERATED_MARKERS.some((marker) => header.includes(marker));
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
fs.closeSync(fd);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Returns the exclusion reason, or null when the file should be analyzed. */
|
|
77
|
+
function classify(filePath, config) {
|
|
78
|
+
if (isReIncluded(filePath, config))
|
|
79
|
+
return null;
|
|
80
|
+
// Fix unit 8: raw *.js.map diffed files are source maps themselves -> generated,
|
|
81
|
+
// before the code-extension guard would drop them into the unsupported bucket.
|
|
82
|
+
if (hasSourceMapExtension(filePath))
|
|
83
|
+
return 'source map file (.map)';
|
|
84
|
+
if (!hasCodeExtension(filePath))
|
|
85
|
+
return null;
|
|
86
|
+
// Fix unit 8: own classification reason for test files (M1).
|
|
87
|
+
if (hasTestFileMarker(filePath))
|
|
88
|
+
return 'test file';
|
|
89
|
+
if (hasMinJsSuffix(filePath))
|
|
90
|
+
return 'minified filename (.min.js)';
|
|
91
|
+
if (hasSourceMapSidecar(filePath))
|
|
92
|
+
return 'source map sidecar (.js.map)';
|
|
93
|
+
if (hasGeneratedHeader(filePath))
|
|
94
|
+
return 'generated header marker';
|
|
95
|
+
// Core owns the excluded-path-segment list (/dist/, /node_modules/, ...).
|
|
96
|
+
if (!isAnalyzableFile(filePath))
|
|
97
|
+
return 'excluded path segment (core isAnalyzableFile)';
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
export function isGenerated(filePath, config) {
|
|
101
|
+
return classify(filePath, config) !== null;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Partitions diffed intervals into analyzable files vs generated exclusions.
|
|
105
|
+
* Input map is never mutated; key order of kept files is preserved.
|
|
106
|
+
*/
|
|
107
|
+
export function filterDiffedFiles(intervals, config) {
|
|
108
|
+
const filtered = new Map();
|
|
109
|
+
const excluded = [];
|
|
110
|
+
for (const [file, value] of intervals) {
|
|
111
|
+
const reason = classify(file, config);
|
|
112
|
+
if (reason !== null) {
|
|
113
|
+
excluded.push({ file, reason });
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
filtered.set(file, value);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { filtered, excluded };
|
|
120
|
+
}
|
|
@@ -21,6 +21,8 @@ export interface ProviderEntry {
|
|
|
21
21
|
export interface ProviderConfig {
|
|
22
22
|
version: number;
|
|
23
23
|
providers: ProviderEntry[];
|
|
24
|
+
/** Re-include patterns for the generated-file filter (default []). */
|
|
25
|
+
generatedIgnorePatterns?: string[];
|
|
24
26
|
}
|
|
25
27
|
export interface ResolvedProvider {
|
|
26
28
|
language: string;
|
package/dist/providers/config.js
CHANGED
|
@@ -64,6 +64,7 @@ const DOTNET_RUNNER = {
|
|
|
64
64
|
export function builtinConfig() {
|
|
65
65
|
return {
|
|
66
66
|
version: 1,
|
|
67
|
+
generatedIgnorePatterns: [],
|
|
67
68
|
providers: [
|
|
68
69
|
{
|
|
69
70
|
language: 'javascript',
|
|
@@ -153,13 +154,24 @@ function rejectCoverageCmd(entry, i) {
|
|
|
153
154
|
throw new Error(`config: providers[${i}].coverageCmd not supported (never executed); remove the key`);
|
|
154
155
|
}
|
|
155
156
|
}
|
|
157
|
+
// BEHAVIOR CHANGE (plan task 4, guardrail C1): version 2 accepted alongside 1;
|
|
158
|
+
// absent version is treated as 1. v2 exists to carry `generatedIgnorePatterns`
|
|
159
|
+
// (Q4 re-include escape hatch). Existing v1 configs load unchanged.
|
|
156
160
|
function validateConfig(raw) {
|
|
157
161
|
if (!isRecord(raw))
|
|
158
162
|
throw new Error('config: not an object');
|
|
159
|
-
|
|
163
|
+
const version = raw.version === undefined ? 1 : raw.version;
|
|
164
|
+
if (version !== 1 && version !== 2)
|
|
160
165
|
throw new Error(`config: unsupported version ${String(raw.version)}`);
|
|
161
166
|
if (!Array.isArray(raw.providers))
|
|
162
167
|
throw new Error('config: missing providers array');
|
|
168
|
+
let generatedIgnorePatterns;
|
|
169
|
+
if (raw.generatedIgnorePatterns !== undefined) {
|
|
170
|
+
if (!Array.isArray(raw.generatedIgnorePatterns) || raw.generatedIgnorePatterns.some((p) => typeof p !== 'string')) {
|
|
171
|
+
throw new Error('config: generatedIgnorePatterns must be an array of strings');
|
|
172
|
+
}
|
|
173
|
+
generatedIgnorePatterns = raw.generatedIgnorePatterns;
|
|
174
|
+
}
|
|
163
175
|
for (const [i, entry] of raw.providers.entries()) {
|
|
164
176
|
if (!isRecord(entry))
|
|
165
177
|
throw new Error(`config: providers[${i}] not an object`);
|
|
@@ -176,7 +188,8 @@ function validateConfig(raw) {
|
|
|
176
188
|
}
|
|
177
189
|
}
|
|
178
190
|
}
|
|
179
|
-
|
|
191
|
+
// Defaults merged so consumers never see undefined (spec §4).
|
|
192
|
+
return { ...raw, version, generatedIgnorePatterns: generatedIgnorePatterns ?? [] };
|
|
180
193
|
}
|
|
181
194
|
const REPO_ROOT_NAMES = [
|
|
182
195
|
'checkchange.providers.json',
|
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.7' };
|
|
3
3
|
/**
|
|
4
4
|
* Evaluate changed functions against the high-CRAP rule.
|
|
5
5
|
* @param changed Array of changed functions
|