@diffci.com/diffci 0.3.23 → 0.3.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-client/src/client/agent-setup.d.ts +23 -0
- package/dist-client/src/client/agent-setup.js +111 -0
- package/dist-client/src/client/cli.js +26 -8
- package/dist-client/src/client/failure-baseline.js +0 -0
- package/dist-client/src/client/full-command.d.ts +10 -0
- package/dist-client/src/client/full-command.js +22 -0
- package/dist-client/src/client/hook.d.ts +1 -0
- package/dist-client/src/client/hook.js +9 -0
- package/dist-client/src/client/mcp.js +10 -4
- package/dist-client/src/client/observe.js +10 -5
- package/dist-client/src/client/verify.js +18 -3
- package/node_modules/@diffci.com/core/README.md +4 -0
- 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 +3 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +16 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.d.ts +4 -0
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +127 -20
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/analyzer.js +9 -2
- package/node_modules/@diffci.com/core/dist/repo/analyzer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +231 -28
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +4 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +40 -6
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.d.ts +5 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +55 -6
- 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 +7 -0
- package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +3 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +13 -0
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +125 -16
- package/node_modules/@diffci.com/core/src/repo/analyzer.ts +9 -2
- package/node_modules/@diffci.com/core/src/repo/graph.ts +206 -30
- package/node_modules/@diffci.com/core/src/repo/impact.ts +37 -6
- package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +52 -8
- package/node_modules/@diffci.com/core/src/repo/types.ts +7 -0
- package/package.json +2 -2
|
@@ -44,6 +44,10 @@ export interface SelectiveTestCommandPlan {
|
|
|
44
44
|
groups: SelectiveTestCommandGroup[];
|
|
45
45
|
/** Selected paths no group could claim. Non-empty means the plan does not cover the selection. */
|
|
46
46
|
unroutedPaths: string[];
|
|
47
|
+
/** Selected paths the full test command never runs either: every Vitest project that would include
|
|
48
|
+
* them excludes them, and the test script runs nothing but that config. The caller reports them
|
|
49
|
+
* outside the full suite rather than as run. */
|
|
50
|
+
outsideSuitePaths?: string[];
|
|
47
51
|
/** Set when no complete plan could be produced. The caller must treat this as "cannot run a
|
|
48
52
|
* subset" and fall back, never as "there is nothing to run". */
|
|
49
53
|
refusalReason?: string;
|
|
@@ -168,6 +172,75 @@ function buildCommand(
|
|
|
168
172
|
return { executable: prefix.executable, args: [...prefix.args, ...invocation.leadingArgs, ...configArgs, ...pathArgs] };
|
|
169
173
|
}
|
|
170
174
|
|
|
175
|
+
/** Include globs that only ever match runtime test files: `*.test.ts`, or Vitest's default include.
|
|
176
|
+
* Neither matches a `*.test-d.ts` type test. */
|
|
177
|
+
function runtimeOnlyGlob(glob: string): boolean {
|
|
178
|
+
return glob.endsWith(".test.ts") || glob.endsWith("*.{test,spec}.?(c|m)[jt]s?(x)");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Groups for a config with inline Vitest projects: each runtime-only project's selected files, in
|
|
183
|
+
* batches that keep every command under 3,500 characters, and every other project in full. `excluded`
|
|
184
|
+
* lists selected files that a project includes and every such project excludes, which the config
|
|
185
|
+
* never runs. Returns a refusal reason when a selected file has no project otherwise. `paths` are
|
|
186
|
+
* relative to the config's directory; `pathPrefix` makes them repository-relative.
|
|
187
|
+
*/
|
|
188
|
+
function projectGroups(
|
|
189
|
+
config: TestRunnerConfig,
|
|
190
|
+
paths: readonly string[],
|
|
191
|
+
wrap: (args: string[]) => CommandSpec,
|
|
192
|
+
runnerPrefix: string,
|
|
193
|
+
pathPrefix: string,
|
|
194
|
+
): { groups: SelectiveTestCommandGroup[]; excluded: string[] } | string {
|
|
195
|
+
const projects = config.projects!;
|
|
196
|
+
const includes = (project: (typeof projects)[number], path: string) => project.includes.some(glob => matchesGlob(path, glob));
|
|
197
|
+
const claims = (project: (typeof projects)[number], path: string) => includes(project, path)
|
|
198
|
+
&& !(project.excludes ?? []).some(glob => matchesGlob(path, glob));
|
|
199
|
+
const unclaimed = paths.filter(path => !projects.some(project => claims(project, path)));
|
|
200
|
+
if (unclaimed.some(path => !projects.some(project => includes(project, path)))) return "Selected test has no declared Vitest project";
|
|
201
|
+
const groups: SelectiveTestCommandGroup[] = [];
|
|
202
|
+
for (const project of projects) {
|
|
203
|
+
// Only conventional runtime-only globs are narrowed. Type/property or
|
|
204
|
+
// unfamiliar projects always retain their full original configuration.
|
|
205
|
+
const runtimeOnly = project.runtimeSelectionSafe && project.includes.every(runtimeOnlyGlob);
|
|
206
|
+
const selected = paths.filter(path => claims(project, path));
|
|
207
|
+
if (runtimeOnly && !selected.length) continue;
|
|
208
|
+
const prefix = ["run", "--config", config.file, "--project", project.name];
|
|
209
|
+
if (!runtimeOnly) {
|
|
210
|
+
groups.push({ runnerId: `${runnerPrefix}project:${project.name}`, label: "Full auxiliary project", paths: [], commandSpec: wrap(prefix) });
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const batches: string[][] = [[]];
|
|
214
|
+
for (const path of selected) {
|
|
215
|
+
if (path.length > 3000) return "Vitest project selection exceeds the safe command length";
|
|
216
|
+
const batch = batches[batches.length - 1]!;
|
|
217
|
+
if (batch.length && [...prefix, ...batch, path].join(" ").length > 3500) batches.push([path]);
|
|
218
|
+
else batch.push(path);
|
|
219
|
+
}
|
|
220
|
+
for (const [index, batch] of batches.entries()) {
|
|
221
|
+
groups.push({ runnerId: `${runnerPrefix}project:${project.name}${batches.length > 1 ? `:${index}` : ""}`, label: "Selected runtime project", paths: batch.map(path => `${pathPrefix}${path}`), commandSpec: wrap([...prefix, ...batch]) });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return { groups, excluded: unclaimed.map(path => `${pathPrefix}${path}`) };
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Whether the `test` script runs only the default Vitest config: each `&&` phase is `vitest` or
|
|
229
|
+
* `vitest run` with flags that keep the config, or a package-manager run of another such script. A
|
|
230
|
+
* script that does not exist runs no tests. Anything else could run files the config excludes.
|
|
231
|
+
*/
|
|
232
|
+
function runsOnlyDefaultVitest(scripts: Readonly<Record<string, string>>, name = "test", depth = 0): boolean {
|
|
233
|
+
const script = scripts[name];
|
|
234
|
+
if (script === undefined) return depth > 0;
|
|
235
|
+
if (depth > 5 || !script.trim() || scripts[`pre${name}`] || scripts[`post${name}`]) return false;
|
|
236
|
+
return script.split(/\s*&&\s*/).every((phase) => {
|
|
237
|
+
const run = /^(?:npm|pnpm|yarn|bun) (?:run )?([\w:-]+)$/.exec(phase.trim());
|
|
238
|
+
if (run) return runsOnlyDefaultVitest(scripts, run[1]!, depth + 1);
|
|
239
|
+
const words = phase.trim().split(/\s+/);
|
|
240
|
+
return words[0] === "vitest" && words.slice(1).every((word, index) => (index === 0 && word === "run") || /^--(?:silent|reporter|coverage|passWithNoTests)(?:=\S+)?$/.test(word));
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
171
244
|
/**
|
|
172
245
|
* Routes each selected test to the runner configuration that claims it, then emits one command per
|
|
173
246
|
* group. A repository with `vitest.config.ts` and `vitest.e2e.config.ts` gets two commands, because
|
|
@@ -184,32 +257,45 @@ export function planSelectiveTestCommands(
|
|
|
184
257
|
const suites = profile.workspaceTestPackages;
|
|
185
258
|
const refuse = (reason: string): SelectiveTestCommandPlan => ({ commands: [], groups: [], unroutedPaths: [...selectedPaths], refusalReason: reason });
|
|
186
259
|
if (!["pnpm", "npm"].includes(profile.packageManager) || suites.some(s => suites.some(other => other !== s && s.packageRoot.startsWith(`${other.packageRoot}/`)))) return refuse("Workspace routing requires non-overlapping declared npm or pnpm packages");
|
|
187
|
-
|
|
260
|
+
const owned = (path: string) => suites.some(s => path.startsWith(`${s.packageRoot}/`) && s.profile.testFilePaths.includes(path.slice(s.packageRoot.length + 1)));
|
|
261
|
+
// Tests no workspace package owns belong to the root package's own suite, planned as a
|
|
262
|
+
// single-package repository would be (2026-11-04: LobeHub keeps its app and server tests at the
|
|
263
|
+
// root beside `packages/*`, and every selection was refused).
|
|
264
|
+
const rootPaths = selectedPaths.filter(path => !owned(path));
|
|
265
|
+
if (rootPaths.some(path => suites.some(s => path.startsWith(`${s.packageRoot}/`)))) return refuse("A selected test has no verified workspace owner");
|
|
266
|
+
const rootScript = profile.packageJson.scripts.test ?? "";
|
|
267
|
+
const runsWorkspaceScripts = !rootScript.trim() || /(?:^|\s)(?:-r|--recursive|--filter|-F|--workspaces?|-ws)(?:[\s=]|$)|\b(?:turbo|nx|lerna)\b/.test(rootScript);
|
|
188
268
|
const groups: SelectiveTestCommandGroup[] = [];
|
|
269
|
+
let outsideSuitePaths: string[] | undefined;
|
|
270
|
+
if (rootPaths.length) {
|
|
271
|
+
const root = planSelectiveTestCommands({ ...profile, workspaceTestPackages: undefined }, rootPaths);
|
|
272
|
+
if (root.refusalReason || root.unroutedPaths.length) return refuse(root.refusalReason ?? "A selected root test has no runner");
|
|
273
|
+
groups.push(...root.groups);
|
|
274
|
+
outsideSuitePaths = root.outsideSuitePaths;
|
|
275
|
+
}
|
|
189
276
|
for (const suite of suites) {
|
|
190
277
|
const child = suite.profile;
|
|
191
278
|
const script = child.packageJson.scripts.test?.trim();
|
|
192
|
-
if (!/^vitest(?: run)?(?: --typecheck)?$/.test(script ?? "") || child.packageJson.scripts.pretest || child.packageJson.scripts.posttest || child.testUniverse?.blindSpot || child.testUniverse?.declaredFrameworks.length !== 1 || child.testUniverse.declaredFrameworks[0] !== "vitest" || child.workspaceTestPackages?.length) return refuse("Workspace test scripts require a single declared Vitest phase without lifecycle hooks or discovery blind spots");
|
|
193
279
|
const paths = selectedPaths.filter(path => path.startsWith(`${suite.packageRoot}/`)).map(path => path.slice(suite.packageRoot.length + 1));
|
|
280
|
+
if (!/^vitest(?: run)?(?: --typecheck)?$/.test(script ?? "") || child.packageJson.scripts.pretest || child.packageJson.scripts.posttest || child.testUniverse?.blindSpot || child.testUniverse?.declaredFrameworks.length !== 1 || child.testUniverse.declaredFrameworks[0] !== "vitest" || child.workspaceTestPackages?.length) {
|
|
281
|
+
// A package with no selected test has nothing to narrow when the root test script never runs
|
|
282
|
+
// workspace scripts, so their extra phases are not part of full validation either, unless it
|
|
283
|
+
// runs type tests, which the graph does not track (2026-11-04: LobeHub's root runs only its own
|
|
284
|
+
// Vitest suite, and 13 packages, `e2e` among them, have other scripts).
|
|
285
|
+
if (!paths.length && !runsWorkspaceScripts && !/--typecheck\b/.test(script ?? "")) continue;
|
|
286
|
+
return refuse("Workspace test scripts require a single declared Vitest phase without lifecycle hooks or discovery blind spots");
|
|
287
|
+
}
|
|
194
288
|
const wrap = (args: string[]): CommandSpec => profile.packageManager === "npm"
|
|
195
289
|
? { executable: "npm", args: ["exec", "--offline", `--workspace=${suite.packageRoot}`, "--", "vitest", ...args] }
|
|
196
290
|
: { executable: "pnpm", args: ["--dir", suite.packageRoot, "exec", "vitest", ...args] };
|
|
197
291
|
const projectConfigs = child.testRunnerConfigs?.filter(config => config.projects !== undefined) ?? [];
|
|
198
292
|
if (projectConfigs.length) {
|
|
199
293
|
if (projectConfigs.length !== 1 || child.testRunnerConfigs?.length !== 1 || !projectConfigs[0]!.projects) return refuse("Vitest projects must be statically declared inline in one configuration");
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
// unfamiliar projects always retain their full original configuration.
|
|
206
|
-
const runtimeOnly = project.runtimeSelectionSafe && project.includes.every(glob => glob.endsWith(".test.ts"));
|
|
207
|
-
const selected = paths.filter(path => project.includes.some(glob => matchesGlob(path, glob)));
|
|
208
|
-
if (runtimeOnly && !selected.length) continue;
|
|
209
|
-
const args = ["run", "--config", config.file, "--project", project.name, ...(runtimeOnly ? selected : [])];
|
|
210
|
-
if (args.join(" ").length > 3500) return refuse("Vitest project selection exceeds the safe command length");
|
|
211
|
-
groups.push({ runnerId: `${suite.packageRoot}:project:${project.name}`, label: runtimeOnly ? "Selected runtime project" : "Full auxiliary project", paths: runtimeOnly ? selected.map(path => `${suite.packageRoot}/${path}`) : [], commandSpec: wrap(args) });
|
|
212
|
-
}
|
|
294
|
+
const planned = projectGroups(projectConfigs[0]!, paths, wrap, `${suite.packageRoot}:`, `${suite.packageRoot}/`);
|
|
295
|
+
if (typeof planned === "string") return refuse(planned);
|
|
296
|
+
// The package's test script is plain `vitest` (checked above), so files its projects exclude never run.
|
|
297
|
+
groups.push(...planned.groups);
|
|
298
|
+
if (planned.excluded.length) outsideSuitePaths = [...(outsideSuitePaths ?? []), ...planned.excluded];
|
|
213
299
|
continue;
|
|
214
300
|
}
|
|
215
301
|
if (child.testRunnerConfigs?.some(config => config.runtimeSelectionUnsafe)) {
|
|
@@ -221,6 +307,7 @@ export function planSelectiveTestCommands(
|
|
|
221
307
|
}
|
|
222
308
|
const local = planSelectiveTestCommands({ ...child, packageManager: "pnpm" }, paths);
|
|
223
309
|
if (local.refusalReason) return refuse(local.refusalReason);
|
|
310
|
+
if (local.outsideSuitePaths?.length) outsideSuitePaths = [...(outsideSuitePaths ?? []), ...local.outsideSuitePaths.map(path => `${suite.packageRoot}/${path}`)];
|
|
224
311
|
for (const group of local.groups) {
|
|
225
312
|
const prefix = group.commandSpec.args.slice(0, group.commandSpec.args.length - group.paths.length);
|
|
226
313
|
const batches: string[][] = [[]];
|
|
@@ -236,7 +323,7 @@ export function planSelectiveTestCommands(
|
|
|
236
323
|
if (script?.endsWith(" --typecheck")) groups.push({ runnerId: `${suite.packageRoot}:types`, label: "Full workspace type tests", paths: [], commandSpec: wrap(["run", "--typecheck.only", "--passWithNoTests"]) });
|
|
237
324
|
}
|
|
238
325
|
if (!groups.some(group => group.paths.length)) return refuse("No workspace runtime suite can be safely narrowed; full validation is required");
|
|
239
|
-
return { commands: groups.map(g => g.commandSpec), groups, unroutedPaths: [] };
|
|
326
|
+
return { commands: groups.map(g => g.commandSpec), groups, unroutedPaths: [], ...(outsideSuitePaths?.length ? { outsideSuitePaths: outsideSuitePaths.sort() } : {}) };
|
|
240
327
|
}
|
|
241
328
|
if (profile.vueScope) {
|
|
242
329
|
const scope = profile.vueScope;
|
|
@@ -291,6 +378,28 @@ export function planSelectiveTestCommands(
|
|
|
291
378
|
const configs = profile.testRunnerConfigs ?? [];
|
|
292
379
|
if (configs.some(config => config.runtimeSelectionUnsafe)) return { commands: [], groups: [], unroutedPaths: paths, refusalReason: "Non-isolated or ambiguous Vitest isolation requires full validation" };
|
|
293
380
|
|
|
381
|
+
// Inline Vitest projects give each file its project's options, so files run per project. The lifted
|
|
382
|
+
// include globs mix every project's, and routing by them sent `apps/server` tests nowhere and package
|
|
383
|
+
// tests to a config that excludes them (2026-11-04, LobeHub).
|
|
384
|
+
const projectConfigs = configs.filter(config => config.projects !== undefined);
|
|
385
|
+
if (projectConfigs.length) {
|
|
386
|
+
const refuse = (reason: string): SelectiveTestCommandPlan => ({ commands: [], groups: [], unroutedPaths: paths, refusalReason: reason });
|
|
387
|
+
const config = projectConfigs[0]!;
|
|
388
|
+
if (projectConfigs.length !== 1 || !config.projects || configs.some(other => other !== config && other.runner === "vitest")) return refuse("Vitest projects must be statically declared inline in one configuration");
|
|
389
|
+
const prefix = execPrefix(profile.packageManager, "vitest");
|
|
390
|
+
const planned = projectGroups(config, paths, args => ({ executable: prefix.executable, args: [...prefix.args, ...args] }), "vitest:", "");
|
|
391
|
+
if (typeof planned === "string") return refuse(planned);
|
|
392
|
+
// Files every including project excludes are outside the full suite only when the test script runs
|
|
393
|
+
// nothing but this config (2026-11-04, LobeHub: `apps/desktop` tests, run by a separate CI job).
|
|
394
|
+
if (planned.excluded.length && !runsOnlyDefaultVitest(profile.packageJson.scripts)) return refuse("Selected test has no declared Vitest project");
|
|
395
|
+
return {
|
|
396
|
+
commands: planned.groups.map(group => group.commandSpec),
|
|
397
|
+
groups: planned.groups,
|
|
398
|
+
unroutedPaths: [],
|
|
399
|
+
...(planned.excluded.length ? { outsideSuitePaths: planned.excluded } : {}),
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
|
|
294
403
|
if (frameworks.length === 0 && configs.length === 0) {
|
|
295
404
|
return {
|
|
296
405
|
commands: [],
|
|
@@ -64,7 +64,12 @@ function detectPackageManager(repoPath: string): PackageManager {
|
|
|
64
64
|
if (existsSync(join(repoPath, "package-lock.json"))) {
|
|
65
65
|
return "npm";
|
|
66
66
|
}
|
|
67
|
-
|
|
67
|
+
// A repository that commits no lockfile (pnpm `lockfile: false`, as LobeHub sets) still names its
|
|
68
|
+
// manager in package.json for Corepack (2026-11-04: LobeHub read as "unknown", so workspace routing
|
|
69
|
+
// refused every selection and verify ran the full suite).
|
|
70
|
+
const declared = readJson<{ packageManager?: unknown }>(join(repoPath, "package.json"))?.packageManager;
|
|
71
|
+
const name = typeof declared === "string" ? declared.split("@", 1)[0] : undefined;
|
|
72
|
+
return name === "npm" || name === "pnpm" || name === "yarn" || name === "bun" ? name : "unknown";
|
|
68
73
|
}
|
|
69
74
|
|
|
70
75
|
function findConfig(repoPath: string, name: string): string | undefined {
|
|
@@ -466,7 +471,8 @@ export function analyzeRepository(
|
|
|
466
471
|
);
|
|
467
472
|
|
|
468
473
|
let testFileCount = testFilePaths.length;
|
|
469
|
-
|
|
474
|
+
// Only a lockfile that exists: a manager named in package.json alone has none.
|
|
475
|
+
const lockfileName =
|
|
470
476
|
packageManager === "npm"
|
|
471
477
|
? "package-lock.json"
|
|
472
478
|
: packageManager === "yarn"
|
|
@@ -476,6 +482,7 @@ export function analyzeRepository(
|
|
|
476
482
|
: packageManager === "bun"
|
|
477
483
|
? (existsSync(join(repoPath, "bun.lockb")) ? "bun.lockb" : "bun.lock")
|
|
478
484
|
: undefined;
|
|
485
|
+
const lockfile = lockfileName && existsSync(join(repoPath, lockfileName)) ? lockfileName : undefined;
|
|
479
486
|
|
|
480
487
|
const nextConfigFile = findConfig(repoPath, "next.config");
|
|
481
488
|
|
|
@@ -16,6 +16,7 @@ import type {
|
|
|
16
16
|
GraphIntegrityFinding,
|
|
17
17
|
GraphIntegrityReport,
|
|
18
18
|
GraphPerformanceMetrics,
|
|
19
|
+
RepositoryProfile,
|
|
19
20
|
ResolutionReference,
|
|
20
21
|
SourceRoot,
|
|
21
22
|
UnresolvedDependency,
|
|
@@ -26,6 +27,76 @@ interface ImportRef {
|
|
|
26
27
|
kind: DependencyEdgeKind;
|
|
27
28
|
dynamic: boolean;
|
|
28
29
|
computed?: boolean;
|
|
30
|
+
/** For a computed load whose target set is still bounded by literal text: `` import(`./x/${a}.json`) ``
|
|
31
|
+
* or `import.meta.glob("./x/*.json")`. `base` is the literal directory prefix (a specifier ending in
|
|
32
|
+
* "/"); `regex` matches paths relative to it. Unresolvable patterns keep the load computed. */
|
|
33
|
+
patterns?: { base: string; regex: string; negated: boolean }[];
|
|
34
|
+
/** `import { type A, type B }` or `export { type A } from`: every specifier is inline `type`, so the
|
|
35
|
+
* statement is erased unless the importer's tsconfig preserves imports (see `keepsTypeOnlyImports`). */
|
|
36
|
+
inlineTypeOnly?: boolean;
|
|
37
|
+
/** A `vi.mock("./x")` / `jest.mock("./x")` target. Vitest counts these as dependencies of the test;
|
|
38
|
+
* an unresolvable one (a virtual or aliased module) is dropped rather than made unsafe. */
|
|
39
|
+
mock?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Test-runner calls whose literal first argument names a module the test depends on. */
|
|
43
|
+
const MOCK_MODULE_CALLS = new Set([
|
|
44
|
+
"vi.mock", "vi.doMock", "vi.unmock", "vi.doUnmock", "vi.importActual", "vi.importMock",
|
|
45
|
+
"jest.mock", "jest.doMock", "jest.unmock", "jest.dontMock", "jest.requireActual", "jest.requireMock", "jest.createMockFromModule",
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
/** Whether this importer's emit keeps statements whose specifiers are all inline `type`. Without these
|
|
49
|
+
* options TypeScript, esbuild and oxc drop the whole statement, so it never loads the target. */
|
|
50
|
+
function keepsTypeOnlyImports(options: ts.CompilerOptions): boolean {
|
|
51
|
+
return Boolean(options.verbatimModuleSyntax || options.preserveValueImports || options.importsNotUsedAsValues === ts.ImportsNotUsedAsValues.Preserve);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function allInlineType(elements: readonly (ts.ImportSpecifier | ts.ExportSpecifier)[]): boolean {
|
|
55
|
+
return elements.length > 0 && elements.every((element) => element.isTypeOnly);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const escapeRegex = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
59
|
+
// A specifier may omit the extension or name a directory's index module.
|
|
60
|
+
const OPTIONAL_MODULE_SUFFIX = "(?:\\.[A-Za-z0-9]+|/index\\.[A-Za-z0-9]+)?";
|
|
61
|
+
|
|
62
|
+
/** `` `@/../locales/${lng}/${ns}.json` `` -> base "@/../locales/", each substitution matching any text. A
|
|
63
|
+
* substitution can hold "/" so it matches across directories, which can only over-select. */
|
|
64
|
+
function templatePattern(template: ts.TemplateExpression): ImportRef["patterns"] {
|
|
65
|
+
const head = template.head.text;
|
|
66
|
+
const cut = head.lastIndexOf("/");
|
|
67
|
+
if (cut < 0) return undefined;
|
|
68
|
+
const regex = escapeRegex(head.slice(cut + 1)) + template.templateSpans.map((span) => `.*${escapeRegex(span.literal.text)}`).join("");
|
|
69
|
+
return [{ base: head.slice(0, cut + 1), regex: `${regex}${OPTIONAL_MODULE_SUFFIX}`, negated: false }];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One Vite `import.meta.glob` pattern; `[...]` classes are not translated and keep the load computed. */
|
|
73
|
+
function globPattern(glob: string): NonNullable<ImportRef["patterns"]>[number] | undefined {
|
|
74
|
+
const negated = glob.startsWith("!");
|
|
75
|
+
const body = negated ? glob.slice(1) : glob;
|
|
76
|
+
const firstWild = body.search(/[*?{[]/);
|
|
77
|
+
const cut = body.lastIndexOf("/", firstWild < 0 ? body.length : firstWild);
|
|
78
|
+
if (cut < 0 || body.includes("[")) return undefined;
|
|
79
|
+
let regex = "";
|
|
80
|
+
const rest = body.slice(cut + 1);
|
|
81
|
+
for (let i = 0; i < rest.length; i++) {
|
|
82
|
+
const char = rest[i]!;
|
|
83
|
+
if (rest.startsWith("**/", i)) { regex += "(?:.*/)?"; i += 2; }
|
|
84
|
+
else if (rest.startsWith("**", i)) { regex += ".*"; i += 1; }
|
|
85
|
+
else if (char === "*") regex += "[^/]*";
|
|
86
|
+
else if (char === "?") regex += "[^/]";
|
|
87
|
+
else if (char === "{") {
|
|
88
|
+
const close = rest.indexOf("}", i);
|
|
89
|
+
if (close < 0) return undefined;
|
|
90
|
+
regex += `(?:${rest.slice(i + 1, close).split(",").map(escapeRegex).join("|")})`;
|
|
91
|
+
i = close;
|
|
92
|
+
} else regex += escapeRegex(char);
|
|
93
|
+
}
|
|
94
|
+
return { base: body.slice(0, cut + 1), regex, negated };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function isImportMetaGlob(expression: ts.Expression): boolean {
|
|
98
|
+
return ts.isPropertyAccessExpression(expression) && /^glob(?:Eager)?$/.test(expression.name.text)
|
|
99
|
+
&& ts.isMetaProperty(expression.expression) && expression.expression.keywordToken === ts.SyntaxKind.ImportKeyword;
|
|
29
100
|
}
|
|
30
101
|
|
|
31
102
|
const SOURCE_EXTENSIONS = new Set([
|
|
@@ -126,9 +197,12 @@ function extractImportRefs(sourceFile: ts.SourceFile): ImportRef[] {
|
|
|
126
197
|
if (ts.isImportDeclaration(node)) {
|
|
127
198
|
const specifier = node.moduleSpecifier;
|
|
128
199
|
if (ts.isStringLiteral(specifier)) {
|
|
129
|
-
const
|
|
200
|
+
const clause = node.importClause;
|
|
201
|
+
const isTypeOnly = clause?.isTypeOnly ?? false;
|
|
130
202
|
const kind: DependencyEdgeKind = isTypeOnly ? "type-import" : "import";
|
|
131
|
-
|
|
203
|
+
const inlineTypeOnly = !isTypeOnly && !!clause && !clause.name && !!clause.namedBindings
|
|
204
|
+
&& ts.isNamedImports(clause.namedBindings) && allInlineType(clause.namedBindings.elements);
|
|
205
|
+
refs.push({ specifier: specifier.text, kind, dynamic: false, ...(inlineTypeOnly ? { inlineTypeOnly } : {}) });
|
|
132
206
|
}
|
|
133
207
|
} else if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)) {
|
|
134
208
|
const specifier = node.moduleReference.expression;
|
|
@@ -139,7 +213,8 @@ function extractImportRefs(sourceFile: ts.SourceFile): ImportRef[] {
|
|
|
139
213
|
const specifier = node.moduleSpecifier;
|
|
140
214
|
if (ts.isStringLiteral(specifier)) {
|
|
141
215
|
const kind: DependencyEdgeKind = node.isTypeOnly ? "type-import" : "re-export";
|
|
142
|
-
|
|
216
|
+
const inlineTypeOnly = !node.isTypeOnly && !!node.exportClause && ts.isNamedExports(node.exportClause) && allInlineType(node.exportClause.elements);
|
|
217
|
+
refs.push({ specifier: specifier.text, kind, dynamic: false, ...(inlineTypeOnly ? { inlineTypeOnly } : {}) });
|
|
143
218
|
}
|
|
144
219
|
} else if (ts.isCallExpression(node)) {
|
|
145
220
|
const firstArg = node.arguments[0];
|
|
@@ -147,11 +222,29 @@ function extractImportRefs(sourceFile: ts.SourceFile): ImportRef[] {
|
|
|
147
222
|
const isRequire = ts.isIdentifier(node.expression) && node.expression.text === "require" && shadowDepth === 0;
|
|
148
223
|
if ((isImport || isRequire) && firstArg) {
|
|
149
224
|
const literal = ts.isStringLiteral(firstArg) || ts.isNoSubstitutionTemplateLiteral(firstArg);
|
|
225
|
+
const patterns = ts.isTemplateExpression(firstArg) ? templatePattern(firstArg) : undefined;
|
|
150
226
|
refs.push({
|
|
151
227
|
specifier: literal ? firstArg.text : firstArg.getText(sourceFile).slice(0, 200),
|
|
152
228
|
kind: isImport ? "dynamic-import" : "require",
|
|
153
229
|
dynamic: isImport || !literal,
|
|
154
230
|
computed: !literal,
|
|
231
|
+
...(patterns ? { patterns } : {}),
|
|
232
|
+
});
|
|
233
|
+
} else if (firstArg && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression)
|
|
234
|
+
&& MOCK_MODULE_CALLS.has(`${node.expression.expression.text}.${node.expression.name.text}`)
|
|
235
|
+
&& (ts.isStringLiteral(firstArg) || ts.isNoSubstitutionTemplateLiteral(firstArg))) {
|
|
236
|
+
refs.push({ specifier: firstArg.text, kind: "import", dynamic: false, mock: true });
|
|
237
|
+
} else if (isImportMetaGlob(node.expression) && firstArg) {
|
|
238
|
+
// Vite expands these at build time; without them a file loaded only through a glob had no edge.
|
|
239
|
+
const items = ts.isArrayLiteralExpression(firstArg) ? [...firstArg.elements] : [firstArg];
|
|
240
|
+
const globs = items.map((item) => ts.isStringLiteral(item) || ts.isNoSubstitutionTemplateLiteral(item) ? item.text : undefined);
|
|
241
|
+
const patterns = globs.every((glob) => glob !== undefined) ? globs.map((glob) => globPattern(glob!)) : [];
|
|
242
|
+
refs.push({
|
|
243
|
+
specifier: firstArg.getText(sourceFile).slice(0, 200),
|
|
244
|
+
kind: "dynamic-import",
|
|
245
|
+
dynamic: true,
|
|
246
|
+
computed: true,
|
|
247
|
+
...(patterns.length && patterns.every(Boolean) ? { patterns: patterns as NonNullable<ImportRef["patterns"]> } : {}),
|
|
155
248
|
});
|
|
156
249
|
}
|
|
157
250
|
}
|
|
@@ -169,6 +262,8 @@ class DependencyGraphImpl implements DependencyGraph {
|
|
|
169
262
|
readonly edges: DependencyEdge[];
|
|
170
263
|
readonly forward: Record<string, string[]> = {};
|
|
171
264
|
readonly reverse: Record<string, string[]> = {};
|
|
265
|
+
/** `reverse` without `import type` edges, which TypeScript erases before anything runs. */
|
|
266
|
+
private readonly reverseRuntime: Record<string, string[]> = {};
|
|
172
267
|
|
|
173
268
|
constructor(
|
|
174
269
|
sourcePaths: ReadonlySet<string>,
|
|
@@ -199,6 +294,7 @@ class DependencyGraphImpl implements DependencyGraph {
|
|
|
199
294
|
for (const node of this.nodes) {
|
|
200
295
|
this.forward[node.path] = [];
|
|
201
296
|
this.reverse[node.path] = [];
|
|
297
|
+
this.reverseRuntime[node.path] = [];
|
|
202
298
|
}
|
|
203
299
|
|
|
204
300
|
for (const edge of this.edges) {
|
|
@@ -207,14 +303,14 @@ class DependencyGraphImpl implements DependencyGraph {
|
|
|
207
303
|
}
|
|
208
304
|
if (this.reverse[edge.to] !== undefined) {
|
|
209
305
|
this.reverse[edge.to]!.push(edge.from);
|
|
306
|
+
if (edge.kind !== "type-import") this.reverseRuntime[edge.to]!.push(edge.from);
|
|
210
307
|
}
|
|
211
308
|
}
|
|
212
309
|
|
|
213
|
-
for (const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.reverse[key] = [...new Set(this.reverse[key]!)].sort();
|
|
310
|
+
for (const adjacency of [this.forward, this.reverse, this.reverseRuntime]) {
|
|
311
|
+
for (const key of Object.keys(adjacency)) {
|
|
312
|
+
adjacency[key] = [...new Set(adjacency[key]!)].sort();
|
|
313
|
+
}
|
|
218
314
|
}
|
|
219
315
|
}
|
|
220
316
|
|
|
@@ -237,34 +333,31 @@ class DependencyGraphImpl implements DependencyGraph {
|
|
|
237
333
|
}
|
|
238
334
|
|
|
239
335
|
transitiveDependenciesOf(filePath: string): string[] {
|
|
240
|
-
return this.transitiveTraversal(filePath,
|
|
336
|
+
return this.transitiveTraversal(filePath, this.forward);
|
|
241
337
|
}
|
|
242
338
|
|
|
243
339
|
transitiveDependentsOf(filePath: string): string[] {
|
|
244
|
-
return this.transitiveTraversal(filePath,
|
|
340
|
+
return this.transitiveTraversal(filePath, this.reverse);
|
|
245
341
|
}
|
|
246
342
|
|
|
247
|
-
|
|
248
|
-
filePath
|
|
249
|
-
|
|
250
|
-
|
|
343
|
+
transitiveRuntimeDependentsOf(filePath: string): string[] {
|
|
344
|
+
return this.transitiveTraversal(filePath, this.reverseRuntime);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
private transitiveTraversal(filePath: string, adjacency: Record<string, string[]>): string[] {
|
|
251
348
|
const rel = this.normalizeQuery(filePath);
|
|
252
|
-
const visited = new Set<string>();
|
|
349
|
+
const visited = new Set<string>([rel]);
|
|
350
|
+
// An index, not shift(): shift() is O(n) and made dependents of hub modules quadratic (2026-11-03,
|
|
351
|
+
// 379 s of impact analysis on one LobeHub commit whose changed files had ~14k dependents).
|
|
253
352
|
const queue: string[] = [rel];
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (visited.has(current)) continue;
|
|
260
|
-
visited.add(current);
|
|
261
|
-
if (current !== rel) result.push(current);
|
|
262
|
-
for (const next of adjacency[current] ?? []) {
|
|
263
|
-
if (!visited.has(next)) queue.push(next);
|
|
353
|
+
for (let head = 0; head < queue.length; head++) {
|
|
354
|
+
for (const next of adjacency[queue[head]!] ?? []) {
|
|
355
|
+
if (visited.has(next)) continue;
|
|
356
|
+
visited.add(next);
|
|
357
|
+
queue.push(next);
|
|
264
358
|
}
|
|
265
359
|
}
|
|
266
|
-
|
|
267
|
-
return result.sort();
|
|
360
|
+
return queue.slice(1).sort();
|
|
268
361
|
}
|
|
269
362
|
|
|
270
363
|
private normalizeQuery(filePath: string): string {
|
|
@@ -771,6 +864,7 @@ export async function buildDependencyGraph(
|
|
|
771
864
|
ref: ImportRef,
|
|
772
865
|
reason: string,
|
|
773
866
|
): void {
|
|
867
|
+
if (ref.mock) return;
|
|
774
868
|
unresolved.push({
|
|
775
869
|
importer: importerRel,
|
|
776
870
|
specifier: ref.specifier,
|
|
@@ -786,6 +880,7 @@ export async function buildDependencyGraph(
|
|
|
786
880
|
importer: string,
|
|
787
881
|
ref: ImportRef,
|
|
788
882
|
): void {
|
|
883
|
+
if (ref.mock && resolution === "unresolved") return;
|
|
789
884
|
references.push({
|
|
790
885
|
resolution,
|
|
791
886
|
specifier: ref.specifier,
|
|
@@ -800,6 +895,35 @@ export async function buildDependencyGraph(
|
|
|
800
895
|
addEdge(importerRel, assetRel, "asset");
|
|
801
896
|
}
|
|
802
897
|
|
|
898
|
+
/** Every repository file a bounded computed load can name, or undefined to keep it computed: the
|
|
899
|
+
* base directory does not resolve, nothing matches, or a match is neither analyzed source nor an
|
|
900
|
+
* asset. Alias directories resolve as in findAssetCandidate, and all candidates are unioned. */
|
|
901
|
+
function resolvePatternTargets(importerAbs: string, patterns: NonNullable<ImportRef["patterns"]>, importerOptions: ts.CompilerOptions): string[] | undefined {
|
|
902
|
+
const compilerAliases = Object.entries(importerOptions.paths ?? {}).map(([pattern, substitutions]) => ({ pattern, substitutions }));
|
|
903
|
+
const aliasRoot = importerOptions.baseUrl ?? (importerOptions as { pathsBasePath?: string }).pathsBasePath ?? repoPath;
|
|
904
|
+
const included = new Set<string>();
|
|
905
|
+
const excluded = new Set<string>();
|
|
906
|
+
for (const pattern of patterns) {
|
|
907
|
+
const base = pattern.base.replace(/\/+$/, "") || ".";
|
|
908
|
+
if (base.startsWith("/")) return undefined;
|
|
909
|
+
const directories = base.startsWith(".") ? [resolve(dirname(importerAbs), base)]
|
|
910
|
+
: [...expandAliasCandidates(base, compilerAliases, aliasRoot), ...expandAliasCandidates(base, profile.pathAliases, repoPath)];
|
|
911
|
+
const matcher = new RegExp(`^${pattern.regex}$`);
|
|
912
|
+
for (const directory of directories) {
|
|
913
|
+
const rel = toRelativeInternal(repoPath, directory);
|
|
914
|
+
if (rel === undefined) continue;
|
|
915
|
+
const prefix = rel === "." ? "" : `${rel}/`;
|
|
916
|
+
for (const file of files) {
|
|
917
|
+
if (file.startsWith(prefix) && matcher.test(file.slice(prefix.length))) (pattern.negated ? excluded : included).add(file);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
const importerRel = toRelativeInternal(repoPath, importerAbs);
|
|
922
|
+
const targets = [...included].filter((file) => !excluded.has(file) && file !== importerRel).sort();
|
|
923
|
+
if (!targets.length || targets.some((file) => !internalSourcePaths.has(file) && !isAssetFileName(file))) return undefined;
|
|
924
|
+
return targets;
|
|
925
|
+
}
|
|
926
|
+
|
|
803
927
|
let filesParsed = sourceFiles.length;
|
|
804
928
|
let followedImplementationFiles = 0;
|
|
805
929
|
|
|
@@ -861,11 +985,23 @@ export async function buildDependencyGraph(
|
|
|
861
985
|
|
|
862
986
|
const importerOptions = optionsFor(sf.fileName);
|
|
863
987
|
|
|
864
|
-
const
|
|
988
|
+
const keepsTypeImports = keepsTypeOnlyImports(importerOptions);
|
|
989
|
+
const refs = extractImportRefs(sf).map((ref) => ref.inlineTypeOnly && !keepsTypeImports ? { ...ref, kind: "type-import" as const } : ref);
|
|
865
990
|
if (scope && sf.referencedFiles.length) adapterBlockers.push(`Triple-slash file references in the scoped suite require full validation: ${importerRel}`);
|
|
866
991
|
for (const ref of refs) {
|
|
867
992
|
// Expression text is not a module name. In particular, import(name) must
|
|
868
993
|
// not be classified as an external package called "name".
|
|
994
|
+
if (ref.computed && ref.patterns) {
|
|
995
|
+
const targets = resolvePatternTargets(sf.fileName, ref.patterns, importerOptions);
|
|
996
|
+
if (targets) {
|
|
997
|
+
for (const target of targets) {
|
|
998
|
+
if (internalSourcePaths.has(target)) addEdge(importerRel, target, ref.kind);
|
|
999
|
+
else recordAssetEdge(importerRel, target);
|
|
1000
|
+
}
|
|
1001
|
+
recordReference(targets.some((target) => internalSourcePaths.has(target)) ? "internal-source" : "internal-asset", importerRel, ref);
|
|
1002
|
+
continue;
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
869
1005
|
if (ref.computed) {
|
|
870
1006
|
recordUnresolved(importerRel, ref, "computed module specifier requires full validation");
|
|
871
1007
|
recordReference("unresolved", importerRel, ref);
|
|
@@ -1123,6 +1259,7 @@ export async function buildDependencyGraph(
|
|
|
1123
1259
|
confidence,
|
|
1124
1260
|
integrity,
|
|
1125
1261
|
resolvedViaProjectReferences,
|
|
1262
|
+
runtimeTestSelection: runtimeTestSelectionEligible(repoPath, files, profile),
|
|
1126
1263
|
};
|
|
1127
1264
|
}
|
|
1128
1265
|
|
|
@@ -1291,6 +1428,35 @@ export function validateDependencyGraph(graph: DependencyGraph): GraphIntegrityR
|
|
|
1291
1428
|
};
|
|
1292
1429
|
}
|
|
1293
1430
|
|
|
1431
|
+
/**
|
|
1432
|
+
* Whether an `import type` edge can be ignored when selecting tests (2026-11-03). Vitest transpiles
|
|
1433
|
+
* without type checking, so a type-only change cannot alter a runtime test's outcome; ts-jest, tsd,
|
|
1434
|
+
* tstyche and Vitest's typecheck mode do check types. Any sign of them anywhere in the repository,
|
|
1435
|
+
* including workspace packages, keeps type-only edges selecting tests. Type tests (`*.test-d.ts`) are
|
|
1436
|
+
* selected through every edge either way (impact.ts).
|
|
1437
|
+
*/
|
|
1438
|
+
function runtimeTestSelectionEligible(repoPath: string, files: readonly string[], profile: RepositoryProfile): boolean {
|
|
1439
|
+
const configs = profile.testRunnerConfigs ?? [];
|
|
1440
|
+
if (!configs.length || configs.some((config) => config.runner !== "vitest")) return false;
|
|
1441
|
+
const read = (path: string) => { try { return readFileSync(join(repoPath, path), "utf8"); } catch { return undefined; } };
|
|
1442
|
+
for (const file of files) {
|
|
1443
|
+
if (file.split("/").includes("node_modules")) continue;
|
|
1444
|
+
const name = file.slice(file.lastIndexOf("/") + 1);
|
|
1445
|
+
if (/^jest\.config\./.test(name)) return false;
|
|
1446
|
+
if (/^vit(?:e|est)[\w.-]*\.(?:config|workspace|projects)\.[cm]?[jt]s$/.test(name)) {
|
|
1447
|
+
const text = read(file);
|
|
1448
|
+
if (text === undefined || /\btypecheck\b/.test(text)) return false;
|
|
1449
|
+
} else if (name === "package.json") {
|
|
1450
|
+
let manifest: { scripts?: Record<string, unknown>; dependencies?: object; devDependencies?: object; peerDependencies?: object; optionalDependencies?: object };
|
|
1451
|
+
try { manifest = JSON.parse(read(file) ?? ""); } catch { return false; }
|
|
1452
|
+
const packages = [manifest.dependencies, manifest.devDependencies, manifest.peerDependencies, manifest.optionalDependencies].flatMap((group) => Object.keys(group ?? {}));
|
|
1453
|
+
if (packages.some((name) => ["jest", "ts-jest", "tsd", "tstyche"].includes(name))) return false;
|
|
1454
|
+
if (Object.values(manifest.scripts ?? {}).some((script) => typeof script !== "string" || /(?:^|[\s&;|(])(?:jest|tsd|tstyche)(?:\s|$)|--typecheck/.test(script))) return false;
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
return true;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1294
1460
|
function computeConfidence(
|
|
1295
1461
|
unresolvedCount: number,
|
|
1296
1462
|
dynamicUnresolvedCount: number,
|
|
@@ -1372,13 +1538,23 @@ export function refineConfidenceForDelta(result: DependencyGraphResult, changedF
|
|
|
1372
1538
|
if (result.unresolved.length === 0) return result.confidence;
|
|
1373
1539
|
|
|
1374
1540
|
const reachableFromChanged = new Set<string>();
|
|
1541
|
+
const dependents = new Set<string>();
|
|
1542
|
+
const runtimeDependents = new Set<string>();
|
|
1543
|
+
const runtimeOnly = result.runtimeTestSelection === true && typeof result.graph.transitiveRuntimeDependentsOf === "function";
|
|
1375
1544
|
for (const file of changedFiles) {
|
|
1376
1545
|
for (const dep of result.graph.transitiveDependenciesOf(file)) reachableFromChanged.add(dep);
|
|
1377
|
-
for (const dep of result.graph.transitiveDependentsOf(file)) reachableFromChanged.add(dep);
|
|
1546
|
+
for (const dep of result.graph.transitiveDependentsOf(file)) { reachableFromChanged.add(dep); dependents.add(dep); }
|
|
1547
|
+
if (runtimeOnly) for (const dep of result.graph.transitiveRuntimeDependentsOf!(file)) runtimeDependents.add(dep);
|
|
1378
1548
|
}
|
|
1379
1549
|
const changedSet = new Set(changedFiles);
|
|
1380
1550
|
|
|
1381
|
-
|
|
1551
|
+
// An importer that already depends on a changed file is affected, and so is everything depending on
|
|
1552
|
+
// it: whatever its missing edge points at, following that edge cannot reach a test that is not already
|
|
1553
|
+
// selected (2026-11-03: one broken `import type` in a LobeHub test file made 35 of 40 commits UNSAFE).
|
|
1554
|
+
// "Already depends" means through the edges that select tests: runtime edges when type-only ones do
|
|
1555
|
+
// not select (runtimeTestSelection), unless the missing edge is itself type-only.
|
|
1556
|
+
const alreadyAffected = (u: UnresolvedDependency) => (runtimeOnly && !u.typeOnly ? runtimeDependents : dependents).has(u.importer);
|
|
1557
|
+
const relevantUnresolved = result.unresolved.some((u) => !u.computed && !alreadyAffected(u) && (changedSet.has(u.importer) || reachableFromChanged.has(u.importer)));
|
|
1382
1558
|
if (relevantUnresolved) return "UNSAFE";
|
|
1383
1559
|
|
|
1384
1560
|
// None of the unresolved imports are reachable from this delta's changed files - narrow to what
|