@diffci.com/diffci 0.3.15 → 0.3.17
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-selection.js +30 -0
- package/dist-client/src/client/cli.js +21 -2
- package/dist-client/src/client/gate-checks.js +120 -0
- package/dist-client/src/client/hook.js +94 -0
- package/dist-client/src/client/mcp.js +11 -3
- package/dist-client/src/client/observe.js +7 -2
- package/dist-client/src/client/verify.js +49 -8
- package/node_modules/@diffci.com/core/LICENSE +21 -661
- package/node_modules/@diffci.com/core/NOTICE +2 -2
- package/node_modules/@diffci.com/core/README.md +21 -3
- package/node_modules/@diffci.com/core/dist/analyze.js +1 -1
- package/node_modules/@diffci.com/core/dist/analyze.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/schema.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/schema.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/cli.js +1 -1
- package/node_modules/@diffci.com/core/dist/cli.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +29 -4
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +136 -22
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/types.d.ts +7 -0
- package/node_modules/@diffci.com/core/dist/index.js +1 -1
- package/node_modules/@diffci.com/core/dist/index.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/measurement.js +1 -1
- package/node_modules/@diffci.com/core/dist/measurement.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.d.ts +45 -0
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +252 -0
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.d.ts +60 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js +241 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/planner/script-reads.d.ts +31 -0
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js +197 -0
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/planner/type-program.d.ts +33 -0
- package/node_modules/@diffci.com/core/dist/planner/type-program.js +106 -0
- package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +32 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +180 -9
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +4 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +19 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +105 -3
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.d.ts +27 -0
- package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.js +116 -0
- package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/workspaces.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/workspaces.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/test-activity.js +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/test-activity.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
- package/node_modules/@diffci.com/core/package.json +1 -1
- package/node_modules/@diffci.com/core/src/analyze.ts +1 -1
- package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/causal.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/evidence.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/reference-graph.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/schema.ts +1 -1
- package/node_modules/@diffci.com/core/src/cli.ts +1 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +127 -21
- package/node_modules/@diffci.com/core/src/git/types.ts +7 -0
- package/node_modules/@diffci.com/core/src/index.ts +1 -1
- package/node_modules/@diffci.com/core/src/measurement.ts +1 -1
- package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +269 -0
- package/node_modules/@diffci.com/core/src/planner/pipeline-steps.ts +243 -0
- package/node_modules/@diffci.com/core/src/planner/script-reads.ts +174 -0
- package/node_modules/@diffci.com/core/src/planner/type-program.ts +103 -0
- package/node_modules/@diffci.com/core/src/repo/compiled-projects.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +170 -9
- package/node_modules/@diffci.com/core/src/repo/impact-types.ts +4 -0
- package/node_modules/@diffci.com/core/src/repo/impact.ts +115 -2
- package/node_modules/@diffci.com/core/src/repo/npm-lockfile.ts +109 -0
- package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/workspaces.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/path-baseline.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/registry.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/test-activity.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
2
|
/**
|
|
3
3
|
* Who reads this file? (2026-10-21, telemetry from two dogfood repositories.)
|
|
4
4
|
*
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { readFileSync, statSync } from "node:fs";
|
|
35
35
|
import { join, posix } from "node:path";
|
|
36
|
+
import { matchesGlob } from "./test-discovery.js";
|
|
36
37
|
|
|
37
38
|
const MAX_READ_BYTES = 1_048_576;
|
|
38
39
|
|
|
@@ -141,6 +142,13 @@ export interface ReferenceResolutionInput {
|
|
|
141
142
|
/** Changed files whose content analyzeGitDelta proved cannot change how tests run
|
|
142
143
|
* (GitDeltaAnalysis.referenceResolvedPaths); a workflow reading them does not block. */
|
|
143
144
|
contentCleared?: ReadonlySet<string>;
|
|
145
|
+
/** Treat a reader that tooling loads implicitly (wrangler config, Dockerfile, `*.config.*`) as
|
|
146
|
+
* unresolvable. Used for code: such a reader can run the file without anything naming it. */
|
|
147
|
+
implicitReadersUnresolvable?: boolean;
|
|
148
|
+
/** Resolve a file the root test script runs directly (`node scripts/test-security.js`) to that phase
|
|
149
|
+
* of the script instead of failing closed (ReferenceResolution.phases). Off by default: a caller
|
|
150
|
+
* that does not run the returned phases must keep the fallback. */
|
|
151
|
+
testPhases?: boolean;
|
|
144
152
|
}
|
|
145
153
|
|
|
146
154
|
export interface ReferenceResolution {
|
|
@@ -152,6 +160,9 @@ export interface ReferenceResolution {
|
|
|
152
160
|
unresolvable: string[];
|
|
153
161
|
/** Every reader found, for evidence. */
|
|
154
162
|
readers: Array<{ path: string; kind: ReaderKind; via: string }>;
|
|
163
|
+
/** Phases of the root test script, verbatim, that run a reader directly; the caller must run them.
|
|
164
|
+
* Only produced with `testPhases`. */
|
|
165
|
+
phases: string[];
|
|
155
166
|
}
|
|
156
167
|
|
|
157
168
|
const MAX_DEPTH = 5;
|
|
@@ -180,20 +191,163 @@ export function testScriptClosure(scripts: Readonly<Record<string, string>>): Se
|
|
|
180
191
|
return closure;
|
|
181
192
|
}
|
|
182
193
|
|
|
183
|
-
|
|
194
|
+
const GLOB_CHARS = /[*?[\]{}]/;
|
|
195
|
+
const PATH_WORD = /^[A-Za-z0-9._\-/@+~*?[\]{}!,]+$/;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Whether a script body names `target`, judged word by word (2026-10-28). The reference pattern alone
|
|
199
|
+
* matched a test script that lists `ops/cloudflare/src/a.test.mjs` as naming every file under
|
|
200
|
+
* `ops/cloudflare/`, because the directory is a prefix of the listed file - in one dogfood repository, whose
|
|
201
|
+
* `test` script lists ~60 files, that made every data file under `scripts/` and `ops/` unresolvable.
|
|
202
|
+
* A word that is a different concrete path names that file, not its directories. Anything the check
|
|
203
|
+
* cannot read as a plain path or glob (inline code, variables, quotes inside a word) still counts as
|
|
204
|
+
* naming the target whenever the reference pattern matches it.
|
|
205
|
+
*/
|
|
206
|
+
export function scriptNamesPath(body: string, target: string, pattern: RegExp, { ancestors = true, cwd = "" }: { ancestors?: boolean; cwd?: string } = {}): boolean {
|
|
207
|
+
if (!pattern.test(body)) return false;
|
|
208
|
+
const targetBase = posix.basename(target);
|
|
209
|
+
const dirs: string[] = [];
|
|
210
|
+
for (let dir = posix.dirname(target); ancestors && dir !== "." && dir !== "/"; dir = posix.dirname(dir)) dirs.push(dir);
|
|
211
|
+
for (const raw of body.split(/\s+/)) {
|
|
212
|
+
const word = raw.replace(/^["']+|["']+$/g, "");
|
|
213
|
+
if (!word) continue;
|
|
214
|
+
for (const candidate of word.includes("=") ? [word, word.slice(word.indexOf("=") + 1)] : [word]) {
|
|
215
|
+
if (!candidate) continue;
|
|
216
|
+
if (!PATH_WORD.test(candidate)) {
|
|
217
|
+
if (pattern.test(candidate) || pattern.test(raw)) return true;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
if (candidate.startsWith("../") || candidate.startsWith("/") || candidate.startsWith("~")) {
|
|
221
|
+
if (posix.basename(candidate) === targetBase || pattern.test(` ${candidate} `)) return true;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const resolved = posix.normalize(posix.join(cwd || ".", candidate)).replace(/\/+$/, "");
|
|
225
|
+
if (GLOB_CHARS.test(candidate)) {
|
|
226
|
+
// Character classes are widened to any character, so an unsupported class syntax can only
|
|
227
|
+
// over-match. A glob naming a directory (`ops/*`) reaches the files inside it.
|
|
228
|
+
const widened = resolved.replace(/\[[^\]]*\]/g, "?");
|
|
229
|
+
if ([target, ...dirs].some((path) => matchesGlob(path, widened))) return true;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (resolved === target || dirs.includes(resolved)) return true;
|
|
233
|
+
if (!candidate.includes("/") && (candidate === targetBase || dirs.some((dir) => posix.basename(dir) === candidate))) return true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const CONTENT_PATH_WORD = /[A-Za-z0-9._\-/@+~*?{}[\]!,$]+/g;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Whether `content`, read from `readerPath`, names `target` (or, with `ancestors`, one of its
|
|
243
|
+
* directories), once each matching word is read as a whole path (2026-10-28). The reference pattern
|
|
244
|
+
* matches on the basename, so every `wrangler.jsonc` with `"main": "./src/index.js"` named every
|
|
245
|
+
* `src/index.js` in the repository, and `ops/cloudflare/src/a.js` named `ops/cloudflare/src/b.json` by
|
|
246
|
+
* sharing its directory. A word that resolves - from the reader's directory or the repository root - to
|
|
247
|
+
* a different file names that file. Bare names, globs and variables keep the conservative answer.
|
|
248
|
+
*/
|
|
249
|
+
export function contentNamesPath(content: string, readerPath: string, target: string, pattern: RegExp, ancestors: boolean): boolean {
|
|
250
|
+
if (!pattern.test(content)) return false;
|
|
251
|
+
const dirs: string[] = [];
|
|
252
|
+
for (let dir = posix.dirname(target); ancestors && dir !== "." && dir !== "/"; dir = posix.dirname(dir)) dirs.push(dir);
|
|
253
|
+
const names = [target, ...dirs];
|
|
254
|
+
const readerDir = posix.dirname(readerPath);
|
|
255
|
+
for (const match of content.matchAll(CONTENT_PATH_WORD)) {
|
|
256
|
+
const word = match[0].replace(/[,.]+$/, "");
|
|
257
|
+
if (!pattern.test(`"${word}"`)) continue;
|
|
258
|
+
if (!word.includes("/") || /[*?{}[\]!$]/.test(word)) return true;
|
|
259
|
+
const trimmed = word.replace(/\/+$/, "");
|
|
260
|
+
const resolved = [posix.normalize(posix.join(readerDir, trimmed))];
|
|
261
|
+
if (!trimmed.startsWith("../")) resolved.push(posix.normalize(trimmed.replace(/^\/+/, "")));
|
|
262
|
+
if (resolved.some((path) => names.includes(path))) return true;
|
|
263
|
+
if (trimmed.startsWith(".")) continue;
|
|
264
|
+
// Relative to an unknown working directory, or an absolute path: any suffix relation counts.
|
|
265
|
+
if (names.some((name) => name === trimmed || name.endsWith(`/${trimmed}`) || trimmed.endsWith(`/${name}`))) return true;
|
|
266
|
+
}
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Configs that tooling loads by their default name and that can run a repository file - a Worker
|
|
271
|
+
* entry point, a container command, a test setup file, a bundler plugin - without a test naming
|
|
272
|
+
* either. `tsconfig.json`, `.gitignore` and lint or style configs list paths but run nothing; a
|
|
273
|
+
* non-default `wrangler.validation.json` is used only when a command names it. */
|
|
274
|
+
const RUNS_FILES_WITHOUT_NAMING = /^(?:wrangler\.(?:toml|json|jsonc)|dockerfile.*|docker-compose.*|compose\.ya?ml|procfile|makefile|justfile|taskfile\.ya?ml|(?:vitest|vite|jest|playwright|cypress|ava|babel|webpack|rollup|esbuild|vue|nuxt|svelte|astro|next)\.config\..+|\.mocharc.*|\.babelrc.*|\.c8rc.*|\.nycrc.*)$/i;
|
|
275
|
+
|
|
276
|
+
function loadsWithoutNaming(path: string): boolean {
|
|
277
|
+
return RUNS_FILES_WITHOUT_NAMING.test(posix.basename(path));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const ENV_TEMPLATE = /^\.env(?:\.[^.]+)*\.(?:example|sample|template|dist)$|^env\.(?:example|sample|template)$/i;
|
|
281
|
+
/** Packages that load `.env.example` without being told its name. */
|
|
282
|
+
const IMPLICIT_ENV_TEMPLATE_LOADERS = /["'](?:dotenv-safe|dotenv-extended|dotenv-mono)["']/;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Files whose only loader is outside the test process, so with no reader at all the suite cannot
|
|
286
|
+
* observe them (2026-10-28):
|
|
287
|
+
* - a workflow analyzeGitDelta already showed runs no tests (contentCleared) - GitHub runs it, a test
|
|
288
|
+
* only sees it by naming it;
|
|
289
|
+
* - an environment template (`.env.example`) - a person copies it; dotenv loads `.env`, never the
|
|
290
|
+
* template, unless the repository depends on a loader that reads the template by default.
|
|
291
|
+
* Every other file with no reader stays unknown: absence of a reference is not proof in general.
|
|
292
|
+
*/
|
|
293
|
+
function loadedOnlyOutsideTests(filePath: string, input: ReferenceResolutionInput, read: (path: string) => string | undefined): boolean {
|
|
294
|
+
if (/^\.github\/workflows\/[^/]+\.ya?ml$/.test(filePath)) return input.contentCleared?.has(filePath) === true;
|
|
295
|
+
if (!ENV_TEMPLATE.test(posix.basename(filePath))) return false;
|
|
296
|
+
const manifest = read("package.json");
|
|
297
|
+
return manifest !== undefined && !IMPLICIT_ENV_TEMPLATE_LOADERS.test(manifest);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
const PHASE_INTERPRETERS = new Set(["node", "tsx"]);
|
|
301
|
+
const PHASE_VALUE_FLAGS = new Set(["--conditions", "-C", "--import", "--require", "-r", "--loader", "--experimental-loader", "--env-file", "--tsconfig"]);
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* The `&&` phases of the root test closure that run `target` directly with an interpreter
|
|
305
|
+
* (`node scripts/test-security.js`, `tsx --import ./setup.mjs scripts/x.ts`), when those phases
|
|
306
|
+
* are the only way the closure names it; undefined otherwise (2026-10-28). Such a phase is a test in
|
|
307
|
+
* all but name: one dogfood repository's `npm test` ends with two, one of which reads every file under `src/`
|
|
308
|
+
* and `scripts/`, and every data file there fell back to the full suite for it. Running the phase
|
|
309
|
+
* itself covers it.
|
|
310
|
+
*/
|
|
311
|
+
function directTestPhases(content: string, target: string, pattern: RegExp, ancestors: boolean): string[] | undefined {
|
|
312
|
+
let record: Record<string, string>;
|
|
313
|
+
try {
|
|
314
|
+
const scripts = (JSON.parse(content) as { scripts?: unknown }).scripts;
|
|
315
|
+
if (!scripts || typeof scripts !== "object") return undefined;
|
|
316
|
+
record = Object.fromEntries(Object.entries(scripts).filter((entry): entry is [string, string] => typeof entry[1] === "string"));
|
|
317
|
+
} catch {
|
|
318
|
+
return undefined;
|
|
319
|
+
}
|
|
320
|
+
const found: string[] = [];
|
|
321
|
+
for (const name of testScriptClosure(record)) {
|
|
322
|
+
const rest: string[] = [];
|
|
323
|
+
for (const phase of (record[name] ?? "").split("&&").map((part) => part.trim())) {
|
|
324
|
+
const words = phase.split(/\s+/);
|
|
325
|
+
const runs = words.length >= 2 && PHASE_INTERPRETERS.has(words[0]!)
|
|
326
|
+
&& posix.normalize(words[words.length - 1]!) === target
|
|
327
|
+
&& words.slice(1, -1).every((word, index, middle) => word.startsWith("-") || PHASE_VALUE_FLAGS.has(middle[index - 1] ?? ""))
|
|
328
|
+
&& !/[|;<>`$(]/.test(phase);
|
|
329
|
+
if (runs) found.push(phase); else rest.push(phase);
|
|
330
|
+
}
|
|
331
|
+
if (scriptNamesPath(rest.join(" && "), target, pattern, { ancestors })) return undefined;
|
|
332
|
+
}
|
|
333
|
+
return found.length > 0 ? found : undefined;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function packageJsonNames(content: string, pattern: RegExp, target: string, ancestors: boolean, cwd: string): "yes" | "no" | "unparseable" {
|
|
184
337
|
let parsed: unknown;
|
|
185
338
|
try { parsed = JSON.parse(content); } catch { return "unparseable"; }
|
|
186
339
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return "unparseable";
|
|
187
340
|
const scripts = (parsed as { scripts?: unknown }).scripts;
|
|
188
341
|
if (!scripts || typeof scripts !== "object") return "no";
|
|
189
342
|
const record = Object.fromEntries(Object.entries(scripts).filter((entry): entry is [string, string] => typeof entry[1] === "string"));
|
|
190
|
-
for (const name of testScriptClosure(record)) if (
|
|
343
|
+
for (const name of testScriptClosure(record)) if (scriptNamesPath(record[name] ?? "", target, pattern, { ancestors, cwd })) return "yes";
|
|
191
344
|
return "no";
|
|
192
345
|
}
|
|
193
346
|
|
|
194
347
|
/** Resolves who reads `filePath`. See the module comment for the rule and its limits. */
|
|
195
348
|
export function resolveFileReferences(filePath: string, input: ReferenceResolutionInput): ReferenceResolution {
|
|
196
|
-
const resolution: ReferenceResolution = { tests: [], code: [], unresolvable: [], readers: [] };
|
|
349
|
+
const resolution: ReferenceResolution = { tests: [], code: [], unresolvable: [], readers: [], phases: [] };
|
|
350
|
+
const phases = new Set<string>();
|
|
197
351
|
const tests = new Set<string>();
|
|
198
352
|
const code = new Set<string>();
|
|
199
353
|
const visited = new Set<string>([filePath]);
|
|
@@ -209,26 +363,32 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
209
363
|
// directory. A reader reached through the changed file (a script, a manifest) matters only if
|
|
210
364
|
// something runs or reads it by name; matching its directories as well made `"tests"` and
|
|
211
365
|
// `"fixtures"` match nearly every file and no generic name (package.json) could resolve.
|
|
212
|
-
const
|
|
366
|
+
const ancestors = target.path === filePath;
|
|
367
|
+
const pattern = referencePattern(referenceTokens(target.path, { ancestors }));
|
|
213
368
|
for (const candidate of input.files) {
|
|
214
369
|
if (visited.has(candidate) || candidate === target.path || LOCKFILES.has(posix.basename(candidate))) continue;
|
|
215
370
|
const base = posix.basename(candidate);
|
|
216
371
|
if (base === "package.json") {
|
|
217
372
|
const content = read(candidate);
|
|
218
373
|
if (content === undefined) continue;
|
|
219
|
-
const named = packageJsonNames(content, pattern);
|
|
374
|
+
const named = packageJsonNames(content, pattern, target.path, ancestors, posix.dirname(candidate));
|
|
220
375
|
if (named === "no") continue;
|
|
221
376
|
visited.add(candidate);
|
|
222
377
|
if (named === "unparseable") { resolution.unresolvable.push(`${candidate} could not be parsed`); continue; }
|
|
223
378
|
resolution.readers.push({ path: candidate, kind: "package-script", via: target.path });
|
|
379
|
+
const direct = input.testPhases && candidate === "package.json" ? directTestPhases(content, target.path, pattern, ancestors) : undefined;
|
|
380
|
+
if (direct) { for (const phase of direct) phases.add(phase); continue; }
|
|
224
381
|
resolution.unresolvable.push(`${candidate} runs ${target.path} as part of its test script`);
|
|
225
382
|
continue;
|
|
226
383
|
}
|
|
227
384
|
if (input.isDocumentation(candidate)) continue;
|
|
228
385
|
const content = read(candidate);
|
|
229
|
-
if (content === undefined || !
|
|
386
|
+
if (content === undefined || !contentNamesPath(content, candidate, target.path, pattern, ancestors)) continue;
|
|
230
387
|
visited.add(candidate);
|
|
231
|
-
if (
|
|
388
|
+
if (input.implicitReadersUnresolvable && loadsWithoutNaming(candidate)) {
|
|
389
|
+
resolution.readers.push({ path: candidate, kind: "unresolvable", via: target.path });
|
|
390
|
+
resolution.unresolvable.push(`${candidate} is loaded by tooling and names ${target.path}`);
|
|
391
|
+
} else if (candidate.startsWith(".github/")) {
|
|
232
392
|
// A workflow step that comes before a test step in its job, or a composite action, may feed
|
|
233
393
|
// the file to the suite's environment; issue templates and standalone CI checks do not.
|
|
234
394
|
// A change content inspection already showed cannot alter how tests run (a version bump)
|
|
@@ -266,9 +426,10 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
266
426
|
// script or test-feeding workflow step reaches: the suite cannot observe the file. Finding no such
|
|
267
427
|
// reader at all is different - the file's reader is unknown, so it stays unknown.
|
|
268
428
|
const executableReaders = resolution.readers.some((reader) => reader.kind === "transitive");
|
|
269
|
-
if (resolution.unresolvable.length === 0 && tests.size === 0 && code.size === 0 && !executableReaders) {
|
|
429
|
+
if (resolution.unresolvable.length === 0 && tests.size === 0 && code.size === 0 && !executableReaders && !loadedOnlyOutsideTests(filePath, input, read)) {
|
|
270
430
|
resolution.unresolvable.push(`no test or source file names ${filePath}`);
|
|
271
431
|
}
|
|
432
|
+
resolution.phases = resolution.unresolvable.length === 0 ? [...phases].sort() : [];
|
|
272
433
|
resolution.tests = [...tests].sort();
|
|
273
434
|
resolution.code = [...code].sort();
|
|
274
435
|
return resolution;
|
|
@@ -88,6 +88,10 @@ export interface ImpactResult {
|
|
|
88
88
|
/** Affected tests that the test script does not run. Not part of the selection, which stays a
|
|
89
89
|
* subset of the full suite, but still worth running. Present only with `fullSuiteTestCount`. */
|
|
90
90
|
testsOutsideFullSuite?: TestImpact[];
|
|
91
|
+
/** Phases of the root test script, verbatim, that a selective run must execute besides the selected
|
|
92
|
+
* test files (`node scripts/test-security.js`). Only produced with `selectTestPhases`; present
|
|
93
|
+
* whenever the selection relies on them. */
|
|
94
|
+
testPhases?: string[];
|
|
91
95
|
affectedEntryPoints: EntryPointImpact[];
|
|
92
96
|
affectedScripts: string[];
|
|
93
97
|
|
|
@@ -8,7 +8,7 @@ import { refineConfidenceForDelta } from "./graph.js";
|
|
|
8
8
|
import { repositoryLayout, UNKNOWN_REPOSITORY_LAYOUT, type RepositoryLayout } from "./layout.js";
|
|
9
9
|
import { DEFAULT_TEST_FILE_MATCHER, matchesGlob as matchesTestGlob, testDiscoveryErrors, testFileMatcherForProfile } from "./test-discovery.js";
|
|
10
10
|
import { resolveTestFixtureOwners } from "./test-fixture-ownership.js";
|
|
11
|
-
import { infrastructureRole, isImplicitlyLoadedFile, resolveFileReferences } from "./file-references.js";
|
|
11
|
+
import { infrastructureRole, isImplicitlyLoadedFile, resolveFileReferences, testScriptClosure } from "./file-references.js";
|
|
12
12
|
import { workflowFeedsTests } from "./workflow-test-steps.js";
|
|
13
13
|
import { modelTestScriptUniverse, type ScriptUniverse } from "./script-universe.js";
|
|
14
14
|
import { compiledProjects, type CompiledProject } from "./compiled-projects.js";
|
|
@@ -192,6 +192,9 @@ export interface ImpactAnalyzeOptions {
|
|
|
192
192
|
* `repositoryFiles` it enables resolving the readers of non-code files by reference
|
|
193
193
|
* (src/repo/file-references.ts). Omitting it keeps such files unknown, exactly as before. */
|
|
194
194
|
readRepositoryFile?: (path: string) => string | undefined;
|
|
195
|
+
/** Let a file the root test script runs directly be covered by running that phase
|
|
196
|
+
* (ImpactResult.testPhases) instead of falling back. Only for callers that execute the phases. */
|
|
197
|
+
selectTestPhases?: boolean;
|
|
195
198
|
}
|
|
196
199
|
|
|
197
200
|
function changedFileReasons(file: ChangedFile): ImpactReason[] {
|
|
@@ -252,6 +255,8 @@ export class ImpactAnalyzer {
|
|
|
252
255
|
private sortedRepositoryFiles: string[] = [];
|
|
253
256
|
private compiledProjectCache: CompiledProject[] | undefined;
|
|
254
257
|
private goEmbedPaths = new Set<string>();
|
|
258
|
+
private selectTestPhases = false;
|
|
259
|
+
private testPhases = new Set<string>();
|
|
255
260
|
constructor(alwaysRunChecks: AlwaysRunCheck[] = DEFAULT_ALWAYS_RUN_CHECKS) { this.alwaysRunChecks = alwaysRunChecks; }
|
|
256
261
|
|
|
257
262
|
analyze(delta: GitDelta, graphResult: DependencyGraphResult, profile: RepositoryProfile, options: ImpactAnalyzeOptions = {}): ImpactResult {
|
|
@@ -260,6 +265,8 @@ export class ImpactAnalyzer {
|
|
|
260
265
|
this.isTestFile = testFileMatcherForProfile(profile);
|
|
261
266
|
this.layout = repositoryLayout(profile);
|
|
262
267
|
this.repositoryFiles = options.repositoryFiles;
|
|
268
|
+
this.selectTestPhases = options.selectTestPhases === true;
|
|
269
|
+
this.testPhases = new Set();
|
|
263
270
|
this.sortedRepositoryFiles = options.repositoryFiles ? [...options.repositoryFiles].sort() : [];
|
|
264
271
|
this.compiledProjectCache = undefined;
|
|
265
272
|
// One read per file per analysis, however many changed files ask who reads them.
|
|
@@ -348,6 +355,8 @@ export class ImpactAnalyzer {
|
|
|
348
355
|
}
|
|
349
356
|
}
|
|
350
357
|
|
|
358
|
+
this.collectTestScriptAdditions(delta, graph, affectedTests, evidence, riskSignals, fallbackReasons);
|
|
359
|
+
this.collectDependencyChangeTests(delta, graphResult, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, riskSignals, fallbackReasons);
|
|
351
360
|
this.handleStructuralNextLayout(changedImpacts, profile, affectedEntryPoints, affectedSources, evidence);
|
|
352
361
|
this.handleAddedEntryPoints(delta, affectedEntryPoints, affectedSources, affectedTests, evidence, fallbackReasons);
|
|
353
362
|
this.collectAlwaysRunTests(profile, graph, affectedTests, evidence, graphResult.profile.vueRuntimeAlwaysRunPaths ?? []);
|
|
@@ -396,6 +405,7 @@ export class ImpactAnalyzer {
|
|
|
396
405
|
fullSuiteTestCount: fullSuite.tests.length,
|
|
397
406
|
testsOutsideFullSuite: testsOutsideFullSuite.sort((a, b) => a.path.localeCompare(b.path)),
|
|
398
407
|
} : {}),
|
|
408
|
+
...(this.testPhases.size ? { testPhases: [...this.testPhases].sort() } : {}),
|
|
399
409
|
affectedEntryPoints: Array.from(affectedEntryPoints.values()).sort((a, b) => a.path.localeCompare(b.path)),
|
|
400
410
|
affectedScripts: Array.from(affectedScripts.keys()).sort(),
|
|
401
411
|
riskSignals: dedupedRiskSignals,
|
|
@@ -431,6 +441,97 @@ export class ImpactAnalyzer {
|
|
|
431
441
|
}
|
|
432
442
|
}
|
|
433
443
|
|
|
444
|
+
/** A test file a test-list edit added to the test script now runs as part of the suite, whether or
|
|
445
|
+
* not it changed (src/git/git-diff.ts, testListEdit). One that is missing at HEAD would make the
|
|
446
|
+
* script fail, so it falls back. */
|
|
447
|
+
private collectTestScriptAdditions(delta: GitDelta, graph: DependencyGraph, affectedTests: Map<string, TestImpact>, evidence: ImpactEvidence[], riskSignals: ImpactRiskSignal[], fallbackReasons: string[]): void {
|
|
448
|
+
for (const path of delta.analysis.testScriptAddedPaths ?? []) {
|
|
449
|
+
if (this.repositoryFiles && !this.repositoryFiles.has(path)) {
|
|
450
|
+
const message = `package.json test script now lists ${path}, which does not exist; full validation required`;
|
|
451
|
+
riskSignals.push({ level: "critical", reason: "DEPENDENCY_MANIFEST", message, paths: ["package.json"] });
|
|
452
|
+
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
this.addAffectedTest("package.json", path, graph, affectedTests, "NEW_TEST_FILE", evidence);
|
|
456
|
+
evidence.push(makeEvidence("NEW_TEST_FILE", "package.json", `package.json test script now runs ${path}`, path));
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Selects the tests that load each direct dependency whose installed tree changed
|
|
462
|
+
* (GitDeltaAnalysis.changedDependencies, 2026-10-28). A package reaches a test only by being loaded:
|
|
463
|
+
* imported by graph code, which selects the importer's dependent tests; imported by code outside the
|
|
464
|
+
* graph, whose own readers are resolved by reference; or loaded by tooling, which this cannot see.
|
|
465
|
+
* So the change falls back when no repository code imports the package (a CLI, a plugin, `@types/*`),
|
|
466
|
+
* when a test-closure script names it, or when a file tooling loads implicitly names it (a config
|
|
467
|
+
* that registers a plugin or a preset).
|
|
468
|
+
*/
|
|
469
|
+
private collectDependencyChangeTests(
|
|
470
|
+
delta: GitDelta,
|
|
471
|
+
graphResult: DependencyGraphResult,
|
|
472
|
+
profile: RepositoryProfile,
|
|
473
|
+
affectedSources: Map<string, ImpactEvidence[]>,
|
|
474
|
+
affectedEntryPoints: Map<string, EntryPointImpact>,
|
|
475
|
+
affectedTests: Map<string, TestImpact>,
|
|
476
|
+
affectedScripts: Map<string, ImpactEvidence[]>,
|
|
477
|
+
evidence: ImpactEvidence[],
|
|
478
|
+
riskSignals: ImpactRiskSignal[],
|
|
479
|
+
fallbackReasons: string[],
|
|
480
|
+
): void {
|
|
481
|
+
const packages = delta.analysis.changedDependencies;
|
|
482
|
+
if (!packages || packages.length === 0) return;
|
|
483
|
+
const { graph } = graphResult;
|
|
484
|
+
const fail = (message: string) => {
|
|
485
|
+
riskSignals.push({ level: "critical", reason: "DEPENDENCY_MANIFEST", message, paths: ["package.json"] });
|
|
486
|
+
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
487
|
+
};
|
|
488
|
+
// Typecheck and build tasks still see a dependency change (planner globalRiskTriggers).
|
|
489
|
+
riskSignals.push({ level: "info", reason: "DEPENDENCY_MANIFEST", message: `Dependencies changed: ${packages.join(", ")}`, paths: ["package.json"] });
|
|
490
|
+
if (!this.repositoryFiles || !this.readRepositoryFile) {
|
|
491
|
+
fail(`Dependency change (${packages.join(", ")}) cannot be traced without repository contents; full validation required`);
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const packageRoot = (specifier: string) => {
|
|
495
|
+
const parts = specifier.split("/");
|
|
496
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]!;
|
|
497
|
+
};
|
|
498
|
+
const scripts = profile.packageJson.scripts;
|
|
499
|
+
const closureBodies = [...testScriptClosure(scripts)].map((name) => scripts[name] ?? "");
|
|
500
|
+
for (const name of packages) {
|
|
501
|
+
const importers = [...new Set(graphResult.references
|
|
502
|
+
.filter((ref) => ref.resolution === "external-package" && packageRoot(ref.specifier) === name)
|
|
503
|
+
.map((ref) => ref.importer))].sort();
|
|
504
|
+
if (importers.length === 0) {
|
|
505
|
+
fail(`Dependency ${name} changed and no repository source imports it; full validation required`);
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
const quoted = new RegExp(`["'\`]${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:/[^"'\`]*)?["'\`]`);
|
|
509
|
+
const bare = new RegExp(`(?:^|[\\s"'=])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?=$|[\\s"'/@])`);
|
|
510
|
+
if (closureBodies.some((body) => bare.test(body))) {
|
|
511
|
+
fail(`Dependency ${name} changed and the test script runs it; full validation required`);
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
const toolingReader = this.sortedRepositoryFiles.find((path) => isImplicitlyLoadedFile(path) && !isLockfile(path) && quoted.test(this.readRepositoryFile!(path) ?? ""));
|
|
515
|
+
if (toolingReader) {
|
|
516
|
+
fail(`Dependency ${name} changed and ${toolingReader} loads it; full validation required`);
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
for (const importer of importers) {
|
|
520
|
+
evidence.push(makeEvidence("DEPENDENCY", "package.json", `${importer} imports changed dependency ${name}`, importer));
|
|
521
|
+
if (this.isTestFile(importer)) this.addAffectedTest("package.json", importer, graph, affectedTests, "DEPENDENCY", evidence);
|
|
522
|
+
this.processSourceChange(importer, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
|
|
523
|
+
}
|
|
524
|
+
// Code outside the graph that loads the package reaches the suite only if something runs it.
|
|
525
|
+
for (const path of this.sortedRepositoryFiles) {
|
|
526
|
+
if (!isSourceFilePath(path) || hasNode(graph, path) || !quoted.test(this.readRepositoryFile(path) ?? "")) continue;
|
|
527
|
+
if (!this.resolveByReference(path, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) {
|
|
528
|
+
fail(`Dependency ${name} changed and ${path}, which loads it, is outside the dependency graph; full validation required`);
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
434
535
|
private processChangedPath(
|
|
435
536
|
changedPath: string,
|
|
436
537
|
changedImpact: ChangedImpact,
|
|
@@ -500,7 +601,12 @@ export class ImpactAnalyzer {
|
|
|
500
601
|
return;
|
|
501
602
|
}
|
|
502
603
|
if (infrastructureRole(changedPath) === "code" && !hasNode(graph, changedPath) && changedImpact.file.changeType !== "deleted") {
|
|
503
|
-
// Code under ops/ is classified like code anywhere else only while the graph can see it.
|
|
604
|
+
// Code under ops/ is classified like code anywhere else only while the graph can see it. Outside
|
|
605
|
+
// the graph, a test can still reach it only by naming it - one dogfood repository's tests read the Worker
|
|
606
|
+
// entry point `ops/cloudflare/src/index.js` as text (2026-10-28: 7 of 42 replayed fallbacks) - so
|
|
607
|
+
// its readers are resolved like any other non-code file. A deployment definition that names it
|
|
608
|
+
// (wrangler.*, Dockerfile) runs it without naming anything a test would, so that stays global.
|
|
609
|
+
if (this.resolveByReference(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, { implicitReadersUnresolvable: true })) return;
|
|
504
610
|
const message = `Infrastructure code ${changedPath} is outside the dependency graph; full validation required`;
|
|
505
611
|
evidence.push(makeEvidence("INFRASTRUCTURE_GLOBAL", changedPath, message));
|
|
506
612
|
riskSignals.push({ level: "critical", reason: "INFRASTRUCTURE_GLOBAL", message, paths: [changedPath] });
|
|
@@ -567,6 +673,7 @@ export class ImpactAnalyzer {
|
|
|
567
673
|
affectedTests: Map<string, TestImpact>,
|
|
568
674
|
affectedScripts: Map<string, ImpactEvidence[]>,
|
|
569
675
|
evidence: ImpactEvidence[],
|
|
676
|
+
{ implicitReadersUnresolvable = false }: { implicitReadersUnresolvable?: boolean } = {},
|
|
570
677
|
): boolean {
|
|
571
678
|
if (!this.repositoryFiles || !this.readRepositoryFile || isImplicitlyLoadedFile(changedPath)) return false;
|
|
572
679
|
const layout = this.layout;
|
|
@@ -580,6 +687,8 @@ export class ImpactAnalyzer {
|
|
|
580
687
|
isCodeFile: isSourceFilePath,
|
|
581
688
|
workflowFeedsTests: (content, names) => workflowFeedsTests(content, names, scripts),
|
|
582
689
|
contentCleared: this.contentCleared,
|
|
690
|
+
implicitReadersUnresolvable,
|
|
691
|
+
testPhases: this.selectTestPhases,
|
|
583
692
|
});
|
|
584
693
|
if (resolution.unresolvable.length > 0) {
|
|
585
694
|
evidence.push(makeEvidence("UNKNOWN_FILE", changedPath, `References to ${changedPath} could not be resolved: ${resolution.unresolvable[0]}`));
|
|
@@ -590,6 +699,10 @@ export class ImpactAnalyzer {
|
|
|
590
699
|
evidence.push(makeEvidence("FILE_REFERENCE", changedPath, `${reader.path} names ${reader.via}`, reader.path));
|
|
591
700
|
}
|
|
592
701
|
for (const test of resolution.tests) this.addAffectedTest(changedPath, test, graph, affectedTests, "FILE_REFERENCE", evidence);
|
|
702
|
+
for (const phase of resolution.phases) {
|
|
703
|
+
this.testPhases.add(phase);
|
|
704
|
+
evidence.push(makeEvidence("FILE_REFERENCE", changedPath, `the test script runs \`${phase}\`, which reads ${changedPath}`));
|
|
705
|
+
}
|
|
593
706
|
for (const code of resolution.code) {
|
|
594
707
|
if (!affectedSources.has(code)) affectedSources.set(code, []);
|
|
595
708
|
affectedSources.get(code)!.push(makeEvidence("FILE_REFERENCE", changedPath, `${code} reads ${changedPath}`, code));
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Which direct dependencies did a package-lock.json change reach? (2026-10-28.)
|
|
4
|
+
*
|
|
5
|
+
* WHY. A dependency bump changes package.json and the lockfile together, and each used to force the
|
|
6
|
+
* full suite. In one dogfood repository's paired experiment those two signals were behind 19 of 40 runs.
|
|
7
|
+
* A bump can only change the behaviour of code that loads the bumped package, and code loads a
|
|
8
|
+
* transitive package only through a direct dependency. So the question for selection is which direct
|
|
9
|
+
* dependencies now resolve to a different installed tree; the impact analyzer then selects the tests
|
|
10
|
+
* that import those packages, and falls back when a package is not imported by any repository file.
|
|
11
|
+
*
|
|
12
|
+
* THE MODEL. npm lockfiles v2 and v3 list every installed package under `packages`, keyed by its
|
|
13
|
+
* install path (`node_modules/a`, `node_modules/a/node_modules/b`). An entry whose content changed, or
|
|
14
|
+
* which was added or removed, is a changed install. Each install's own `dependencies`,
|
|
15
|
+
* `optionalDependencies` and `peerDependencies` are resolved the way Node does, by walking up the
|
|
16
|
+
* install path. A direct dependency is affected when its closure, in the old or the new lockfile,
|
|
17
|
+
* contains a changed install.
|
|
18
|
+
*
|
|
19
|
+
* FAILING CLOSED. Anything this does not model returns undefined, and the caller keeps the global
|
|
20
|
+
* lockfile signal: lockfile v1, an unparseable file, workspace or linked entries (keys outside
|
|
21
|
+
* `node_modules/`), or a changed install no direct dependency reaches (a hoisting change the model
|
|
22
|
+
* cannot attribute).
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
interface LockEntry {
|
|
26
|
+
dependencies?: Record<string, string>;
|
|
27
|
+
optionalDependencies?: Record<string, string>;
|
|
28
|
+
peerDependencies?: Record<string, string>;
|
|
29
|
+
link?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Lockfile {
|
|
33
|
+
lockfileVersion?: number;
|
|
34
|
+
packages?: Record<string, LockEntry>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parse(content: string | undefined): Record<string, LockEntry> | undefined {
|
|
38
|
+
if (content === undefined) return undefined;
|
|
39
|
+
let lock: Lockfile;
|
|
40
|
+
try { lock = JSON.parse(content) as Lockfile; } catch { return undefined; }
|
|
41
|
+
if (!lock || typeof lock !== "object" || typeof lock.lockfileVersion !== "number" || lock.lockfileVersion < 2) return undefined;
|
|
42
|
+
if (!lock.packages || typeof lock.packages !== "object") return undefined;
|
|
43
|
+
return lock.packages;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The install path a package named `name`, required from `fromKey`, resolves to. */
|
|
47
|
+
function resolveInstall(packages: Record<string, LockEntry>, fromKey: string, name: string): string | undefined {
|
|
48
|
+
let base = fromKey;
|
|
49
|
+
while (true) {
|
|
50
|
+
const candidate = base ? `${base}/node_modules/${name}` : `node_modules/${name}`;
|
|
51
|
+
if (packages[candidate]) return candidate;
|
|
52
|
+
if (!base) return undefined;
|
|
53
|
+
const index = base.lastIndexOf("/node_modules/");
|
|
54
|
+
base = index === -1 ? "" : base.slice(0, index);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function closure(packages: Record<string, LockEntry>, root: string): Set<string> {
|
|
59
|
+
const seen = new Set<string>();
|
|
60
|
+
const queue = [root];
|
|
61
|
+
while (queue.length > 0) {
|
|
62
|
+
const key = queue.pop()!;
|
|
63
|
+
if (seen.has(key) || !packages[key]) continue;
|
|
64
|
+
seen.add(key);
|
|
65
|
+
const entry = packages[key]!;
|
|
66
|
+
for (const field of [entry.dependencies, entry.optionalDependencies, entry.peerDependencies]) {
|
|
67
|
+
for (const name of Object.keys(field ?? {})) {
|
|
68
|
+
const resolved = resolveInstall(packages, key, name);
|
|
69
|
+
if (resolved && !seen.has(resolved)) queue.push(resolved);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return seen;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The direct dependencies (names from the root package.json, old and new) whose installed tree
|
|
78
|
+
* differs between two package-lock.json contents, or undefined when the change cannot be attributed.
|
|
79
|
+
*/
|
|
80
|
+
export function npmLockAffectedDependencies(oldContent: string | undefined, newContent: string | undefined, directDependencies: readonly string[]): string[] | undefined {
|
|
81
|
+
const before = parse(oldContent);
|
|
82
|
+
const after = parse(newContent);
|
|
83
|
+
if (!before || !after) return undefined;
|
|
84
|
+
const changed = new Set<string>();
|
|
85
|
+
for (const key of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
86
|
+
if (key === "") continue; // the root entry mirrors package.json, which the caller compares itself
|
|
87
|
+
if (!key.startsWith("node_modules/")) return undefined;
|
|
88
|
+
if (before[key]?.link || after[key]?.link) return undefined;
|
|
89
|
+
if (JSON.stringify(before[key]) !== JSON.stringify(after[key])) changed.add(key);
|
|
90
|
+
}
|
|
91
|
+
const affected = new Set<string>();
|
|
92
|
+
const attributed = new Set<string>();
|
|
93
|
+
for (const name of directDependencies) {
|
|
94
|
+
for (const packages of [before, after]) {
|
|
95
|
+
const root = `node_modules/${name}`;
|
|
96
|
+
if (!packages[root]) {
|
|
97
|
+
if (changed.has(root)) { affected.add(name); attributed.add(root); }
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
for (const key of closure(packages, root)) {
|
|
101
|
+
if (!changed.has(key)) continue;
|
|
102
|
+
affected.add(name);
|
|
103
|
+
attributed.add(key);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if ([...changed].some((key) => !attributed.has(key))) return undefined;
|
|
108
|
+
return [...affected].sort();
|
|
109
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
2
|
import type { RepositoryProfile } from "../../repo/types.js";
|
|
3
3
|
import type { CITaskDefinition, TaskRegistry } from "../../planner/task-registry.js";
|
|
4
4
|
import { createTaskRegistry } from "../../planner/task-registry.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// SPDX-License-Identifier:
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
2
|
/**
|
|
3
3
|
* Stage 2C measurement-pipeline repair (2026-08-21, docs/research/2026-08-21-stage2c-*.md). Root cause:
|
|
4
4
|
* inferCategory() (workflow-parser.ts) only ever looked at a job's `name:` field (or its YAML key) and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@diffci.com/diffci",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.17",
|
|
4
4
|
"description": "Fail-closed, change-aware verification for AI coding agents with conservative affected-test selection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ci",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"test": "node scripts/run-tests.mjs"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@diffci.com/core": "git+https://github.com/DiffCI/core.git#
|
|
62
|
+
"@diffci.com/core": "git+https://github.com/DiffCI/core.git#909d79d40e0c3d813c80dcad21b8cefcc2c55674",
|
|
63
63
|
"yaml": "^2.9.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|