checkchange 0.4.3 → 0.4.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/README.md CHANGED
@@ -109,7 +109,7 @@ Those are evidence states, not judgments about whether the software is ultimatel
109
109
 
110
110
  The package is published on npm as `checkchange`.
111
111
 
112
- Current registry version: **0.4.2**
112
+ Current registry version: **0.4.4**
113
113
 
114
114
  ### npm
115
115
 
@@ -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.2
177
+ // its tool is checkchange and its version is the package version — same 0.4.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.4.2';
180
+ const FALLBACK_TOOL_VERSION = '0.4.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
@@ -51,6 +51,12 @@
51
51
  * - Constructors ARE reported, as functionName === the type name (so
52
52
  * displayName is `Foo.Foo`). Rich-path naming may differ; that difference is
53
53
  * in the pinned delta table.
54
+ * - Primary-constructor TYPE DECLARATIONS (`public record R(int X)`,
55
+ * `public record struct S(int Y)`, `public class C(int Z)`) are containers,
56
+ * not methods: their members are reported normally and no phantom descriptor
57
+ * named after the type is emitted. `isMethodHead` returns null for them, so
58
+ * the head reaches the CONTAINER_RE branch instead of the pushMember branch.
59
+ * `record struct X` captures `X`, not `struct`.
54
60
  * - Malformed source degrades to whatever was recognised before the imbalance; a
55
61
  * file with no recognisable method yields `[]`. Degradation is NON-THROWING
56
62
  * but not faithful, and the deviation is worse than "stopped early": an
@@ -78,7 +84,10 @@ const STATEMENT_KEYWORDS = new Set([
78
84
  'sizeof', 'stackalloc', 'struct', 'switch', 'this', 'throw', 'try', 'typeof', 'unchecked', 'unsafe', 'using',
79
85
  'value', 'var', 'when', 'where', 'while', 'with', 'yield',
80
86
  ]);
81
- const CONTAINER_RE = /\b(?:class|struct|interface|record|enum)\s+([A-Za-z_]\w*)/;
87
+ // The `record (struct|class)` alternative MUST come first: C# `record struct X`
88
+ // is a type declaration named `X`, and the plain `record` alternative would
89
+ // otherwise match first and capture `struct` as the container name.
90
+ const CONTAINER_RE = /\b(?:record\s+(?:struct|class)|class|struct|interface|record|enum)\s+([A-Za-z_]\w*)/;
82
91
  // One pass, ordered alternation. Word-boundary keywords first (so `foreach` is
83
92
  // not also counted as `for`), then the boolean operators, then `??`, then the
84
93
  // ternary.
@@ -302,7 +311,25 @@ function signatureOf(head) {
302
311
  return { name, returnPart: before.slice(0, before.length - name.length).trim(), head: stripped };
303
312
  }
304
313
  function isMethodHead(head, containerName) {
305
- const sig = signatureOf(head);
314
+ // A type DECLARATION head is never a method. Checked FIRST, before any `(` /
315
+ // `returnPart` gate, because the gate that used to catch it read the FIRST
316
+ // token of the head — and on `public record CtorRecord(int X)` that is
317
+ // `public`, which is NOT in STATEMENT_KEYWORDS (record/class/struct ARE, but
318
+ // they are not first). So a primary-constructor type produced a phantom
319
+ // method NAMED AFTER THE TYPE and, worse, the `{` caller then did
320
+ // `i = close + 1` past its whole body, silently dropping every real member
321
+ // inside. Returning null routes the head to the CONTAINER_RE branch instead,
322
+ // where its members are scanned normally.
323
+ //
324
+ // ponytail: reuses CONTAINER_RE rather than a second keyword regex — the
325
+ // guard is exactly "this head is a type declaration AND carries a parameter
326
+ // list", which is the primary-constructor shape. `where T : class` and
327
+ // `where T : class, new()` are constrained METHOD heads and do NOT match
328
+ // (their `class` is followed by `,`/nothing, never by an identifier).
329
+ const strippedHead = stripAttributes(head);
330
+ if (CONTAINER_RE.test(strippedHead) && strippedHead.includes('('))
331
+ return null;
332
+ const sig = signatureOf(strippedHead);
306
333
  if (!sig)
307
334
  return null;
308
335
  // Read the first token from the attribute-stripped head, not the raw one.
package/dist/coverage.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as path from 'node:path';
2
2
  import * as fs from 'node:fs';
3
- import { access, constants, readFile } from 'node:fs/promises';
3
+ import { access, constants, readFile, readdir } from 'node:fs/promises';
4
4
  import { spawnSync } from 'node:child_process';
5
5
  import { createHash } from 'node:crypto';
6
6
  import { parseCoverageReport } from '@barney-media/crap-typescript-core';
@@ -501,9 +501,13 @@ export async function readCoverage(cwd, coverageFile, trace, autoGenerated) {
501
501
  ? [...new Set([...registry.values()].flatMap((r) => r.coverageFiles))]
502
502
  : [...PYTHON_COVERAGE_FILES];
503
503
  for (const file of coverageCandidates) {
504
- const filePath = path.join(cwd, file);
504
+ // WS4: the exact literal is still tried FIRST (precedence unchanged), and only a
505
+ // miss falls through to a case-insensitive lookup in the candidate's own directory.
506
+ // null = miss, skipped exactly as silently as before.
507
+ const filePath = await resolveReadableCandidate(cwd, file);
508
+ if (filePath === null)
509
+ continue;
505
510
  try {
506
- await access(filePath, constants.R_OK);
507
511
  artifactFound = true;
508
512
  const result = await readCoverageFile(filePath, cwd, false);
509
513
  // Conversion/read succeeded — ACCUMULATE, never return early
@@ -527,7 +531,8 @@ export async function readCoverage(cwd, coverageFile, trace, autoGenerated) {
527
531
  // Continue to next file in precedence
528
532
  }
529
533
  catch {
530
- // File doesn't exist or not readable, continue to next
534
+ // Read/conversion threw (it normally returns a result object instead) — continue
535
+ // to the next candidate, same as before.
531
536
  }
532
537
  }
533
538
  // ponytail: a literal candidate produced a map — the merged result wins and the
@@ -577,6 +582,53 @@ export async function readCoverage(cwd, coverageFile, trace, autoGenerated) {
577
582
  return { available: false, coverageMap: null, error: false };
578
583
  }
579
584
  }
585
+ /**
586
+ * Resolve one literal coverage candidate to a readable path, or null on a miss.
587
+ *
588
+ * The EXACT literal is tried first and returns unchanged, so precedence is untouched: a
589
+ * candidate that exists keeps winning over any case-variant sibling beside it. Only on a
590
+ * miss do we list the candidate's OWN directory — a single `readdir`, no recursion, depth
591
+ * fixed at one — and take the first name matching case-insensitively.
592
+ *
593
+ * Why here and not in the config literals: `access()` is case-sensitive on Linux ext4, so
594
+ * an artifact emitted as `COVERAGE.XML` was invisible to discovery there while the same
595
+ * repo reported coverage on macOS's case-insensitive APFS. Fixing discovery (not the
596
+ * literal list) makes every provider's `coverageFiles` benefit, and it cannot turn a glob
597
+ * entry into something that works: exactly one basename is ever consulted.
598
+ */
599
+ async function resolveReadableCandidate(cwd, file) {
600
+ const exact = path.join(cwd, file);
601
+ try {
602
+ await access(exact, constants.R_OK);
603
+ return exact;
604
+ }
605
+ catch {
606
+ // Miss — fall through to the case-insensitive sibling lookup.
607
+ }
608
+ const dir = path.dirname(exact);
609
+ const wanted = path.basename(exact).toLowerCase();
610
+ let names;
611
+ try {
612
+ names = await readdir(dir);
613
+ }
614
+ catch {
615
+ // Missing/unreadable directory — a miss, skipped silently exactly as before. A cwd
616
+ // that is a FILE also lands here (ENOTDIR), which is the degradation the WS3.4 arms
617
+ // pin for the scan.
618
+ return null;
619
+ }
620
+ const hit = names.find((name) => name.toLowerCase() === wanted);
621
+ if (hit === undefined)
622
+ return null;
623
+ const sibling = path.join(dir, hit);
624
+ try {
625
+ await access(sibling, constants.R_OK);
626
+ return sibling;
627
+ }
628
+ catch {
629
+ return null;
630
+ }
631
+ }
580
632
  /**
581
633
  * Detect the coverage format and dispatch to the matching parser.
582
634
  *
@@ -665,7 +717,7 @@ async function readCoverageFile(coveragePath, cwd, isExplicit, autoGenerated) {
665
717
  // conversion and returning reason 'malformed' (:548) before any format
666
718
  // dispatch ran. `.cobertura.xml` is Cobertura; only `coverage.xml` is the
667
719
  // pytest-cov artifact `coverage json` can read.
668
- const isPythonCoverageXml = ext === '.xml' && basename === 'coverage.xml';
720
+ const isPythonCoverageXml = ext === '.xml' && basename.toLowerCase() === 'coverage.xml';
669
721
  // For Python .coverage binary or coverage.xml, try to convert to JSON first
670
722
  let actualPath = coveragePath;
671
723
  let tempFileToCleanup = null;
@@ -1,5 +1,5 @@
1
1
  export declare const crapCalcProvenance: {
2
2
  readonly tool: "checkchange";
3
- readonly version: "0.4.2";
3
+ readonly version: "0.4.4";
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
2
  // (matches existing hard-coded '0.5.0' style for the core package).
3
- export const crapCalcProvenance = { tool: 'checkchange', version: '0.4.2' };
3
+ export const crapCalcProvenance = { tool: 'checkchange', version: '0.4.4' };
4
4
  export function calculateCrap(cc, coveragePercent) {
5
5
  if (coveragePercent == null) {
6
6
  return null;
@@ -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.2";
34
+ readonly version: "0.4.4";
35
35
  };
36
36
  export interface EvidenceOutput {
37
37
  schemaVersion: string;
package/dist/evidence.js CHANGED
@@ -20,7 +20,7 @@ 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
22
  // Self provenance; version mirrors package.json (existing codebase style hard-codes '0.5.0').
23
- export const evidenceProvenance = { tool: 'checkchange', version: '0.4.2' };
23
+ export const evidenceProvenance = { tool: 'checkchange', version: '0.4.4' };
24
24
  function sha256Hex(content) {
25
25
  return createHash('sha256').update(content).digest('hex');
26
26
  }
@@ -78,9 +78,10 @@ export function builtinConfig() {
78
78
  // ponytail: no complexityCmd — createGenericCommandProvider returns null for
79
79
  // an entry without one (genericCommand.ts:35), which is INTENDED: the csharp
80
80
  // provider is composed by the registration branch at evidence.ts, not by a
81
- // shell command. coverageFiles are LITERAL paths (acceptance item 11): both
82
- // consumers path.join + access() them and silently skip a miss, so a glob
83
- // entry would be inert.
81
+ // shell command. coverageFiles are LITERAL paths (acceptance item 11): discovery tries
82
+ // exact literal via path.join + access(), then case-insensitive readdir
83
+ // fallback in candidate's dirname; only misses both paths silently. Glob
84
+ // entries stay inert (no consumer globs them).
84
85
  // Deliberately EMPTY. A Coverlet artifact lands in a per-run
85
86
  // `TestResults/<GUID>/` directory whose name vstest generates; no literal
86
87
  // can name it, and the three plausible-looking candidates previously listed
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.2";
4
+ readonly version: "0.4.4";
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.2' };
2
+ export const rulesProvenance = { tool: 'checkchange', version: '0.4.4' };
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.3",
3
+ "version": "0.4.4",
4
4
  "license": "MIT",
5
5
  "packageManager": "pnpm@11.17.0",
6
6
  "type": "module",