@diffci.com/diffci 0.3.12 → 0.3.14

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 (65) hide show
  1. package/dist-client/src/client/agent-selection.js +4 -1
  2. package/dist-client/src/client/cli.js +4 -49
  3. package/dist-client/src/client/command-batches.js +80 -0
  4. package/dist-client/src/client/failure-baseline.js +99 -0
  5. package/dist-client/src/client/observe.js +11 -3
  6. package/dist-client/src/client/pilot-packet.js +0 -31
  7. package/dist-client/src/client/verify-savings.js +12 -1
  8. package/dist-client/src/client/verify.js +53 -5
  9. package/dist-client/src/client/workflow-templates.js +80 -0
  10. package/node_modules/@diffci.com/core/README.md +13 -7
  11. package/node_modules/@diffci.com/core/dist/analyze.js +2 -1
  12. package/node_modules/@diffci.com/core/dist/analyze.js.map +1 -1
  13. package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
  14. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +1 -1
  15. package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +9 -0
  16. package/node_modules/@diffci.com/core/dist/git/git-diff.js +122 -19
  17. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  18. package/node_modules/@diffci.com/core/dist/git/types.d.ts +9 -0
  19. package/node_modules/@diffci.com/core/dist/planner/test-command.js +16 -3
  20. package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
  21. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +99 -42
  22. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
  23. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.d.ts +16 -0
  24. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js +101 -0
  25. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js.map +1 -0
  26. package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +68 -0
  27. package/node_modules/@diffci.com/core/dist/repo/file-references.js +278 -0
  28. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -0
  29. package/node_modules/@diffci.com/core/dist/repo/graph.d.ts +4 -2
  30. package/node_modules/@diffci.com/core/dist/repo/graph.js +107 -31
  31. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  32. package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +7 -1
  33. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +32 -0
  34. package/node_modules/@diffci.com/core/dist/repo/impact.js +241 -20
  35. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  36. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +9 -3
  37. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
  38. package/node_modules/@diffci.com/core/dist/repo/script-universe.d.ts +16 -0
  39. package/node_modules/@diffci.com/core/dist/repo/script-universe.js +173 -0
  40. package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -0
  41. package/node_modules/@diffci.com/core/dist/repo/test-discovery.d.ts +12 -0
  42. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +54 -7
  43. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
  44. package/node_modules/@diffci.com/core/dist/repo/types.d.ts +8 -0
  45. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.d.ts +15 -0
  46. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +157 -0
  47. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -0
  48. package/node_modules/@diffci.com/core/package.json +5 -0
  49. package/node_modules/@diffci.com/core/src/analyze.ts +2 -1
  50. package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +1 -1
  51. package/node_modules/@diffci.com/core/src/git/git-diff.ts +106 -20
  52. package/node_modules/@diffci.com/core/src/git/types.ts +9 -0
  53. package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -3
  54. package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +120 -30
  55. package/node_modules/@diffci.com/core/src/repo/compiled-projects.ts +108 -0
  56. package/node_modules/@diffci.com/core/src/repo/file-references.ts +275 -0
  57. package/node_modules/@diffci.com/core/src/repo/graph.ts +104 -31
  58. package/node_modules/@diffci.com/core/src/repo/impact-types.ts +10 -0
  59. package/node_modules/@diffci.com/core/src/repo/impact.ts +243 -18
  60. package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +6 -3
  61. package/node_modules/@diffci.com/core/src/repo/script-universe.ts +158 -0
  62. package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +62 -7
  63. package/node_modules/@diffci.com/core/src/repo/types.ts +5 -0
  64. package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +117 -0
  65. package/package.json +2 -2
@@ -0,0 +1,278 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ /**
3
+ * Who reads this file? (2026-10-21, telemetry from two dogfood repositories.)
4
+ *
5
+ * WHY. A changed file that is not code - `site/docs/x.html`, `scripts/train.py`, `ops/.../blockers.json`,
6
+ * `.env.example` - previously meant "Unknown changed file" and a full run. Across 256 verification
7
+ * receipts this was the third most common fallback (76 receipts), and 138 of one repository's unknown files
8
+ * were site HTML whose only readers are two tests. The engine has no import edge for these, because tests
9
+ * reach them through the filesystem: `readFileSync(join(root, "site", ...))`, `readdirSync("fixtures")`,
10
+ * `spawn("python3", ["scripts/train.py"])`.
11
+ *
12
+ * THE RULE. A test suite can only observe a non-code file by naming it, or by naming a directory that
13
+ * contains it. So: collect every text file at HEAD that names the changed file's path, its basename, or
14
+ * one of its ancestor directories as a string, and resolve each reader:
15
+ *
16
+ * - a test reader is selected;
17
+ * - a code reader in the dependency graph selects the tests that depend on it;
18
+ * - a package.json reader counts only when the naming script runs as part of `npm test`;
19
+ * - a test-running workflow, a composite action or an unparseable package.json is unresolvable;
20
+ * - documentation names files constantly and executes nothing, so it is never a reader;
21
+ * - any other file - a shell script, a JSON manifest, or code no test imports (a standalone check
22
+ * script outside the dependency graph) - may itself be executed or read, so ITS readers are
23
+ * resolved in turn, to a bounded depth. A test can only run such a file by naming it.
24
+ *
25
+ * FAILING CLOSED. No reader at all, or any unresolvable reader, keeps the file unknown (full run).
26
+ * Evidence of who reads a file is required before anything narrows; the absence of a reference is never
27
+ * treated as proof that nothing reads it. Files that tools load implicitly, without any code naming them
28
+ * (`.gitignore`, `.env`, `tsconfig.json`, `wrangler.toml`, `Dockerfile`), never reach this resolver.
29
+ *
30
+ * RESIDUAL RISK. A reader that computes the path from parts that never appear as strings, or walks the
31
+ * whole repository from its root without naming a directory, is invisible here. Required CI stays
32
+ * authoritative for exactly that reason.
33
+ */
34
+ import { readFileSync, statSync } from "node:fs";
35
+ import { join, posix } from "node:path";
36
+ const MAX_READ_BYTES = 1_048_576;
37
+ /** Reads repo-relative text files from a checkout at HEAD, the same tree the dependency graph reads.
38
+ * Binary content (a NUL byte in the first 8 KiB) and files over 1 MiB are unreadable. */
39
+ export function repositoryFileReader(repoPath) {
40
+ return (path) => {
41
+ try {
42
+ const full = join(repoPath, path);
43
+ if (statSync(full).size > MAX_READ_BYTES)
44
+ return undefined;
45
+ const bytes = readFileSync(full);
46
+ if (bytes.subarray(0, 8192).includes(0))
47
+ return undefined;
48
+ return bytes.toString("utf8");
49
+ }
50
+ catch {
51
+ return undefined;
52
+ }
53
+ };
54
+ }
55
+ /** Names tools read without any code naming them. A change to one of these is never reference-resolved. */
56
+ const IMPLICIT_BASENAMES = new Set([
57
+ ".gitignore", ".gitattributes", ".gitmodules", ".npmrc", ".yarnrc", ".yarnrc.yml", ".nvmrc", ".node-version",
58
+ ".tool-versions", ".editorconfig", ".browserslistrc", ".babelrc", ".swcrc", ".mocharc", ".c8rc", ".nycrc",
59
+ "makefile", "procfile", "justfile", "taskfile.yml", "compose.yaml", "compose.yml", "turbo.json", "nx.json", "lerna.json",
60
+ ]);
61
+ const IMPLICIT_PREFIXES = ["tsconfig", "jsconfig", "wrangler.", "dockerfile", "docker-compose", ".dockerignore", ".mocharc.", ".c8rc.", ".nycrc.", "babel.config", ".babelrc."];
62
+ const ENV_TEMPLATE_SUFFIX = /\.(?:example|sample|template|dist)$/;
63
+ /** True when tooling may load `filePath` implicitly, so no reference to it would ever be written. */
64
+ export function isImplicitlyLoadedFile(filePath) {
65
+ const base = posix.basename(filePath).toLowerCase();
66
+ if (IMPLICIT_BASENAMES.has(base))
67
+ return true;
68
+ if (IMPLICIT_PREFIXES.some((prefix) => base.startsWith(prefix)))
69
+ return true;
70
+ if (/\.config\.[^.]+$/.test(base))
71
+ return true;
72
+ if (base === ".env" || (base.startsWith(".env.") && !ENV_TEMPLATE_SUFFIX.test(base)))
73
+ return true;
74
+ return /\.(?:tf|tfvars|hcl)$/.test(base);
75
+ }
76
+ const INFRASTRUCTURE_DIRS = new Set(["ops", "terraform", "cloudformation", "pulumi", "cdktf", "deploy", "deployments", "kubernetes", "k8s", "helm", "docker"]);
77
+ const CODE_EXTENSIONS = /\.(?:[cm]?[jt]sx?|vue|go|java|kt)$/i;
78
+ const DOCUMENT_EXTENSIONS = /\.(?:md|mdx)$/i;
79
+ /**
80
+ * What a file under an infrastructure directory is (2026-10-21). Everything under `ops/` used to force
81
+ * full validation - 55 of one dogfood repository's 124 receipts - yet that tree holds tested Worker code, runbooks
82
+ * and JSON evidence manifests as well as deployment definitions. Only a definition that tooling loads by
83
+ * convention is global; code goes through the dependency graph, Markdown is documentation, and other
84
+ * files are data whose readers are resolved by reference. `undefined` outside infrastructure trees.
85
+ */
86
+ export function infrastructureRole(filePath) {
87
+ const base = posix.basename(filePath);
88
+ if (/dockerfile/i.test(base))
89
+ return "definition";
90
+ const first = filePath.split("/")[0];
91
+ if (!first || !INFRASTRUCTURE_DIRS.has(first) || !filePath.includes("/"))
92
+ return undefined;
93
+ if (isImplicitlyLoadedFile(filePath))
94
+ return "definition";
95
+ if (CODE_EXTENSIONS.test(base))
96
+ return "code";
97
+ if (DOCUMENT_EXTENSIONS.test(base))
98
+ return "documentation";
99
+ return "data";
100
+ }
101
+ /** The strings whose appearance means a file names `filePath`: the path itself, its basename, and every
102
+ * ancestor directory (as a path and as a name). A bare name (no dot, no slash) must be delimited by
103
+ * quotes or slashes on both sides, so prose and identifiers do not match; anything else may also be
104
+ * delimited by whitespace, as in a shell command line.
105
+ *
106
+ * `ancestors: false` drops the directories. A script is run by naming it, so following who runs a code
107
+ * reader needs only its path and basename; in one dogfood repository the bare `"scripts"` matched nearly every
108
+ * file and no change under `site/` could ever resolve (2026-10-21 replay). */
109
+ export function referenceTokens(filePath, { ancestors = true } = {}) {
110
+ const tokens = new Map();
111
+ const add = (value) => { if (value && value !== ".")
112
+ tokens.set(value, { value, bare: !/[./]/.test(value) }); };
113
+ add(filePath);
114
+ add(posix.basename(filePath));
115
+ let dir = posix.dirname(filePath);
116
+ while (ancestors && dir !== "." && dir !== "/") {
117
+ add(dir);
118
+ add(posix.basename(dir));
119
+ dir = posix.dirname(dir);
120
+ }
121
+ return [...tokens.values()];
122
+ }
123
+ function escape(value) { return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); }
124
+ /** One regular expression matching any of `tokens` at a reference boundary. */
125
+ export function referencePattern(tokens) {
126
+ const parts = tokens.map(({ value, bare }) => bare
127
+ ? `["'\`/]${escape(value)}(?=["'\`/])`
128
+ : `(?:^|["'\`/\\s=(])${escape(value)}(?=$|["'\`/\\s),;:])`);
129
+ return new RegExp(parts.join("|"), "m");
130
+ }
131
+ const MAX_DEPTH = 5;
132
+ const MAX_TRANSITIVE_READERS = 50;
133
+ const LOCKFILES = new Set(["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lock", "bun.lockb", "npm-shrinkwrap.json"]);
134
+ const TEST_LIFECYCLE = ["pretest", "test", "posttest", "prepare", "preinstall", "install", "postinstall"];
135
+ /** Non-code files that can run something or direct what code reads: shell and interpreter scripts,
136
+ * and structured manifests. Only these are followed to their own readers. */
137
+ const DIRECTING_EXTENSIONS = /\.(?:sh|bash|zsh|ps1|psm1|bat|cmd|py|rb|pl|json|jsonc|json5|ya?ml|toml|ini|cfg|conf)$/i;
138
+ /** Script names reachable from `npm test`, including lifecycle hooks and any script one of those bodies
139
+ * names. Over-inclusive by design: a script name appearing anywhere in a reachable body is followed. */
140
+ export function testScriptClosure(scripts) {
141
+ const closure = new Set();
142
+ const queue = TEST_LIFECYCLE.filter((name) => typeof scripts[name] === "string");
143
+ while (queue.length > 0) {
144
+ const name = queue.shift();
145
+ if (closure.has(name))
146
+ continue;
147
+ closure.add(name);
148
+ for (const hook of [`pre${name}`, `post${name}`])
149
+ if (typeof scripts[hook] === "string")
150
+ queue.push(hook);
151
+ const body = scripts[name] ?? "";
152
+ for (const candidate of Object.keys(scripts)) {
153
+ if (!closure.has(candidate) && new RegExp(`(?:^|[\\s"'=&|;(])${escape(candidate)}(?=$|[\\s"'&|;)])`).test(body))
154
+ queue.push(candidate);
155
+ }
156
+ }
157
+ return closure;
158
+ }
159
+ function packageJsonNames(content, pattern) {
160
+ let parsed;
161
+ try {
162
+ parsed = JSON.parse(content);
163
+ }
164
+ catch {
165
+ return "unparseable";
166
+ }
167
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
168
+ return "unparseable";
169
+ const scripts = parsed.scripts;
170
+ if (!scripts || typeof scripts !== "object")
171
+ return "no";
172
+ const record = Object.fromEntries(Object.entries(scripts).filter((entry) => typeof entry[1] === "string"));
173
+ for (const name of testScriptClosure(record))
174
+ if (pattern.test(record[name] ?? ""))
175
+ return "yes";
176
+ return "no";
177
+ }
178
+ /** Resolves who reads `filePath`. See the module comment for the rule and its limits. */
179
+ export function resolveFileReferences(filePath, input) {
180
+ const resolution = { tests: [], code: [], unresolvable: [], readers: [] };
181
+ const tests = new Set();
182
+ const code = new Set();
183
+ const visited = new Set([filePath]);
184
+ let frontier = [{ path: filePath, via: filePath }];
185
+ let transitiveCount = 0;
186
+ const contents = new Map();
187
+ const read = (path) => { if (!contents.has(path))
188
+ contents.set(path, input.read(path)); return contents.get(path); };
189
+ for (let depth = 0; depth < MAX_DEPTH && frontier.length > 0; depth++) {
190
+ const next = [];
191
+ for (const target of frontier) {
192
+ // Directories are matched only for the changed file itself, which a test may find by listing its
193
+ // directory. A reader reached through the changed file (a script, a manifest) matters only if
194
+ // something runs or reads it by name; matching its directories as well made `"tests"` and
195
+ // `"fixtures"` match nearly every file and no generic name (package.json) could resolve.
196
+ const pattern = referencePattern(referenceTokens(target.path, { ancestors: target.path === filePath }));
197
+ for (const candidate of input.files) {
198
+ if (visited.has(candidate) || candidate === target.path || LOCKFILES.has(posix.basename(candidate)))
199
+ continue;
200
+ const base = posix.basename(candidate);
201
+ if (base === "package.json") {
202
+ const content = read(candidate);
203
+ if (content === undefined)
204
+ continue;
205
+ const named = packageJsonNames(content, pattern);
206
+ if (named === "no")
207
+ continue;
208
+ visited.add(candidate);
209
+ if (named === "unparseable") {
210
+ resolution.unresolvable.push(`${candidate} could not be parsed`);
211
+ continue;
212
+ }
213
+ resolution.readers.push({ path: candidate, kind: "package-script", via: target.path });
214
+ resolution.unresolvable.push(`${candidate} runs ${target.path} as part of its test script`);
215
+ continue;
216
+ }
217
+ if (input.isDocumentation(candidate))
218
+ continue;
219
+ const content = read(candidate);
220
+ if (content === undefined || !pattern.test(content))
221
+ continue;
222
+ visited.add(candidate);
223
+ if (candidate.startsWith(".github/")) {
224
+ // A workflow step that comes before a test step in its job, or a composite action, may feed
225
+ // the file to the suite's environment; issue templates and standalone CI checks do not.
226
+ // A change content inspection already showed cannot alter how tests run (a version bump)
227
+ // stays that way when a workflow reads the file.
228
+ const executes = candidate.startsWith(".github/actions/")
229
+ || (/^\.github\/workflows\//.test(candidate) && !input.contentCleared?.has(target.path) && input.workflowFeedsTests(content, pattern));
230
+ if (!executes)
231
+ continue;
232
+ resolution.readers.push({ path: candidate, kind: "unresolvable", via: target.path });
233
+ resolution.unresolvable.push(`${candidate} names ${target.path}`);
234
+ }
235
+ else if (input.isCodeFile(candidate) && input.isTestFile(candidate)) {
236
+ resolution.readers.push({ path: candidate, kind: "test", via: target.path });
237
+ tests.add(candidate);
238
+ }
239
+ else if (input.isCodeFile(candidate) && input.inGraph(candidate)) {
240
+ resolution.readers.push({ path: candidate, kind: "graph-code", via: target.path });
241
+ code.add(candidate);
242
+ }
243
+ else if (input.isCodeFile(candidate) || DIRECTING_EXTENSIONS.test(candidate)) {
244
+ resolution.readers.push({ path: candidate, kind: "transitive", via: target.path });
245
+ if (++transitiveCount > MAX_TRANSITIVE_READERS) {
246
+ resolution.unresolvable.push(`more than ${MAX_TRANSITIVE_READERS} non-code files name ${filePath}`);
247
+ break;
248
+ }
249
+ next.push({ path: candidate, via: target.path });
250
+ }
251
+ else {
252
+ // Markup, prose, images and licences name paths in links and URLs but execute nothing and
253
+ // direct no reads, so nothing reaches the suite through them.
254
+ resolution.readers.push({ path: candidate, kind: "documentation", via: target.path });
255
+ }
256
+ }
257
+ if (resolution.unresolvable.length > 0)
258
+ break;
259
+ }
260
+ if (resolution.unresolvable.length > 0)
261
+ break;
262
+ frontier = next;
263
+ }
264
+ if (resolution.unresolvable.length === 0 && frontier.length > 0) {
265
+ resolution.unresolvable.push(`reference chain from ${filePath} is deeper than ${MAX_DEPTH} files`);
266
+ }
267
+ // Found readers that something could run (check scripts, manifests), none of which any test, test
268
+ // script or test-feeding workflow step reaches: the suite cannot observe the file. Finding no such
269
+ // reader at all is different - the file's reader is unknown, so it stays unknown.
270
+ const executableReaders = resolution.readers.some((reader) => reader.kind === "transitive");
271
+ if (resolution.unresolvable.length === 0 && tests.size === 0 && code.size === 0 && !executableReaders) {
272
+ resolution.unresolvable.push(`no test or source file names ${filePath}`);
273
+ }
274
+ resolution.tests = [...tests].sort();
275
+ resolution.code = [...code].sort();
276
+ return resolution;
277
+ }
278
+ //# sourceMappingURL=file-references.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-references.js","sourceRoot":"","sources":["../../src/repo/file-references.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,O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DependencyGraph): GraphIn
51
51
  * graph for EVERY delta, for as long as that one file's import stays unresolved, regardless of whether
52
52
  * the delta being analyzed has anything to do with it.
53
53
  *
54
- * This narrows that: an unresolved import only makes THIS delta's confidence untrustworthy if the
55
- * unresolved import's importer file is actually reachable from the delta's changed files (in either
54
+ * For static unresolved references, this narrows that: an unresolved import makes THIS delta's
55
+ * confidence untrustworthy if its importer is actually reachable from the changed files (in either
56
56
  * direction - the changed file might depend on the incomplete file, or something reachable from the
57
57
  * changed file might). If none of the graph's unresolved imports are anywhere near this delta, the
58
58
  * graph's real incompleteness elsewhere cannot plausibly affect what can safely be determined about
59
59
  * THIS specific change.
60
60
  *
61
61
  * Deliberately NOT narrowed - these remain hard, global blockers regardless of the delta:
62
+ * - Unresolved runtime imports/requires: a computed target has no known graph edge, so lack of
63
+ * reachability cannot establish that it does not load one of the changed files.
62
64
  * - `sourceFileCount === 0` (an empty graph gives no reachability information to reason about at all).
63
65
  * - `integrity.criticalCount > 0` (the graph's own internal structure is broken - a construction bug,
64
66
  * not a property of any one file, so no delta-specific narrowing is meaningful).
@@ -64,9 +64,29 @@ function toRelativeInternal(repoPath, absolutePath) {
64
64
  function isExcludedPath(rel, excludeDirs) {
65
65
  return excludeDirs.some((dir) => rel === dir || rel.startsWith(`${dir}/`));
66
66
  }
67
+ /**
68
+ * Whether `require` at this call names a local binding rather than the module loader, as in an
69
+ * assertion helper `const require = (condition, code) => ...`. Such calls load nothing, so treating
70
+ * their arguments as computed specifiers made every delta in one dogfood repository UNSAFE. A local
71
+ * `require` initialised from `createRequire(...)` is the loader and is not a shadow. Scopes are
72
+ * tracked during the walk: source files parsed by the Program have no parent pointers.
73
+ */
74
+ function scopeShadowsRequire(scope) {
75
+ const declares = (name) => !!name && ts.isIdentifier(name) && name.text === "require";
76
+ const loaderInitializer = (init) => !!init && ts.isCallExpression(init) && ts.isIdentifier(init.expression) && init.expression.text === "createRequire";
77
+ const statementShadows = (statement) => (ts.isFunctionDeclaration(statement) && declares(statement.name)) ||
78
+ (ts.isVariableStatement(statement) && statement.declarationList.declarations.some((d) => declares(d.name) && !loaderInitializer(d.initializer)));
79
+ if ((ts.isBlock(scope) || ts.isSourceFile(scope) || ts.isModuleBlock(scope)) && scope.statements.some(statementShadows))
80
+ return true;
81
+ return ts.isFunctionLike(scope) && scope.parameters.some((p) => declares(p.name));
82
+ }
67
83
  function extractImportRefs(sourceFile) {
68
84
  const refs = [];
85
+ let shadowDepth = 0;
69
86
  function visit(node) {
87
+ const shadows = scopeShadowsRequire(node);
88
+ if (shadows)
89
+ shadowDepth++;
70
90
  if (ts.isImportDeclaration(node)) {
71
91
  const specifier = node.moduleSpecifier;
72
92
  if (ts.isStringLiteral(specifier)) {
@@ -75,6 +95,12 @@ function extractImportRefs(sourceFile) {
75
95
  refs.push({ specifier: specifier.text, kind, dynamic: false });
76
96
  }
77
97
  }
98
+ else if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)) {
99
+ const specifier = node.moduleReference.expression;
100
+ if (specifier && ts.isStringLiteral(specifier)) {
101
+ refs.push({ specifier: specifier.text, kind: node.isTypeOnly ? "type-import" : "require", dynamic: false });
102
+ }
103
+ }
78
104
  else if (ts.isExportDeclaration(node) && node.moduleSpecifier) {
79
105
  const specifier = node.moduleSpecifier;
80
106
  if (ts.isStringLiteral(specifier)) {
@@ -84,34 +110,21 @@ function extractImportRefs(sourceFile) {
84
110
  }
85
111
  else if (ts.isCallExpression(node)) {
86
112
  const firstArg = node.arguments[0];
87
- if (node.expression.kind === ts.SyntaxKind.ImportKeyword && firstArg) {
88
- if (ts.isStringLiteral(firstArg)) {
89
- refs.push({
90
- specifier: firstArg.text,
91
- kind: "dynamic-import",
92
- dynamic: true,
93
- });
94
- }
95
- else {
96
- refs.push({
97
- specifier: firstArg.getText(sourceFile).slice(0, 200),
98
- kind: "dynamic-import",
99
- dynamic: true,
100
- });
101
- }
102
- }
103
- else if (ts.isIdentifier(node.expression) &&
104
- node.expression.text === "require" &&
105
- firstArg &&
106
- ts.isStringLiteral(firstArg)) {
113
+ const isImport = node.expression.kind === ts.SyntaxKind.ImportKeyword;
114
+ const isRequire = ts.isIdentifier(node.expression) && node.expression.text === "require" && shadowDepth === 0;
115
+ if ((isImport || isRequire) && firstArg) {
116
+ const literal = ts.isStringLiteral(firstArg) || ts.isNoSubstitutionTemplateLiteral(firstArg);
107
117
  refs.push({
108
- specifier: firstArg.text,
109
- kind: "require",
110
- dynamic: false,
118
+ specifier: literal ? firstArg.text : firstArg.getText(sourceFile).slice(0, 200),
119
+ kind: isImport ? "dynamic-import" : "require",
120
+ dynamic: isImport || !literal,
121
+ computed: !literal,
111
122
  });
112
123
  }
113
124
  }
114
125
  ts.forEachChild(node, visit);
126
+ if (shadows)
127
+ shadowDepth--;
115
128
  }
116
129
  visit(sourceFile);
117
130
  return refs;
@@ -447,16 +460,45 @@ function createProgram(repoPath, fallbackSourceRoots = [], additionalSources = [
447
460
  fileNames = [...new Set([...fileNames, ...additionalSources])];
448
461
  options = { module: ts.ModuleKind.ESNext, moduleResolution: ts.ModuleResolutionKind.Bundler, target: ts.ScriptTarget.ES2022, ...options, allowJs: true };
449
462
  }
463
+ // The graph extracts syntax and import edges; it never asks TypeScript for a type checker or
464
+ // semantic diagnostics. Letting the Program resolve imports made it load every lib and node_modules
465
+ // declaration file: 5.6s of a median 8.2s analysis across a dogfood repository's paired runs (2026-10-21
466
+ // telemetry). Imports are resolved explicitly below with the original options, and an implementation
467
+ // file the root list missed is parsed when an import reaches it, within a budget that fails closed.
468
+ // `syntaxOnly` (scoped analysis) used to be the only caller given these options.
469
+ void syntaxOnly;
450
470
  const program = ts.createProgram({
451
471
  rootNames: fileNames,
452
- // Scoped analysis already inventories every implementation file. It extracts
453
- // syntax/import edges, never asks TypeScript for semantic diagnostics. Keep
454
- // the original options below for explicit module resolution.
455
- options: syntaxOnly ? { ...options, noResolve: true, noLib: true, types: [] } : options,
472
+ options: { ...options, noResolve: true, noLib: true, types: [] },
456
473
  configFileParsingDiagnostics,
457
474
  });
458
475
  return { program, options, fileNames, resolvedViaProjectReferences };
459
476
  }
477
+ /**
478
+ * Module resolution asks whether the same `node_modules` directories and candidate files exist for
479
+ * every importer; the moduleResolutionCache does not cover those probes. They were the largest single
480
+ * cost of graph construction (2026-10-21 profile). The tree does not change during one analysis, so
481
+ * each answer is read from the disk once.
482
+ */
483
+ function memoizedResolutionHost(system) {
484
+ const memo = (fn) => {
485
+ const answers = new Map();
486
+ return (path) => {
487
+ if (!answers.has(path))
488
+ answers.set(path, fn(path));
489
+ return answers.get(path);
490
+ };
491
+ };
492
+ return {
493
+ fileExists: memo((path) => system.fileExists(path)),
494
+ directoryExists: memo((path) => system.directoryExists(path)),
495
+ readFile: memo((path) => system.readFile(path)),
496
+ realpath: system.realpath ? memo((path) => system.realpath(path)) : undefined,
497
+ getCurrentDirectory: () => system.getCurrentDirectory(),
498
+ getDirectories: memo((path) => system.getDirectories(path)),
499
+ useCaseSensitiveFileNames: system.useCaseSensitiveFileNames,
500
+ };
501
+ }
460
502
  function classifySpecifier(specifier) {
461
503
  if (specifier.startsWith("`./") || specifier.startsWith("`../"))
462
504
  return "relative";
@@ -584,6 +626,11 @@ export async function buildDependencyGraph(options = {}) {
584
626
  profile.adapters = contributions.map(({ id, version, blockers }) => ({ id, version, blockers }));
585
627
  profile.goTestPackages = Object.assign({}, ...contributions.map((item) => item.testPackages));
586
628
  profile.goTestEnvironment = contributions.find((item) => item.id === "go")?.executionEnv;
629
+ const goContribution = contributions.find((item) => item.id === "go");
630
+ profile.goDependencyPaths = goContribution ? {
631
+ sources: [...new Set(goContribution.sourcePaths)].sort(),
632
+ embeds: [...new Set(goContribution.assetPaths)].sort(),
633
+ } : undefined;
587
634
  profile.mavenTestModules = Object.assign({}, ...contributions.filter((item) => item.id === "maven").map((item) => item.testPackages));
588
635
  const adapterTests = contributions.flatMap((item) => item.testFiles);
589
636
  profile.testFilePaths = [...new Set([...profile.testFilePaths, ...adapterTests])].sort();
@@ -637,6 +684,7 @@ export async function buildDependencyGraph(options = {}) {
637
684
  specifier: ref.specifier,
638
685
  reason,
639
686
  dynamic: ref.dynamic,
687
+ ...(ref.computed ? { computed: true } : {}),
640
688
  typeOnly: ref.kind === "type-import",
641
689
  });
642
690
  }
@@ -658,6 +706,7 @@ export async function buildDependencyGraph(options = {}) {
658
706
  // Resolve each importer with its own nearest project, never another package's
659
707
  // aliases. Invalid project configuration remains a hard safety blocker.
660
708
  const projectOptions = new Map();
709
+ const resolutionHost = memoizedResolutionHost(ts.sys);
661
710
  function hasUnavailableExternalBase(config, errors) {
662
711
  if (!config || typeof config !== "object")
663
712
  return false;
@@ -672,7 +721,19 @@ export async function buildDependencyGraph(options = {}) {
672
721
  // aliases. Any other diagnostic remains a hard blocker.
673
722
  return errors.every(error => error.code === 18003 || error.code === 5083 || error.code === 6053);
674
723
  }
724
+ // Nearest tsconfig.json per importer directory. Probing the disk for every importer walked to the
725
+ // repository root once per file: about a third of graph build time on a 2,000-file repository (2026-10-21).
726
+ const nearestConfig = new Map();
675
727
  function optionsFor(file) {
728
+ const key = dirname(file);
729
+ let options = nearestConfig.get(key);
730
+ if (!options) {
731
+ options = findOptionsFor(file);
732
+ nearestConfig.set(key, options);
733
+ }
734
+ return options;
735
+ }
736
+ function findOptionsFor(file) {
676
737
  let directory = dirname(file);
677
738
  while (toRelativeInternal(repoPath, directory) !== undefined) {
678
739
  const config = join(directory, "tsconfig.json");
@@ -709,6 +770,13 @@ export async function buildDependencyGraph(options = {}) {
709
770
  if (scope && sf.referencedFiles.length)
710
771
  adapterBlockers.push(`Triple-slash file references in the scoped suite require full validation: ${importerRel}`);
711
772
  for (const ref of refs) {
773
+ // Expression text is not a module name. In particular, import(name) must
774
+ // not be classified as an external package called "name".
775
+ if (ref.computed) {
776
+ recordUnresolved(importerRel, ref, "computed module specifier requires full validation");
777
+ recordReference("unresolved", importerRel, ref);
778
+ continue;
779
+ }
712
780
  if (!ref.specifier) {
713
781
  recordUnresolved(importerRel, ref, "empty specifier");
714
782
  recordReference("unresolved", importerRel, ref);
@@ -734,7 +802,7 @@ export async function buildDependencyGraph(options = {}) {
734
802
  recordReference("unresolved", importerRel, ref);
735
803
  continue;
736
804
  }
737
- const resolution = ts.resolveModuleName(resolvableSpecifier, sf.fileName, importerOptions, ts.sys, moduleResolutionCache);
805
+ const resolution = ts.resolveModuleName(resolvableSpecifier, sf.fileName, importerOptions, resolutionHost, moduleResolutionCache);
738
806
  if (!resolution.resolvedModule || !resolution.resolvedModule.resolvedFileName) {
739
807
  const category = classifySpecifier(ref.specifier);
740
808
  if (category === "relative" || category === "absolute" || category === "alias") {
@@ -1133,14 +1201,16 @@ function computeConfidence(unresolvedCount, dynamicUnresolvedCount, integrityCri
1133
1201
  * graph for EVERY delta, for as long as that one file's import stays unresolved, regardless of whether
1134
1202
  * the delta being analyzed has anything to do with it.
1135
1203
  *
1136
- * This narrows that: an unresolved import only makes THIS delta's confidence untrustworthy if the
1137
- * unresolved import's importer file is actually reachable from the delta's changed files (in either
1204
+ * For static unresolved references, this narrows that: an unresolved import makes THIS delta's
1205
+ * confidence untrustworthy if its importer is actually reachable from the changed files (in either
1138
1206
  * direction - the changed file might depend on the incomplete file, or something reachable from the
1139
1207
  * changed file might). If none of the graph's unresolved imports are anywhere near this delta, the
1140
1208
  * graph's real incompleteness elsewhere cannot plausibly affect what can safely be determined about
1141
1209
  * THIS specific change.
1142
1210
  *
1143
1211
  * Deliberately NOT narrowed - these remain hard, global blockers regardless of the delta:
1212
+ * - Unresolved runtime imports/requires: a computed target has no known graph edge, so lack of
1213
+ * reachability cannot establish that it does not load one of the changed files.
1144
1214
  * - `sourceFileCount === 0` (an empty graph gives no reachability information to reason about at all).
1145
1215
  * - `integrity.criticalCount > 0` (the graph's own internal structure is broken - a construction bug,
1146
1216
  * not a property of any one file, so no delta-specific narrowing is meaningful).
@@ -1154,6 +1224,12 @@ function computeConfidence(unresolvedCount, dynamicUnresolvedCount, integrityCri
1154
1224
  export function refineConfidenceForDelta(result, changedFiles) {
1155
1225
  if (result.adapterBlockers?.length)
1156
1226
  return "UNSAFE";
1227
+ // A computed runtime target can be any file, so its missing edge proves nothing about which changed
1228
+ // file it loads. It cannot, however, change the behaviour of a test that never runs the importer:
1229
+ // ImpactAnalyzer selects every test that does (COMPUTED_IMPORT) and falls back when the importer is
1230
+ // outside the graph. Computed references are therefore excluded from reachability below rather
1231
+ // than blocking every delta. A literal dynamic import names its only possible target and is
1232
+ // narrowed like any other unresolved import.
1157
1233
  // Anything that was never UNSAFE in the first place passes through untouched - there is nothing to
1158
1234
  // narrow, and re-deriving sourceFileCount/integrity from raw fields here (rather than trusting the
1159
1235
  // already-computed confidence) would be both redundant and a real correctness risk: a caller's
@@ -1184,7 +1260,7 @@ export function refineConfidenceForDelta(result, changedFiles) {
1184
1260
  reachableFromChanged.add(dep);
1185
1261
  }
1186
1262
  const changedSet = new Set(changedFiles);
1187
- const relevantUnresolved = result.unresolved.some((u) => changedSet.has(u.importer) || reachableFromChanged.has(u.importer));
1263
+ const relevantUnresolved = result.unresolved.some((u) => !u.computed && (changedSet.has(u.importer) || reachableFromChanged.has(u.importer)));
1188
1264
  if (relevantUnresolved)
1189
1265
  return "UNSAFE";
1190
1266
  // None of the unresolved imports are reachable from this delta's changed files - narrow to what