@diffci.com/diffci 0.3.23 → 0.3.25

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.
Files changed (55) hide show
  1. package/dist-client/src/client/agent-setup.d.ts +23 -0
  2. package/dist-client/src/client/agent-setup.js +111 -0
  3. package/dist-client/src/client/cli.js +26 -8
  4. package/dist-client/src/client/failure-baseline.js +0 -0
  5. package/dist-client/src/client/full-command.d.ts +10 -0
  6. package/dist-client/src/client/full-command.js +22 -0
  7. package/dist-client/src/client/hook.d.ts +1 -0
  8. package/dist-client/src/client/hook.js +9 -0
  9. package/dist-client/src/client/mcp.js +10 -4
  10. package/dist-client/src/client/observe.js +10 -5
  11. package/dist-client/src/client/verify.js +18 -3
  12. package/dist-client/src/client/workflow-templates.d.ts +2 -2
  13. package/dist-client/src/client/workflow-templates.js +2 -2
  14. package/node_modules/@diffci.com/core/README.md +7 -0
  15. package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
  16. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +3 -1
  17. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
  18. package/node_modules/@diffci.com/core/dist/git/git-diff.js +16 -0
  19. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  20. package/node_modules/@diffci.com/core/dist/planner/test-command.d.ts +4 -0
  21. package/node_modules/@diffci.com/core/dist/planner/test-command.js +127 -20
  22. package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
  23. package/node_modules/@diffci.com/core/dist/repo/analyzer.js +9 -2
  24. package/node_modules/@diffci.com/core/dist/repo/analyzer.js.map +1 -1
  25. package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +22 -2
  26. package/node_modules/@diffci.com/core/dist/repo/file-references.js +70 -10
  27. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
  28. package/node_modules/@diffci.com/core/dist/repo/graph.js +231 -28
  29. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  30. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +28 -0
  31. package/node_modules/@diffci.com/core/dist/repo/impact.js +167 -11
  32. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  33. package/node_modules/@diffci.com/core/dist/repo/test-discovery.d.ts +5 -1
  34. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +55 -6
  35. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
  36. package/node_modules/@diffci.com/core/dist/repo/types.d.ts +7 -0
  37. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.d.ts +2 -2
  38. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +7 -5
  39. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
  40. package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +3 -1
  41. package/node_modules/@diffci.com/core/src/git/git-diff.ts +13 -0
  42. package/node_modules/@diffci.com/core/src/planner/test-command.ts +125 -16
  43. package/node_modules/@diffci.com/core/src/repo/analyzer.ts +9 -2
  44. package/node_modules/@diffci.com/core/src/repo/file-references.ts +74 -11
  45. package/node_modules/@diffci.com/core/src/repo/graph.ts +206 -30
  46. package/node_modules/@diffci.com/core/src/repo/impact.ts +169 -12
  47. package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +52 -8
  48. package/node_modules/@diffci.com/core/src/repo/types.ts +7 -0
  49. package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +8 -6
  50. package/node_modules/source-map-js/lib/quick-sort.js +10 -1
  51. package/node_modules/source-map-js/lib/source-map-consumer.js +51 -3
  52. package/node_modules/source-map-js/lib/source-map-generator.js +6 -4
  53. package/node_modules/source-map-js/lib/source-node.js +7 -0
  54. package/node_modules/source-map-js/package.json +1 -1
  55. package/package.json +2 -2
@@ -6,6 +6,72 @@ import ts from "typescript";
6
6
  import { adapterFiles, REPOSITORY_ADAPTERS } from "./adapters/index.js";
7
7
  import { analyzeRepository } from "./analyzer.js";
8
8
  import { applyVueScope, inVuePackage } from "./vue-scope.js";
9
+ /** Test-runner calls whose literal first argument names a module the test depends on. */
10
+ const MOCK_MODULE_CALLS = new Set([
11
+ "vi.mock", "vi.doMock", "vi.unmock", "vi.doUnmock", "vi.importActual", "vi.importMock",
12
+ "jest.mock", "jest.doMock", "jest.unmock", "jest.dontMock", "jest.requireActual", "jest.requireMock", "jest.createMockFromModule",
13
+ ]);
14
+ /** Whether this importer's emit keeps statements whose specifiers are all inline `type`. Without these
15
+ * options TypeScript, esbuild and oxc drop the whole statement, so it never loads the target. */
16
+ function keepsTypeOnlyImports(options) {
17
+ return Boolean(options.verbatimModuleSyntax || options.preserveValueImports || options.importsNotUsedAsValues === ts.ImportsNotUsedAsValues.Preserve);
18
+ }
19
+ function allInlineType(elements) {
20
+ return elements.length > 0 && elements.every((element) => element.isTypeOnly);
21
+ }
22
+ const escapeRegex = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
23
+ // A specifier may omit the extension or name a directory's index module.
24
+ const OPTIONAL_MODULE_SUFFIX = "(?:\\.[A-Za-z0-9]+|/index\\.[A-Za-z0-9]+)?";
25
+ /** `` `@/../locales/${lng}/${ns}.json` `` -> base "@/../locales/", each substitution matching any text. A
26
+ * substitution can hold "/" so it matches across directories, which can only over-select. */
27
+ function templatePattern(template) {
28
+ const head = template.head.text;
29
+ const cut = head.lastIndexOf("/");
30
+ if (cut < 0)
31
+ return undefined;
32
+ const regex = escapeRegex(head.slice(cut + 1)) + template.templateSpans.map((span) => `.*${escapeRegex(span.literal.text)}`).join("");
33
+ return [{ base: head.slice(0, cut + 1), regex: `${regex}${OPTIONAL_MODULE_SUFFIX}`, negated: false }];
34
+ }
35
+ /** One Vite `import.meta.glob` pattern; `[...]` classes are not translated and keep the load computed. */
36
+ function globPattern(glob) {
37
+ const negated = glob.startsWith("!");
38
+ const body = negated ? glob.slice(1) : glob;
39
+ const firstWild = body.search(/[*?{[]/);
40
+ const cut = body.lastIndexOf("/", firstWild < 0 ? body.length : firstWild);
41
+ if (cut < 0 || body.includes("["))
42
+ return undefined;
43
+ let regex = "";
44
+ const rest = body.slice(cut + 1);
45
+ for (let i = 0; i < rest.length; i++) {
46
+ const char = rest[i];
47
+ if (rest.startsWith("**/", i)) {
48
+ regex += "(?:.*/)?";
49
+ i += 2;
50
+ }
51
+ else if (rest.startsWith("**", i)) {
52
+ regex += ".*";
53
+ i += 1;
54
+ }
55
+ else if (char === "*")
56
+ regex += "[^/]*";
57
+ else if (char === "?")
58
+ regex += "[^/]";
59
+ else if (char === "{") {
60
+ const close = rest.indexOf("}", i);
61
+ if (close < 0)
62
+ return undefined;
63
+ regex += `(?:${rest.slice(i + 1, close).split(",").map(escapeRegex).join("|")})`;
64
+ i = close;
65
+ }
66
+ else
67
+ regex += escapeRegex(char);
68
+ }
69
+ return { base: body.slice(0, cut + 1), regex, negated };
70
+ }
71
+ function isImportMetaGlob(expression) {
72
+ return ts.isPropertyAccessExpression(expression) && /^glob(?:Eager)?$/.test(expression.name.text)
73
+ && ts.isMetaProperty(expression.expression) && expression.expression.keywordToken === ts.SyntaxKind.ImportKeyword;
74
+ }
9
75
  const SOURCE_EXTENSIONS = new Set([
10
76
  ".ts",
11
77
  ".tsx",
@@ -90,9 +156,12 @@ function extractImportRefs(sourceFile) {
90
156
  if (ts.isImportDeclaration(node)) {
91
157
  const specifier = node.moduleSpecifier;
92
158
  if (ts.isStringLiteral(specifier)) {
93
- const isTypeOnly = node.importClause?.isTypeOnly ?? false;
159
+ const clause = node.importClause;
160
+ const isTypeOnly = clause?.isTypeOnly ?? false;
94
161
  const kind = isTypeOnly ? "type-import" : "import";
95
- refs.push({ specifier: specifier.text, kind, dynamic: false });
162
+ const inlineTypeOnly = !isTypeOnly && !!clause && !clause.name && !!clause.namedBindings
163
+ && ts.isNamedImports(clause.namedBindings) && allInlineType(clause.namedBindings.elements);
164
+ refs.push({ specifier: specifier.text, kind, dynamic: false, ...(inlineTypeOnly ? { inlineTypeOnly } : {}) });
96
165
  }
97
166
  }
98
167
  else if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)) {
@@ -105,7 +174,8 @@ function extractImportRefs(sourceFile) {
105
174
  const specifier = node.moduleSpecifier;
106
175
  if (ts.isStringLiteral(specifier)) {
107
176
  const kind = node.isTypeOnly ? "type-import" : "re-export";
108
- refs.push({ specifier: specifier.text, kind, dynamic: false });
177
+ const inlineTypeOnly = !node.isTypeOnly && !!node.exportClause && ts.isNamedExports(node.exportClause) && allInlineType(node.exportClause.elements);
178
+ refs.push({ specifier: specifier.text, kind, dynamic: false, ...(inlineTypeOnly ? { inlineTypeOnly } : {}) });
109
179
  }
110
180
  }
111
181
  else if (ts.isCallExpression(node)) {
@@ -114,11 +184,31 @@ function extractImportRefs(sourceFile) {
114
184
  const isRequire = ts.isIdentifier(node.expression) && node.expression.text === "require" && shadowDepth === 0;
115
185
  if ((isImport || isRequire) && firstArg) {
116
186
  const literal = ts.isStringLiteral(firstArg) || ts.isNoSubstitutionTemplateLiteral(firstArg);
187
+ const patterns = ts.isTemplateExpression(firstArg) ? templatePattern(firstArg) : undefined;
117
188
  refs.push({
118
189
  specifier: literal ? firstArg.text : firstArg.getText(sourceFile).slice(0, 200),
119
190
  kind: isImport ? "dynamic-import" : "require",
120
191
  dynamic: isImport || !literal,
121
192
  computed: !literal,
193
+ ...(patterns ? { patterns } : {}),
194
+ });
195
+ }
196
+ else if (firstArg && ts.isPropertyAccessExpression(node.expression) && ts.isIdentifier(node.expression.expression)
197
+ && MOCK_MODULE_CALLS.has(`${node.expression.expression.text}.${node.expression.name.text}`)
198
+ && (ts.isStringLiteral(firstArg) || ts.isNoSubstitutionTemplateLiteral(firstArg))) {
199
+ refs.push({ specifier: firstArg.text, kind: "import", dynamic: false, mock: true });
200
+ }
201
+ else if (isImportMetaGlob(node.expression) && firstArg) {
202
+ // Vite expands these at build time; without them a file loaded only through a glob had no edge.
203
+ const items = ts.isArrayLiteralExpression(firstArg) ? [...firstArg.elements] : [firstArg];
204
+ const globs = items.map((item) => ts.isStringLiteral(item) || ts.isNoSubstitutionTemplateLiteral(item) ? item.text : undefined);
205
+ const patterns = globs.every((glob) => glob !== undefined) ? globs.map((glob) => globPattern(glob)) : [];
206
+ refs.push({
207
+ specifier: firstArg.getText(sourceFile).slice(0, 200),
208
+ kind: "dynamic-import",
209
+ dynamic: true,
210
+ computed: true,
211
+ ...(patterns.length && patterns.every(Boolean) ? { patterns: patterns } : {}),
122
212
  });
123
213
  }
124
214
  }
@@ -135,6 +225,8 @@ class DependencyGraphImpl {
135
225
  edges;
136
226
  forward = {};
137
227
  reverse = {};
228
+ /** `reverse` without `import type` edges, which TypeScript erases before anything runs. */
229
+ reverseRuntime = {};
138
230
  constructor(sourcePaths, assetPaths, edges, repoPath, isTestFile = DEFAULT_TEST_FILE_MATCHER) {
139
231
  this.repoPath = repoPath;
140
232
  this.edges = [...edges].sort(DependencyGraphImpl.compareEdges);
@@ -158,6 +250,7 @@ class DependencyGraphImpl {
158
250
  for (const node of this.nodes) {
159
251
  this.forward[node.path] = [];
160
252
  this.reverse[node.path] = [];
253
+ this.reverseRuntime[node.path] = [];
161
254
  }
162
255
  for (const edge of this.edges) {
163
256
  if (this.forward[edge.from] !== undefined) {
@@ -165,13 +258,14 @@ class DependencyGraphImpl {
165
258
  }
166
259
  if (this.reverse[edge.to] !== undefined) {
167
260
  this.reverse[edge.to].push(edge.from);
261
+ if (edge.kind !== "type-import")
262
+ this.reverseRuntime[edge.to].push(edge.from);
168
263
  }
169
264
  }
170
- for (const key of Object.keys(this.forward)) {
171
- this.forward[key] = [...new Set(this.forward[key])].sort();
172
- }
173
- for (const key of Object.keys(this.reverse)) {
174
- this.reverse[key] = [...new Set(this.reverse[key])].sort();
265
+ for (const adjacency of [this.forward, this.reverse, this.reverseRuntime]) {
266
+ for (const key of Object.keys(adjacency)) {
267
+ adjacency[key] = [...new Set(adjacency[key])].sort();
268
+ }
175
269
  }
176
270
  }
177
271
  static compareEdges(a, b) {
@@ -188,30 +282,29 @@ class DependencyGraphImpl {
188
282
  return this.reverse[rel] ?? [];
189
283
  }
190
284
  transitiveDependenciesOf(filePath) {
191
- return this.transitiveTraversal(filePath, "forward");
285
+ return this.transitiveTraversal(filePath, this.forward);
192
286
  }
193
287
  transitiveDependentsOf(filePath) {
194
- return this.transitiveTraversal(filePath, "reverse");
288
+ return this.transitiveTraversal(filePath, this.reverse);
195
289
  }
196
- transitiveTraversal(filePath, direction) {
290
+ transitiveRuntimeDependentsOf(filePath) {
291
+ return this.transitiveTraversal(filePath, this.reverseRuntime);
292
+ }
293
+ transitiveTraversal(filePath, adjacency) {
197
294
  const rel = this.normalizeQuery(filePath);
198
- const visited = new Set();
295
+ const visited = new Set([rel]);
296
+ // An index, not shift(): shift() is O(n) and made dependents of hub modules quadratic (2026-11-03,
297
+ // 379 s of impact analysis on one LobeHub commit whose changed files had ~14k dependents).
199
298
  const queue = [rel];
200
- const result = [];
201
- const adjacency = direction === "forward" ? this.forward : this.reverse;
202
- while (queue.length > 0) {
203
- const current = queue.shift();
204
- if (visited.has(current))
205
- continue;
206
- visited.add(current);
207
- if (current !== rel)
208
- result.push(current);
209
- for (const next of adjacency[current] ?? []) {
210
- if (!visited.has(next))
211
- queue.push(next);
299
+ for (let head = 0; head < queue.length; head++) {
300
+ for (const next of adjacency[queue[head]] ?? []) {
301
+ if (visited.has(next))
302
+ continue;
303
+ visited.add(next);
304
+ queue.push(next);
212
305
  }
213
306
  }
214
- return result.sort();
307
+ return queue.slice(1).sort();
215
308
  }
216
309
  normalizeQuery(filePath) {
217
310
  const rel = toPosix(normalize(relative(this.repoPath, resolve(this.repoPath, filePath))));
@@ -679,6 +772,8 @@ export async function buildDependencyGraph(options = {}) {
679
772
  edges.push({ from, to, kind });
680
773
  }
681
774
  function recordUnresolved(importerRel, ref, reason) {
775
+ if (ref.mock)
776
+ return;
682
777
  unresolved.push({
683
778
  importer: importerRel,
684
779
  specifier: ref.specifier,
@@ -689,6 +784,8 @@ export async function buildDependencyGraph(options = {}) {
689
784
  });
690
785
  }
691
786
  function recordReference(resolution, importer, ref) {
787
+ if (ref.mock && resolution === "unresolved")
788
+ return;
692
789
  references.push({
693
790
  resolution,
694
791
  specifier: ref.specifier,
@@ -701,6 +798,38 @@ export async function buildDependencyGraph(options = {}) {
701
798
  assetPaths.add(assetRel);
702
799
  addEdge(importerRel, assetRel, "asset");
703
800
  }
801
+ /** Every repository file a bounded computed load can name, or undefined to keep it computed: the
802
+ * base directory does not resolve, nothing matches, or a match is neither analyzed source nor an
803
+ * asset. Alias directories resolve as in findAssetCandidate, and all candidates are unioned. */
804
+ function resolvePatternTargets(importerAbs, patterns, importerOptions) {
805
+ const compilerAliases = Object.entries(importerOptions.paths ?? {}).map(([pattern, substitutions]) => ({ pattern, substitutions }));
806
+ const aliasRoot = importerOptions.baseUrl ?? importerOptions.pathsBasePath ?? repoPath;
807
+ const included = new Set();
808
+ const excluded = new Set();
809
+ for (const pattern of patterns) {
810
+ const base = pattern.base.replace(/\/+$/, "") || ".";
811
+ if (base.startsWith("/"))
812
+ return undefined;
813
+ const directories = base.startsWith(".") ? [resolve(dirname(importerAbs), base)]
814
+ : [...expandAliasCandidates(base, compilerAliases, aliasRoot), ...expandAliasCandidates(base, profile.pathAliases, repoPath)];
815
+ const matcher = new RegExp(`^${pattern.regex}$`);
816
+ for (const directory of directories) {
817
+ const rel = toRelativeInternal(repoPath, directory);
818
+ if (rel === undefined)
819
+ continue;
820
+ const prefix = rel === "." ? "" : `${rel}/`;
821
+ for (const file of files) {
822
+ if (file.startsWith(prefix) && matcher.test(file.slice(prefix.length)))
823
+ (pattern.negated ? excluded : included).add(file);
824
+ }
825
+ }
826
+ }
827
+ const importerRel = toRelativeInternal(repoPath, importerAbs);
828
+ const targets = [...included].filter((file) => !excluded.has(file) && file !== importerRel).sort();
829
+ if (!targets.length || targets.some((file) => !internalSourcePaths.has(file) && !isAssetFileName(file)))
830
+ return undefined;
831
+ return targets;
832
+ }
704
833
  let filesParsed = sourceFiles.length;
705
834
  let followedImplementationFiles = 0;
706
835
  // Resolve each importer with its own nearest project, never another package's
@@ -766,12 +895,26 @@ export async function buildDependencyGraph(options = {}) {
766
895
  if (isExcludedPath(importerRel, options.excludeDirs ?? []))
767
896
  continue;
768
897
  const importerOptions = optionsFor(sf.fileName);
769
- const refs = extractImportRefs(sf);
898
+ const keepsTypeImports = keepsTypeOnlyImports(importerOptions);
899
+ const refs = extractImportRefs(sf).map((ref) => ref.inlineTypeOnly && !keepsTypeImports ? { ...ref, kind: "type-import" } : ref);
770
900
  if (scope && sf.referencedFiles.length)
771
901
  adapterBlockers.push(`Triple-slash file references in the scoped suite require full validation: ${importerRel}`);
772
902
  for (const ref of refs) {
773
903
  // Expression text is not a module name. In particular, import(name) must
774
904
  // not be classified as an external package called "name".
905
+ if (ref.computed && ref.patterns) {
906
+ const targets = resolvePatternTargets(sf.fileName, ref.patterns, importerOptions);
907
+ if (targets) {
908
+ for (const target of targets) {
909
+ if (internalSourcePaths.has(target))
910
+ addEdge(importerRel, target, ref.kind);
911
+ else
912
+ recordAssetEdge(importerRel, target);
913
+ }
914
+ recordReference(targets.some((target) => internalSourcePaths.has(target)) ? "internal-source" : "internal-asset", importerRel, ref);
915
+ continue;
916
+ }
917
+ }
775
918
  if (ref.computed) {
776
919
  recordUnresolved(importerRel, ref, "computed module specifier requires full validation");
777
920
  recordReference("unresolved", importerRel, ref);
@@ -1018,6 +1161,7 @@ export async function buildDependencyGraph(options = {}) {
1018
1161
  confidence,
1019
1162
  integrity,
1020
1163
  resolvedViaProjectReferences,
1164
+ runtimeTestSelection: runtimeTestSelectionEligible(repoPath, files, profile),
1021
1165
  };
1022
1166
  }
1023
1167
  /** Product eligibility includes native adapters; legacy TS corpus classification stays separate. */
@@ -1171,6 +1315,51 @@ export function validateDependencyGraph(graph) {
1171
1315
  },
1172
1316
  };
1173
1317
  }
1318
+ /**
1319
+ * Whether an `import type` edge can be ignored when selecting tests (2026-11-03). Vitest transpiles
1320
+ * without type checking, so a type-only change cannot alter a runtime test's outcome; ts-jest, tsd,
1321
+ * tstyche and Vitest's typecheck mode do check types. Any sign of them anywhere in the repository,
1322
+ * including workspace packages, keeps type-only edges selecting tests. Type tests (`*.test-d.ts`) are
1323
+ * selected through every edge either way (impact.ts).
1324
+ */
1325
+ function runtimeTestSelectionEligible(repoPath, files, profile) {
1326
+ const configs = profile.testRunnerConfigs ?? [];
1327
+ if (!configs.length || configs.some((config) => config.runner !== "vitest"))
1328
+ return false;
1329
+ const read = (path) => { try {
1330
+ return readFileSync(join(repoPath, path), "utf8");
1331
+ }
1332
+ catch {
1333
+ return undefined;
1334
+ } };
1335
+ for (const file of files) {
1336
+ if (file.split("/").includes("node_modules"))
1337
+ continue;
1338
+ const name = file.slice(file.lastIndexOf("/") + 1);
1339
+ if (/^jest\.config\./.test(name))
1340
+ return false;
1341
+ if (/^vit(?:e|est)[\w.-]*\.(?:config|workspace|projects)\.[cm]?[jt]s$/.test(name)) {
1342
+ const text = read(file);
1343
+ if (text === undefined || /\btypecheck\b/.test(text))
1344
+ return false;
1345
+ }
1346
+ else if (name === "package.json") {
1347
+ let manifest;
1348
+ try {
1349
+ manifest = JSON.parse(read(file) ?? "");
1350
+ }
1351
+ catch {
1352
+ return false;
1353
+ }
1354
+ const packages = [manifest.dependencies, manifest.devDependencies, manifest.peerDependencies, manifest.optionalDependencies].flatMap((group) => Object.keys(group ?? {}));
1355
+ if (packages.some((name) => ["jest", "ts-jest", "tsd", "tstyche"].includes(name)))
1356
+ return false;
1357
+ if (Object.values(manifest.scripts ?? {}).some((script) => typeof script !== "string" || /(?:^|[\s&;|(])(?:jest|tsd|tstyche)(?:\s|$)|--typecheck/.test(script)))
1358
+ return false;
1359
+ }
1360
+ }
1361
+ return true;
1362
+ }
1174
1363
  function computeConfidence(unresolvedCount, dynamicUnresolvedCount, integrityCriticalCount, sourceFileCount, resolvedViaProjectReferences) {
1175
1364
  // An empty graph has nothing to flag as unresolved and nothing to violate integrity
1176
1365
  // checks, so without this it would fall through to "COMPLETE" — the worst possible
@@ -1253,14 +1442,28 @@ export function refineConfidenceForDelta(result, changedFiles) {
1253
1442
  if (result.unresolved.length === 0)
1254
1443
  return result.confidence;
1255
1444
  const reachableFromChanged = new Set();
1445
+ const dependents = new Set();
1446
+ const runtimeDependents = new Set();
1447
+ const runtimeOnly = result.runtimeTestSelection === true && typeof result.graph.transitiveRuntimeDependentsOf === "function";
1256
1448
  for (const file of changedFiles) {
1257
1449
  for (const dep of result.graph.transitiveDependenciesOf(file))
1258
1450
  reachableFromChanged.add(dep);
1259
- for (const dep of result.graph.transitiveDependentsOf(file))
1451
+ for (const dep of result.graph.transitiveDependentsOf(file)) {
1260
1452
  reachableFromChanged.add(dep);
1453
+ dependents.add(dep);
1454
+ }
1455
+ if (runtimeOnly)
1456
+ for (const dep of result.graph.transitiveRuntimeDependentsOf(file))
1457
+ runtimeDependents.add(dep);
1261
1458
  }
1262
1459
  const changedSet = new Set(changedFiles);
1263
- const relevantUnresolved = result.unresolved.some((u) => !u.computed && (changedSet.has(u.importer) || reachableFromChanged.has(u.importer)));
1460
+ // An importer that already depends on a changed file is affected, and so is everything depending on
1461
+ // it: whatever its missing edge points at, following that edge cannot reach a test that is not already
1462
+ // selected (2026-11-03: one broken `import type` in a LobeHub test file made 35 of 40 commits UNSAFE).
1463
+ // "Already depends" means through the edges that select tests: runtime edges when type-only ones do
1464
+ // not select (runtimeTestSelection), unless the missing edge is itself type-only.
1465
+ const alreadyAffected = (u) => (runtimeOnly && !u.typeOnly ? runtimeDependents : dependents).has(u.importer);
1466
+ const relevantUnresolved = result.unresolved.some((u) => !u.computed && !alreadyAffected(u) && (changedSet.has(u.importer) || reachableFromChanged.has(u.importer)));
1264
1467
  if (relevantUnresolved)
1265
1468
  return "UNSAFE";
1266
1469
  // None of the unresolved imports are reachable from this delta's changed files - narrow to what