@diffci.com/diffci 0.3.30 → 0.3.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-client/src/client/cli.js +26 -1
- package/dist-client/src/client/command-batches.d.ts +5 -0
- package/dist-client/src/client/command-batches.js +9 -0
- package/dist-client/src/client/coverage-map.d.ts +46 -0
- package/dist-client/src/client/coverage-map.js +213 -0
- package/dist-client/src/client/failure-baseline.js +0 -0
- package/dist-client/src/client/observe.js +3 -0
- package/dist-client/src/client/report.d.ts +3 -0
- package/dist-client/src/client/verify.d.ts +4 -0
- package/dist-client/src/client/verify.js +32 -2
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +59 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/types.d.ts +4 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.d.ts +11 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +65 -9
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +10 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +57 -16
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +7 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +43 -16
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/test-fixture-ownership.d.ts +1 -1
- package/node_modules/@diffci.com/core/dist/repo/test-fixture-ownership.js +48 -5
- package/node_modules/@diffci.com/core/dist/repo/test-fixture-ownership.js.map +1 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +48 -0
- package/node_modules/@diffci.com/core/src/git/types.ts +4 -0
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +54 -9
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +60 -18
- package/node_modules/@diffci.com/core/src/repo/impact-types.ts +3 -0
- package/node_modules/@diffci.com/core/src/repo/impact.ts +39 -16
- package/node_modules/@diffci.com/core/src/repo/test-fixture-ownership.ts +39 -5
- package/package.json +2 -2
|
@@ -173,6 +173,10 @@ export interface ReferenceResolution {
|
|
|
173
173
|
code: string[];
|
|
174
174
|
/** Why the file cannot be narrowed; empty when it can. */
|
|
175
175
|
unresolvable: string[];
|
|
176
|
+
/** Each unresolvable reason with the readers leading to it, from the changed file to the file it was
|
|
177
|
+
* found through. Every blocker of the level where the first one appeared is reported, not only the first,
|
|
178
|
+
* so one run explains a fallback that used to take one fix per blocker to uncover (2026-11-05). */
|
|
179
|
+
blockers: Array<{ reason: string; chain: string[] }>;
|
|
176
180
|
/** Every reader found, for evidence. */
|
|
177
181
|
readers: Array<{ path: string; kind: ReaderKind; via: string }>;
|
|
178
182
|
/** Phases of the root test script, verbatim, that run a reader directly; the caller must run them.
|
|
@@ -223,6 +227,10 @@ export function scriptNamesPath(body: string, target: string, pattern: RegExp, {
|
|
|
223
227
|
const targetBase = posix.basename(target);
|
|
224
228
|
const dirs: string[] = [];
|
|
225
229
|
for (let dir = posix.dirname(target); ancestors && dir !== "." && dir !== "/"; dir = posix.dirname(dir)) dirs.push(dir);
|
|
230
|
+
// A file name with an extension is the script's own directory's file (`vitest -c vitest.config.mts` in
|
|
231
|
+
// apps/cli/package.json is apps/cli's config, not packages/alint's; 2026-11-05) unless the script runs
|
|
232
|
+
// somewhere else: a `cd`, a workspace-wide run or a directory flag keeps any same-named file.
|
|
233
|
+
const elsewhere = /(?:^|[\s;&|(])(?:cd|pushd)\s|--(?:dir|cwd|prefix|filter|recursive|workspaces?)\b|(?:^|\s)-[rC]\s|\b(?:turbo|nx|lerna)\b/.test(body);
|
|
226
234
|
for (const raw of body.split(/\s+/)) {
|
|
227
235
|
const word = raw.replace(/^["']+|["']+$/g, "");
|
|
228
236
|
if (!word) continue;
|
|
@@ -245,7 +253,7 @@ export function scriptNamesPath(body: string, target: string, pattern: RegExp, {
|
|
|
245
253
|
continue;
|
|
246
254
|
}
|
|
247
255
|
if (resolved === target || dirs.includes(resolved)) return true;
|
|
248
|
-
if (!candidate.includes("/") && (candidate === targetBase || dirs.some((dir) => posix.basename(dir) === candidate))) return true;
|
|
256
|
+
if (!candidate.includes("/") && ((candidate === targetBase && (elsewhere || !/\.[A-Za-z0-9]+$/.test(candidate))) || dirs.some((dir) => posix.basename(dir) === candidate))) return true;
|
|
249
257
|
}
|
|
250
258
|
}
|
|
251
259
|
return false;
|
|
@@ -291,7 +299,7 @@ function inExclusionList(content: string, index: number): boolean {
|
|
|
291
299
|
* a different file names that file, and a glob names only what it matches (2026-11-04). Bare names and
|
|
292
300
|
* variables inside a path keep the conservative answer.
|
|
293
301
|
*/
|
|
294
|
-
export function contentNamesPath(content: string, readerPath: string, target: string, pattern: RegExp, ancestors: boolean): boolean {
|
|
302
|
+
export function contentNamesPath(content: string, readerPath: string, target: string, pattern: RegExp, ancestors: boolean, readGlobs = true): boolean {
|
|
295
303
|
if (!pattern.test(content)) return false;
|
|
296
304
|
const dirs: string[] = [];
|
|
297
305
|
for (let dir = posix.dirname(target); ancestors && dir !== "." && dir !== "/"; dir = posix.dirname(dir)) dirs.push(dir);
|
|
@@ -314,6 +322,7 @@ export function contentNamesPath(content: string, readerPath: string, target: st
|
|
|
314
322
|
}
|
|
315
323
|
if (!word.includes("/") || /[!$]/.test(word)) return true;
|
|
316
324
|
if (/[*?{}[\]]/.test(word)) {
|
|
325
|
+
if (!readGlobs) continue;
|
|
317
326
|
if (word.startsWith("../")) return true;
|
|
318
327
|
// A glob names what it matches, from the reader's directory, the root, or any directory below the
|
|
319
328
|
// root; `packages/sdk/**` in a workflow's `paths` filter does not name `packages/database/`.
|
|
@@ -363,6 +372,20 @@ export function directoryWalkers(filePath: string, tests: readonly string[], rea
|
|
|
363
372
|
* non-default `wrangler.validation.json` is used only when a command names it. */
|
|
364
373
|
const RUNS_FILES_WITHOUT_NAMING = /^(?:wrangler\.(?:toml|json|jsonc)|dockerfile.*|docker-compose.*|compose\.ya?ml|procfile|makefile|justfile|taskfile\.ya?ml|(?:vitest|vite|jest|playwright|cypress|ava|babel|webpack|rollup|esbuild|vue|nuxt|svelte|astro|next)\.config\..+|\.mocharc.*|\.babelrc.*|\.c8rc.*|\.nycrc.*)$/i;
|
|
365
374
|
|
|
375
|
+
/** TypeScript project files: they list what to compile, and a non-code file they name is read only
|
|
376
|
+
* through an import, which the dependency graph already has. */
|
|
377
|
+
const PATH_LIST_CONFIG = /^[jt]sconfig(?:\.[^/]+)?\.json$/i;
|
|
378
|
+
const LINTERS = new Set(["eslint", "oxlint", "stylelint", "prettier", "alint", "cspell", "markdownlint", "commitlint", "lintstaged", "lint-staged", "biome", "knip", "dprint"]);
|
|
379
|
+
|
|
380
|
+
/** A linter's or formatter's configuration (`alint.config.toml`, `.eslintrc.json`, `biome.json`). */
|
|
381
|
+
export function isLintConfig(filePath: string): boolean {
|
|
382
|
+
const base = posix.basename(filePath).toLowerCase();
|
|
383
|
+
const stem = base.replace(/^\./, "").split(".")[0]!;
|
|
384
|
+
const tool = stem.replace(/rc$/, "");
|
|
385
|
+
if (!LINTERS.has(tool)) return false;
|
|
386
|
+
return stem !== tool || base.includes(".config.") || /^(?:biome|knip|dprint|cspell)\.(?:json|jsonc|ts|js|mjs|cjs|ya?ml)$/.test(base);
|
|
387
|
+
}
|
|
388
|
+
|
|
366
389
|
export function loadsWithoutNaming(path: string): boolean {
|
|
367
390
|
return RUNS_FILES_WITHOUT_NAMING.test(posix.basename(path));
|
|
368
391
|
}
|
|
@@ -483,18 +506,24 @@ function packageJsonNames(content: string, pattern: RegExp, target: string, ance
|
|
|
483
506
|
|
|
484
507
|
/** Resolves who reads `filePath`. See the module comment for the rule and its limits. */
|
|
485
508
|
export function resolveFileReferences(filePath: string, input: ReferenceResolutionInput): ReferenceResolution {
|
|
486
|
-
const resolution: ReferenceResolution = { tests: [], code: [], unresolvable: [], readers: [], phases: [] };
|
|
509
|
+
const resolution: ReferenceResolution = { tests: [], code: [], unresolvable: [], blockers: [], readers: [], phases: [] };
|
|
510
|
+
const parent = new Map<string, string>();
|
|
511
|
+
const chainOf = (path: string) => { const chain = [path]; while (parent.has(chain[0]!)) chain.unshift(parent.get(chain[0]!)!); return chain; };
|
|
512
|
+
const block = (reason: string, through: string) => { resolution.unresolvable.push(reason); resolution.blockers.push({ reason, chain: chainOf(through) }); };
|
|
487
513
|
const phases = new Set<string>();
|
|
488
514
|
const tests = new Set<string>();
|
|
489
515
|
const code = new Set<string>();
|
|
490
516
|
const visited = new Set<string>([filePath]);
|
|
491
|
-
|
|
517
|
+
// `lint`: the file configures a linter, so only a test or graph code naming it is followed; anything else
|
|
518
|
+
// that reads it is lint tooling and runs no test (isLintConfig; 2026-11-05: LobeHub's oxlint.config.mts
|
|
519
|
+
// chain under scripts/stylexMigration/legacyFiles.json went past the depth limit).
|
|
520
|
+
let frontier: Array<{ path: string; via: string; lint?: boolean }> = [{ path: filePath, via: filePath }];
|
|
492
521
|
let transitiveCount = 0;
|
|
493
522
|
const contents = new Map<string, string | undefined>();
|
|
494
523
|
const read = (path: string) => { if (!contents.has(path)) contents.set(path, input.read(path)); return contents.get(path); };
|
|
495
524
|
|
|
496
525
|
for (let depth = 0; depth < MAX_DEPTH && frontier.length > 0; depth++) {
|
|
497
|
-
const next: Array<{ path: string; via: string }> = [];
|
|
526
|
+
const next: Array<{ path: string; via: string; lint?: boolean }> = [];
|
|
498
527
|
for (const target of frontier) {
|
|
499
528
|
// Directories are matched only for the changed file itself, which a test may find by listing its
|
|
500
529
|
// directory. A reader reached through the changed file (a script, a manifest) matters only if
|
|
@@ -505,29 +534,41 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
505
534
|
for (const candidate of input.files) {
|
|
506
535
|
if (visited.has(candidate) || candidate === target.path || LOCKFILES.has(posix.basename(candidate))) continue;
|
|
507
536
|
const base = posix.basename(candidate);
|
|
537
|
+
// A lint step in a workflow or a package's lint script reads a linter's configuration to lint,
|
|
538
|
+
// which no test observes; a test or graph code naming it is still followed (2026-11-05: LobeHub's
|
|
539
|
+
// alint.config.toml names fixture directories and its test workflow runs alint before the tests).
|
|
540
|
+
if (target.lint && (base === "package.json" || candidate.startsWith(".github/"))) continue;
|
|
508
541
|
if (base === "package.json") {
|
|
509
542
|
const content = read(candidate);
|
|
510
543
|
if (content === undefined) {
|
|
511
|
-
if (input.allowNoReaders)
|
|
544
|
+
if (input.allowNoReaders) block(`${candidate} could not be read`, target.path);
|
|
512
545
|
continue;
|
|
513
546
|
}
|
|
514
547
|
const named = packageJsonNames(content, pattern, target.path, ancestors, posix.dirname(candidate));
|
|
515
548
|
if (named === "no") continue;
|
|
516
549
|
visited.add(candidate);
|
|
517
|
-
if (named === "unparseable") {
|
|
550
|
+
if (named === "unparseable") { block(`${candidate} could not be parsed`, target.path); continue; }
|
|
518
551
|
resolution.readers.push({ path: candidate, kind: "package-script", via: target.path });
|
|
519
552
|
const direct = input.testPhases && candidate === "package.json" ? directTestPhases(content, target.path, pattern, ancestors) : undefined;
|
|
520
553
|
if (direct) { for (const phase of direct) phases.add(phase); continue; }
|
|
521
|
-
|
|
554
|
+
block(`${candidate} runs ${target.path} as part of its test script`, target.path);
|
|
522
555
|
continue;
|
|
523
556
|
}
|
|
524
557
|
if (input.isDocumentation(candidate)) continue;
|
|
558
|
+
// 2026-11-05: LobeHub's root tsconfig `include` names scripts/, and with every tsconfig extending it
|
|
559
|
+
// the readers of scripts/stylexMigration/legacyFiles.json passed the transitive limit. tsc compiles
|
|
560
|
+
// what a tsconfig lists and runs none of it, and changed code it compiles is a compiled project's.
|
|
561
|
+
if (PATH_LIST_CONFIG.test(base)) continue;
|
|
525
562
|
const content = read(candidate);
|
|
526
563
|
if (content === undefined && input.allowNoReaders && (input.isCodeFile(candidate) || DIRECTING_EXTENSIONS.test(candidate) || isImplicitlyLoadedFile(candidate))) {
|
|
527
|
-
|
|
564
|
+
block(`${candidate} could not be read`, target.path);
|
|
528
565
|
continue;
|
|
529
566
|
}
|
|
530
|
-
|
|
567
|
+
// A test runner's include and exclude globs select test files, so one matching a data file does not
|
|
568
|
+
// make the runner read it; an exact path in the config still counts (2026-11-05: LobeHub's
|
|
569
|
+
// packages/alint/vitest.config.mts excludes fixture directories under scripts/).
|
|
570
|
+
const globsSelectTests = loadsWithoutNaming(candidate) && !input.isCodeFile(target.path);
|
|
571
|
+
if (content === undefined || !contentNamesPath(content, candidate, target.path, pattern, ancestors, !globsSelectTests)) continue;
|
|
531
572
|
visited.add(candidate);
|
|
532
573
|
if (input.allowNoReaders && /^dockerfile/i.test(base) && copiesOnly(content, target.path)) {
|
|
533
574
|
// The caller modelled what the file does when installed (dependency selection); a Dockerfile
|
|
@@ -536,7 +577,7 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
536
577
|
resolution.readers.push({ path: candidate, kind: "documentation", via: target.path });
|
|
537
578
|
} else if (input.implicitReadersUnresolvable && loadsWithoutNaming(candidate)) {
|
|
538
579
|
resolution.readers.push({ path: candidate, kind: "unresolvable", via: target.path });
|
|
539
|
-
|
|
580
|
+
block(`${candidate} is loaded by tooling and names ${target.path}`, target.path);
|
|
540
581
|
} else if (candidate.startsWith(".github/")) {
|
|
541
582
|
// A workflow step that comes before a test step in its job, or a composite action, may feed
|
|
542
583
|
// the file to the suite's environment; issue templates and standalone CI checks do not.
|
|
@@ -546,37 +587,38 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
546
587
|
|| (/^\.github\/workflows\//.test(candidate) && !input.contentCleared?.has(target.path) && input.workflowFeedsTests(content, (text) => contentNamesPath(text, candidate, target.path, pattern, ancestors)));
|
|
547
588
|
if (!executes) continue;
|
|
548
589
|
resolution.readers.push({ path: candidate, kind: "unresolvable", via: target.path });
|
|
549
|
-
|
|
590
|
+
block(`${candidate} names ${target.path}`, target.path);
|
|
550
591
|
} else if (input.isCodeFile(candidate) && input.isTestFile(candidate)) {
|
|
551
592
|
resolution.readers.push({ path: candidate, kind: "test", via: target.path });
|
|
552
593
|
tests.add(candidate);
|
|
553
594
|
} else if (input.isCodeFile(candidate) && input.inGraph(candidate)) {
|
|
554
595
|
resolution.readers.push({ path: candidate, kind: "graph-code", via: target.path });
|
|
555
596
|
code.add(candidate);
|
|
556
|
-
} else if (input.isCodeFile(candidate) || DIRECTING_EXTENSIONS.test(candidate)) {
|
|
597
|
+
} else if (!target.lint && (input.isCodeFile(candidate) || DIRECTING_EXTENSIONS.test(candidate))) {
|
|
557
598
|
resolution.readers.push({ path: candidate, kind: "transitive", via: target.path });
|
|
558
|
-
if (++transitiveCount > MAX_TRANSITIVE_READERS) {
|
|
559
|
-
|
|
599
|
+
if (++transitiveCount > MAX_TRANSITIVE_READERS) { block(`more than ${MAX_TRANSITIVE_READERS} non-code files name ${filePath}`, target.path); break; }
|
|
600
|
+
parent.set(candidate, target.path);
|
|
601
|
+
next.push({ path: candidate, via: target.path, lint: isLintConfig(candidate) });
|
|
560
602
|
} else {
|
|
561
603
|
// Markup, prose, images and licences name paths in links and URLs but execute nothing and
|
|
562
604
|
// direct no reads, so nothing reaches the suite through them.
|
|
563
605
|
resolution.readers.push({ path: candidate, kind: "documentation", via: target.path });
|
|
564
606
|
}
|
|
565
607
|
}
|
|
566
|
-
if (
|
|
608
|
+
if (transitiveCount > MAX_TRANSITIVE_READERS) break;
|
|
567
609
|
}
|
|
568
610
|
if (resolution.unresolvable.length > 0) break;
|
|
569
611
|
frontier = next;
|
|
570
612
|
}
|
|
571
613
|
if (resolution.unresolvable.length === 0 && frontier.length > 0) {
|
|
572
|
-
|
|
614
|
+
block(`reference chain from ${filePath} is deeper than ${MAX_DEPTH} files`, filePath);
|
|
573
615
|
}
|
|
574
616
|
// Found readers that something could run (check scripts, manifests), none of which any test, test
|
|
575
617
|
// script or test-feeding workflow step reaches: the suite cannot observe the file. Finding no such
|
|
576
618
|
// reader at all is different - the file's reader is unknown, so it stays unknown.
|
|
577
619
|
const executableReaders = resolution.readers.some((reader) => reader.kind === "transitive");
|
|
578
620
|
if (resolution.unresolvable.length === 0 && tests.size === 0 && code.size === 0 && !executableReaders && !input.allowNoReaders && !input.removed && !loadedOnlyOutsideTests(filePath, input, read)) {
|
|
579
|
-
|
|
621
|
+
block(`no test or source file names ${filePath}`, filePath);
|
|
580
622
|
}
|
|
581
623
|
resolution.phases = resolution.unresolvable.length === 0 ? [...phases].sort() : [];
|
|
582
624
|
resolution.tests = [...tests].sort();
|
|
@@ -101,6 +101,9 @@ export interface ImpactResult {
|
|
|
101
101
|
|
|
102
102
|
fallbackRequired: boolean;
|
|
103
103
|
fallbackReasons: string[];
|
|
104
|
+
/** For a changed file whose readers could not be resolved: every blocker, each with the chain of readers
|
|
105
|
+
* that leads to it (`reader names x (via a <- b)`). Present only on a fallback (2026-11-05). */
|
|
106
|
+
fallbackDetails?: Record<string, string[]>;
|
|
104
107
|
|
|
105
108
|
analysisStatus: "SAFE_TO_PROPOSE" | "FALLBACK";
|
|
106
109
|
|
|
@@ -258,6 +258,7 @@ export class ImpactAnalyzer {
|
|
|
258
258
|
private contentCleared: ReadonlySet<string> = new Set();
|
|
259
259
|
private dependencyLockfile: string | undefined;
|
|
260
260
|
private packageJsonSpecifiersOnly = false;
|
|
261
|
+
private specifiersOnlyManifests: ReadonlySet<string> = new Set();
|
|
261
262
|
private readRepositoryFile: ((path: string) => string | undefined) | undefined;
|
|
262
263
|
private sortedRepositoryFiles: string[] = [];
|
|
263
264
|
private compiledProjectCache: CompiledProject[] | undefined;
|
|
@@ -267,6 +268,8 @@ export class ImpactAnalyzer {
|
|
|
267
268
|
private workersOutsideSuite: boolean | undefined;
|
|
268
269
|
private runtimeTestSelection = false;
|
|
269
270
|
private unresolved: readonly UnresolvedDependency[] = [];
|
|
271
|
+
/** Why each changed file the reference resolver could not narrow is unresolvable, for fallbackDetails. */
|
|
272
|
+
private referenceBlockers = new Map<string, string[]>();
|
|
270
273
|
private walkerTests: string[] | undefined;
|
|
271
274
|
private knownTests: string[] | undefined;
|
|
272
275
|
private declaredCovered = new Set<string>();
|
|
@@ -330,6 +333,7 @@ export class ImpactAnalyzer {
|
|
|
330
333
|
this.declaredCovered = new Set();
|
|
331
334
|
this.runtimeTestSelection = graphResult.runtimeTestSelection === true;
|
|
332
335
|
this.unresolved = graphResult.unresolved ?? [];
|
|
336
|
+
this.referenceBlockers = new Map();
|
|
333
337
|
this.sortedRepositoryFiles = options.repositoryFiles ? [...options.repositoryFiles].sort() : [];
|
|
334
338
|
this.compiledProjectCache = undefined;
|
|
335
339
|
// One read per file per analysis, however many changed files ask who reads them.
|
|
@@ -343,6 +347,7 @@ export class ImpactAnalyzer {
|
|
|
343
347
|
this.contentCleared = referenceResolved;
|
|
344
348
|
this.dependencyLockfile = delta.analysis.dependencyLockfile;
|
|
345
349
|
this.packageJsonSpecifiersOnly = delta.analysis.packageJsonSpecifiersOnly === true;
|
|
350
|
+
this.specifiersOnlyManifests = new Set(delta.analysis.specifiersOnlyManifests ?? []);
|
|
346
351
|
const changedImpacts: ChangedImpact[] = delta.files.map((file) => ({ file, category: classifyChangedFile(file, this.isTestFile, this.layout, options.repositoryFiles, referenceResolved), reasons: changedFileReasons(file) }));
|
|
347
352
|
const evidence: ImpactEvidence[] = [];
|
|
348
353
|
const riskSignals: ImpactRiskSignal[] = [];
|
|
@@ -489,6 +494,7 @@ export class ImpactAnalyzer {
|
|
|
489
494
|
riskSignals: dedupedRiskSignals,
|
|
490
495
|
fallbackRequired,
|
|
491
496
|
fallbackReasons,
|
|
497
|
+
...(fallbackRequired && this.referenceBlockers.size ? { fallbackDetails: this.fallbackDetails(fallbackReasons) } : {}),
|
|
492
498
|
analysisStatus,
|
|
493
499
|
effectiveGraphConfidence,
|
|
494
500
|
evidence: evidence.sort((a, b) => { const c = a.changedFile.localeCompare(b.changedFile); if (c !== 0) return c; return a.message.localeCompare(b.message); }),
|
|
@@ -496,6 +502,16 @@ export class ImpactAnalyzer {
|
|
|
496
502
|
};
|
|
497
503
|
}
|
|
498
504
|
|
|
505
|
+
/** Blockers of each file a fallback reason names, at most 20 files and 10 blockers each. */
|
|
506
|
+
private fallbackDetails(fallbackReasons: readonly string[]): Record<string, string[]> {
|
|
507
|
+
const details: Record<string, string[]> = {};
|
|
508
|
+
for (const [path, blockers] of [...this.referenceBlockers].sort(([a], [b]) => a.localeCompare(b))) {
|
|
509
|
+
if (Object.keys(details).length >= 20) break;
|
|
510
|
+
if (fallbackReasons.some((reason) => reason.includes(path))) details[path] = blockers.slice(0, 10);
|
|
511
|
+
}
|
|
512
|
+
return details;
|
|
513
|
+
}
|
|
514
|
+
|
|
499
515
|
private applyGlobalRiskRules(delta: GitDelta, riskSignals: ImpactRiskSignal[], fallbackReasons: string[]): void {
|
|
500
516
|
type SignalKey = keyof NonNullable<GitDelta["analysis"]["signalPaths"]>;
|
|
501
517
|
const reasons: Array<{ reason: ImpactReason; message: string; signal: SignalKey; check: (a: GitDelta["analysis"]) => boolean }> = [
|
|
@@ -767,23 +783,14 @@ export class ImpactAnalyzer {
|
|
|
767
783
|
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
768
784
|
return;
|
|
769
785
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
const ownership = resolveTestFixtureOwners(changedPath, this.isTestFile, this.repositoryFiles);
|
|
774
|
-
if (ownership) {
|
|
775
|
-
for (const owner of ownership.owners) {
|
|
776
|
-
this.addAffectedTest(changedPath, owner, graph, affectedTests, "TEST_FIXTURE_OWNER", evidence);
|
|
777
|
-
}
|
|
778
|
-
evidence.push(makeEvidence("TEST_FIXTURE_OWNER", changedPath, `Test fixture ${changedPath} under ${ownership.fixtureDir} is owned by ${ownership.owners.length} test(s) in ${ownership.testsDir} (${ownership.scope})`));
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
786
|
+
// Resolved per change PATH (a rename's old path resolves independently); an unresolvable side
|
|
787
|
+
// degrades to the unknown-file fallback below rather than being silently dropped.
|
|
788
|
+
if (category === "test-fixture" && this.claimFixture(changedPath, graph, affectedTests, evidence)) return;
|
|
782
789
|
if (category === "unknown" || category === "test-fixture") {
|
|
783
790
|
// A package.json edit limited to dependency requests is covered by dependency selection, like
|
|
784
791
|
// the lockfile above, so finding no reader is not a gap. Tooling that loads a file naming it
|
|
785
792
|
// still is (2026-11-02).
|
|
786
|
-
const specifiersOnly = changedPath === "package.json" && this.packageJsonSpecifiersOnly;
|
|
793
|
+
const specifiersOnly = (changedPath === "package.json" && this.packageJsonSpecifiersOnly) || this.specifiersOnlyManifests.has(changedPath);
|
|
787
794
|
const options = specifiersOnly ? { allowNoReaders: true, implicitReadersUnresolvable: true } : {};
|
|
788
795
|
if (this.resolveByReference(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, options)) return;
|
|
789
796
|
if (covered) return;
|
|
@@ -799,7 +806,10 @@ export class ImpactAnalyzer {
|
|
|
799
806
|
if (isAssetFilePath(changedPath) && !hasNode(graph, changedPath) && !removed && !isDocumentationFile(changedPath, this.layout) && !isLockfile(changedPath)) {
|
|
800
807
|
// An asset no module imports can still be read from disk by a test. It used to select nothing
|
|
801
808
|
// and require nothing, which is a silent skip; it now needs reader evidence like any other
|
|
802
|
-
// non-code file (2026-10-21).
|
|
809
|
+
// non-code file (2026-10-21). Assets (`.json`, `.txt`) are classified before fixture ownership is
|
|
810
|
+
// tried, so a fixture no module imports is claimed here (2026-11-05: LobeHub's
|
|
811
|
+
// src/spawn/__fixtures__/copilotAcp/handshake.json beside the spawn tests).
|
|
812
|
+
if (this.claimFixture(changedPath, graph, affectedTests, evidence)) return;
|
|
803
813
|
if (this.resolveByReference(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) return;
|
|
804
814
|
if (covered) return;
|
|
805
815
|
const message = `Unknown changed file: ${changedPath}`;
|
|
@@ -864,6 +874,15 @@ export class ImpactAnalyzer {
|
|
|
864
874
|
this.processSourceChange(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
|
|
865
875
|
}
|
|
866
876
|
|
|
877
|
+
/** Selects the tests that own `path` as a test fixture (src/repo/test-fixture-ownership.ts), if any do. */
|
|
878
|
+
private claimFixture(path: string, graph: DependencyGraph, affectedTests: Map<string, TestImpact>, evidence: ImpactEvidence[]): boolean {
|
|
879
|
+
const ownership = resolveTestFixtureOwners(path, this.isTestFile, this.repositoryFiles);
|
|
880
|
+
if (!ownership) return false;
|
|
881
|
+
for (const owner of ownership.owners) this.addAffectedTest(path, owner, graph, affectedTests, "TEST_FIXTURE_OWNER", evidence);
|
|
882
|
+
evidence.push(makeEvidence("TEST_FIXTURE_OWNER", path, `Test fixture ${path} under ${ownership.fixtureDir} is owned by ${ownership.owners.length} test(s) in ${ownership.testsDir} (${ownership.scope})`));
|
|
883
|
+
return true;
|
|
884
|
+
}
|
|
885
|
+
|
|
867
886
|
/**
|
|
868
887
|
* A file gone at HEAD that the HEAD graph has no node for (2026-11-04). Its old importers cannot be
|
|
869
888
|
* listed, but each one is either changed in this delta (its import was edited or removed, so it is
|
|
@@ -890,7 +909,9 @@ export class ImpactAnalyzer {
|
|
|
890
909
|
// Conservative: any unresolved import whose last segment could name the file blocks, wherever it is.
|
|
891
910
|
const importer = this.unresolved.find((ref) => !ref.computed && names.has(posix.basename(ref.specifier.split(/[?#]/)[0]!)));
|
|
892
911
|
if (importer) {
|
|
893
|
-
|
|
912
|
+
const blocker = `${importer.importer} imports ${importer.specifier}, which may have resolved to the removed ${removedPath}`;
|
|
913
|
+
evidence.push(makeEvidence("UNKNOWN_FILE", removedPath, blocker));
|
|
914
|
+
this.referenceBlockers.set(removedPath, [blocker]);
|
|
894
915
|
return false;
|
|
895
916
|
}
|
|
896
917
|
if (!this.resolveByReference(removedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, { implicitReadersUnresolvable: true, removed: true })) return false;
|
|
@@ -971,7 +992,9 @@ export class ImpactAnalyzer {
|
|
|
971
992
|
workerConfigsOutsideSuite: this.workerConfigsOutsideSuite(),
|
|
972
993
|
});
|
|
973
994
|
if (resolution.unresolvable.length > 0) {
|
|
974
|
-
|
|
995
|
+
const blockers = resolution.blockers.map(({ reason, chain }) => chain.length > 1 ? `${reason} (via ${chain.slice(1).join(" <- ")})` : reason);
|
|
996
|
+
this.referenceBlockers.set(changedPath, blockers);
|
|
997
|
+
evidence.push(makeEvidence("UNKNOWN_FILE", changedPath, `References to ${changedPath} could not be resolved: ${blockers.slice(0, 5).join("; ")}${blockers.length > 5 ? `; and ${blockers.length - 5} more` : ""}`));
|
|
975
998
|
return false;
|
|
976
999
|
}
|
|
977
1000
|
for (const reader of resolution.readers) {
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* 1. the nearest ancestor directory named `tests`, `test` or `__tests__` is the tests dir T;
|
|
16
16
|
* 2. the segment directly under T must be a fixture directory by name (`snapshots`,
|
|
17
17
|
* `goal-snapshots`, `fixtures`, `__fixtures__`, `__snapshots__`, ...) - a `.jsonl` elsewhere
|
|
18
|
-
* under T (or outside any tests dir) is NOT claimed
|
|
18
|
+
* under T (or outside any tests dir) is NOT claimed, except a non-code file directly in T, which
|
|
19
|
+
* the direct test children of T own (2026-11-05);
|
|
19
20
|
* 3. owners are the recognised test files (profile test patterns) that are DIRECT children of T.
|
|
20
21
|
* When the fixture dir is snapshot-named and T has snapshot-family tests, only those are owned
|
|
21
22
|
* (a snapshots dir is read by snapshot suites); otherwise all direct test children; if T has no
|
|
@@ -24,6 +25,12 @@
|
|
|
24
25
|
* undefined and the file stays "unknown" (fallback). Deleted fixtures resolve against HEAD: the
|
|
25
26
|
* tests dir still exists -> its tests are selected; tests dir gone -> unknown.
|
|
26
27
|
*
|
|
28
|
+
* A fixture directory BESIDE its tests (2026-11-05, LobeHub `verification/fixtures/assets/*` next to
|
|
29
|
+
* `verification/__tests__/`, `src/spawn/__fixtures__/` next to `src/spawn/*.test.ts`) is owned the same
|
|
30
|
+
* way when no tests-dir ancestor claims it: the nearest fixture-named ancestor F, its parent P, and as
|
|
31
|
+
* owners the tests directly in P or directly in P's `tests`/`test`/`__tests__`; if there are none, every
|
|
32
|
+
* test under P/** (scope `sibling-recursive`).
|
|
33
|
+
*
|
|
27
34
|
* Ownership is by directory convention only; nothing here inspects file contents or file extensions,
|
|
28
35
|
* so the same rule covers `.jsonl`, `.json`, `.txt`, `.expected.*` fixtures alike.
|
|
29
36
|
*/
|
|
@@ -31,15 +38,36 @@ import { testFamilyOfPath } from "./test-discovery.js";
|
|
|
31
38
|
|
|
32
39
|
const TESTS_DIR_NAMES = new Set(["tests", "test", "__tests__"]);
|
|
33
40
|
const FIXTURE_DIR = /(^|[-_.])(snapshots?|fixtures?)([-_.]|$)|^__(snapshots|fixtures)__$/i;
|
|
41
|
+
const CODE_FILE = /\.(?:[cm]?[jt]sx?|vue|svelte|go|java|kt|py|rb)$/i;
|
|
34
42
|
|
|
35
43
|
export interface FixtureOwnership {
|
|
36
44
|
testsDir: string;
|
|
37
45
|
fixtureDir: string;
|
|
38
46
|
/** How owners were chosen - surfaced in evidence so over-selection is auditable. */
|
|
39
|
-
scope: "direct-snapshot-family" | "direct" | "recursive";
|
|
47
|
+
scope: "direct-snapshot-family" | "direct" | "recursive" | "sibling" | "sibling-recursive";
|
|
40
48
|
owners: string[];
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
/** Owners of a fixture directory that sits beside its tests rather than inside a tests dir. */
|
|
52
|
+
function siblingOwners(segments: readonly string[], isTestFile: (p: string) => boolean, repositoryFiles: ReadonlySet<string>): FixtureOwnership | undefined {
|
|
53
|
+
let f = -1;
|
|
54
|
+
for (let i = segments.length - 2; i >= 1; i--) { if (FIXTURE_DIR.test(segments[i]!)) { f = i; break; } }
|
|
55
|
+
if (f === -1) return undefined;
|
|
56
|
+
const scope = segments.slice(0, f).join("/");
|
|
57
|
+
const fixtureDir = `${scope}/${segments[f]}`;
|
|
58
|
+
const direct: string[] = [];
|
|
59
|
+
const recursive: string[] = [];
|
|
60
|
+
for (const file of repositoryFiles) {
|
|
61
|
+
if (!file.startsWith(`${scope}/`) || !isTestFile(file)) continue;
|
|
62
|
+
recursive.push(file);
|
|
63
|
+
const rest = file.slice(scope.length + 1).split("/");
|
|
64
|
+
if (rest.length === 1 || (rest.length === 2 && TESTS_DIR_NAMES.has(rest[0]!))) direct.push(file);
|
|
65
|
+
}
|
|
66
|
+
if (direct.length > 0) return { testsDir: scope, fixtureDir, scope: "sibling", owners: direct.sort() };
|
|
67
|
+
if (recursive.length > 0) return { testsDir: scope, fixtureDir, scope: "sibling-recursive", owners: recursive.sort() };
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
|
|
43
71
|
export function resolveTestFixtureOwners(
|
|
44
72
|
changedPath: string,
|
|
45
73
|
isTestFile: (p: string) => boolean,
|
|
@@ -51,10 +79,16 @@ export function resolveTestFixtureOwners(
|
|
|
51
79
|
// nearest tests-dir ancestor (search from the deepest directory upward)
|
|
52
80
|
let t = -1;
|
|
53
81
|
for (let i = segments.length - 2; i >= 0; i--) { if (TESTS_DIR_NAMES.has(segments[i]!)) { t = i; break; } }
|
|
54
|
-
|
|
55
|
-
|
|
82
|
+
// A data file directly in a tests dir (`__tests__/recordedRun.json`) is read by the tests beside it
|
|
83
|
+
// (2026-11-05, LobeHub). Code there is a helper the graph sees, so only non-code files are claimed.
|
|
84
|
+
if (t !== -1 && t === segments.length - 2 && /\.[^./]+$/.test(changedPath) && !CODE_FILE.test(changedPath)) {
|
|
85
|
+
const testsDir = segments.slice(0, t + 1).join("/");
|
|
86
|
+
const owners = [...repositoryFiles].filter((f) => f.startsWith(`${testsDir}/`) && !f.slice(testsDir.length + 1).includes("/") && isTestFile(f)).sort();
|
|
87
|
+
if (owners.length > 0) return { testsDir, fixtureDir: testsDir, scope: "direct", owners };
|
|
88
|
+
}
|
|
89
|
+
const fixtureSegment = t === -1 ? undefined : segments[t + 1];
|
|
56
90
|
// must be a fixture DIRECTORY (at least one more segment = the file itself), and fixture-named
|
|
57
|
-
if (fixtureSegment === undefined || t + 1 >= segments.length - 1 || !FIXTURE_DIR.test(fixtureSegment)) return
|
|
91
|
+
if (fixtureSegment === undefined || t + 1 >= segments.length - 1 || !FIXTURE_DIR.test(fixtureSegment)) return siblingOwners(segments, isTestFile, repositoryFiles);
|
|
58
92
|
const testsDir = segments.slice(0, t + 1).join("/");
|
|
59
93
|
const prefix = `${testsDir}/`;
|
|
60
94
|
const direct: string[] = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diffci.com/diffci",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.31",
|
|
4
4
|
"description": "Fail-closed, change-aware verification for AI coding agents with conservative affected-test selection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"test": "node scripts/run-tests.mjs"
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
|
-
"@diffci.com/core": "git+https://github.com/DiffCI/core.git#
|
|
79
|
+
"@diffci.com/core": "git+https://github.com/DiffCI/core.git#d21cb9328c244fcc973364a699000f5f59807f2b",
|
|
80
80
|
"yaml": "^2.9.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|