@diffci.com/diffci 0.3.60 → 0.3.61

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.
@@ -356,6 +356,10 @@ export class ImpactAnalyzer {
356
356
  * package with tests and no other package's test file names it by reference; every other
357
357
  * discovery-excluded path keeps full validation. */
358
358
  private goPackageTestDataOwner = new Map<string, string>();
359
+ /** Directory-level verdicts keyed by testdata directory, scoped to one analysis run. Every
360
+ * changed file under the same tree asks the same question of the same readers; the file-specific
361
+ * token check stays per file (review of #90). */
362
+ private goTestDataDirDisqualified = new Map<string, boolean>();
359
363
 
360
364
  /** Test files known to the graph: nodes matching the profile's test globs or the test-file matcher. */
361
365
  private knownTestPaths(profile: RepositoryProfile, graph: DependencyGraph): string[] {
@@ -405,6 +409,7 @@ export class ImpactAnalyzer {
405
409
  */
406
410
  private mapGoPackageTestData(delta: GitDelta, profile: RepositoryProfile): Map<string, string> {
407
411
  this.goPackageTestDataOwner = new Map();
412
+ this.goTestDataDirDisqualified = new Map();
408
413
  const byOwner = new Map<string, string[]>();
409
414
  for (const [test, owner] of Object.entries(profile.goTestPackages ?? {})) {
410
415
  if (!test.endsWith("_test.go")) continue;
@@ -480,27 +485,84 @@ export class ImpactAnalyzer {
480
485
  const tests = byOwner.get(owner);
481
486
  if (!tests?.length) return undefined;
482
487
  const dataDir = [...segments.slice(0, at), "testdata"].join("/");
483
- const filePattern = referencePattern(referenceTokens(path));
484
- const dirPattern = referencePattern(referenceTokens(dataDir));
485
- const disqualifies = (reader: string): boolean => {
486
- const content = readRepositoryFile(reader);
487
- // A listed test file that cannot be read could still name the testdata; without its
488
- // contents the conservative answer is no selective route at all.
489
- if (content === undefined) return true;
490
- const references = isGoReaderFile(reader) ? goReaderReferences(content) : content;
491
- return contentNamesPath(references, reader, path, filePattern, true)
492
- || contentNamesPath(references, reader, dataDir, dirPattern, true);
488
+ const bareTestdata = (token: { value: string; bare: boolean }) => !(token.bare && token.value === "testdata");
489
+ const fileTokens = referenceTokens(path);
490
+ const dirTokens = referenceTokens(dataDir);
491
+ // A go-reported package's readers run with that package as their working directory, so a bare
492
+ // `testdata` there names their own tree, not this one. Drop that token for them (but keep the
493
+ // slash-bearing path and the bare ancestor package name, so `filepath.Join("..", "p",
494
+ // "testdata")` is still caught). Readers outside package discovery have an unknown working
495
+ // directory and keep the conservative, unfiltered pattern (review of #90).
496
+ const filePattern = referencePattern(fileTokens.filter(bareTestdata));
497
+ const dirPattern = referencePattern(dirTokens.filter(bareTestdata));
498
+ const outsideFilePattern = referencePattern(fileTokens);
499
+ const outsideDirPattern = referencePattern(dirTokens);
500
+ // A package below the owner also runs with its own directory as the working
501
+ // directory, so a bare `testdata` there can reach the owner's tree via `..`
502
+ // (for p/sub reading p/testdata, `../testdata`). Those readers need the
503
+ // unfiltered patterns too, or the prefilter never reaches the path resolver.
504
+ const below = (pkg: string) => owner === "." || pkg.startsWith(`${owner}/`);
505
+ const patternsFor = (pkg: string) => below(pkg)
506
+ ? { file: outsideFilePattern, dir: outsideDirPattern }
507
+ : { file: filePattern, dir: dirPattern };
508
+ const referencesOf = (reader: string, content: string) => isGoReaderFile(reader) ? goReaderReferences(content) : content;
509
+
510
+ // Directory-level verdict: same readers and same directory tokens for every changed file under
511
+ // this tree. Cache it for the rest of the analysis run and short-circuit the whole tree when a
512
+ // reader names it (review of #90). One read per reader even across both checks below.
513
+ const contents = new Map<string, string | undefined>();
514
+ const read = (reader: string) => {
515
+ if (!contents.has(reader)) contents.set(reader, readRepositoryFile(reader));
516
+ return contents.get(reader);
493
517
  };
518
+ let dirDisqualified = this.goTestDataDirDisqualified.get(dataDir);
519
+ if (dirDisqualified === undefined) {
520
+ dirDisqualified = false;
521
+ for (const [pkg, readers] of this.goReadersByPackage) {
522
+ if (pkg === owner) continue;
523
+ const { dir } = patternsFor(pkg);
524
+ for (const reader of readers) {
525
+ const content = read(reader);
526
+ // An unreadable reader could still name the testdata, so answer conservatively.
527
+ if (content === undefined || contentNamesPath(referencesOf(reader, content), reader, dataDir, dir, true)) {
528
+ dirDisqualified = true;
529
+ break;
530
+ }
531
+ }
532
+ if (dirDisqualified) break;
533
+ }
534
+ // Readers outside the go-reported packages (tests of nested modules or other languages,
535
+ // ordinary `.go` files outside package discovery, non-test source modules in a mixed
536
+ // repository) never take the package-owned convention: their tests run with a different
537
+ // working directory, so a reference there disqualifies like a cross-package one (review #85).
538
+ if (!dirDisqualified) {
539
+ for (const reader of this.goOutsideReaders) {
540
+ const content = read(reader);
541
+ if (content === undefined || contentNamesPath(referencesOf(reader, content), reader, dataDir, outsideDirPattern, true)) {
542
+ dirDisqualified = true;
543
+ break;
544
+ }
545
+ }
546
+ }
547
+ this.goTestDataDirDisqualified.set(dataDir, dirDisqualified);
548
+ }
549
+ if (dirDisqualified) return undefined;
550
+
551
+ // File-specific tokens (basename and full path) still need checking per changed file.
494
552
  for (const [pkg, readers] of this.goReadersByPackage) {
495
553
  if (pkg === owner) continue;
496
- if (readers.some(disqualifies)) return undefined;
497
- }
498
- // Readers outside the go-reported packages (tests of nested modules or other languages, ordinary
499
- // `.go` files outside package discovery, non-test source modules in a mixed repository) never
500
- // take the package-owned convention, since their tests run with a different working directory;
501
- // a reference there disqualifies the selective route exactly like a cross-package one
502
- // (2026-11-09, review of #85).
503
- if ([...this.goOutsideReaders].some(disqualifies)) return undefined;
554
+ const { file } = patternsFor(pkg);
555
+ for (const reader of readers) {
556
+ const content = read(reader);
557
+ if (content === undefined) return undefined;
558
+ if (contentNamesPath(referencesOf(reader, content), reader, path, file, true)) return undefined;
559
+ }
560
+ }
561
+ for (const reader of this.goOutsideReaders) {
562
+ const content = read(reader);
563
+ if (content === undefined) return undefined;
564
+ if (contentNamesPath(referencesOf(reader, content), reader, path, outsideFilePattern, true)) return undefined;
565
+ }
504
566
  return owner;
505
567
  }
506
568
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diffci.com/diffci",
3
- "version": "0.3.60",
3
+ "version": "0.3.61",
4
4
  "description": "Verification for AI coding agents: runs the tests and checks a change affects, with full fallback and a receipt",
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#722ff899567a5b58d274c6f0554363932fb73de3",
79
+ "@diffci.com/core": "git+https://github.com/DiffCI/core.git#2304f706d00f49759517b94257caef67ef4c3fa3",
80
80
  "saxes": "6.0.0",
81
81
  "yaml": "^2.9.0"
82
82
  },
@@ -87,5 +87,6 @@
87
87
  },
88
88
  "bundleDependencies": [
89
89
  "@diffci.com/core"
90
- ]
90
+ ],
91
+ "gitHead": "ec24f7c817ee3eac2574f15d35a987f5e7143828"
91
92
  }