checkchange 0.4.4 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -251,6 +251,10 @@ Some of the most useful options are:
251
251
  | `--verbose` | Show additional diagnostics | off |
252
252
  | `--auto-coverage` | Attempt automatic coverage setup | off |
253
253
 
254
+ Flags are per-command: `checkchange check --help` lists `--format`, `--base`,
255
+ `--json`; every subcommand lists its own flags. Unknown flags are rejected
256
+ with `Error: Unknown option <arg>` (exit 1) rather than silently ignored.
257
+
254
258
  The base reference is automatically detected when `--base` is not supplied.
255
259
 
256
260
  Provider configuration can be supplied explicitly or discovered from the repository.
@@ -364,6 +368,32 @@ coverageArtifact: present
364
368
 
365
369
  ---
366
370
 
371
+ # Gate contract
372
+
373
+ The `gate` field of the evidence output is never null (as of 0.5.0). It is one
374
+ of four values:
375
+
376
+ | `gate` | Meaning |
377
+ |---|---|
378
+ | `PASS` | No rule violations and coverage sufficient. |
379
+ | `WARN` | At least one rule violated (e.g. CRAP above threshold). |
380
+ | `NOT_EVALUATED` | Nothing to evaluate (unsupported source, empty intervals, absent coverage). |
381
+ | `FAILED` | Analysis could not complete (coverage missing/malformed, complexity failed). |
382
+
383
+ `gateReason` (optional) explains why a non-PASS gate was emitted, e.g.
384
+ `no-supported-file-extensions`, `complexity-analysis-failed`, or the coverage
385
+ error reason (`missing` / `malformed` / `failed`).
386
+
387
+ Exit codes:
388
+
389
+ | Condition | Exit code |
390
+ |---|---|
391
+ | `FAILED` analysisStatus or `gate === 'FAILED'` | 1 |
392
+ | `gate === 'WARN'` | 1 |
393
+ | `PASS` / `NOT_EVALUATED` | 0 |
394
+
395
+ ---
396
+
367
397
  # Why the evidence matters
368
398
 
369
399
  One of the design goals of CheckChange is to distinguish **"we measured it"** from **"we don't have enough evidence."**
@@ -437,6 +467,28 @@ This makes it possible to use the same evidence both for human-facing developmen
437
467
 
438
468
  ---
439
469
 
470
+ # Delta input paths
471
+
472
+ `checkchange delta --baseline <path> --current <path>` reads both evidence
473
+ artifacts through a fail-closed containment seam (`src/fs-safety.ts`): the
474
+ resolved (realpath-expanded) file must be inside the current working
475
+ directory. Absolute paths outside the cwd — and symlink targets that escape
476
+ it — are rejected with `delta: input path escapes cwd: <path>` and exit 1.
477
+
478
+ Run `delta` from the directory that contains the artifacts, or pass paths
479
+ relative to it:
480
+
481
+ ```bash
482
+ checkchange delta --baseline evidence-a.json --current evidence-b.json --json
483
+ ```
484
+
485
+ Note the deliberate asymmetry: an explicit `check --coverage-file <path>`
486
+ *is* allowed outside the cwd (user-provided artifacts are trusted), while
487
+ delta inputs are not. Auto-detected coverage files use the same containment
488
+ seam as delta.
489
+
490
+ ---
491
+
440
492
  # Dependencies and external tools
441
493
 
442
494
  CheckChange uses a small number of external packages and tools for its analysis.
package/dist/cli.d.ts CHANGED
@@ -15,7 +15,7 @@ export interface CheckArgs {
15
15
  export declare function parseCliArgs(argv?: string[]): CheckArgs;
16
16
  interface EvidenceOutputShape {
17
17
  analysisStatus: string;
18
- gate: string | null;
18
+ gate: 'PASS' | 'WARN' | 'NOT_EVALUATED' | 'FAILED';
19
19
  completeness: string;
20
20
  changedFunctions: Array<Record<string, unknown>>;
21
21
  ruleResults: Array<{
package/dist/cli.js CHANGED
@@ -42,8 +42,9 @@ function splitValue(argv, i, name) {
42
42
  // value slot is mistaken for the flag (`check --base --version` printed the
43
43
  // version instead of resolving `--version` as the base ref). Skip value slots.
44
44
  // Mirrors how each subcommand consumes them: --base is exact-match next-slot in
45
- // parseCliArgs, --baseline/--current are exact-match next-slot in runDelta; the
46
- // other four match by prefix and take `--flag=value` (no slot) or the next slot.
45
+ // parseCliArgs (check); --baseline/--current are exact-match next-slot in
46
+ // runDelta; doctor/explain/trace take --provider-config/--crap-threshold/
47
+ // --coverage-file/--format and explain/trace also --base as inline-or-next.
47
48
  const VALUE_FLAGS_NEXT_SLOT_ONLY = new Set([
48
49
  '--base',
49
50
  '--baseline',
@@ -55,6 +56,8 @@ const VALUE_FLAGS_INLINE_OR_NEXT = [
55
56
  '--coverage-file',
56
57
  '--format',
57
58
  ];
59
+ // Allowed value flags for the two commands that share a flag set (explain/trace).
60
+ const EXPLAIN_TRACE_VALUE_FLAGS = ['--base', '--crap-threshold', '--coverage-file'];
58
61
  // One pass, two questions: the duplication was the loop, not the data.
59
62
  // A1 asks "was --version passed as a flag?"; A2 asks "is there a positional
60
63
  // argument at all?" — the dispatcher resolves any argv whose first token is
@@ -84,6 +87,28 @@ function scanArgv(args) {
84
87
  }
85
88
  return { hasVersion, hasPositional };
86
89
  }
90
+ // A3: doctor/explain/trace used to accept any stray flag silently (argv.includes
91
+ // never rejected), so `doctor --format sarif` ran as if --format were
92
+ // absent. delta/prepare-repo already reject; this makes the other three agree.
93
+ // Value slots are skipped by the loop below (same convention as scanArgv); a
94
+ // bare value flag like `--base --json` is not "Unknown option" here — the
95
+ // value parser (flagValueInlineOrNext) reports `requires a value` instead.
96
+ function assertKnownFlags(argv, allowedValueFlags, allowedBooleans) {
97
+ for (let i = 0; i < argv.length; i += 1) {
98
+ const arg = argv[i];
99
+ if (!arg.startsWith('-'))
100
+ continue; // value slot or ruleId positional
101
+ const inline = arg.includes('=');
102
+ const name = inline ? arg.slice(0, arg.indexOf('=')) : arg;
103
+ if (allowedValueFlags.includes(name)) {
104
+ if (!inline)
105
+ i += 1;
106
+ }
107
+ else if (!allowedBooleans.includes(arg)) {
108
+ throw new Error(`Unknown option ${arg}`);
109
+ }
110
+ }
111
+ }
87
112
  function parseCrapThreshold(value) {
88
113
  const parsed = parseFloat(value);
89
114
  if (!isFinite(parsed) || parsed < 0) {
@@ -242,7 +267,7 @@ export function formatOutput(output, opts, resolvedBase, cacheEnabled) {
242
267
  }
243
268
  else {
244
269
  // For WP1, we primarily want JSON, but let's output a simple summary if not JSON
245
- console.log(`Analysis complete. Base: ${resolvedBase}, Changed functions: ${output.changedFunctions.length}`);
270
+ console.log(`Analysis complete. Base: ${resolvedBase}, Changed functions: ${output.changedFunctions.length}, Gate: ${output.gate}`);
246
271
  // H2: a FALLBACK complexity stage is otherwise invisible in the text path —
247
272
  // the run reports PASS/NOT_EVALUATED over approximate measurements. Warn on
248
273
  // stderr (stdout stays the machine-readable summary); nothing is printed when
@@ -269,9 +294,8 @@ export function formatOutput(output, opts, resolvedBase, cacheEnabled) {
269
294
  exitCode = 1;
270
295
  }
271
296
  else if (output.analysisStatus === 'UNSUPPORTED') {
272
- // null gate = nothing to evaluate (all-unsupported or NOT_APPLICABLE) → exit 0
273
- // NOT_EVALUATED gate = no-supported-files / empty intervals → exit 0
274
- if (output.gate !== null && output.gate !== 'NOT_EVALUATED') {
297
+ // NOT_EVALUATED / PASS → exit 0; WARN → exit 1. (gate is never null post-0.5.0)
298
+ if (output.gate === 'WARN') {
275
299
  exitCode = 1;
276
300
  }
277
301
  }
@@ -341,10 +365,11 @@ const DOTNET_COVERAGE_HINT = ' or `dotnet test --collect:"XPlat Code Coverage"`
341
365
  * no analysis engine duplication.
342
366
  */
343
367
  async function runDoctor(argv) {
368
+ assertKnownFlags(argv, ['--provider-config'], ['--json', '--allow-external-config']);
344
369
  const json = argv.includes('--json');
345
- // Parse --provider-config from argv for doctor
346
- const pcIdx = argv.indexOf('--provider-config');
347
- const providerConfigPath = pcIdx !== -1 ? argv[pcIdx + 1] : undefined;
370
+ // --provider-config is inline-or-next; a bare flag now errors instead of
371
+ // silently treating the following token (e.g. --json) as a path.
372
+ const providerConfigPath = flagValueInlineOrNext(argv, '--provider-config');
348
373
  const allowExternalConfig = argv.includes('--allow-external-config');
349
374
  const { registry, source: providerSource } = initProviderConfig(providerConfigPath, allowExternalConfig);
350
375
  SUPPORTED_EXTENSIONS = new Set(registry.keys());
@@ -443,15 +468,54 @@ async function runDoctor(argv) {
443
468
  }
444
469
  }
445
470
  /**
446
- * Reads the value of a space-separated CLI flag, if present.
447
- * ponytail: shared by explain; check uses parseCliArgs (full validation).
471
+ * Reads a value-taking flag in either `--flag=value` or `--flag value` form.
472
+ * Absent flag → undefined. Present without a value (missing next slot, or the
473
+ * next slot is another flag) → throws; main maps it to `Error: ...` + exit 1.
448
474
  */
449
- function flagValue(argv, name) {
450
- const index = argv.indexOf(name);
475
+ function flagValueInlineOrNext(argv, name) {
476
+ const inlinePrefix = `${name}=`;
477
+ const index = argv.findIndex((arg) => arg === name || arg.startsWith(inlinePrefix));
451
478
  if (index === -1)
452
479
  return undefined;
480
+ const arg = argv[index];
481
+ if (arg.startsWith(inlinePrefix)) {
482
+ // `--base=` is an empty value, same as a bare flag: reject rather than
483
+ // silently default (parseCliArgs rejects empty --coverage-file the same way).
484
+ const value = arg.slice(inlinePrefix.length);
485
+ if (value === '') {
486
+ throw new Error(`${name} requires a value`);
487
+ }
488
+ return value;
489
+ }
453
490
  const value = argv[index + 1];
454
- return value === undefined || value.startsWith('-') ? undefined : value;
491
+ if (value === undefined || value.startsWith('-')) {
492
+ throw new Error(`${name} requires a value`);
493
+ }
494
+ return value;
495
+ }
496
+ /**
497
+ * Provider source for the complexity measurement: the engine-reported quality
498
+ * wins; otherwise infer it from the complexity stage capability.
499
+ */
500
+ function deriveComplexity(output) {
501
+ return (output.diagnostics?.quality?.complexity ??
502
+ (output.capabilities?.complexity === 'failed' ? 'UNAVAILABLE' : 'NATIVE'));
503
+ }
504
+ /**
505
+ * Coverage quality: the engine-reported value wins; otherwise DIRECT only when
506
+ * the coverage artifact was actually available.
507
+ */
508
+ function deriveCoverageQuality(output) {
509
+ return (output.diagnostics?.quality?.coverage ??
510
+ (output.capabilities?.coverageArtifact === 'available' ? 'DIRECT' : 'UNAVAILABLE'));
511
+ }
512
+ /** Reason the score fell back to null, from the run's status and coverage quality. */
513
+ function deriveFallback(analysisStatus, coverageQuality) {
514
+ if (analysisStatus === 'UNSUPPORTED')
515
+ return 'analysis skipped — unsupported source';
516
+ if (coverageQuality === 'DIRECT')
517
+ return 'none — coverage direct evidence used';
518
+ return 'coverage direct evidence absent — score null (INV-01: null, not 0%)';
455
519
  }
456
520
  /**
457
521
  * `explain` subcommand: prints provider/input/threshold/fallback derivation for
@@ -459,12 +523,13 @@ function flagValue(argv, name) {
459
523
  * derivation logic. Optional ruleId positional filters rule results.
460
524
  */
461
525
  async function runExplain(argv) {
526
+ assertKnownFlags(argv, EXPLAIN_TRACE_VALUE_FLAGS, ['--json']);
462
527
  const json = argv.includes('--json');
463
528
  const ruleId = argv.find((a) => !a.startsWith('-'));
464
- const rawThreshold = flagValue(argv, '--crap-threshold');
465
- const threshold = rawThreshold !== undefined ? parseFloat(rawThreshold) : 30;
466
- const baseArg = flagValue(argv, '--base');
467
- const coverageFile = flagValue(argv, '--coverage-file');
529
+ const rawThreshold = flagValueInlineOrNext(argv, '--crap-threshold');
530
+ const threshold = rawThreshold === undefined ? 30 : parseCrapThreshold(rawThreshold);
531
+ const baseArg = flagValueInlineOrNext(argv, '--base');
532
+ const coverageFile = flagValueInlineOrNext(argv, '--coverage-file');
468
533
  const base = baseArg ?? (await detectDefaultBase(false));
469
534
  if (base === null) {
470
535
  throw new Error('Cannot auto-detect base branch. Provide --base <ref> explicitly.');
@@ -473,15 +538,9 @@ async function runExplain(argv) {
473
538
  const resolvedBase = await resolveBaseRef(base);
474
539
  const { intervals } = await getChangedIntervals(resolvedBase);
475
540
  const output = await buildEvidenceOutput(resolvedBase, intervals, process.cwd(), threshold, coverageFile);
476
- const complexity = output.diagnostics?.quality?.complexity ??
477
- (output.capabilities?.complexity === 'failed' ? 'UNAVAILABLE' : 'NATIVE');
478
- const coverageQuality = output.diagnostics?.quality?.coverage ??
479
- (output.capabilities?.coverageArtifact === 'available' ? 'DIRECT' : 'UNAVAILABLE');
480
- const fallback = output.analysisStatus === 'UNSUPPORTED'
481
- ? 'analysis skipped — unsupported source'
482
- : coverageQuality === 'DIRECT'
483
- ? 'none — coverage direct evidence used'
484
- : 'coverage direct evidence absent — score null (INV-01: null, not 0%)';
541
+ const complexity = deriveComplexity(output);
542
+ const coverageQuality = deriveCoverageQuality(output);
543
+ const fallback = deriveFallback(output.analysisStatus, coverageQuality);
485
544
  const ruleResults = ruleId === undefined
486
545
  ? output.ruleResults
487
546
  : output.ruleResults.filter((r) => r.ruleId === ruleId);
@@ -519,11 +578,12 @@ async function runExplain(argv) {
519
578
  * (evidence-contract.md:341) carries no timing, so `check --json` is unchanged.
520
579
  */
521
580
  async function runTrace(argv) {
581
+ assertKnownFlags(argv, EXPLAIN_TRACE_VALUE_FLAGS, ['--json']);
522
582
  const json = argv.includes('--json');
523
- const rawThreshold = flagValue(argv, '--crap-threshold');
524
- const threshold = rawThreshold !== undefined ? parseFloat(rawThreshold) : 30;
525
- const baseArg = flagValue(argv, '--base');
526
- const coverageFile = flagValue(argv, '--coverage-file');
583
+ const rawThreshold = flagValueInlineOrNext(argv, '--crap-threshold');
584
+ const threshold = rawThreshold === undefined ? 30 : parseCrapThreshold(rawThreshold);
585
+ const baseArg = flagValueInlineOrNext(argv, '--base');
586
+ const coverageFile = flagValueInlineOrNext(argv, '--coverage-file');
527
587
  const base = baseArg ?? (await detectDefaultBase(false));
528
588
  if (base === null) {
529
589
  throw new Error('Cannot auto-detect base branch. Provide --base <ref> explicitly.');
@@ -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.4.4
177
+ // its tool is checkchange and its version is the package version — same 0.5.1
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.4.4';
180
+ const FALLBACK_TOOL_VERSION = '0.5.1';
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,5 +1,5 @@
1
1
  export declare const crapCalcProvenance: {
2
2
  readonly tool: "checkchange";
3
- readonly version: "0.4.4";
3
+ readonly version: "0.5.1";
4
4
  };
5
5
  export declare function calculateCrap(cc: number, coveragePercent: number | null): number | null;
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.0' style for the core package).
3
- export const crapCalcProvenance = { tool: 'checkchange', version: '0.4.4' };
2
+ // (matches existing hard-coded '0.5.1' style for the core package).
3
+ export const crapCalcProvenance = { tool: 'checkchange', version: '0.5.1' };
4
4
  export function calculateCrap(cc, coveragePercent) {
5
5
  if (coveragePercent == null) {
6
6
  return null;
package/dist/delta.d.ts CHANGED
@@ -19,7 +19,7 @@ export interface EvidenceOutput {
19
19
  };
20
20
  ruleResults: RuleResult[];
21
21
  analysisStatus: string;
22
- gate: string | null;
22
+ gate: 'PASS' | 'WARN' | 'NOT_EVALUATED' | 'FAILED';
23
23
  completeness: string;
24
24
  coverageErrorReason?: string;
25
25
  diagnostics?: {
@@ -35,13 +35,13 @@ export interface DeltaOutput {
35
35
  baseline: {
36
36
  base: string;
37
37
  analysisStatus: string;
38
- gate: string | null;
38
+ gate: 'PASS' | 'WARN' | 'NOT_EVALUATED' | 'FAILED';
39
39
  changedFunctions: number;
40
40
  };
41
41
  current: {
42
42
  base: string;
43
43
  analysisStatus: string;
44
- gate: string | null;
44
+ gate: 'PASS' | 'WARN' | 'NOT_EVALUATED' | 'FAILED';
45
45
  changedFunctions: number;
46
46
  };
47
47
  thresholds: {
@@ -31,7 +31,7 @@ export interface DiagnosticLineageEntry {
31
31
  }
32
32
  export declare const evidenceProvenance: {
33
33
  readonly tool: "checkchange";
34
- readonly version: "0.4.4";
34
+ readonly version: "0.5.1";
35
35
  };
36
36
  export interface EvidenceOutput {
37
37
  schemaVersion: string;
@@ -50,9 +50,10 @@ export interface EvidenceOutput {
50
50
  };
51
51
  ruleResults: RuleResult[];
52
52
  analysisStatus: string;
53
- gate: string | null;
53
+ gate: 'PASS' | 'WARN' | 'NOT_EVALUATED' | 'FAILED';
54
54
  completeness: string;
55
55
  coverageErrorReason?: string;
56
+ gateReason?: string;
56
57
  diagnostics?: {
57
58
  lineage: DiagnosticLineageEntry[];
58
59
  quality: DiagnosticQuality;
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.0').
23
- export const evidenceProvenance = { tool: 'checkchange', version: '0.4.4' };
22
+ // Self provenance; version mirrors package.json (existing codebase style hard-codes '0.5.1').
23
+ export const evidenceProvenance = { tool: 'checkchange', version: '0.5.1' };
24
24
  function sha256Hex(content) {
25
25
  return createHash('sha256').update(content).digest('hex');
26
26
  }
@@ -532,6 +532,7 @@ async function emptyIntervalsReturn(base, threshold, detectedExtension, cwd, cov
532
532
  analysisStatus: 'UNSUPPORTED',
533
533
  gate: 'NOT_EVALUATED',
534
534
  completeness: 'INCOMPLETE',
535
+ gateReason: 'no-changed-lines',
535
536
  ...(covEarly.errorReason !== undefined ? { coverageErrorReason: covEarly.errorReason } : {})
536
537
  }, lineage, buildQuality({ complexityCapability: 'unavailable', coverageUsable: false }));
537
538
  }
@@ -634,7 +635,7 @@ export function buildOutput(base, changed, threshold = 30, capabilities = { git:
634
635
  */
635
636
  function resolveCoverageFailure(coverageCapability, coverageErrorReason, autoGenerated, base, gitCapability, complexityCapability, threshold, lineage, complexityCapabilityForQuality, complexityQuality) {
636
637
  let analysisStatus = 'SUCCESS';
637
- let gate = null;
638
+ let gate = '';
638
639
  let completeness = 'COMPLETE';
639
640
  if (coverageCapability === 'failed') {
640
641
  if (autoGenerated) {
@@ -780,8 +781,9 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
780
781
  crapThreshold: threshold
781
782
  },
782
783
  analysisStatus: 'UNSUPPORTED',
783
- gate: null,
784
- completeness: 'INCOMPLETE'
784
+ gate: 'NOT_EVALUATED',
785
+ completeness: 'INCOMPLETE',
786
+ gateReason: 'no-supported-file-extensions'
785
787
  }, lineage, buildQuality({ complexityCapability, complexityQuality: measurementQuality(complexityInfo), coverageUsable: false }));
786
788
  }
787
789
  // Step 2: Read coverage
@@ -816,8 +818,9 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
816
818
  },
817
819
  ruleResults: [],
818
820
  analysisStatus: 'UNSUPPORTED',
819
- gate: null,
820
- completeness: 'NOT_APPLICABLE'
821
+ gate: 'NOT_EVALUATED',
822
+ completeness: 'NOT_APPLICABLE',
823
+ gateReason: 'complexity-analysis-failed'
821
824
  }, lineage, buildQuality({ complexityCapability, complexityQuality: measurementQuality(complexityInfo), coverageUsable: false }));
822
825
  return earlyReturn;
823
826
  }
@@ -850,6 +853,7 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
850
853
  // Step 8: Compute overall gate and completeness
851
854
  let { gate: gateValue, completeness: completenessValue } = computeGateAndCompleteness(ruleResults);
852
855
  // §5 vacuous-PASS ban: coverage absent + needs coverage → NOT_EVALUATED gate.
856
+ const coverageAbsentFlip = coverageCapability === 'absent' && changedFunctions.length > 0;
853
857
  gateValue = applyAbsentCoverageGate(gateValue, coverageCapability, changedFunctions.length);
854
858
  // Step 9: Determine analysisStatus
855
859
  // If we have no relevant TS functions after successful analysis -> SUCCESS
@@ -901,7 +905,8 @@ export async function buildEvidenceOutput(base, intervals, cwd, threshold = 30,
901
905
  ruleResults: ruleResults,
902
906
  analysisStatus: analysisStatus,
903
907
  gate: gateValue,
904
- completeness: completenessValue
908
+ completeness: completenessValue,
909
+ ...(coverageAbsentFlip ? { gateReason: 'coverage-absent' } : {})
905
910
  }, lineage, buildQuality({
906
911
  complexityCapability,
907
912
  complexityQuality: measurementQuality(complexityInfo),
@@ -930,8 +935,9 @@ function buildFailedOutput(base, gitCapability, complexityCapability, coverageCa
930
935
  },
931
936
  ruleResults: [],
932
937
  analysisStatus: 'FAILED',
933
- gate: null,
938
+ gate: 'FAILED',
934
939
  completeness: 'INCOMPLETE',
940
+ gateReason: coverageErrorReason !== undefined ? coverageErrorReason : 'analysis-failed',
935
941
  ...(coverageErrorReason !== undefined ? { coverageErrorReason } : {}),
936
942
  };
937
943
  }
@@ -34,7 +34,7 @@ export interface RuleResultShape {
34
34
  * formatters define their own and CLI passes its cast output in Task 2). */
35
35
  export interface EvidenceOutputShape {
36
36
  analysisStatus: string;
37
- gate: string | null;
37
+ gate: 'PASS' | 'WARN' | 'NOT_EVALUATED' | 'FAILED';
38
38
  completeness: string;
39
39
  schemaVersion: string;
40
40
  changedFunctions: ChangedFunctionShape[];
@@ -18,6 +18,9 @@ export function formatSARIF(out, opts) {
18
18
  message: { text: `${r.method} CRAP ${r.crap} > ${r.threshold} (cc ${r.cc}, cov ${r.coverage})` },
19
19
  }));
20
20
  return JSON.stringify({
21
+ // SARIF 2.1.0 top-level schema key is `$schema`; the schemastore schema
22
+ // has additionalProperties:false, so `schema` would make the doc invalid.
23
+ $schema: 'https://json.schemastore.org/sarif-2.1.0.json',
21
24
  version: '2.1.0',
22
25
  runs: [
23
26
  {
package/dist/git.js CHANGED
@@ -29,6 +29,12 @@ export async function resolveBaseRef(base, cwd = process.cwd(), trace) {
29
29
  throw new Error('Git executable not found');
30
30
  }
31
31
  if (result.exitCode !== 0) {
32
+ // git prints `fatal: not a git repository` when run outside a repo; surface
33
+ // that distinction instead of reporting a ref-resolution failure, which
34
+ // sends users hunting for the wrong base ref.
35
+ if (result.stderr.includes('not a git repository')) {
36
+ throw new Error('Not a git repository — run from a repo root or initialize one with `git init`.');
37
+ }
32
38
  throw new Error(`Cannot resolve base reference: ${base}`);
33
39
  }
34
40
  return result.stdout.trim();
package/dist/help.js CHANGED
@@ -216,7 +216,8 @@ Options:
216
216
  --version Print version and exit
217
217
 
218
218
  Run 'checkchange <command> --help' for command-specific help.
219
- Tip: 'checkchange <command> --help --json' for machine-readable help.`;
219
+ Tip: 'checkchange <command> --help --json' for machine-readable help.
220
+ Flags are per-command: run 'checkchange check --help' to list --format, --base, --json; every subcommand lists its own flags.`;
220
221
  function jsonTip(command) {
221
222
  return `Tip: 'checkchange ${command} --help --json' for machine-readable help.`;
222
223
  }
package/dist/rules.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ChangedFunction } from './evidence.js';
2
2
  export declare const rulesProvenance: {
3
3
  readonly tool: "checkchange";
4
- readonly version: "0.4.4";
4
+ readonly version: "0.5.1";
5
5
  };
6
6
  export interface RuleResult {
7
7
  ruleId: string;
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.4.4' };
2
+ export const rulesProvenance = { tool: 'checkchange', version: '0.5.1' };
3
3
  /**
4
4
  * Evaluate changed functions against the high-CRAP rule.
5
5
  * @param changed Array of changed functions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "checkchange",
3
- "version": "0.4.4",
3
+ "version": "0.5.1",
4
4
  "license": "MIT",
5
5
  "packageManager": "pnpm@11.17.0",
6
6
  "type": "module",