@diffci.com/diffci 0.3.37 → 0.3.39
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 +3 -3
- package/dist-client/src/client/agent-setup.d.ts +1 -1
- package/dist-client/src/client/agent-setup.js +1 -1
- package/dist-client/src/client/check-plan-junit.js +12 -3
- package/dist-client/src/client/command-batches.d.ts +6 -0
- package/dist-client/src/client/command-batches.js +7 -1
- package/dist-client/src/client/node-bin-launch.d.ts +10 -0
- package/dist-client/src/client/node-bin-launch.js +71 -0
- package/dist-client/src/client/verify-savings.js +18 -11
- package/node_modules/@diffci.com/core/README.md +15 -4
- package/node_modules/@diffci.com/core/dist/cache/economics-context.d.ts +4 -1
- package/node_modules/@diffci.com/core/dist/cache/economics-context.js +7 -3
- package/node_modules/@diffci.com/core/dist/cache/economics-context.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +5 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +2 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +7 -6
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js +24 -7
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/analyzer.js +16 -1
- package/node_modules/@diffci.com/core/dist/repo/analyzer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/export-reach.d.ts +16 -0
- package/node_modules/@diffci.com/core/dist/repo/export-reach.js +113 -0
- package/node_modules/@diffci.com/core/dist/repo/export-reach.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +2 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +429 -39
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +51 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +296 -9
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/lockfiles.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/repo/lockfiles.js +12 -0
- package/node_modules/@diffci.com/core/dist/repo/lockfiles.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/repo-config.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/repo/repo-config.js +3 -1
- package/node_modules/@diffci.com/core/dist/repo/repo-config.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/types.d.ts +35 -1
- package/node_modules/@diffci.com/core/dist/repo/workspace-sources.d.ts +35 -0
- package/node_modules/@diffci.com/core/dist/repo/workspace-sources.js +292 -0
- package/node_modules/@diffci.com/core/dist/repo/workspace-sources.js.map +1 -0
- package/node_modules/@diffci.com/core/package.json +1 -1
- package/node_modules/@diffci.com/core/src/cache/economics-context.ts +7 -3
- package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +5 -1
- package/node_modules/@diffci.com/core/src/ci-inference/evidence.ts +1 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +7 -6
- package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +23 -7
- package/node_modules/@diffci.com/core/src/repo/analyzer.ts +15 -1
- package/node_modules/@diffci.com/core/src/repo/export-reach.ts +92 -0
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +2 -1
- package/node_modules/@diffci.com/core/src/repo/graph.ts +365 -35
- package/node_modules/@diffci.com/core/src/repo/impact-types.ts +2 -0
- package/node_modules/@diffci.com/core/src/repo/impact.ts +267 -9
- package/node_modules/@diffci.com/core/src/repo/lockfiles.ts +13 -0
- package/node_modules/@diffci.com/core/src/repo/repo-config.ts +8 -1
- package/node_modules/@diffci.com/core/src/repo/types.ts +32 -1
- package/node_modules/@diffci.com/core/src/repo/workspace-sources.ts +273 -0
- package/package.json +3 -3
|
@@ -5,20 +5,36 @@ import { refineConfidenceForDelta, relevantScopedAdapterBlockers } from "./graph
|
|
|
5
5
|
import { repositoryLayout, UNKNOWN_REPOSITORY_LAYOUT } from "./layout.js";
|
|
6
6
|
import { DEFAULT_TEST_FILE_MATCHER, matchesGlob as matchesTestGlob, testDiscoveryErrors, testFileMatcherForProfile } from "./test-discovery.js";
|
|
7
7
|
import { resolveTestFixtureOwners } from "./test-fixture-ownership.js";
|
|
8
|
-
import { compilerConfigNames, directoryWalkers, DIRECTING_EXTENSIONS, infrastructureRole, isAgentConfigurationPath, listsDirectories, loadsWithoutNaming, isImplicitlyLoadedFile, isWorkerConfig, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
|
|
8
|
+
import { compilerConfigNames, contentNamesPath, directoryWalkers, DIRECTING_EXTENSIONS, infrastructureRole, isAgentConfigurationPath, listsDirectories, loadsWithoutNaming, isImplicitlyLoadedFile, isWorkerConfig, referencePattern, referenceTokens, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
|
|
9
9
|
import { workflowFeedsTests } from "./workflow-test-steps.js";
|
|
10
10
|
import { modelTestScriptUniverse } from "./script-universe.js";
|
|
11
11
|
import { compiledProjects } from "./compiled-projects.js";
|
|
12
12
|
import { isPlaywrightSpec, nextAppRoute, routeMatches, visitedRoutes } from "./route-visits.js";
|
|
13
|
+
import { exportLevelReach } from "./export-reach.js";
|
|
14
|
+
import { LOCKFILE } from "./lockfiles.js";
|
|
13
15
|
const SOURCE_EXTENSIONS = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".mts", ".cts", ".vue", ".go", ".java", ".kt"]);
|
|
14
16
|
const ASSET_EXTENSIONS = new Set([".css", ".scss", ".sass", ".less", ".json", ".jsonc", ".svg", ".png", ".jpg", ".jpeg", ".gif", ".webp", ".ico", ".bmp", ".woff", ".woff2", ".ttf", ".otf", ".eot", ".wasm", ".md", ".txt"]);
|
|
15
17
|
const NEXT_ENTRY_NAMES = new Set(["page", "layout", "route", "api", "loading", "error", "template", "not-found", "middleware", "generatemetadata", "generatestaticparams"]);
|
|
16
18
|
// Lockfiles are reported by the lockfile rule; resolving their readers would only repeat it.
|
|
17
|
-
function isLockfile(filePath) { return
|
|
19
|
+
function isLockfile(filePath) { return LOCKFILE.test(posix.basename(filePath)); }
|
|
18
20
|
function isSourceFilePath(filePath) { return SOURCE_EXTENSIONS.has(extname(filePath).toLowerCase()); }
|
|
19
21
|
function isAssetFilePath(filePath) { return ASSET_EXTENSIONS.has(extname(filePath).toLowerCase()); }
|
|
22
|
+
function isGoReaderFile(filePath) { return filePath.endsWith(".go"); }
|
|
23
|
+
/**
|
|
24
|
+
* Reads a go reader's references without its import clauses: an import names the package, not any
|
|
25
|
+
* directory inside it, and counting `example.com/project/p` as a reference to a changed `p/...`
|
|
26
|
+
* path would disqualify every sibling package's package-owned testdata route (2026-11-09, review of
|
|
27
|
+
* #85). String literals and call arguments — where a testdata read actually appears — are kept.
|
|
28
|
+
*/
|
|
29
|
+
function goReaderReferences(content) {
|
|
30
|
+
return content
|
|
31
|
+
.replace(/^[ \t]*import[ \t]+[^(){}[\]\n]*\n/gm, "")
|
|
32
|
+
.replace(/^[ \t]*import[ \t]*\([^)]*\)[ \t]*(?:\/\/[^\n]*)?\n/gm, "");
|
|
33
|
+
}
|
|
20
34
|
/** Vitest's default `typecheck.include`: tests whose outcome is the type checker's. */
|
|
21
35
|
const TYPE_TEST_FILE = /\.(?:test|spec)-d\.[cm]?[jt]sx?$/;
|
|
36
|
+
/** tstyche type tests, which type-check whatever they import. */
|
|
37
|
+
const TYPE_CHECK_TEST_FILE = /\.tst\.[cm]?[jt]sx?$/;
|
|
22
38
|
// Phase 01 follow-up (2026-08-26): "is this auxiliary code?" and "is this documentation?" are answered
|
|
23
39
|
// from the repository's own discovered layout (src/repo/layout.ts), not from DiffCI's directory names.
|
|
24
40
|
// These previously read `startsWith("scripts/") || startsWith("ops/")` and `startsWith("docs/")`, which
|
|
@@ -49,6 +65,8 @@ function isConfigFile(filePath) {
|
|
|
49
65
|
return true;
|
|
50
66
|
if (base.startsWith("jest.config"))
|
|
51
67
|
return true;
|
|
68
|
+
if (base.startsWith("babel.config") || base.startsWith(".babelrc"))
|
|
69
|
+
return true;
|
|
52
70
|
if (base.startsWith("prettier.config"))
|
|
53
71
|
return true;
|
|
54
72
|
if (base.startsWith(".prettierrc"))
|
|
@@ -295,12 +313,44 @@ export class ImpactAnalyzer {
|
|
|
295
313
|
testPhases = new Set();
|
|
296
314
|
workersOutsideSuite;
|
|
297
315
|
runtimeTestSelection = false;
|
|
316
|
+
typeTestGlobs = [];
|
|
317
|
+
/** A file a type-test runner checks: its outcome depends on types, which runtime and export-level selection ignore. */
|
|
318
|
+
isTypeTest(path) {
|
|
319
|
+
return TYPE_TEST_FILE.test(path) || TYPE_CHECK_TEST_FILE.test(path) || this.typeTestGlobs.some((glob) => matchesTestGlob(path, glob));
|
|
320
|
+
}
|
|
321
|
+
/** Export-level bindings (export-reach.ts) and each test's reach under them, per analysis. */
|
|
322
|
+
bindings;
|
|
323
|
+
runtimeForward = new Map();
|
|
324
|
+
exportReach = new Map();
|
|
298
325
|
unresolved = [];
|
|
299
326
|
/** Why each changed file the reference resolver could not narrow is unresolvable, for fallbackDetails. */
|
|
300
327
|
referenceBlockers = new Map();
|
|
301
328
|
walkerTests;
|
|
302
329
|
knownTests;
|
|
303
330
|
declaredCovered = new Set();
|
|
331
|
+
/** Go test files grouped by their package's directory value (`profile.goTestPackages` keys are test
|
|
332
|
+
* files; go test files always end `_test.go`). Built once per analysis. */
|
|
333
|
+
goPackageTestFilesByOwner = new Map();
|
|
334
|
+
/** Each go-reported package's full file list keyed like `testPackages` (owner itself included). Profiles
|
|
335
|
+
* from the current adapter put a package's test files into `sourcePaths` too, so when this map is
|
|
336
|
+
* populated a package's members are exactly its sourcePaths; legacy cached profiles leave it empty. */
|
|
337
|
+
goSourceFilesByOwner = new Map();
|
|
338
|
+
/** Every go-reported package's testdata-reading candidates keyed by its directory: with source
|
|
339
|
+
* metadata the package's members (ordinary sources and test files, a package without tests of its
|
|
340
|
+
* own included — helpers there read other packages' testdata for their callers' tests); legacy
|
|
341
|
+
* cached profiles only ever knew the listed tests. The cross-package scan checks every package's
|
|
342
|
+
* entry except the owner (2026-11-09, review of #85). */
|
|
343
|
+
goReadersByPackage = new Map();
|
|
344
|
+
/** Repository files that no go-reported package reported — code outside package discovery whose
|
|
345
|
+
* references to a package's testdata disqualify the selective route like a cross-package one:
|
|
346
|
+
* tests in nested modules or other languages, ordinary `.go` files excluded from package
|
|
347
|
+
* discovery, and non-test source modules in a mixed repository. Their readers run with a
|
|
348
|
+
* different working directory, so the package-owned convention cannot hold for them. */
|
|
349
|
+
goOutsideReaders = new Set();
|
|
350
|
+
/** A changed `testdata/` path selects its owning package's tests when the parent directory is a Go
|
|
351
|
+
* package with tests and no other package's test file names it by reference; every other
|
|
352
|
+
* discovery-excluded path keeps full validation. */
|
|
353
|
+
goPackageTestDataOwner = new Map();
|
|
304
354
|
/** Test files known to the graph: nodes matching the profile's test globs or the test-file matcher. */
|
|
305
355
|
knownTestPaths(profile, graph) {
|
|
306
356
|
if (this.knownTests)
|
|
@@ -325,7 +375,138 @@ export class ImpactAnalyzer {
|
|
|
325
375
|
if (inputs.length === 0)
|
|
326
376
|
return undefined;
|
|
327
377
|
const globs = inputs.flatMap((input) => input.tests);
|
|
328
|
-
|
|
378
|
+
// Go profiles declare no test locations (`profile.tests` is a JS-runner notion), so the go
|
|
379
|
+
// adapter's package-reported `_test.go` files join the candidates; without them a declaration
|
|
380
|
+
// naming any Go path is always stale and files the very fallback the declaration was meant to
|
|
381
|
+
// override. They are additional candidates behind globs the repository names - nothing is
|
|
382
|
+
// selected that the declaration did not ask for (2026-11-09, issue #83).
|
|
383
|
+
const goTestCandidates = profile.adapters?.some(adapter => adapter.id === "go")
|
|
384
|
+
? Object.keys(profile.goTestPackages ?? {}).filter(test => test.endsWith("_test.go"))
|
|
385
|
+
: [];
|
|
386
|
+
return [...this.knownTestPaths(profile, graph), ...goTestCandidates].filter((test) => globs.some((glob) => matchesTestGlob(test, glob)));
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Groups the Go adapter's test files by their package's directory and maps each changed
|
|
390
|
+
* `testdata/` path to its owning package (`testdata` is excluded from package discovery, so go
|
|
391
|
+
* list cannot report this ownership itself; the go tool runs a package's tests with its
|
|
392
|
+
* directory as the working directory, which is the convention the path follows). Paths that
|
|
393
|
+
* qualify select that package's tests for the changed path instead of full validation; a legacy
|
|
394
|
+
* cached profile without test-package evidence, repository contents being unavailable, a parent
|
|
395
|
+
* directory that is no Go package with tests, `_`-prefixed or `.`-prefixed directories, or
|
|
396
|
+
* another package naming the path or its `testdata` directory by literal reference (its test
|
|
397
|
+
* files or ordinary sources, a helper package with no tests of its own included, or a source
|
|
398
|
+
* module outside the go-reported packages; also, a `_`/`.`-prefixed directory inside the
|
|
399
|
+
* testdata tree) leave the fallback as before.
|
|
400
|
+
*/
|
|
401
|
+
mapGoPackageTestData(delta, profile) {
|
|
402
|
+
this.goPackageTestDataOwner = new Map();
|
|
403
|
+
const byOwner = new Map();
|
|
404
|
+
for (const [test, owner] of Object.entries(profile.goTestPackages ?? {})) {
|
|
405
|
+
if (!test.endsWith("_test.go"))
|
|
406
|
+
continue;
|
|
407
|
+
const tests = byOwner.get(owner);
|
|
408
|
+
if (tests)
|
|
409
|
+
tests.push(test);
|
|
410
|
+
else
|
|
411
|
+
byOwner.set(owner, [test]);
|
|
412
|
+
}
|
|
413
|
+
this.goPackageTestFilesByOwner = byOwner;
|
|
414
|
+
// The current go adapter puts each package's test files into `sourcePaths`, so with source
|
|
415
|
+
// metadata a package's members are exactly its sourcePaths and the test-file grouping only
|
|
416
|
+
// stands in for it.
|
|
417
|
+
this.goSourceFilesByOwner = new Map();
|
|
418
|
+
const knownSources = new Set();
|
|
419
|
+
for (const source of profile.goDependencyPaths?.sources ?? []) {
|
|
420
|
+
knownSources.add(source);
|
|
421
|
+
const dir = source.slice(0, source.lastIndexOf("/"));
|
|
422
|
+
const pkg = dir ? `./${dir}` : ".";
|
|
423
|
+
const members = this.goSourceFilesByOwner.get(pkg);
|
|
424
|
+
if (members)
|
|
425
|
+
members.push(source);
|
|
426
|
+
else
|
|
427
|
+
this.goSourceFilesByOwner.set(pkg, [source]);
|
|
428
|
+
}
|
|
429
|
+
// The cross-package scan checks every go-reported package's readers, not only packages with
|
|
430
|
+
// tests: a helper in an ordinary `.go` file of a package with no tests of its own (the
|
|
431
|
+
// `testutil/golden.go` pattern) can read a package's testdata on behalf of its callers' tests,
|
|
432
|
+
// and such a package never enters the test-file grouping (2026-11-09, review of #85). With
|
|
433
|
+
// source metadata a package's readers are its sourcePaths (which include its test files);
|
|
434
|
+
// legacy cached profiles only ever knew the listed tests, so their entries keep just those.
|
|
435
|
+
this.goReadersByPackage = new Map();
|
|
436
|
+
for (const pkg of new Set([...this.goSourceFilesByOwner.keys(), ...byOwner.keys()])) {
|
|
437
|
+
const sourceFiles = this.goSourceFilesByOwner.get(pkg);
|
|
438
|
+
const testFiles = byOwner.get(pkg);
|
|
439
|
+
if (sourceFiles?.length) {
|
|
440
|
+
this.goReadersByPackage.set(pkg, testFiles?.length ? [...new Set([...sourceFiles, ...testFiles])] : sourceFiles);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
this.goReadersByPackage.set(pkg, testFiles ?? []);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
// And readers outside every go-reported package (tests in nested modules or other languages,
|
|
447
|
+
// ordinary `.go` files excluded from package discovery, and non-test source modules in a mixed
|
|
448
|
+
// repository) can name a package's testdata directly; they run with a different working
|
|
449
|
+
// directory, so the package-owned convention cannot hold and such a reference disqualifies
|
|
450
|
+
// the selective route (2026-11-09, review of #85).
|
|
451
|
+
const reportedGoTests = new Set(Object.keys(profile.goTestPackages ?? {}));
|
|
452
|
+
const pythonSources = new Set(profile.pythonSources ?? []);
|
|
453
|
+
this.goOutsideReaders = new Set((this.sortedRepositoryFiles ?? []).filter(file => !knownSources.has(file) && !reportedGoTests.has(file)
|
|
454
|
+
&& (isSourceFilePath(file) || pythonSources.has(file) || this.isTestFile(file))));
|
|
455
|
+
if (!profile.goTestPackages || !this.readRepositoryFile)
|
|
456
|
+
return this.goPackageTestDataOwner;
|
|
457
|
+
const readRepositoryFile = this.readRepositoryFile;
|
|
458
|
+
for (const path of new Set(delta.files.flatMap(allChangePaths))) {
|
|
459
|
+
const owner = this.goPackageTestDataOwnerFor(path, byOwner, readRepositoryFile);
|
|
460
|
+
if (owner !== undefined)
|
|
461
|
+
this.goPackageTestDataOwner.set(path, owner);
|
|
462
|
+
}
|
|
463
|
+
return this.goPackageTestDataOwner;
|
|
464
|
+
}
|
|
465
|
+
goPackageTestDataOwnerFor(path, byOwner, readRepositoryFile) {
|
|
466
|
+
const segments = path.split("/");
|
|
467
|
+
const at = segments.indexOf("testdata");
|
|
468
|
+
if (at === -1)
|
|
469
|
+
return undefined;
|
|
470
|
+
// An embedded testdata file is a production runtime input, not only test input: it keeps the
|
|
471
|
+
// embed fallback, and never takes the package-owned test data route.
|
|
472
|
+
if (this.goEmbedPaths.has(path))
|
|
473
|
+
return undefined;
|
|
474
|
+
// Only `testdata` gets the package convention: discovery-excluded directory names around it
|
|
475
|
+
// (both on the way to the package and inside the testdata tree) keep the fallback.
|
|
476
|
+
const ignored = (segment) => segment === "" || segment.startsWith("_") || segment.startsWith(".");
|
|
477
|
+
if (segments.slice(0, at).some(ignored) || segments.slice(at + 1).some(ignored))
|
|
478
|
+
return undefined;
|
|
479
|
+
const owner = segments.slice(0, at).length === 0 ? "." : `./${segments.slice(0, at).join("/")}`;
|
|
480
|
+
const tests = byOwner.get(owner);
|
|
481
|
+
if (!tests?.length)
|
|
482
|
+
return undefined;
|
|
483
|
+
const dataDir = [...segments.slice(0, at), "testdata"].join("/");
|
|
484
|
+
const filePattern = referencePattern(referenceTokens(path));
|
|
485
|
+
const dirPattern = referencePattern(referenceTokens(dataDir));
|
|
486
|
+
const disqualifies = (reader) => {
|
|
487
|
+
const content = readRepositoryFile(reader);
|
|
488
|
+
// A listed test file that cannot be read could still name the testdata; without its
|
|
489
|
+
// contents the conservative answer is no selective route at all.
|
|
490
|
+
if (content === undefined)
|
|
491
|
+
return true;
|
|
492
|
+
const references = isGoReaderFile(reader) ? goReaderReferences(content) : content;
|
|
493
|
+
return contentNamesPath(references, reader, path, filePattern, true)
|
|
494
|
+
|| contentNamesPath(references, reader, dataDir, dirPattern, true);
|
|
495
|
+
};
|
|
496
|
+
for (const [pkg, readers] of this.goReadersByPackage) {
|
|
497
|
+
if (pkg === owner)
|
|
498
|
+
continue;
|
|
499
|
+
if (readers.some(disqualifies))
|
|
500
|
+
return undefined;
|
|
501
|
+
}
|
|
502
|
+
// Readers outside the go-reported packages (tests of nested modules or other languages, ordinary
|
|
503
|
+
// `.go` files outside package discovery, non-test source modules in a mixed repository) never
|
|
504
|
+
// take the package-owned convention, since their tests run with a different working directory;
|
|
505
|
+
// a reference there disqualifies the selective route exactly like a cross-package one
|
|
506
|
+
// (2026-11-09, review of #85).
|
|
507
|
+
if ([...this.goOutsideReaders].some(disqualifies))
|
|
508
|
+
return undefined;
|
|
509
|
+
return owner;
|
|
329
510
|
}
|
|
330
511
|
/** Dependents whose tests a change to `path` can affect. When the graph allows runtime selection
|
|
331
512
|
* (DependencyGraphResult.runtimeTestSelection) an `import type` edge selects only type tests. */
|
|
@@ -334,10 +515,59 @@ export class ImpactAnalyzer {
|
|
|
334
515
|
return new Set(dependents);
|
|
335
516
|
const selected = new Set(graph.transitiveRuntimeDependentsOf(path));
|
|
336
517
|
for (const dependent of dependents)
|
|
337
|
-
if (
|
|
518
|
+
if (this.isTypeTest(dependent))
|
|
338
519
|
selected.add(dependent);
|
|
339
520
|
return selected;
|
|
340
521
|
}
|
|
522
|
+
/** Tests among `loaders` whose code reaches `importer` by name, or all of them when the walk does not apply. */
|
|
523
|
+
computedLoadRunners(importer, loaders) {
|
|
524
|
+
const bindings = this.bindings;
|
|
525
|
+
if (!bindings || bindings[importer]?.computedAtLoad || !bindings[importer])
|
|
526
|
+
return loaders;
|
|
527
|
+
return loaders.filter((test) => test === importer || this.isTypeTest(test) || this.reachOf(test, bindings).has(importer));
|
|
528
|
+
}
|
|
529
|
+
reachOf(test, bindings) {
|
|
530
|
+
let reach = this.exportReach.get(test);
|
|
531
|
+
if (!reach) {
|
|
532
|
+
reach = exportLevelReach(test, bindings, (file) => this.runtimeForward.get(file) ?? [], !this.runtimeTestSelection);
|
|
533
|
+
this.exportReach.set(test, reach);
|
|
534
|
+
}
|
|
535
|
+
return reach;
|
|
536
|
+
}
|
|
537
|
+
/** Drops tests whose imports never reach `path` by name (export-reach.ts). Without bindings (older
|
|
538
|
+
* caches) the file-level set stands. */
|
|
539
|
+
exportLevelTests(path, tests, evidence) {
|
|
540
|
+
// Type tests (`*.test-d.ts`, tstyche's `*.tst.ts`) check types, which the walk does not narrow.
|
|
541
|
+
const bindings = this.bindings;
|
|
542
|
+
if (!bindings)
|
|
543
|
+
return tests;
|
|
544
|
+
const kept = new Set();
|
|
545
|
+
const droppedTests = [];
|
|
546
|
+
let reaching = 0;
|
|
547
|
+
for (const test of tests) {
|
|
548
|
+
if (!this.isTestFile(test) || this.isTypeTest(test)) {
|
|
549
|
+
kept.add(test);
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
if (this.reachOf(test, bindings).has(path)) {
|
|
553
|
+
kept.add(test);
|
|
554
|
+
reaching++;
|
|
555
|
+
}
|
|
556
|
+
else
|
|
557
|
+
droppedTests.push(test);
|
|
558
|
+
}
|
|
559
|
+
if (!droppedTests.length)
|
|
560
|
+
return kept;
|
|
561
|
+
// A barrel still loads every module it re-exports, so an error thrown while `path` loads fails every
|
|
562
|
+
// importer, used names or not. Any test that reaches `path` by name shows such an error; when none does,
|
|
563
|
+
// keep one dropped test to load it.
|
|
564
|
+
if (reaching === 0)
|
|
565
|
+
kept.add(droppedTests.sort()[0]);
|
|
566
|
+
const skipped = droppedTests.length - (reaching === 0 ? 1 : 0);
|
|
567
|
+
if (skipped)
|
|
568
|
+
evidence.push(makeEvidence("DEPENDENCY", path, `${skipped} test(s) import ${path} only through re-exports of names they do not use, in side-effect-free packages (export-level selection)${reaching === 0 ? `; ${droppedTests[0]} is kept to load it` : ""}`));
|
|
569
|
+
return kept;
|
|
570
|
+
}
|
|
341
571
|
/** True when nothing in the repository runs a Worker (file-references.ts, suiteMayRunWorkers); false,
|
|
342
572
|
* which keeps wrangler configs global, whenever repository contents are unavailable. */
|
|
343
573
|
workerConfigsOutsideSuite() {
|
|
@@ -361,6 +591,24 @@ export class ImpactAnalyzer {
|
|
|
361
591
|
this.knownTests = undefined;
|
|
362
592
|
this.declaredCovered = new Set();
|
|
363
593
|
this.runtimeTestSelection = graphResult.runtimeTestSelection === true;
|
|
594
|
+
this.typeTestGlobs = graphResult.typeTestGlobs ?? [];
|
|
595
|
+
this.bindings = graphResult.bindings;
|
|
596
|
+
this.exportReach = new Map();
|
|
597
|
+
this.runtimeForward = new Map();
|
|
598
|
+
// Where tests may be type-checked as they run (no runtime test selection: Jest, ts-jest, tstyche, tsd,
|
|
599
|
+
// --typecheck), a type import can fail a test too, so the walk follows it as a whole-module edge.
|
|
600
|
+
if (this.bindings)
|
|
601
|
+
for (const edge of graph.edges) {
|
|
602
|
+
if (edge.kind === "asset" || (edge.kind === "type-import" && this.runtimeTestSelection))
|
|
603
|
+
continue;
|
|
604
|
+
const targets = this.runtimeForward.get(edge.from);
|
|
605
|
+
if (targets) {
|
|
606
|
+
if (!targets.includes(edge.to))
|
|
607
|
+
targets.push(edge.to);
|
|
608
|
+
}
|
|
609
|
+
else
|
|
610
|
+
this.runtimeForward.set(edge.from, [edge.to]);
|
|
611
|
+
}
|
|
364
612
|
this.unresolved = graphResult.unresolved ?? [];
|
|
365
613
|
this.referenceBlockers = new Map();
|
|
366
614
|
this.sortedRepositoryFiles = options.repositoryFiles ? [...options.repositoryFiles].sort() : [];
|
|
@@ -393,17 +641,19 @@ export class ImpactAnalyzer {
|
|
|
393
641
|
}
|
|
394
642
|
const hasGoAdapter = profile.adapters?.some(adapter => adapter.id === "go");
|
|
395
643
|
this.goEmbedPaths = new Set(hasGoAdapter ? profile.goDependencyPaths?.embeds : []);
|
|
644
|
+
const goPackageTestDataOwner = hasGoAdapter ? this.mapGoPackageTestData(delta, profile) : new Map();
|
|
396
645
|
if (hasGoAdapter) {
|
|
397
646
|
// go list models package sources and embeds, not arbitrary runtime reads. Neither a
|
|
398
647
|
// familiar extension/directory nor membership in another adapter's graph proves ownership.
|
|
399
648
|
// Check both identities of renames/copies, including files absent from the HEAD inventory.
|
|
400
649
|
// Missing metadata in older cached profiles deliberately fails closed as well.
|
|
401
650
|
const modeledPaths = new Set([...(profile.goDependencyPaths?.sources ?? []), ...this.goEmbedPaths]);
|
|
402
|
-
const unmodeledPaths = [...new Set(delta.files.flatMap(allChangePaths))]
|
|
651
|
+
const unmodeledPaths = [...new Set(delta.files.flatMap(allChangePaths))]
|
|
652
|
+
.filter(path => !modeledPaths.has(path) && !goPackageTestDataOwner.has(path));
|
|
403
653
|
if (unmodeledPaths.length)
|
|
404
654
|
fallbackReasons.push(`Go runtime inputs outside source/embed metadata require full validation: ${unmodeledPaths.slice(0, 20).join(", ")}`);
|
|
405
655
|
}
|
|
406
|
-
if (hasGoAdapter && delta.files.some(file => allChangePaths(file).some(isGoDiscoveryIgnoredPath))) {
|
|
656
|
+
if (hasGoAdapter && delta.files.some(file => allChangePaths(file).some(path => isGoDiscoveryIgnoredPath(path) && !goPackageTestDataOwner.has(path)))) {
|
|
407
657
|
fallbackReasons.push("Changes in Go discovery-excluded paths require full validation, including runtime test data");
|
|
408
658
|
}
|
|
409
659
|
const excludedGoRoots = profile.goExcludedModuleRoots ?? [];
|
|
@@ -493,6 +743,22 @@ export class ImpactAnalyzer {
|
|
|
493
743
|
if (!fallbackReasons.includes(message))
|
|
494
744
|
fallbackReasons.push(message);
|
|
495
745
|
}
|
|
746
|
+
// The same blind spot inside one workspace package (2026-11-09, Sentry): node-integration-tests runs
|
|
747
|
+
// `vitest run` on `./**/test.ts` from a vite.config.ts DiffCI does not read, so its 277 tests were plain
|
|
748
|
+
// source. A change reaching that package selected none of them, not even the changed one. A changed or
|
|
749
|
+
// affected file inside a package whose own test script runs a framework with no discovered test falls back.
|
|
750
|
+
for (const { packageRoot, profile: child } of profile.workspaceTestPackages ?? []) {
|
|
751
|
+
if (child.testUniverse?.blindSpot !== true)
|
|
752
|
+
continue;
|
|
753
|
+
const prefix = `${packageRoot}/`;
|
|
754
|
+
const reached = [...changedPaths, ...affectedSources.keys(), ...affectedTests.keys()].some((path) => path.startsWith(prefix));
|
|
755
|
+
if (!reached)
|
|
756
|
+
continue;
|
|
757
|
+
const message = `Workspace package ${packageRoot} declares ${child.testUniverse.declaredFrameworks.join(", ")} but no test files were discovered in it; full validation required`;
|
|
758
|
+
riskSignals.push({ level: "critical", reason: "WORKSPACE_TEST_UNIVERSE_EMPTY", message });
|
|
759
|
+
if (!fallbackReasons.includes(message))
|
|
760
|
+
fallbackReasons.push(message);
|
|
761
|
+
}
|
|
496
762
|
// 2026-10-21: affected tests that `npm test` never runs are not part of the full suite, so they are
|
|
497
763
|
// reported beside the selection rather than inside it (src/repo/script-universe.ts). They have
|
|
498
764
|
// already satisfied the changed-test invariant above and are still meant to be run.
|
|
@@ -787,6 +1053,18 @@ export class ImpactAnalyzer {
|
|
|
787
1053
|
this.processAssetChange(changedPath, graph, profile, affectedAssets, affectedEntryPoints, affectedTests, affectedSources, evidence);
|
|
788
1054
|
return;
|
|
789
1055
|
}
|
|
1056
|
+
// A `testdata/` path whose parent directory is a Go package's is conventionally read by that
|
|
1057
|
+
// package's tests. Ownership and cross-references were resolved above, so every path reaching
|
|
1058
|
+
// here selects those tests; the loosened cases (no owner package, cross-package readers,
|
|
1059
|
+
// discovery-excluded directory names) fell back and never reach this route.
|
|
1060
|
+
const goPackageOwner = this.goPackageTestDataOwner.get(changedPath);
|
|
1061
|
+
if (goPackageOwner !== undefined) {
|
|
1062
|
+
evidence.push(makeEvidence("GO_TESTDATA", changedPath, `${changedPath} is testdata of Go package ${goPackageOwner}`));
|
|
1063
|
+
for (const test of this.goPackageTestFilesByOwner.get(goPackageOwner) ?? []) {
|
|
1064
|
+
this.addAffectedTest(changedPath, test, graph, affectedTests, "GO_TESTDATA", evidence);
|
|
1065
|
+
}
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
790
1068
|
// Non-code files are resolved by reference below, directories included; code is not, so a test that
|
|
791
1069
|
// lists the directory a code file is in is added here (file-references.ts, directoryWalkers).
|
|
792
1070
|
if (isSourceFilePath(changedPath) && this.readRepositoryFile) {
|
|
@@ -1129,7 +1407,7 @@ export class ImpactAnalyzer {
|
|
|
1129
1407
|
this.addAffectedEntryPoint(sourcePath, profile, affectedEntryPoints, "NEXT_ENTRY_POINT", sourcePath, evidence);
|
|
1130
1408
|
}
|
|
1131
1409
|
const dependents = graph.transitiveDependentsOf(sourcePath);
|
|
1132
|
-
const testDependents = this.testDependents(graph, sourcePath, dependents);
|
|
1410
|
+
const testDependents = this.exportLevelTests(sourcePath, this.testDependents(graph, sourcePath, dependents), evidence);
|
|
1133
1411
|
for (const dependent of dependents) {
|
|
1134
1412
|
if (!this.isTestFile(dependent)) {
|
|
1135
1413
|
if (!affectedSources.has(dependent))
|
|
@@ -1282,12 +1560,21 @@ export class ImpactAnalyzer {
|
|
|
1282
1560
|
fallbackReasons.push(message);
|
|
1283
1561
|
continue;
|
|
1284
1562
|
}
|
|
1563
|
+
if (graphResult.profile.diffciConfig?.computedImports === "follow-path-literals") {
|
|
1564
|
+
evidence.push(makeEvidence("COMPUTED_IMPORT", importer, `${importer} loads a computed module specifier; the repository declares (diffci.json computedImports: follow-path-literals) that such loads reach only files named by path strings, which are already dependencies`));
|
|
1565
|
+
continue;
|
|
1566
|
+
}
|
|
1285
1567
|
const importerDependents = graph.transitiveDependentsOf(importer);
|
|
1286
1568
|
const testDependents = this.testDependents(graph, importer, importerDependents);
|
|
1287
|
-
const
|
|
1569
|
+
const loaders = [importer, ...importerDependents.filter((path) => testDependents.has(path))].filter((path) => this.isTestFile(path));
|
|
1570
|
+
// A load inside a function runs only when that function's module runs in the test (export-reach.ts):
|
|
1571
|
+
// a test that imports other names from the importer's barrel never calls it. A load at module load
|
|
1572
|
+
// time runs for every test that loads the module, so those keep every dependent.
|
|
1573
|
+
const runners = this.computedLoadRunners(importer, loaders);
|
|
1288
1574
|
for (const test of runners)
|
|
1289
1575
|
this.addAffectedTest(importer, test, graph, affectedTests, "COMPUTED_IMPORT", evidence);
|
|
1290
|
-
|
|
1576
|
+
const skipped = loaders.length - runners.length;
|
|
1577
|
+
evidence.push(makeEvidence("COMPUTED_IMPORT", importer, `${importer} loads a computed module specifier; the ${runners.length} test(s) that run it are selected${skipped ? ` (${skipped} that only load its package through re-exports are not)` : ""}`));
|
|
1291
1578
|
}
|
|
1292
1579
|
}
|
|
1293
1580
|
/** Playwright specs that visit an affected Next.js route (route-visits.ts, 2026-11-06). Without the
|