@diffci.com/diffci 0.3.38 → 0.3.40
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/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 +4 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +20 -7
- 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 +33 -7
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +8 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.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.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/repo/graph.js +512 -41
- 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/test-discovery.js +134 -3
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.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 +22 -7
- package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +32 -7
- package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +5 -0
- 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 +439 -37
- 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/test-discovery.ts +107 -3
- 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
|
@@ -25,6 +25,7 @@ export type ImpactReason =
|
|
|
25
25
|
| "TEST_FIXTURE_OWNER"
|
|
26
26
|
| "ALWAYS_RUN_POLICY"
|
|
27
27
|
| "DECLARED_INPUT"
|
|
28
|
+
| "GO_TESTDATA"
|
|
28
29
|
| "ROUTE_VISIT"
|
|
29
30
|
| "DELETED_FILE_LEGACY_DEPENDENTS"
|
|
30
31
|
| "DELETED_FILE_UNKNOWABLE_GRAPH"
|
|
@@ -33,6 +34,7 @@ export type ImpactReason =
|
|
|
33
34
|
| "DIRECT_TEST_CHANGE"
|
|
34
35
|
| "TEST_SELECTION_INVARIANT"
|
|
35
36
|
| "TEST_UNIVERSE_EMPTY"
|
|
37
|
+
| "WORKSPACE_TEST_UNIVERSE_EMPTY"
|
|
36
38
|
| "EMPTY_DELTA";
|
|
37
39
|
|
|
38
40
|
export interface ImpactEvidencePath {
|
|
@@ -8,22 +8,38 @@ import { refineConfidenceForDelta, relevantScopedAdapterBlockers } from "./graph
|
|
|
8
8
|
import { repositoryLayout, UNKNOWN_REPOSITORY_LAYOUT, type RepositoryLayout } from "./layout.js";
|
|
9
9
|
import { DEFAULT_TEST_FILE_MATCHER, matchesGlob as matchesTestGlob, testDiscoveryErrors, testFileMatcherForProfile } from "./test-discovery.js";
|
|
10
10
|
import { resolveTestFixtureOwners } from "./test-fixture-ownership.js";
|
|
11
|
-
import { compilerConfigNames, directoryWalkers, DIRECTING_EXTENSIONS, infrastructureRole, isAgentConfigurationPath, listsDirectories, loadsWithoutNaming, isImplicitlyLoadedFile, isWorkerConfig, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
|
|
11
|
+
import { compilerConfigNames, contentNamesPath, directoryWalkers, DIRECTING_EXTENSIONS, infrastructureRole, isAgentConfigurationPath, listsDirectories, loadsWithoutNaming, isImplicitlyLoadedFile, isWorkerConfig, referencePattern, referenceTokens, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
|
|
12
12
|
import { workflowFeedsTests } from "./workflow-test-steps.js";
|
|
13
13
|
import { modelTestScriptUniverse, type ScriptUniverse } from "./script-universe.js";
|
|
14
14
|
import { compiledProjects, type CompiledProject } from "./compiled-projects.js";
|
|
15
15
|
import { isPlaywrightSpec, nextAppRoute, routeMatches, visitedRoutes } from "./route-visits.js";
|
|
16
|
+
import { exportLevelReach } from "./export-reach.js";
|
|
17
|
+
import { LOCKFILE } from "./lockfiles.js";
|
|
16
18
|
|
|
17
19
|
const SOURCE_EXTENSIONS = new Set([".ts",".tsx",".js",".jsx",".mjs",".cjs",".mts",".cts",".vue",".go",".java",".kt"]);
|
|
18
20
|
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"]);
|
|
19
21
|
const NEXT_ENTRY_NAMES = new Set(["page","layout","route","api","loading","error","template","not-found","middleware","generatemetadata","generatestaticparams"]);
|
|
20
22
|
|
|
21
23
|
// Lockfiles are reported by the lockfile rule; resolving their readers would only repeat it.
|
|
22
|
-
function isLockfile(filePath: string): boolean { return
|
|
24
|
+
function isLockfile(filePath: string): boolean { return LOCKFILE.test(posix.basename(filePath)); }
|
|
23
25
|
function isSourceFilePath(filePath: string): boolean { return SOURCE_EXTENSIONS.has(extname(filePath).toLowerCase()); }
|
|
24
26
|
function isAssetFilePath(filePath: string): boolean { return ASSET_EXTENSIONS.has(extname(filePath).toLowerCase()); }
|
|
27
|
+
function isGoReaderFile(filePath: string): boolean { return filePath.endsWith(".go"); }
|
|
28
|
+
/**
|
|
29
|
+
* Reads a go reader's references without its import clauses: an import names the package, not any
|
|
30
|
+
* directory inside it, and counting `example.com/project/p` as a reference to a changed `p/...`
|
|
31
|
+
* path would disqualify every sibling package's package-owned testdata route (2026-11-09, review of
|
|
32
|
+
* #85). String literals and call arguments — where a testdata read actually appears — are kept.
|
|
33
|
+
*/
|
|
34
|
+
function goReaderReferences(content: string): string {
|
|
35
|
+
return content
|
|
36
|
+
.replace(/^[ \t]*import[ \t]+[^(){}[\]\n]*\n/gm, "")
|
|
37
|
+
.replace(/^[ \t]*import[ \t]*\([^)]*\)[ \t]*(?:\/\/[^\n]*)?\n/gm, "");
|
|
38
|
+
}
|
|
25
39
|
/** Vitest's default `typecheck.include`: tests whose outcome is the type checker's. */
|
|
26
40
|
const TYPE_TEST_FILE = /\.(?:test|spec)-d\.[cm]?[jt]sx?$/;
|
|
41
|
+
/** tstyche type tests, which type-check whatever they import. */
|
|
42
|
+
const TYPE_CHECK_TEST_FILE = /\.tst\.[cm]?[jt]sx?$/;
|
|
27
43
|
// "Is this a test?" is answered by the profile's test patterns (src/repo/test-discovery.ts) - one shared
|
|
28
44
|
// definition with analyzer discovery and graph node flags. Module-level helpers receive it explicitly.
|
|
29
45
|
type IsTestFile = (filePath: string) => boolean;
|
|
@@ -47,6 +63,7 @@ function isConfigFile(filePath: string): boolean {
|
|
|
47
63
|
if (base.startsWith(".eslintrc")) return true;
|
|
48
64
|
if (base.startsWith("vitest.config")) return true;
|
|
49
65
|
if (base.startsWith("jest.config")) return true;
|
|
66
|
+
if (base.startsWith("babel.config") || base.startsWith(".babelrc")) return true;
|
|
50
67
|
if (base.startsWith("prettier.config")) return true;
|
|
51
68
|
if (base.startsWith(".prettierrc")) return true;
|
|
52
69
|
if (/^\.github\/(?:workflows|actions)\//.test(filePath)) return true;
|
|
@@ -272,12 +289,44 @@ export class ImpactAnalyzer {
|
|
|
272
289
|
private testPhases = new Set<string>();
|
|
273
290
|
private workersOutsideSuite: boolean | undefined;
|
|
274
291
|
private runtimeTestSelection = false;
|
|
292
|
+
private typeTestGlobs: readonly string[] = [];
|
|
293
|
+
/** A file a type-test runner checks: its outcome depends on types, which runtime and export-level selection ignore. */
|
|
294
|
+
private isTypeTest(path: string): boolean {
|
|
295
|
+
return TYPE_TEST_FILE.test(path) || TYPE_CHECK_TEST_FILE.test(path) || this.typeTestGlobs.some((glob) => matchesTestGlob(path, glob));
|
|
296
|
+
}
|
|
297
|
+
/** Export-level bindings (export-reach.ts) and each test's reach under them, per analysis. */
|
|
298
|
+
private bindings: DependencyGraphResult["bindings"];
|
|
299
|
+
private runtimeForward = new Map<string, string[]>();
|
|
300
|
+
private exportReach = new Map<string, Set<string>>();
|
|
275
301
|
private unresolved: readonly UnresolvedDependency[] = [];
|
|
276
302
|
/** Why each changed file the reference resolver could not narrow is unresolvable, for fallbackDetails. */
|
|
277
303
|
private referenceBlockers = new Map<string, string[]>();
|
|
278
304
|
private walkerTests: string[] | undefined;
|
|
279
305
|
private knownTests: string[] | undefined;
|
|
280
306
|
private declaredCovered = new Set<string>();
|
|
307
|
+
/** Go test files grouped by their package's directory value (`profile.goTestPackages` keys are test
|
|
308
|
+
* files; go test files always end `_test.go`). Built once per analysis. */
|
|
309
|
+
private goPackageTestFilesByOwner = new Map<string, string[]>();
|
|
310
|
+
/** Each go-reported package's full file list keyed like `testPackages` (owner itself included). Profiles
|
|
311
|
+
* from the current adapter put a package's test files into `sourcePaths` too, so when this map is
|
|
312
|
+
* populated a package's members are exactly its sourcePaths; legacy cached profiles leave it empty. */
|
|
313
|
+
private goSourceFilesByOwner = new Map<string, string[]>();
|
|
314
|
+
/** Every go-reported package's testdata-reading candidates keyed by its directory: with source
|
|
315
|
+
* metadata the package's members (ordinary sources and test files, a package without tests of its
|
|
316
|
+
* own included — helpers there read other packages' testdata for their callers' tests); legacy
|
|
317
|
+
* cached profiles only ever knew the listed tests. The cross-package scan checks every package's
|
|
318
|
+
* entry except the owner (2026-11-09, review of #85). */
|
|
319
|
+
private goReadersByPackage = new Map<string, string[]>();
|
|
320
|
+
/** Repository files that no go-reported package reported — code outside package discovery whose
|
|
321
|
+
* references to a package's testdata disqualify the selective route like a cross-package one:
|
|
322
|
+
* tests in nested modules or other languages, ordinary `.go` files excluded from package
|
|
323
|
+
* discovery, and non-test source modules in a mixed repository. Their readers run with a
|
|
324
|
+
* different working directory, so the package-owned convention cannot hold for them. */
|
|
325
|
+
private goOutsideReaders = new Set<string>();
|
|
326
|
+
/** A changed `testdata/` path selects its owning package's tests when the parent directory is a Go
|
|
327
|
+
* package with tests and no other package's test file names it by reference; every other
|
|
328
|
+
* discovery-excluded path keeps full validation. */
|
|
329
|
+
private goPackageTestDataOwner = new Map<string, string>();
|
|
281
330
|
|
|
282
331
|
/** Test files known to the graph: nodes matching the profile's test globs or the test-file matcher. */
|
|
283
332
|
private knownTestPaths(profile: RepositoryProfile, graph: DependencyGraph): string[] {
|
|
@@ -301,7 +350,129 @@ export class ImpactAnalyzer {
|
|
|
301
350
|
const inputs = (profile.diffciConfig?.inputs ?? []).filter((input) => input.files.some((glob) => matchesTestGlob(path, glob)));
|
|
302
351
|
if (inputs.length === 0) return undefined;
|
|
303
352
|
const globs = inputs.flatMap((input) => input.tests);
|
|
304
|
-
|
|
353
|
+
// Go profiles declare no test locations (`profile.tests` is a JS-runner notion), so the go
|
|
354
|
+
// adapter's package-reported `_test.go` files join the candidates; without them a declaration
|
|
355
|
+
// naming any Go path is always stale and files the very fallback the declaration was meant to
|
|
356
|
+
// override. They are additional candidates behind globs the repository names - nothing is
|
|
357
|
+
// selected that the declaration did not ask for (2026-11-09, issue #83).
|
|
358
|
+
const goTestCandidates = profile.adapters?.some(adapter => adapter.id === "go")
|
|
359
|
+
? Object.keys(profile.goTestPackages ?? {}).filter(test => test.endsWith("_test.go"))
|
|
360
|
+
: [];
|
|
361
|
+
return [...this.knownTestPaths(profile, graph), ...goTestCandidates].filter((test) => globs.some((glob) => matchesTestGlob(test, glob)));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Groups the Go adapter's test files by their package's directory and maps each changed
|
|
366
|
+
* `testdata/` path to its owning package (`testdata` is excluded from package discovery, so go
|
|
367
|
+
* list cannot report this ownership itself; the go tool runs a package's tests with its
|
|
368
|
+
* directory as the working directory, which is the convention the path follows). Paths that
|
|
369
|
+
* qualify select that package's tests for the changed path instead of full validation; a legacy
|
|
370
|
+
* cached profile without test-package evidence, repository contents being unavailable, a parent
|
|
371
|
+
* directory that is no Go package with tests, `_`-prefixed or `.`-prefixed directories, or
|
|
372
|
+
* another package naming the path or its `testdata` directory by literal reference (its test
|
|
373
|
+
* files or ordinary sources, a helper package with no tests of its own included, or a source
|
|
374
|
+
* module outside the go-reported packages; also, a `_`/`.`-prefixed directory inside the
|
|
375
|
+
* testdata tree) leave the fallback as before.
|
|
376
|
+
*/
|
|
377
|
+
private mapGoPackageTestData(delta: GitDelta, profile: RepositoryProfile): Map<string, string> {
|
|
378
|
+
this.goPackageTestDataOwner = new Map();
|
|
379
|
+
const byOwner = new Map<string, string[]>();
|
|
380
|
+
for (const [test, owner] of Object.entries(profile.goTestPackages ?? {})) {
|
|
381
|
+
if (!test.endsWith("_test.go")) continue;
|
|
382
|
+
const tests = byOwner.get(owner);
|
|
383
|
+
if (tests) tests.push(test);
|
|
384
|
+
else byOwner.set(owner, [test]);
|
|
385
|
+
}
|
|
386
|
+
this.goPackageTestFilesByOwner = byOwner;
|
|
387
|
+
// The current go adapter puts each package's test files into `sourcePaths`, so with source
|
|
388
|
+
// metadata a package's members are exactly its sourcePaths and the test-file grouping only
|
|
389
|
+
// stands in for it.
|
|
390
|
+
this.goSourceFilesByOwner = new Map<string, string[]>();
|
|
391
|
+
const knownSources = new Set<string>();
|
|
392
|
+
for (const source of profile.goDependencyPaths?.sources ?? []) {
|
|
393
|
+
knownSources.add(source);
|
|
394
|
+
const dir = source.slice(0, source.lastIndexOf("/"));
|
|
395
|
+
const pkg = dir ? `./${dir}` : ".";
|
|
396
|
+
const members = this.goSourceFilesByOwner.get(pkg);
|
|
397
|
+
if (members) members.push(source);
|
|
398
|
+
else this.goSourceFilesByOwner.set(pkg, [source]);
|
|
399
|
+
}
|
|
400
|
+
// The cross-package scan checks every go-reported package's readers, not only packages with
|
|
401
|
+
// tests: a helper in an ordinary `.go` file of a package with no tests of its own (the
|
|
402
|
+
// `testutil/golden.go` pattern) can read a package's testdata on behalf of its callers' tests,
|
|
403
|
+
// and such a package never enters the test-file grouping (2026-11-09, review of #85). With
|
|
404
|
+
// source metadata a package's readers are its sourcePaths (which include its test files);
|
|
405
|
+
// legacy cached profiles only ever knew the listed tests, so their entries keep just those.
|
|
406
|
+
this.goReadersByPackage = new Map();
|
|
407
|
+
for (const pkg of new Set([...this.goSourceFilesByOwner.keys(), ...byOwner.keys()])) {
|
|
408
|
+
const sourceFiles = this.goSourceFilesByOwner.get(pkg);
|
|
409
|
+
const testFiles = byOwner.get(pkg);
|
|
410
|
+
if (sourceFiles?.length) {
|
|
411
|
+
this.goReadersByPackage.set(pkg, testFiles?.length ? [...new Set([...sourceFiles, ...testFiles])] : sourceFiles);
|
|
412
|
+
} else {
|
|
413
|
+
this.goReadersByPackage.set(pkg, testFiles ?? []);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
// And readers outside every go-reported package (tests in nested modules or other languages,
|
|
417
|
+
// ordinary `.go` files excluded from package discovery, and non-test source modules in a mixed
|
|
418
|
+
// repository) can name a package's testdata directly; they run with a different working
|
|
419
|
+
// directory, so the package-owned convention cannot hold and such a reference disqualifies
|
|
420
|
+
// the selective route (2026-11-09, review of #85).
|
|
421
|
+
const reportedGoTests = new Set(Object.keys(profile.goTestPackages ?? {}));
|
|
422
|
+
const pythonSources = new Set(profile.pythonSources ?? []);
|
|
423
|
+
this.goOutsideReaders = new Set((this.sortedRepositoryFiles ?? []).filter(file =>
|
|
424
|
+
!knownSources.has(file) && !reportedGoTests.has(file)
|
|
425
|
+
&& (isSourceFilePath(file) || pythonSources.has(file) || this.isTestFile(file))));
|
|
426
|
+
if (!profile.goTestPackages || !this.readRepositoryFile) return this.goPackageTestDataOwner;
|
|
427
|
+
const readRepositoryFile = this.readRepositoryFile;
|
|
428
|
+
for (const path of new Set(delta.files.flatMap(allChangePaths))) {
|
|
429
|
+
const owner = this.goPackageTestDataOwnerFor(path, byOwner, readRepositoryFile);
|
|
430
|
+
if (owner !== undefined) this.goPackageTestDataOwner.set(path, owner);
|
|
431
|
+
}
|
|
432
|
+
return this.goPackageTestDataOwner;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
private goPackageTestDataOwnerFor(
|
|
436
|
+
path: string,
|
|
437
|
+
byOwner: ReadonlyMap<string, string[]>,
|
|
438
|
+
readRepositoryFile: (path: string) => string | undefined,
|
|
439
|
+
): string | undefined {
|
|
440
|
+
const segments = path.split("/");
|
|
441
|
+
const at = segments.indexOf("testdata");
|
|
442
|
+
if (at === -1) return undefined;
|
|
443
|
+
// An embedded testdata file is a production runtime input, not only test input: it keeps the
|
|
444
|
+
// embed fallback, and never takes the package-owned test data route.
|
|
445
|
+
if (this.goEmbedPaths.has(path)) return undefined;
|
|
446
|
+
// Only `testdata` gets the package convention: discovery-excluded directory names around it
|
|
447
|
+
// (both on the way to the package and inside the testdata tree) keep the fallback.
|
|
448
|
+
const ignored = (segment: string) => segment === "" || segment.startsWith("_") || segment.startsWith(".");
|
|
449
|
+
if (segments.slice(0, at).some(ignored) || segments.slice(at + 1).some(ignored)) return undefined;
|
|
450
|
+
const owner = segments.slice(0, at).length === 0 ? "." : `./${segments.slice(0, at).join("/")}`;
|
|
451
|
+
const tests = byOwner.get(owner);
|
|
452
|
+
if (!tests?.length) return undefined;
|
|
453
|
+
const dataDir = [...segments.slice(0, at), "testdata"].join("/");
|
|
454
|
+
const filePattern = referencePattern(referenceTokens(path));
|
|
455
|
+
const dirPattern = referencePattern(referenceTokens(dataDir));
|
|
456
|
+
const disqualifies = (reader: string): boolean => {
|
|
457
|
+
const content = readRepositoryFile(reader);
|
|
458
|
+
// A listed test file that cannot be read could still name the testdata; without its
|
|
459
|
+
// contents the conservative answer is no selective route at all.
|
|
460
|
+
if (content === undefined) return true;
|
|
461
|
+
const references = isGoReaderFile(reader) ? goReaderReferences(content) : content;
|
|
462
|
+
return contentNamesPath(references, reader, path, filePattern, true)
|
|
463
|
+
|| contentNamesPath(references, reader, dataDir, dirPattern, true);
|
|
464
|
+
};
|
|
465
|
+
for (const [pkg, readers] of this.goReadersByPackage) {
|
|
466
|
+
if (pkg === owner) continue;
|
|
467
|
+
if (readers.some(disqualifies)) return undefined;
|
|
468
|
+
}
|
|
469
|
+
// Readers outside the go-reported packages (tests of nested modules or other languages, ordinary
|
|
470
|
+
// `.go` files outside package discovery, non-test source modules in a mixed repository) never
|
|
471
|
+
// take the package-owned convention, since their tests run with a different working directory;
|
|
472
|
+
// a reference there disqualifies the selective route exactly like a cross-package one
|
|
473
|
+
// (2026-11-09, review of #85).
|
|
474
|
+
if ([...this.goOutsideReaders].some(disqualifies)) return undefined;
|
|
475
|
+
return owner;
|
|
305
476
|
}
|
|
306
477
|
|
|
307
478
|
/** Dependents whose tests a change to `path` can affect. When the graph allows runtime selection
|
|
@@ -309,10 +480,49 @@ export class ImpactAnalyzer {
|
|
|
309
480
|
private testDependents(graph: DependencyGraph, path: string, dependents: readonly string[]): ReadonlySet<string> {
|
|
310
481
|
if (!this.runtimeTestSelection || !graph.transitiveRuntimeDependentsOf) return new Set(dependents);
|
|
311
482
|
const selected = new Set(graph.transitiveRuntimeDependentsOf(path));
|
|
312
|
-
for (const dependent of dependents) if (
|
|
483
|
+
for (const dependent of dependents) if (this.isTypeTest(dependent)) selected.add(dependent);
|
|
313
484
|
return selected;
|
|
314
485
|
}
|
|
315
486
|
|
|
487
|
+
/** Tests among `loaders` whose code reaches `importer` by name, or all of them when the walk does not apply. */
|
|
488
|
+
private computedLoadRunners(importer: string, loaders: string[]): string[] {
|
|
489
|
+
const bindings = this.bindings;
|
|
490
|
+
if (!bindings || bindings[importer]?.computedAtLoad || !bindings[importer]) return loaders;
|
|
491
|
+
return loaders.filter((test) => test === importer || this.isTypeTest(test) || this.reachOf(test, bindings).has(importer));
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
private reachOf(test: string, bindings: NonNullable<DependencyGraphResult["bindings"]>): Set<string> {
|
|
495
|
+
let reach = this.exportReach.get(test);
|
|
496
|
+
if (!reach) {
|
|
497
|
+
reach = exportLevelReach(test, bindings, (file) => this.runtimeForward.get(file) ?? [], !this.runtimeTestSelection);
|
|
498
|
+
this.exportReach.set(test, reach);
|
|
499
|
+
}
|
|
500
|
+
return reach;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/** Drops tests whose imports never reach `path` by name (export-reach.ts). Without bindings (older
|
|
504
|
+
* caches) the file-level set stands. */
|
|
505
|
+
private exportLevelTests(path: string, tests: ReadonlySet<string>, evidence: ImpactEvidence[]): ReadonlySet<string> {
|
|
506
|
+
// Type tests (`*.test-d.ts`, tstyche's `*.tst.ts`) check types, which the walk does not narrow.
|
|
507
|
+
const bindings = this.bindings;
|
|
508
|
+
if (!bindings) return tests;
|
|
509
|
+
const kept = new Set<string>();
|
|
510
|
+
const droppedTests: string[] = [];
|
|
511
|
+
let reaching = 0;
|
|
512
|
+
for (const test of tests) {
|
|
513
|
+
if (!this.isTestFile(test) || this.isTypeTest(test)) { kept.add(test); continue; }
|
|
514
|
+
if (this.reachOf(test, bindings).has(path)) { kept.add(test); reaching++; } else droppedTests.push(test);
|
|
515
|
+
}
|
|
516
|
+
if (!droppedTests.length) return kept;
|
|
517
|
+
// A barrel still loads every module it re-exports, so an error thrown while `path` loads fails every
|
|
518
|
+
// importer, used names or not. Any test that reaches `path` by name shows such an error; when none does,
|
|
519
|
+
// keep one dropped test to load it.
|
|
520
|
+
if (reaching === 0) kept.add(droppedTests.sort()[0]!);
|
|
521
|
+
const skipped = droppedTests.length - (reaching === 0 ? 1 : 0);
|
|
522
|
+
if (skipped) 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` : ""}`));
|
|
523
|
+
return kept;
|
|
524
|
+
}
|
|
525
|
+
|
|
316
526
|
/** True when nothing in the repository runs a Worker (file-references.ts, suiteMayRunWorkers); false,
|
|
317
527
|
* which keeps wrangler configs global, whenever repository contents are unavailable. */
|
|
318
528
|
private workerConfigsOutsideSuite(): boolean {
|
|
@@ -337,6 +547,17 @@ export class ImpactAnalyzer {
|
|
|
337
547
|
this.knownTests = undefined;
|
|
338
548
|
this.declaredCovered = new Set();
|
|
339
549
|
this.runtimeTestSelection = graphResult.runtimeTestSelection === true;
|
|
550
|
+
this.typeTestGlobs = graphResult.typeTestGlobs ?? [];
|
|
551
|
+
this.bindings = graphResult.bindings;
|
|
552
|
+
this.exportReach = new Map();
|
|
553
|
+
this.runtimeForward = new Map();
|
|
554
|
+
// Where tests may be type-checked as they run (no runtime test selection: Jest, ts-jest, tstyche, tsd,
|
|
555
|
+
// --typecheck), a type import can fail a test too, so the walk follows it as a whole-module edge.
|
|
556
|
+
if (this.bindings) for (const edge of graph.edges) {
|
|
557
|
+
if (edge.kind === "asset" || (edge.kind === "type-import" && this.runtimeTestSelection)) continue;
|
|
558
|
+
const targets = this.runtimeForward.get(edge.from);
|
|
559
|
+
if (targets) { if (!targets.includes(edge.to)) targets.push(edge.to); } else this.runtimeForward.set(edge.from, [edge.to]);
|
|
560
|
+
}
|
|
340
561
|
this.unresolved = graphResult.unresolved ?? [];
|
|
341
562
|
this.referenceBlockers = new Map();
|
|
342
563
|
this.sortedRepositoryFiles = options.repositoryFiles ? [...options.repositoryFiles].sort() : [];
|
|
@@ -366,16 +587,18 @@ export class ImpactAnalyzer {
|
|
|
366
587
|
}
|
|
367
588
|
const hasGoAdapter = profile.adapters?.some(adapter => adapter.id === "go");
|
|
368
589
|
this.goEmbedPaths = new Set(hasGoAdapter ? profile.goDependencyPaths?.embeds : []);
|
|
590
|
+
const goPackageTestDataOwner = hasGoAdapter ? this.mapGoPackageTestData(delta, profile) : new Map<string, string>();
|
|
369
591
|
if (hasGoAdapter) {
|
|
370
592
|
// go list models package sources and embeds, not arbitrary runtime reads. Neither a
|
|
371
593
|
// familiar extension/directory nor membership in another adapter's graph proves ownership.
|
|
372
594
|
// Check both identities of renames/copies, including files absent from the HEAD inventory.
|
|
373
595
|
// Missing metadata in older cached profiles deliberately fails closed as well.
|
|
374
596
|
const modeledPaths = new Set([...(profile.goDependencyPaths?.sources ?? []), ...this.goEmbedPaths]);
|
|
375
|
-
const unmodeledPaths = [...new Set(delta.files.flatMap(allChangePaths))]
|
|
597
|
+
const unmodeledPaths = [...new Set(delta.files.flatMap(allChangePaths))]
|
|
598
|
+
.filter(path => !modeledPaths.has(path) && !goPackageTestDataOwner.has(path));
|
|
376
599
|
if (unmodeledPaths.length) fallbackReasons.push(`Go runtime inputs outside source/embed metadata require full validation: ${unmodeledPaths.slice(0, 20).join(", ")}`);
|
|
377
600
|
}
|
|
378
|
-
if (hasGoAdapter && delta.files.some(file => allChangePaths(file).some(isGoDiscoveryIgnoredPath))) {
|
|
601
|
+
if (hasGoAdapter && delta.files.some(file => allChangePaths(file).some(path => isGoDiscoveryIgnoredPath(path) && !goPackageTestDataOwner.has(path)))) {
|
|
379
602
|
fallbackReasons.push("Changes in Go discovery-excluded paths require full validation, including runtime test data");
|
|
380
603
|
}
|
|
381
604
|
const excludedGoRoots = profile.goExcludedModuleRoots ?? [];
|
|
@@ -468,6 +691,20 @@ export class ImpactAnalyzer {
|
|
|
468
691
|
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
469
692
|
}
|
|
470
693
|
|
|
694
|
+
// The same blind spot inside one workspace package (2026-11-09, Sentry): node-integration-tests runs
|
|
695
|
+
// `vitest run` on `./**/test.ts` from a vite.config.ts DiffCI does not read, so its 277 tests were plain
|
|
696
|
+
// source. A change reaching that package selected none of them, not even the changed one. A changed or
|
|
697
|
+
// affected file inside a package whose own test script runs a framework with no discovered test falls back.
|
|
698
|
+
for (const { packageRoot, profile: child } of profile.workspaceTestPackages ?? []) {
|
|
699
|
+
if (child.testUniverse?.blindSpot !== true) continue;
|
|
700
|
+
const prefix = `${packageRoot}/`;
|
|
701
|
+
const reached = [...changedPaths, ...affectedSources.keys(), ...affectedTests.keys()].some((path) => path.startsWith(prefix));
|
|
702
|
+
if (!reached) continue;
|
|
703
|
+
const message = `Workspace package ${packageRoot} declares ${child.testUniverse.declaredFrameworks.join(", ")} but no test files were discovered in it; full validation required`;
|
|
704
|
+
riskSignals.push({ level: "critical", reason: "WORKSPACE_TEST_UNIVERSE_EMPTY", message });
|
|
705
|
+
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
706
|
+
}
|
|
707
|
+
|
|
471
708
|
// 2026-10-21: affected tests that `npm test` never runs are not part of the full suite, so they are
|
|
472
709
|
// reported beside the selection rather than inside it (src/repo/script-universe.ts). They have
|
|
473
710
|
// already satisfied the changed-test invariant above and are still meant to be run.
|
|
@@ -779,6 +1016,18 @@ export class ImpactAnalyzer {
|
|
|
779
1016
|
this.processAssetChange(changedPath, graph, profile, affectedAssets, affectedEntryPoints, affectedTests, affectedSources, evidence);
|
|
780
1017
|
return;
|
|
781
1018
|
}
|
|
1019
|
+
// A `testdata/` path whose parent directory is a Go package's is conventionally read by that
|
|
1020
|
+
// package's tests. Ownership and cross-references were resolved above, so every path reaching
|
|
1021
|
+
// here selects those tests; the loosened cases (no owner package, cross-package readers,
|
|
1022
|
+
// discovery-excluded directory names) fell back and never reach this route.
|
|
1023
|
+
const goPackageOwner = this.goPackageTestDataOwner.get(changedPath);
|
|
1024
|
+
if (goPackageOwner !== undefined) {
|
|
1025
|
+
evidence.push(makeEvidence("GO_TESTDATA", changedPath, `${changedPath} is testdata of Go package ${goPackageOwner}`));
|
|
1026
|
+
for (const test of this.goPackageTestFilesByOwner.get(goPackageOwner) ?? []) {
|
|
1027
|
+
this.addAffectedTest(changedPath, test, graph, affectedTests, "GO_TESTDATA", evidence);
|
|
1028
|
+
}
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
782
1031
|
// Non-code files are resolved by reference below, directories included; code is not, so a test that
|
|
783
1032
|
// lists the directory a code file is in is added here (file-references.ts, directoryWalkers).
|
|
784
1033
|
if (isSourceFilePath(changedPath) && this.readRepositoryFile) {
|
|
@@ -1120,7 +1369,7 @@ export class ImpactAnalyzer {
|
|
|
1120
1369
|
}
|
|
1121
1370
|
|
|
1122
1371
|
const dependents = graph.transitiveDependentsOf(sourcePath);
|
|
1123
|
-
const testDependents = this.testDependents(graph, sourcePath, dependents);
|
|
1372
|
+
const testDependents = this.exportLevelTests(sourcePath, this.testDependents(graph, sourcePath, dependents), evidence);
|
|
1124
1373
|
for (const dependent of dependents) {
|
|
1125
1374
|
if (!this.isTestFile(dependent)) {
|
|
1126
1375
|
if (!affectedSources.has(dependent)) affectedSources.set(dependent, []);
|
|
@@ -1316,11 +1565,20 @@ export class ImpactAnalyzer {
|
|
|
1316
1565
|
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
1317
1566
|
continue;
|
|
1318
1567
|
}
|
|
1568
|
+
if (graphResult.profile.diffciConfig?.computedImports === "follow-path-literals") {
|
|
1569
|
+
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`));
|
|
1570
|
+
continue;
|
|
1571
|
+
}
|
|
1319
1572
|
const importerDependents = graph.transitiveDependentsOf(importer);
|
|
1320
1573
|
const testDependents = this.testDependents(graph, importer, importerDependents);
|
|
1321
|
-
const
|
|
1574
|
+
const loaders = [importer, ...importerDependents.filter((path) => testDependents.has(path))].filter((path) => this.isTestFile(path));
|
|
1575
|
+
// A load inside a function runs only when that function's module runs in the test (export-reach.ts):
|
|
1576
|
+
// a test that imports other names from the importer's barrel never calls it. A load at module load
|
|
1577
|
+
// time runs for every test that loads the module, so those keep every dependent.
|
|
1578
|
+
const runners = this.computedLoadRunners(importer, loaders);
|
|
1322
1579
|
for (const test of runners) this.addAffectedTest(importer, test, graph, affectedTests, "COMPUTED_IMPORT", evidence);
|
|
1323
|
-
|
|
1580
|
+
const skipped = loaders.length - runners.length;
|
|
1581
|
+
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)` : ""}`));
|
|
1324
1582
|
}
|
|
1325
1583
|
}
|
|
1326
1584
|
|
|
@@ -8,3 +8,16 @@
|
|
|
8
8
|
* alone still forced the full suite. Sharing this constant keeps the signals in agreement.
|
|
9
9
|
*/
|
|
10
10
|
export const LOCKFILE = /^(?:package-lock\.json|npm-shrinkwrap\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb?)$/;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The same lockfiles as names, for code that needs the files rather than a regex (issue #97). Every name
|
|
14
|
+
* here matches `LOCKFILE`, and `tests/repo/lockfiles.test.ts` checks that the two stay in agreement.
|
|
15
|
+
*/
|
|
16
|
+
export const LOCKFILE_NAMES: readonly string[] = [
|
|
17
|
+
"package-lock.json",
|
|
18
|
+
"npm-shrinkwrap.json",
|
|
19
|
+
"pnpm-lock.yaml",
|
|
20
|
+
"yarn.lock",
|
|
21
|
+
"bun.lock",
|
|
22
|
+
"bun.lockb",
|
|
23
|
+
];
|
|
@@ -45,6 +45,11 @@ export interface DiffCiRepositoryConfig {
|
|
|
45
45
|
vue?: { packageRoot: string; testConfig: string };
|
|
46
46
|
/** Match the Maven lifecycle and profiles used by this repository's CI job. */
|
|
47
47
|
maven?: { goal: "test" | "verify"; profiles?: string[] };
|
|
48
|
+
/** How a computed `import(name)` selects tests. Absent (the default): every test that runs the load. With
|
|
49
|
+
* "follow-path-literals" the repository states that its computed loads reach only files named by path
|
|
50
|
+
* strings in its code, which the graph already follows as `path-literal` edges, so the load selects
|
|
51
|
+
* nothing more (2026-11-10, payloadcms/payload's `dynamicImport` of test-named configs). */
|
|
52
|
+
computedImports?: "follow-path-literals";
|
|
48
53
|
configurationError?: string;
|
|
49
54
|
}
|
|
50
55
|
|
|
@@ -88,6 +93,8 @@ function parseConfig(raw: unknown): DiffCiRepositoryConfig {
|
|
|
88
93
|
: inputs !== undefined && !validInputs ? { configurationError: "Invalid inputs: each entry needs non-empty files and tests glob lists" } : {}),
|
|
89
94
|
...(go?.scope === "root-module" ? { go: { scope: "root-module" as const } } : {}),
|
|
90
95
|
...(validVue ? { vue: { packageRoot: vue.packageRoot as string, testConfig: vue.testConfig as string } } : record.vue !== undefined ? { configurationError: "Invalid Vue package/suite scope" } : {}),
|
|
96
|
+
...(record.computedImports === "follow-path-literals" ? { computedImports: "follow-path-literals" as const }
|
|
97
|
+
: record.computedImports !== undefined ? { configurationError: "Invalid computedImports: the only supported value is follow-path-literals" } : {}),
|
|
91
98
|
...(validMaven ? { maven: { goal: maven.goal as "test" | "verify", ...(maven.profiles ? { profiles: maven.profiles as string[] } : {}) } } : record.maven !== undefined ? { configurationError: "Invalid Maven lifecycle goal or profiles" } : {}),
|
|
92
99
|
};
|
|
93
100
|
}
|
|
@@ -100,7 +107,7 @@ export function readRepositoryConfig(repoPath: string, packageJson?: Record<stri
|
|
|
100
107
|
const dedicated = readJsonFile(join(repoPath, "diffci.json"));
|
|
101
108
|
if (dedicated) {
|
|
102
109
|
const parsed = parseConfig(dedicated);
|
|
103
|
-
if (parsed.alwaysRunTests || parsed.inputs || parsed.go || parsed.vue || parsed.maven || parsed.configurationError) return parsed;
|
|
110
|
+
if (parsed.alwaysRunTests || parsed.inputs || parsed.go || parsed.vue || parsed.maven || parsed.computedImports || parsed.configurationError) return parsed;
|
|
104
111
|
}
|
|
105
112
|
const pkg = packageJson ?? readJsonFile(join(repoPath, "package.json"));
|
|
106
113
|
return parseConfig(pkg?.diffci);
|
|
@@ -64,11 +64,115 @@ export interface TestRunnerConfig {
|
|
|
64
64
|
authoritative: boolean;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
const PATH_MODULES = new Set(["path", "node:path", "path/posix", "node:path/posix"]);
|
|
68
|
+
const URL_MODULES = new Set(["url", "node:url"]);
|
|
69
|
+
|
|
70
|
+
/** Recognises expressions that evaluate to the directory holding the config file, which discovery already
|
|
71
|
+
* treats as the root (configs are read from the directory their globs are relative to): `__dirname`,
|
|
72
|
+
* `import.meta.dirname`, `dirname(fileURLToPath(import.meta.url))`, `fileURLToPath(new URL(".", import.meta.url))`
|
|
73
|
+
* and `resolve(<one of these>)`, possibly through a top-level `const`. `dirname`, `resolve` and
|
|
74
|
+
* `fileURLToPath` count only when imported from node:path / node:url (named, default or namespace), so a
|
|
75
|
+
* local function of the same name stays unsupported. Paperclip's packages/tailscale-https-broker sets
|
|
76
|
+
* `root` this way (2026-11-11), and every change in the repository planned FULL. */
|
|
77
|
+
function configDirectoryMatcher(ast: ts.SourceFile): (node: ts.Expression) => boolean {
|
|
78
|
+
const named = new Map<string, string>(); // local name -> "dirname" | "resolve" | "fileURLToPath"
|
|
79
|
+
const namespaces = new Map<string, "path" | "url">();
|
|
80
|
+
const constants = new Map<string, ts.Expression>();
|
|
81
|
+
const shadowed = new Set<string>();
|
|
82
|
+
for (const statement of ast.statements) {
|
|
83
|
+
if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier) && statement.importClause && !statement.importClause.isTypeOnly) {
|
|
84
|
+
const module = statement.moduleSpecifier.text;
|
|
85
|
+
const kind = PATH_MODULES.has(module) ? "path" : URL_MODULES.has(module) ? "url" : undefined;
|
|
86
|
+
if (!kind) continue;
|
|
87
|
+
const clause = statement.importClause;
|
|
88
|
+
if (clause.name) namespaces.set(clause.name.text, kind);
|
|
89
|
+
const bindings = clause.namedBindings;
|
|
90
|
+
if (bindings && ts.isNamespaceImport(bindings)) namespaces.set(bindings.name.text, kind);
|
|
91
|
+
if (bindings && ts.isNamedImports(bindings)) for (const element of bindings.elements) {
|
|
92
|
+
const imported = (element.propertyName ?? element.name).text;
|
|
93
|
+
if (kind === "path" && (imported === "dirname" || imported === "resolve") || kind === "url" && imported === "fileURLToPath") named.set(element.name.text, imported);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (ts.isVariableStatement(statement) && statement.declarationList.flags & ts.NodeFlags.Const) {
|
|
97
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
98
|
+
if (ts.isIdentifier(declaration.name) && declaration.initializer) constants.set(declaration.name.text, declaration.initializer);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (ts.isFunctionDeclaration(statement) && statement.name) shadowed.add(statement.name.text);
|
|
102
|
+
}
|
|
103
|
+
// A name declared more than once (an inner variable, parameter or function shadowing the top-level
|
|
104
|
+
// binding or import) could mean something else where it is used, so it is not trusted.
|
|
105
|
+
const declarations = new Map<string, number>();
|
|
106
|
+
const count = (name: ts.Node) => { if (ts.isIdentifier(name)) declarations.set(name.text, (declarations.get(name.text) ?? 0) + 1); };
|
|
107
|
+
const collect = (node: ts.Node): void => {
|
|
108
|
+
if ((ts.isVariableDeclaration(node) || ts.isParameter(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)
|
|
109
|
+
|| ts.isImportSpecifier(node) || ts.isNamespaceImport(node) || ts.isBindingElement(node)) && node.name) count(node.name);
|
|
110
|
+
if (ts.isImportClause(node) && node.name) count(node.name);
|
|
111
|
+
ts.forEachChild(node, collect);
|
|
112
|
+
};
|
|
113
|
+
collect(ast);
|
|
114
|
+
for (const [name, total] of declarations) if (total > 1) shadowed.add(name);
|
|
115
|
+
for (const name of shadowed) { named.delete(name); namespaces.delete(name); constants.delete(name); }
|
|
116
|
+
const unwrap = (node: ts.Expression): ts.Expression => {
|
|
117
|
+
while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isNonNullExpression(node)) node = node.expression;
|
|
118
|
+
return node;
|
|
119
|
+
};
|
|
120
|
+
const importMeta = (node: ts.Expression, property: string) => ts.isPropertyAccessExpression(node) && node.name.text === property
|
|
121
|
+
&& ts.isMetaProperty(node.expression) && node.expression.keywordToken === ts.SyntaxKind.ImportKeyword && node.expression.name.text === "meta";
|
|
122
|
+
const callee = (node: ts.Expression): string | undefined => {
|
|
123
|
+
node = unwrap(node);
|
|
124
|
+
if (ts.isIdentifier(node)) return named.get(node.text);
|
|
125
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)) {
|
|
126
|
+
const kind = namespaces.get(node.expression.text);
|
|
127
|
+
const name = node.name.text;
|
|
128
|
+
if (kind === "path" && (name === "dirname" || name === "resolve") || kind === "url" && name === "fileURLToPath") return name;
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
};
|
|
132
|
+
const isFile = (node: ts.Expression, depth = 0): boolean => {
|
|
133
|
+
node = unwrap(node);
|
|
134
|
+
if (depth > 4) return false;
|
|
135
|
+
if (ts.isIdentifier(node)) {
|
|
136
|
+
if (node.text === "__filename" && !declarations.has("__filename")) return true;
|
|
137
|
+
const value = constants.get(node.text);
|
|
138
|
+
return value !== undefined && isFile(value, depth + 1);
|
|
139
|
+
}
|
|
140
|
+
if (importMeta(node, "filename")) return true;
|
|
141
|
+
return ts.isCallExpression(node) && callee(node.expression) === "fileURLToPath" && node.arguments.length === 1 && importMeta(unwrap(node.arguments[0]!), "url");
|
|
142
|
+
};
|
|
143
|
+
const isDirectory = (node: ts.Expression, depth = 0): boolean => {
|
|
144
|
+
node = unwrap(node);
|
|
145
|
+
if (depth > 4) return false;
|
|
146
|
+
if ((ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) && [".", "./", "./."].includes(node.text)) return true;
|
|
147
|
+
if (ts.isIdentifier(node)) {
|
|
148
|
+
if (node.text === "__dirname" && !declarations.has("__dirname")) return true;
|
|
149
|
+
const value = constants.get(node.text);
|
|
150
|
+
return value !== undefined && isDirectory(value, depth + 1);
|
|
151
|
+
}
|
|
152
|
+
if (importMeta(node, "dirname")) return true;
|
|
153
|
+
if (!ts.isCallExpression(node)) return false;
|
|
154
|
+
const name = callee(node.expression);
|
|
155
|
+
const args = node.arguments;
|
|
156
|
+
if (name === "dirname") return args.length === 1 && isFile(args[0]!);
|
|
157
|
+
if (name === "resolve") return args.length >= 1 && isDirectory(args[0]!, depth + 1)
|
|
158
|
+
&& args.slice(1).every(arg => { const a = unwrap(arg); return (ts.isStringLiteral(a) || ts.isNoSubstitutionTemplateLiteral(a)) && [".", "./"].includes(a.text); });
|
|
159
|
+
if (name === "fileURLToPath" && args.length === 1) {
|
|
160
|
+
const url = unwrap(args[0]!);
|
|
161
|
+
return ts.isNewExpression(url) && ts.isIdentifier(url.expression) && url.expression.text === "URL" && url.arguments?.length === 2
|
|
162
|
+
&& ts.isStringLiteral(unwrap(url.arguments[0]!)) && [".", "./"].includes((unwrap(url.arguments[0]!) as ts.StringLiteral).text)
|
|
163
|
+
&& importMeta(unwrap(url.arguments[1]!), "url");
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
};
|
|
167
|
+
return (node) => isDirectory(node);
|
|
168
|
+
}
|
|
169
|
+
|
|
67
170
|
/** Root-relative patterns cannot be interpreted as repository-relative patterns. Keep
|
|
68
171
|
* default roots supported, but require full validation for roots we do not resolve. */
|
|
69
172
|
function unsupportedRoot(source: string, runner: "vitest" | "jest"): string | undefined {
|
|
70
173
|
const key = runner === "jest" ? "rootDir" : "root";
|
|
71
174
|
const ast = ts.createSourceFile("config.ts", source, ts.ScriptTarget.Latest, true);
|
|
175
|
+
const isConfigDirectory = configDirectoryMatcher(ast);
|
|
72
176
|
let unsupported = false;
|
|
73
177
|
const visit = (node: ts.Node): void => {
|
|
74
178
|
if (ts.isBinaryExpression(node) && node.operatorToken.kind >= ts.SyntaxKind.FirstAssignment
|
|
@@ -78,9 +182,9 @@ function unsupportedRoot(source: string, runner: "vitest" | "jest"): string | un
|
|
|
78
182
|
if ((ts.isPropertyAssignment(node) || ts.isShorthandPropertyAssignment(node))
|
|
79
183
|
&& ((ts.isIdentifier(node.name) || ts.isStringLiteral(node.name)) && node.name.text === key
|
|
80
184
|
|| ts.isComputedPropertyName(node.name) && ts.isStringLiteral(node.name.expression) && node.name.expression.text === key)) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
185
|
+
// `{ root }` shorthand names a binding of the same name.
|
|
186
|
+
const value = ts.isPropertyAssignment(node) ? node.initializer : node.name;
|
|
187
|
+
if (!ts.isExpression(value) || !isConfigDirectory(value)) unsupported = true;
|
|
84
188
|
}
|
|
85
189
|
ts.forEachChild(node, visit);
|
|
86
190
|
};
|
|
@@ -143,7 +143,9 @@ export type DependencyEdgeKind =
|
|
|
143
143
|
| "re-export"
|
|
144
144
|
| "dynamic-import"
|
|
145
145
|
| "require"
|
|
146
|
-
| "asset"
|
|
146
|
+
| "asset"
|
|
147
|
+
/** A string naming a code file by path (`'./config.ts'`), which code may load at run time. */
|
|
148
|
+
| "path-literal";
|
|
147
149
|
|
|
148
150
|
export type DependencyResolution =
|
|
149
151
|
| "internal-source"
|
|
@@ -246,7 +248,33 @@ export interface ScopedAdapterBlocker {
|
|
|
246
248
|
directories: string[];
|
|
247
249
|
}
|
|
248
250
|
|
|
251
|
+
/**
|
|
252
|
+
* What one module defines and forwards, and which names it imports from each runtime dependency
|
|
253
|
+
* (2026-11-10). ImpactAnalyzer uses it to skip a test that imports `{ x }` from a side-effect-free barrel
|
|
254
|
+
* when the changed file is not reached through `x`. A dependency missing from `imports` and `reexports`
|
|
255
|
+
* is a whole-module import.
|
|
256
|
+
*/
|
|
257
|
+
export interface ModuleBindings {
|
|
258
|
+
locals: string[];
|
|
259
|
+
/** Exports cannot be listed (CommonJS, `export =`, destructuring): any import means the whole module. */
|
|
260
|
+
opaque?: boolean;
|
|
261
|
+
/** The nearest package.json declares `sideEffects: false`, or lists only stylesheets. */
|
|
262
|
+
sideEffectFree?: boolean;
|
|
263
|
+
/** Names imported from each target, or "*" for the whole module. */
|
|
264
|
+
imports: Record<string, string[] | "*">;
|
|
265
|
+
/** The module makes a computed load when it loads (not inside a function), so every test that loads it may
|
|
266
|
+
* run that load. */
|
|
267
|
+
computedAtLoad?: boolean;
|
|
268
|
+
/** Targets imported with `import type` (or only inline `type` specifiers), which can fail a test that is
|
|
269
|
+
* type-checked as it runs. */
|
|
270
|
+
typeImports?: string[];
|
|
271
|
+
/** What `export ... from` forwards from each target. */
|
|
272
|
+
reexports: Record<string, { pairs: [string, string][]; star: boolean; namespaces: string[] }>;
|
|
273
|
+
}
|
|
274
|
+
|
|
249
275
|
export interface DependencyGraphResult {
|
|
276
|
+
/** Export-level bindings per parsed module. Absent (older caches) means file level. */
|
|
277
|
+
bindings?: Record<string, ModuleBindings>;
|
|
250
278
|
/** Missing framework/language relationships are global, not reachability-narrowable. */
|
|
251
279
|
adapterBlockers?: string[];
|
|
252
280
|
/** Blockers confined to package directories; see ScopedAdapterBlocker. `confidence` still counts them. */
|
|
@@ -273,4 +301,7 @@ export interface DependencyGraphResult {
|
|
|
273
301
|
* checking, so an `import type` edge cannot change a test's outcome (2026-11-03). Absent or false
|
|
274
302
|
* means type-only edges select tests too. */
|
|
275
303
|
runtimeTestSelection?: boolean;
|
|
304
|
+
/** Globs of the files a type-test runner checks (tstyche's `testFileMatch`, tsd's `*.test-d.ts`). They keep
|
|
305
|
+
* their type-only dependents under runtime selection, and export-level selection never narrows them. */
|
|
306
|
+
typeTestGlobs?: string[];
|
|
276
307
|
}
|