@diffci.com/diffci 0.3.24 → 0.3.26
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/cli.js +23 -1
- package/dist-client/src/client/enforce-policy.js +4 -0
- package/dist-client/src/client/gate.d.ts +3 -1
- package/dist-client/src/client/gate.js +1 -0
- package/dist-client/src/client/observe.js +14 -0
- package/dist-client/src/client/outcome-log.d.ts +80 -0
- package/dist-client/src/client/outcome-log.js +145 -0
- package/dist-client/src/client/report.d.ts +8 -0
- package/dist-client/src/client/verify.d.ts +3 -1
- package/dist-client/src/client/verify.js +1 -0
- package/dist-client/src/client/workflow-templates.d.ts +2 -2
- package/dist-client/src/client/workflow-templates.js +2 -2
- package/node_modules/@diffci.com/core/README.md +3 -0
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.d.ts +18 -0
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js +136 -0
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +2 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +17 -4
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/path-baseline.js +2 -1
- package/node_modules/@diffci.com/core/dist/planner/path-baseline.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +22 -2
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +70 -10
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +24 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +128 -6
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.d.ts +2 -2
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +7 -5
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/src/git/ci-config-paths.ts +131 -0
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +18 -4
- package/node_modules/@diffci.com/core/src/planner/path-baseline.ts +2 -1
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +74 -11
- package/node_modules/@diffci.com/core/src/repo/impact.ts +133 -7
- package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +8 -6
- package/node_modules/source-map-js/lib/quick-sort.js +10 -1
- package/node_modules/source-map-js/lib/source-map-consumer.js +51 -3
- package/node_modules/source-map-js/lib/source-map-generator.js +6 -4
- package/node_modules/source-map-js/lib/source-node.js +7 -0
- package/node_modules/source-map-js/package.json +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Which changed paths are CI pipeline definitions (2026-11-05).
|
|
4
|
+
*
|
|
5
|
+
* WHY. A pipeline definition decides which commands CI runs, so changing one can change a test outcome
|
|
6
|
+
* without touching anything a test imports. Only `.github/workflows/` was recognised. A GitLab
|
|
7
|
+
* pipeline file fell through to the unknown-file path, where reference resolution narrowed it to the
|
|
8
|
+
* files that name it: a test reading `.gitlab-ci.yml` became the only selected test, and a file pulled
|
|
9
|
+
* in by `include: local:` (read only by `.gitlab-ci.yml`) selected no tests at all.
|
|
10
|
+
*
|
|
11
|
+
* GitLab has no fixed directory, so this recognises the conventional names and also follows
|
|
12
|
+
* `include` from the root `.gitlab-ci.yml`. Anything it cannot follow (a variable in the path, an
|
|
13
|
+
* unparsable file) makes every YAML file count as pipeline config.
|
|
14
|
+
*/
|
|
15
|
+
import { parse as parseYaml } from "yaml";
|
|
16
|
+
|
|
17
|
+
const GITLAB_ROOT = ".gitlab-ci.yml";
|
|
18
|
+
const YAML = /\.ya?ml$/i;
|
|
19
|
+
const MAX_INCLUDE_DEPTH = 10;
|
|
20
|
+
|
|
21
|
+
/** Recognised by name alone, with no file content. */
|
|
22
|
+
export function isConventionalCiConfigPath(path: string): boolean {
|
|
23
|
+
if (path.startsWith(".github/workflows/")) return true;
|
|
24
|
+
const base = path.slice(path.lastIndexOf("/") + 1).toLowerCase();
|
|
25
|
+
if (/(?:^|\.)gitlab-ci\.ya?ml$/.test(base)) return true; // .gitlab-ci.yml, test.gitlab-ci.yml
|
|
26
|
+
return path.startsWith(".gitlab/") && YAML.test(path); // .gitlab/ci/*.yml and similar
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface GitlabIncludes {
|
|
30
|
+
/** Local files reached from the root through `include`, without the leading slash. */
|
|
31
|
+
paths: Set<string>;
|
|
32
|
+
/** Local include patterns with `*`, as regular expressions over repository paths. */
|
|
33
|
+
patterns: RegExp[];
|
|
34
|
+
/** An include could not be followed, so any YAML file may be pipeline config. */
|
|
35
|
+
unresolved: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function globToRegExp(glob: string): RegExp {
|
|
39
|
+
let source = "";
|
|
40
|
+
for (let i = 0; i < glob.length; i++) {
|
|
41
|
+
const char = glob[i]!;
|
|
42
|
+
if (char === "*" && glob[i + 1] === "*") {
|
|
43
|
+
source += ".*";
|
|
44
|
+
i++;
|
|
45
|
+
if (glob[i + 1] === "/") i++;
|
|
46
|
+
} else if (char === "*") source += "[^/]*";
|
|
47
|
+
else source += char.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
48
|
+
}
|
|
49
|
+
return new RegExp(`^${source}$`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The local include targets one parsed pipeline document names. Remote, project, template and
|
|
53
|
+
* component includes live outside the repository, so a diff of this repository cannot change them. */
|
|
54
|
+
function localIncludeTargets(doc: unknown): { targets: string[]; unresolved: boolean } {
|
|
55
|
+
if (doc === null || typeof doc !== "object" || Array.isArray(doc)) return { targets: [], unresolved: false };
|
|
56
|
+
const include = (doc as Record<string, unknown>).include;
|
|
57
|
+
if (include === undefined) return { targets: [], unresolved: false };
|
|
58
|
+
const entries = Array.isArray(include) ? include : [include];
|
|
59
|
+
const targets: string[] = [];
|
|
60
|
+
let unresolved = false;
|
|
61
|
+
for (const entry of entries) {
|
|
62
|
+
let target: unknown;
|
|
63
|
+
if (typeof entry === "string") {
|
|
64
|
+
if (/^https?:\/\//i.test(entry)) continue; // shorthand for `remote:`
|
|
65
|
+
target = entry;
|
|
66
|
+
} else if (entry !== null && typeof entry === "object") {
|
|
67
|
+
const record = entry as Record<string, unknown>;
|
|
68
|
+
if (!("local" in record)) continue;
|
|
69
|
+
target = record.local;
|
|
70
|
+
} else {
|
|
71
|
+
unresolved = true;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (typeof target !== "string" || target === "" || target.includes("$")) {
|
|
75
|
+
unresolved = true;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
targets.push(target.replace(/^\/+/, ""));
|
|
79
|
+
}
|
|
80
|
+
return { targets, unresolved };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Follows `include` from `.gitlab-ci.yml` at one commit. `read` returns a file's content at that
|
|
85
|
+
* commit, or undefined when it does not exist. `files` lists the repository's files at that commit; it
|
|
86
|
+
* is called only for a wildcard include, whose matches may include further files.
|
|
87
|
+
*/
|
|
88
|
+
export function gitlabLocalIncludes(read: (path: string) => string | undefined, files: () => readonly string[] = () => []): GitlabIncludes {
|
|
89
|
+
const result: GitlabIncludes = { paths: new Set(), patterns: [], unresolved: false };
|
|
90
|
+
const queue: Array<{ path: string; depth: number }> = [{ path: GITLAB_ROOT, depth: 0 }];
|
|
91
|
+
const seen = new Set<string>([GITLAB_ROOT]);
|
|
92
|
+
while (queue.length > 0) {
|
|
93
|
+
const { path, depth } = queue.shift()!;
|
|
94
|
+
const content = read(path);
|
|
95
|
+
if (content === undefined) continue; // a missing include fails the GitLab pipeline itself
|
|
96
|
+
let doc: unknown;
|
|
97
|
+
try {
|
|
98
|
+
doc = parseYaml(content);
|
|
99
|
+
} catch {
|
|
100
|
+
result.unresolved = true;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const { targets, unresolved } = localIncludeTargets(doc);
|
|
104
|
+
if (unresolved) result.unresolved = true;
|
|
105
|
+
for (const target of targets) {
|
|
106
|
+
const matches = target.includes("*")
|
|
107
|
+
? (() => { const pattern = globToRegExp(target); result.patterns.push(pattern); return files().filter((f) => pattern.test(f)); })()
|
|
108
|
+
: [target];
|
|
109
|
+
for (const match of matches) {
|
|
110
|
+
if (match !== GITLAB_ROOT) result.paths.add(match);
|
|
111
|
+
if (seen.has(match)) continue;
|
|
112
|
+
seen.add(match);
|
|
113
|
+
if (depth + 1 >= MAX_INCLUDE_DEPTH) { result.unresolved = true; continue; }
|
|
114
|
+
queue.push({ path: match, depth: depth + 1 });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** A predicate over changed paths: conventional names, plus whatever either commit's includes reach. */
|
|
122
|
+
export function ciConfigPredicate(includes: readonly GitlabIncludes[] = []): (path: string) => boolean {
|
|
123
|
+
const paths = new Set(includes.flatMap((i) => [...i.paths]));
|
|
124
|
+
const patterns = includes.flatMap((i) => i.patterns);
|
|
125
|
+
const anyYaml = includes.some((i) => i.unresolved);
|
|
126
|
+
return (path) =>
|
|
127
|
+
isConventionalCiConfigPath(path)
|
|
128
|
+
|| paths.has(path)
|
|
129
|
+
|| patterns.some((pattern) => pattern.test(path))
|
|
130
|
+
|| (anyYaml && YAML.test(path));
|
|
131
|
+
}
|
|
@@ -16,6 +16,7 @@ import { npmLockAffectedDependencies } from "../repo/npm-lockfile.js";
|
|
|
16
16
|
import { pnpmLockAffectedDependencies } from "../repo/pnpm-lockfile.js";
|
|
17
17
|
import { yarnLockAffectedDependencies } from "../repo/yarn-lockfile.js";
|
|
18
18
|
import { LOCKFILE } from "../repo/lockfiles.js";
|
|
19
|
+
import { ciConfigPredicate, gitlabLocalIncludes, isConventionalCiConfigPath } from "./ci-config-paths.js";
|
|
19
20
|
|
|
20
21
|
export const EMPTY_TREE_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
|
|
21
22
|
export const ZERO_SHA = "0000000000000000000000000000000000000000";
|
|
@@ -441,6 +442,14 @@ function readFileAtSha(sha: string, path: string, repoPath: string | undefined):
|
|
|
441
442
|
return result.stdout;
|
|
442
443
|
}
|
|
443
444
|
|
|
445
|
+
/** Every file path at a commit, for wildcard GitLab includes. Empty when the listing fails, which only
|
|
446
|
+
* loses matches inside a wildcard include's own includes; the wildcard itself still matches changes. */
|
|
447
|
+
function listFilesAtSha(sha: string, repoPath: string | undefined): string[] {
|
|
448
|
+
const result = runGit(["ls-tree", "-r", "--full-tree", "--name-only", "-z", sha], repoPath);
|
|
449
|
+
if (result.status !== 0) return [];
|
|
450
|
+
return result.stdout.split("").filter(Boolean);
|
|
451
|
+
}
|
|
452
|
+
|
|
444
453
|
/** Root entries include directories and gitlinks, which recursive file inventories can omit. */
|
|
445
454
|
function readRootPathsAtSha(sha: string, repoPath: string | undefined): ReadonlySet<string> | undefined {
|
|
446
455
|
const result = runGit(["ls-tree", "--full-tree", "--name-only", "-z", sha], repoPath);
|
|
@@ -452,7 +461,8 @@ function readRootPathsAtSha(sha: string, repoPath: string | undefined): Readonly
|
|
|
452
461
|
return roots.size === paths.length ? roots : undefined;
|
|
453
462
|
}
|
|
454
463
|
|
|
455
|
-
|
|
464
|
+
/** `isCiConfig` defaults to names alone; analyzeGitDelta also passes what GitLab `include` reaches. */
|
|
465
|
+
export function computeAnalysis(files: ChangedFile[], isCiConfig: (path: string) => boolean = isConventionalCiConfigPath): GitDeltaAnalysis {
|
|
456
466
|
const paths = files.flatMap((f) =>
|
|
457
467
|
f.oldPath ? [f.path, f.oldPath] : [f.path],
|
|
458
468
|
);
|
|
@@ -462,7 +472,7 @@ export function computeAnalysis(files: ChangedFile[]): GitDeltaAnalysis {
|
|
|
462
472
|
config: matching((p) => CONFIG_PATTERNS.some((pattern) => pattern.test(p))),
|
|
463
473
|
dependencyManifest: matching((p) => p === "package.json"),
|
|
464
474
|
lockfile: matching((p) => LOCKFILE.test(p)),
|
|
465
|
-
workflow: matching(
|
|
475
|
+
workflow: matching(isCiConfig),
|
|
466
476
|
infrastructure: matching((p) => infrastructureRole(p) === "definition"),
|
|
467
477
|
database: matching((p) => p.startsWith("database/")),
|
|
468
478
|
};
|
|
@@ -616,7 +626,11 @@ export async function analyzeGitDelta(
|
|
|
616
626
|
f.oldPath ? [f.path, f.oldPath] : [f.path],
|
|
617
627
|
);
|
|
618
628
|
|
|
619
|
-
|
|
629
|
+
// A GitLab pipeline can pull in any local file through `include`; follow it at both commits, since
|
|
630
|
+
// dropping an include changes the pipeline as much as adding one (2026-11-05).
|
|
631
|
+
const isCiConfig = ciConfigPredicate([baseSha, headSha].map((sha) =>
|
|
632
|
+
gitlabLocalIncludes((path) => readFileAtSha(sha, path, repoPath), () => listFilesAtSha(sha, repoPath))));
|
|
633
|
+
const analysis = computeAnalysis(filesWithBinary, isCiConfig);
|
|
620
634
|
// Stage 1B fix (2026-08-21): narrow the path-based dependencyManifestChanged signal to whether a
|
|
621
635
|
// behaviorally-relevant field actually changed - only attempted when the root package.json itself
|
|
622
636
|
// was modified (not added/deleted/renamed, which stay unambiguously true - see
|
|
@@ -781,7 +795,7 @@ export async function analyzeGitDelta(
|
|
|
781
795
|
if (narrowed.size > 0) {
|
|
782
796
|
// Do not let the generic path rules undo the content-level narrowing. Other changes in the same
|
|
783
797
|
// delta must still force full validation.
|
|
784
|
-
const remaining = computeAnalysis(filesWithBinary.filter((f) => !narrowed.has(f)));
|
|
798
|
+
const remaining = computeAnalysis(filesWithBinary.filter((f) => !narrowed.has(f)), isCiConfig);
|
|
785
799
|
analysis.configChanged = remaining.configChanged;
|
|
786
800
|
analysis.workflowChanged = remaining.workflowChanged;
|
|
787
801
|
analysis.signalPaths = { ...analysis.signalPaths, config: remaining.signalPaths?.config, workflow: remaining.signalPaths?.workflow,
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
* the rules described someone else's repository.
|
|
38
38
|
*/
|
|
39
39
|
import type { ChangedFile } from "../git/types.js";
|
|
40
|
+
import { isConventionalCiConfigPath } from "../git/ci-config-paths.js";
|
|
40
41
|
import type { RepositoryProfile } from "../repo/types.js";
|
|
41
42
|
import { repositoryLayout, UNKNOWN_REPOSITORY_LAYOUT } from "../repo/layout.js";
|
|
42
43
|
|
|
@@ -145,7 +146,7 @@ export function runPathBaseline(
|
|
|
145
146
|
if (changedPaths.some((p) => p === "package.json" || p === "package-lock.json" || /^(yarn\.lock|pnpm-lock\.yaml|bun\.lockb?)$/.test(p))) {
|
|
146
147
|
return runEverything("config/dependency -> full fallback", "config/dependency change triggers full fallback");
|
|
147
148
|
}
|
|
148
|
-
if (changedPaths.some(
|
|
149
|
+
if (changedPaths.some(isConventionalCiConfigPath)) {
|
|
149
150
|
return runEverything("workflow change -> full fallback", "workflow change triggers full fallback");
|
|
150
151
|
}
|
|
151
152
|
if (changedPaths.some((p) => DATABASE_DIRECTORIES.has(firstSegment(p)))) {
|
|
@@ -142,7 +142,7 @@ export interface ReferenceResolutionInput {
|
|
|
142
142
|
isCodeFile: (path: string) => boolean;
|
|
143
143
|
/** Whether something a workflow names can reach the test suite through it, given a pattern matching
|
|
144
144
|
* the name (src/repo/workflow-test-steps.ts, workflowFeedsTests). */
|
|
145
|
-
workflowFeedsTests: (content: string, names:
|
|
145
|
+
workflowFeedsTests: (content: string, names: (text: string) => boolean) => boolean;
|
|
146
146
|
/** Changed files whose content analyzeGitDelta proved cannot change how tests run
|
|
147
147
|
* (GitDeltaAnalysis.referenceResolvedPaths); a workflow reading them does not block. */
|
|
148
148
|
contentCleared?: ReadonlySet<string>;
|
|
@@ -156,6 +156,10 @@ export interface ReferenceResolutionInput {
|
|
|
156
156
|
/** Treat a reader that tooling loads implicitly (wrangler config, Dockerfile, `*.config.*`) as
|
|
157
157
|
* unresolvable. Used for code: such a reader can run the file without anything naming it. */
|
|
158
158
|
implicitReadersUnresolvable?: boolean;
|
|
159
|
+
/** The file is gone at HEAD and the graph has shown nothing can still import it (ImpactAnalyzer's
|
|
160
|
+
* resolveRemovedFile). Only a reader naming the file itself, not its directories, can observe its
|
|
161
|
+
* absence, and finding none is not a gap; an unreadable file is skipped as in any other resolution. */
|
|
162
|
+
removed?: boolean;
|
|
159
163
|
/** Resolve a file the root test script runs directly (`node scripts/test-security.js`) to that phase
|
|
160
164
|
* of the script instead of failing closed (ReferenceResolution.phases). Off by default: a caller
|
|
161
165
|
* that does not run the returned phases must keep the fallback. */
|
|
@@ -182,7 +186,7 @@ const LOCKFILES = new Set(["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "
|
|
|
182
186
|
const TEST_LIFECYCLE = ["pretest", "test", "posttest", "prepare", "preinstall", "install", "postinstall"];
|
|
183
187
|
/** Non-code files that can run something or direct what code reads: shell and interpreter scripts,
|
|
184
188
|
* and structured manifests. Only these are followed to their own readers. */
|
|
185
|
-
const DIRECTING_EXTENSIONS = /\.(?:sh|bash|zsh|ps1|psm1|bat|cmd|py|rb|pl|json|jsonc|json5|ya?ml|toml|ini|cfg|conf)$/i;
|
|
189
|
+
export const DIRECTING_EXTENSIONS = /\.(?:sh|bash|zsh|ps1|psm1|bat|cmd|py|rb|pl|json|jsonc|json5|ya?ml|toml|ini|cfg|conf)$/i;
|
|
186
190
|
|
|
187
191
|
/** Script names reachable from `npm test`, including lifecycle hooks and any script one of those bodies
|
|
188
192
|
* names. Over-inclusive by design: a script name appearing anywhere in a reachable body is followed. */
|
|
@@ -255,7 +259,8 @@ const CONTENT_PATH_WORD = /[A-Za-z0-9._\-/@+~*?{}[\]!,$]+/g;
|
|
|
255
259
|
* matches on the basename, so every `wrangler.jsonc` with `"main": "./src/index.js"` named every
|
|
256
260
|
* `src/index.js` in the repository, and `ops/cloudflare/src/a.js` named `ops/cloudflare/src/b.json` by
|
|
257
261
|
* sharing its directory. A word that resolves - from the reader's directory or the repository root - to
|
|
258
|
-
* a different file names that file
|
|
262
|
+
* a different file names that file, and a glob names only what it matches (2026-11-04). Bare names and
|
|
263
|
+
* variables inside a path keep the conservative answer.
|
|
259
264
|
*/
|
|
260
265
|
export function contentNamesPath(content: string, readerPath: string, target: string, pattern: RegExp, ancestors: boolean): boolean {
|
|
261
266
|
if (!pattern.test(content)) return false;
|
|
@@ -264,9 +269,29 @@ export function contentNamesPath(content: string, readerPath: string, target: st
|
|
|
264
269
|
const names = [target, ...dirs];
|
|
265
270
|
const readerDir = posix.dirname(readerPath);
|
|
266
271
|
for (const match of content.matchAll(CONTENT_PATH_WORD)) {
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
272
|
+
let word = match[0].replace(/[,.]+$/, "");
|
|
273
|
+
// Judged with the characters around it, so a bare directory name in prose (`the overlay packages,`
|
|
274
|
+
// in a workflow comment) does not count, as the reference pattern intends (2026-11-04).
|
|
275
|
+
if (!pattern.test(content.slice(Math.max(0, match.index - 1), match.index + word.length + 1))) continue;
|
|
276
|
+
// A leading variable is a directory the content does not name (`$GITHUB_ACTION_PATH/../../scripts/x.sh`
|
|
277
|
+
// names `scripts/x.sh` somewhere, not the repository's `scripts/`), so the rest is a path relative to
|
|
278
|
+
// an unknown directory (2026-11-04: a LobeHub composite action blocked every changed file under scripts/).
|
|
279
|
+
const variable = /^\$(?:\{[\w.]+\}|\w+)\/(.+)$/.exec(word);
|
|
280
|
+
if (variable && !/[*?{}[\]!$]/.test(variable[1]!)) {
|
|
281
|
+
const rest = variable[1]!.replace(/^(?:\.\.?\/)+/, "").replace(/\/+$/, "");
|
|
282
|
+
if (names.some((name) => name === rest || name.endsWith(`/${rest}`) || rest.endsWith(`/${name}`))) return true;
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (!word.includes("/") || /[!$]/.test(word)) return true;
|
|
286
|
+
if (/[*?{}[\]]/.test(word)) {
|
|
287
|
+
if (word.startsWith("../")) return true;
|
|
288
|
+
// A glob names what it matches, from the reader's directory, the root, or any directory below the
|
|
289
|
+
// root; `packages/sdk/**` in a workflow's `paths` filter does not name `packages/database/`.
|
|
290
|
+
word = word.replace(/\[[^\]]*\]/g, "?").replace(/^\/+/, "");
|
|
291
|
+
const globs = word.startsWith("./") ? [posix.join(readerDir, word), word.slice(2)] : [word, posix.join(readerDir, word), `**/${word}`];
|
|
292
|
+
if (names.some((name) => globs.some((glob) => matchesGlob(name, glob)))) return true;
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
270
295
|
const trimmed = word.replace(/\/+$/, "");
|
|
271
296
|
const resolved = [posix.normalize(posix.join(readerDir, trimmed))];
|
|
272
297
|
if (!trimmed.startsWith("../")) resolved.push(posix.normalize(trimmed.replace(/^\/+/, "")));
|
|
@@ -278,16 +303,49 @@ export function contentNamesPath(content: string, readerPath: string, target: st
|
|
|
278
303
|
return false;
|
|
279
304
|
}
|
|
280
305
|
|
|
306
|
+
/** Calls that list a directory's contents, in the languages Core analyses and the scripts tests run. */
|
|
307
|
+
const DIRECTORY_WALK = /\b(?:readdir(?:Sync)?|opendir(?:Sync)?|globSync|glob|fastGlob|fg|globby|walk(?:Sync)?|scandir|listdir|iterdir|rglob|WalkDir|Walk|ReadDir|Files\.(?:walk|list|find)|listFiles)\s*\(/;
|
|
308
|
+
|
|
309
|
+
/** Whether `content` calls a directory-listing API; callers pre-filter tests with it once per analysis. */
|
|
310
|
+
export function listsDirectories(content: string | undefined): boolean {
|
|
311
|
+
return content !== undefined && DIRECTORY_WALK.test(content);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Tests that list a directory containing `filePath` (2026-11-04). The CI replay's one miss: a commit
|
|
316
|
+
* added `scripts/ci-reproduction.ts`, and a test that reads every file under `scripts/` failed. Nothing
|
|
317
|
+
* imports a new script, so the graph selected nothing for it, and no fallback said so. A test that calls a
|
|
318
|
+
* directory-listing API and names one of the file's ancestor directories now counts as reading it.
|
|
319
|
+
* Additive only: it never narrows a selection. A walk that starts at the repository root without naming
|
|
320
|
+
* a directory is still invisible, as in resolveFileReferences.
|
|
321
|
+
*/
|
|
322
|
+
export function directoryWalkers(filePath: string, tests: readonly string[], read: (path: string) => string | undefined): string[] {
|
|
323
|
+
const pattern = referencePattern(referenceTokens(filePath));
|
|
324
|
+
return tests.filter((test) => {
|
|
325
|
+
const content = read(test);
|
|
326
|
+
return listsDirectories(content) && contentNamesPath(content!, test, filePath, pattern, true);
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
|
|
281
330
|
/** Configs that tooling loads by their default name and that can run a repository file - a Worker
|
|
282
331
|
* entry point, a container command, a test setup file, a bundler plugin - without a test naming
|
|
283
332
|
* either. `tsconfig.json`, `.gitignore` and lint or style configs list paths but run nothing; a
|
|
284
333
|
* non-default `wrangler.validation.json` is used only when a command names it. */
|
|
285
334
|
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;
|
|
286
335
|
|
|
287
|
-
function loadsWithoutNaming(path: string): boolean {
|
|
336
|
+
export function loadsWithoutNaming(path: string): boolean {
|
|
288
337
|
return RUNS_FILES_WITHOUT_NAMING.test(posix.basename(path));
|
|
289
338
|
}
|
|
290
339
|
|
|
340
|
+
/** A root dependency manifest that a Dockerfile names only in `COPY`/`ADD` instructions, which put it
|
|
341
|
+
* into the image for a package manager to install from. Any other instruction naming it (a `RUN` that
|
|
342
|
+
* reads it) does not qualify. */
|
|
343
|
+
function copiesOnly(content: string, target: string): boolean {
|
|
344
|
+
if (target.includes("/") || !["package.json", ...LOCKFILES].includes(target)) return false;
|
|
345
|
+
const lines = content.split(/\r?\n/).filter((line) => new RegExp(`(?:^|[\\s/"'])${target.replace(/[.]/g, "\\.")}(?=$|[\\s"',\\]])`).test(line));
|
|
346
|
+
return lines.length > 0 && lines.every((line) => /^\s*(?:COPY|ADD)\s/i.test(line));
|
|
347
|
+
}
|
|
348
|
+
|
|
291
349
|
/** A Cloudflare Workers deployment config (`wrangler.toml`, `wrangler.product.jsonc`). */
|
|
292
350
|
export function isWorkerConfig(filePath: string): boolean {
|
|
293
351
|
return /^wrangler(?:\.[^./]+)?\.(?:toml|json|jsonc)$/i.test(posix.basename(filePath));
|
|
@@ -409,7 +467,7 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
409
467
|
// directory. A reader reached through the changed file (a script, a manifest) matters only if
|
|
410
468
|
// something runs or reads it by name; matching its directories as well made `"tests"` and
|
|
411
469
|
// `"fixtures"` match nearly every file and no generic name (package.json) could resolve.
|
|
412
|
-
const ancestors = target.path === filePath;
|
|
470
|
+
const ancestors = target.path === filePath && !input.removed;
|
|
413
471
|
const pattern = referencePattern(referenceTokens(target.path, { ancestors }));
|
|
414
472
|
for (const candidate of input.files) {
|
|
415
473
|
if (visited.has(candidate) || candidate === target.path || LOCKFILES.has(posix.basename(candidate))) continue;
|
|
@@ -438,7 +496,12 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
438
496
|
}
|
|
439
497
|
if (content === undefined || !contentNamesPath(content, candidate, target.path, pattern, ancestors)) continue;
|
|
440
498
|
visited.add(candidate);
|
|
441
|
-
if (input.
|
|
499
|
+
if (input.allowNoReaders && /^dockerfile/i.test(base) && copiesOnly(content, target.path)) {
|
|
500
|
+
// The caller modelled what the file does when installed (dependency selection); a Dockerfile
|
|
501
|
+
// that only copies it into the image to install from it adds nothing (2026-11-04: DentalPresence's
|
|
502
|
+
// `COPY package.json package-lock.json ./` made every dependency bump a full run).
|
|
503
|
+
resolution.readers.push({ path: candidate, kind: "documentation", via: target.path });
|
|
504
|
+
} else if (input.implicitReadersUnresolvable && loadsWithoutNaming(candidate)) {
|
|
442
505
|
resolution.readers.push({ path: candidate, kind: "unresolvable", via: target.path });
|
|
443
506
|
resolution.unresolvable.push(`${candidate} is loaded by tooling and names ${target.path}`);
|
|
444
507
|
} else if (candidate.startsWith(".github/")) {
|
|
@@ -447,7 +510,7 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
447
510
|
// A change content inspection already showed cannot alter how tests run (a version bump)
|
|
448
511
|
// stays that way when a workflow reads the file.
|
|
449
512
|
const executes = candidate.startsWith(".github/actions/")
|
|
450
|
-
|| (/^\.github\/workflows\//.test(candidate) && !input.contentCleared?.has(target.path) && input.workflowFeedsTests(content, pattern));
|
|
513
|
+
|| (/^\.github\/workflows\//.test(candidate) && !input.contentCleared?.has(target.path) && input.workflowFeedsTests(content, (text) => contentNamesPath(text, candidate, target.path, pattern, ancestors)));
|
|
451
514
|
if (!executes) continue;
|
|
452
515
|
resolution.readers.push({ path: candidate, kind: "unresolvable", via: target.path });
|
|
453
516
|
resolution.unresolvable.push(`${candidate} names ${target.path}`);
|
|
@@ -479,7 +542,7 @@ export function resolveFileReferences(filePath: string, input: ReferenceResoluti
|
|
|
479
542
|
// script or test-feeding workflow step reaches: the suite cannot observe the file. Finding no such
|
|
480
543
|
// reader at all is different - the file's reader is unknown, so it stays unknown.
|
|
481
544
|
const executableReaders = resolution.readers.some((reader) => reader.kind === "transitive");
|
|
482
|
-
if (resolution.unresolvable.length === 0 && tests.size === 0 && code.size === 0 && !executableReaders && !input.allowNoReaders && !loadedOnlyOutsideTests(filePath, input, read)) {
|
|
545
|
+
if (resolution.unresolvable.length === 0 && tests.size === 0 && code.size === 0 && !executableReaders && !input.allowNoReaders && !input.removed && !loadedOnlyOutsideTests(filePath, input, read)) {
|
|
483
546
|
resolution.unresolvable.push(`no test or source file names ${filePath}`);
|
|
484
547
|
}
|
|
485
548
|
resolution.phases = resolution.unresolvable.length === 0 ? [...phases].sort() : [];
|
|
@@ -2,13 +2,13 @@ import { extname, posix } from "node:path";
|
|
|
2
2
|
import { isGoDiscoveryIgnoredPath } from "./adapters/go.js";
|
|
3
3
|
import { inVuePackage } from "./vue-scope.js";
|
|
4
4
|
import type { ChangedFile, GitDelta } from "../git/types.js";
|
|
5
|
-
import type { DependencyGraph, DependencyGraphNode, DependencyGraphResult, EntryPoint, RepositoryProfile } from "./types.js";
|
|
5
|
+
import type { DependencyGraph, DependencyGraphNode, DependencyGraphResult, EntryPoint, RepositoryProfile, UnresolvedDependency } from "./types.js";
|
|
6
6
|
import type { ChangedImpact, EntryPointImpact, ImpactEvidence, ImpactEvidencePath, ImpactReason, ImpactResult, ImpactRiskSignal, TestImpact } from "./impact-types.js";
|
|
7
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, isWorkerConfig, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
|
|
11
|
+
import { directoryWalkers, DIRECTING_EXTENSIONS, infrastructureRole, listsDirectories, loadsWithoutNaming, isImplicitlyLoadedFile, isWorkerConfig, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
|
|
12
12
|
import { workflowFeedsTests } from "./workflow-test-steps.js";
|
|
13
13
|
import { modelTestScriptUniverse, type ScriptUniverse } from "./script-universe.js";
|
|
14
14
|
import { compiledProjects, type CompiledProject } from "./compiled-projects.js";
|
|
@@ -70,6 +70,8 @@ function isDatabaseFile(filePath: string): boolean { const DATABASE_DIRS = new S
|
|
|
70
70
|
*/
|
|
71
71
|
function classifyNextEntryPoint(filePath: string, layout: RepositoryLayout): EntryPoint["kind"] | undefined { if (!layout.isNextApp) return undefined; if (!isSourceFilePath(filePath)) return undefined; const base = posix.basename(filePath, extname(filePath)); const lower = base.toLowerCase(); if (lower === "page") return "next-page"; if (lower === "layout") return "next-layout"; if (lower === "route") return "next-route"; if (lower === "api" && filePath.includes("/api/")) return "next-api"; if (lower === "loading") return "next-loading"; if (lower === "error") return "next-error"; if (lower === "template") return "next-template"; if (lower === "not-found") return "next-error"; if (lower === "middleware") return "next-api"; return undefined; }
|
|
72
72
|
function allChangePaths(file: ChangedFile): string[] { return file.oldPath ? [file.path, file.oldPath] : [file.path]; }
|
|
73
|
+
/** The module an extensionless import of `path` names: `a/x.ts` -> `a/x`, `a/x/index.ts` -> `a/x`. */
|
|
74
|
+
function moduleKey(path: string): string { const stem = path.replace(/\.[^./]+$/, ""); return posix.basename(stem) === "index" ? posix.dirname(stem) : stem; }
|
|
73
75
|
function nodeByPath(graph: DependencyGraph, path: string): DependencyGraphNode | undefined { return graph.nodes.find((n) => n.path === path); }
|
|
74
76
|
function hasNode(graph: DependencyGraph, path: string): boolean { return nodeByPath(graph, path) !== undefined; }
|
|
75
77
|
function isEntryPoint(profile: RepositoryProfile, path: string): EntryPoint | undefined { return profile.entryPoints.find((e) => e.path === path); }
|
|
@@ -263,6 +265,8 @@ export class ImpactAnalyzer {
|
|
|
263
265
|
private testPhases = new Set<string>();
|
|
264
266
|
private workersOutsideSuite: boolean | undefined;
|
|
265
267
|
private runtimeTestSelection = false;
|
|
268
|
+
private unresolved: readonly UnresolvedDependency[] = [];
|
|
269
|
+
private walkerTests: string[] | undefined;
|
|
266
270
|
|
|
267
271
|
/** Dependents whose tests a change to `path` can affect. When the graph allows runtime selection
|
|
268
272
|
* (DependencyGraphResult.runtimeTestSelection) an `import type` edge selects only type tests. */
|
|
@@ -293,7 +297,9 @@ export class ImpactAnalyzer {
|
|
|
293
297
|
this.selectTestPhases = options.selectTestPhases === true;
|
|
294
298
|
this.testPhases = new Set();
|
|
295
299
|
this.workersOutsideSuite = undefined;
|
|
300
|
+
this.walkerTests = undefined;
|
|
296
301
|
this.runtimeTestSelection = graphResult.runtimeTestSelection === true;
|
|
302
|
+
this.unresolved = graphResult.unresolved ?? [];
|
|
297
303
|
this.sortedRepositoryFiles = options.repositoryFiles ? [...options.repositoryFiles].sort() : [];
|
|
298
304
|
this.compiledProjectCache = undefined;
|
|
299
305
|
// One read per file per analysis, however many changed files ask who reads them.
|
|
@@ -453,7 +459,7 @@ export class ImpactAnalyzer {
|
|
|
453
459
|
{ reason: "CONFIG_GLOBAL", message: "Configuration file(s) changed; full validation required", signal: "config", check: (a) => a.configChanged },
|
|
454
460
|
{ reason: "DEPENDENCY_MANIFEST", message: "Dependency manifest changed; full validation required", signal: "dependencyManifest", check: (a) => a.dependencyManifestChanged },
|
|
455
461
|
{ reason: "LOCKFILE_GLOBAL", message: "Lockfile changed; full validation required", signal: "lockfile", check: (a) => a.lockfileChanged },
|
|
456
|
-
{ reason: "WORKFLOW_GLOBAL", message: "
|
|
462
|
+
{ reason: "WORKFLOW_GLOBAL", message: "CI workflow definition(s) changed; full validation required", signal: "workflow", check: (a) => a.workflowChanged },
|
|
457
463
|
{ reason: "INFRASTRUCTURE_GLOBAL", message: "Infrastructure definition(s) changed; full validation required", signal: "infrastructure", check: (a) => a.infrastructureChanged },
|
|
458
464
|
{ reason: "DATABASE_GLOBAL", message: "Database definition(s) changed; full validation required", signal: "database", check: (a) => a.databaseChanged },
|
|
459
465
|
];
|
|
@@ -558,7 +564,11 @@ export class ImpactAnalyzer {
|
|
|
558
564
|
.filter((ref) => ref.resolution === "external-package" && packageRoot(ref.specifier) === name)
|
|
559
565
|
.map((ref) => ref.importer))].sort();
|
|
560
566
|
if (importers.length === 0) {
|
|
561
|
-
|
|
567
|
+
const blocker = this.resolveUnimportedPackage(name, changedFile, closureBodies, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
|
|
568
|
+
if (blocker) {
|
|
569
|
+
evidence.push(makeEvidence("DEPENDENCY", changedFile, `${name}: ${blocker}`));
|
|
570
|
+
fail(`${dependencyChange(name)} and no repository source imports it; full validation required`);
|
|
571
|
+
}
|
|
562
572
|
continue;
|
|
563
573
|
}
|
|
564
574
|
const quoted = new RegExp(`["'\`]${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?:/[^"'\`]*)?["'\`]`);
|
|
@@ -588,6 +598,67 @@ export class ImpactAnalyzer {
|
|
|
588
598
|
}
|
|
589
599
|
}
|
|
590
600
|
|
|
601
|
+
/**
|
|
602
|
+
* A changed dependency no repository code imports (2026-11-04). Usually a CLI the repository runs by
|
|
603
|
+
* its executable's name: bumping `@diffci.com/diffci`, run as `diffci`, made all 601 DentalPresence
|
|
604
|
+
* tests run. Such a package reaches the suite only by being run or loaded, so it narrows when
|
|
605
|
+
* package-lock.json records its executables and every file naming the package or one of them
|
|
606
|
+
* resolves: a test is selected, graph code selects its dependent tests, and any other code or
|
|
607
|
+
* directing file must itself resolve by reference. Returns why it cannot narrow: the executables are
|
|
608
|
+
* unknown, the name suggests tooling loads it by convention (types, plugins, presets, test runners),
|
|
609
|
+
* or the test script, a file tooling loads, or a test-feeding workflow step names it.
|
|
610
|
+
*/
|
|
611
|
+
private resolveUnimportedPackage(
|
|
612
|
+
name: string,
|
|
613
|
+
changedFile: string,
|
|
614
|
+
closureBodies: readonly string[],
|
|
615
|
+
graph: DependencyGraph,
|
|
616
|
+
profile: RepositoryProfile,
|
|
617
|
+
affectedSources: Map<string, ImpactEvidence[]>,
|
|
618
|
+
affectedEntryPoints: Map<string, EntryPointImpact>,
|
|
619
|
+
affectedTests: Map<string, TestImpact>,
|
|
620
|
+
affectedScripts: Map<string, ImpactEvidence[]>,
|
|
621
|
+
evidence: ImpactEvidence[],
|
|
622
|
+
): string | undefined {
|
|
623
|
+
if (/(?:^@types\/|types|plugin|preset|config|loader|register|polyfill|setup|eslint|prettier|stylelint|babel|postcss|tailwind|jest|vitest|mocha|ava|playwright|cypress|typescript|ts-node|^tsx$|swc|esbuild|vite|webpack|rollup)/i.test(name)) {
|
|
624
|
+
return "tooling may load it by naming convention";
|
|
625
|
+
}
|
|
626
|
+
if (!this.repositoryFiles?.has("package-lock.json")) return "its executables are unknown without package-lock.json";
|
|
627
|
+
let bin: unknown;
|
|
628
|
+
try {
|
|
629
|
+
const lock = JSON.parse(this.readRepositoryFile!("package-lock.json") ?? "") as { packages?: Record<string, { bin?: unknown }> };
|
|
630
|
+
bin = lock.packages?.[`node_modules/${name}`]?.bin;
|
|
631
|
+
} catch { return "package-lock.json could not be parsed"; }
|
|
632
|
+
const bins = typeof bin === "string" ? [name.split("/").pop()!] : bin && typeof bin === "object" ? Object.keys(bin) : [];
|
|
633
|
+
if (bins.length === 0) return "it has no executable, so only tooling can load it";
|
|
634
|
+
const escape = (value: string) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
635
|
+
const named = new RegExp(`(?:^|[\\s"'\`=/(])(?:${[name, ...bins].map(escape).join("|")})(?=$|[\\s"'\`/@),;:])`, "m");
|
|
636
|
+
if (closureBodies.some((body) => named.test(body))) return "the test script runs it";
|
|
637
|
+
const scripts = profile.packageJson.scripts;
|
|
638
|
+
for (const path of this.sortedRepositoryFiles) {
|
|
639
|
+
if (path === "package.json" || isLockfile(path) || this.layout.isDocumentationPath(path)) continue;
|
|
640
|
+
const content = this.readRepositoryFile!(path);
|
|
641
|
+
if (content === undefined || !named.test(content)) continue;
|
|
642
|
+
if (isImplicitlyLoadedFile(path) || loadsWithoutNaming(path) || posix.basename(path) === "package.json") return `${path} names it and tooling loads that file`;
|
|
643
|
+
if (path.startsWith(".github/")) {
|
|
644
|
+
if (path.startsWith(".github/actions/") || (/^\.github\/workflows\//.test(path) && workflowFeedsTests(content, named, scripts))) return `${path} runs it before tests`;
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
if (isSourceFilePath(path) && this.isTestFile(path)) {
|
|
648
|
+
evidence.push(makeEvidence("DEPENDENCY", changedFile, `${path} names ${name}`, path));
|
|
649
|
+
this.addAffectedTest(changedFile, path, graph, affectedTests, "DEPENDENCY", evidence);
|
|
650
|
+
} else if (isSourceFilePath(path) && hasNode(graph, path)) {
|
|
651
|
+
evidence.push(makeEvidence("DEPENDENCY", changedFile, `${path} names ${name}`, path));
|
|
652
|
+
this.processSourceChange(path, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
|
|
653
|
+
} else if (isSourceFilePath(path) || DIRECTING_EXTENSIONS.test(path)) {
|
|
654
|
+
if (!this.resolveByReference(path, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, { implicitReadersUnresolvable: true })) {
|
|
655
|
+
return `${path} names it and its own readers could not be resolved`;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
return undefined;
|
|
660
|
+
}
|
|
661
|
+
|
|
591
662
|
private processChangedPath(
|
|
592
663
|
changedPath: string,
|
|
593
664
|
changedImpact: ChangedImpact,
|
|
@@ -608,6 +679,17 @@ export class ImpactAnalyzer {
|
|
|
608
679
|
this.processAssetChange(changedPath, graph, profile, affectedAssets, affectedEntryPoints, affectedTests, affectedSources, evidence);
|
|
609
680
|
return;
|
|
610
681
|
}
|
|
682
|
+
// Non-code files are resolved by reference below, directories included; code is not, so a test that
|
|
683
|
+
// lists the directory a code file is in is added here (file-references.ts, directoryWalkers).
|
|
684
|
+
if (isSourceFilePath(changedPath) && this.readRepositoryFile) {
|
|
685
|
+
const read = this.readRepositoryFile;
|
|
686
|
+
this.walkerTests ??= this.sortedRepositoryFiles.filter((path) => this.isTestFile(path) && listsDirectories(read(path)));
|
|
687
|
+
for (const test of directoryWalkers(changedPath, this.walkerTests, this.readRepositoryFile)) {
|
|
688
|
+
if (test === changedPath) continue;
|
|
689
|
+
evidence.push(makeEvidence("FILE_REFERENCE", changedPath, `${test} lists a directory containing ${changedPath}`, test));
|
|
690
|
+
this.addAffectedTest(changedPath, test, graph, affectedTests, "FILE_REFERENCE", evidence);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
611
693
|
const category = changedImpact.category;
|
|
612
694
|
if (changedPath === this.dependencyLockfile) {
|
|
613
695
|
// Dependency selection does not cover a test that reads the lockfile's bytes. Unlike general
|
|
@@ -656,7 +738,9 @@ export class ImpactAnalyzer {
|
|
|
656
738
|
return;
|
|
657
739
|
}
|
|
658
740
|
if (category === "docs") return;
|
|
659
|
-
|
|
741
|
+
// A rename's old path is gone at HEAD like a deleted file (`X.module.css` -> `X.css`).
|
|
742
|
+
const removed = changedImpact.file.changeType === "deleted" || (changedPath === changedImpact.file.oldPath && changedImpact.file.changeType === "renamed");
|
|
743
|
+
if (isAssetFilePath(changedPath) && !hasNode(graph, changedPath) && !removed && !isDocumentationFile(changedPath, this.layout) && !isLockfile(changedPath)) {
|
|
660
744
|
// An asset no module imports can still be read from disk by a test. It used to select nothing
|
|
661
745
|
// and require nothing, which is a silent skip; it now needs reader evidence like any other
|
|
662
746
|
// non-code file (2026-10-21).
|
|
@@ -668,7 +752,8 @@ export class ImpactAnalyzer {
|
|
|
668
752
|
return;
|
|
669
753
|
}
|
|
670
754
|
if (isAssetFilePath(changedPath)) {
|
|
671
|
-
if (
|
|
755
|
+
if (removed && !hasNode(graph, changedPath)) {
|
|
756
|
+
if (this.resolveRemovedFile(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) return;
|
|
672
757
|
const message = `Deleted source/asset ${changedPath} not present in HEAD dependency graph; legacy dependents cannot be determined`;
|
|
673
758
|
evidence.push(makeEvidence("DELETED_FILE_UNKNOWABLE_GRAPH", changedPath, message));
|
|
674
759
|
riskSignals.push({ level: "critical", reason: "DELETED_FILE_UNKNOWABLE_GRAPH", message, paths: [changedPath] });
|
|
@@ -708,6 +793,7 @@ export class ImpactAnalyzer {
|
|
|
708
793
|
return;
|
|
709
794
|
}
|
|
710
795
|
if (changedImpact.file.changeType === "deleted" && !hasNode(graph, changedPath)) {
|
|
796
|
+
if (this.resolveRemovedFile(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence)) return;
|
|
711
797
|
const message = `Deleted source/asset ${changedPath} not present in HEAD dependency graph; legacy dependents cannot be determined`;
|
|
712
798
|
evidence.push(makeEvidence("DELETED_FILE_UNKNOWABLE_GRAPH", changedPath, message));
|
|
713
799
|
riskSignals.push({ level: "critical", reason: "DELETED_FILE_UNKNOWABLE_GRAPH", message, paths: [changedPath] });
|
|
@@ -717,6 +803,45 @@ export class ImpactAnalyzer {
|
|
|
717
803
|
this.processSourceChange(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
|
|
718
804
|
}
|
|
719
805
|
|
|
806
|
+
/**
|
|
807
|
+
* A file gone at HEAD that the HEAD graph has no node for (2026-11-04). Its old importers cannot be
|
|
808
|
+
* listed, but each one is either changed in this delta (its import was edited or removed, so it is
|
|
809
|
+
* analysed as a changed file), still imports the missing path (an unresolved import), or now resolves
|
|
810
|
+
* the same specifier to a sibling (`./x` from a deleted `x.ts` to a surviving `x/index.ts`). The last
|
|
811
|
+
* two are found here; anything else observes the absence only by naming the file, which the reference
|
|
812
|
+
* resolver checks without its directories. A directory listing is not modelled, as for an added asset
|
|
813
|
+
* the graph does import, nor is a tsconfig `paths` fallback that now resolves to another directory. Previously every such file fell back: the LobeHub catch replay's StyleX
|
|
814
|
+
* migration renames `X.module.css` to `X.css` and 16 of 47 verify commits ran the full suite for it.
|
|
815
|
+
*/
|
|
816
|
+
private resolveRemovedFile(
|
|
817
|
+
removedPath: string,
|
|
818
|
+
graph: DependencyGraph,
|
|
819
|
+
profile: RepositoryProfile,
|
|
820
|
+
affectedSources: Map<string, ImpactEvidence[]>,
|
|
821
|
+
affectedEntryPoints: Map<string, EntryPointImpact>,
|
|
822
|
+
affectedTests: Map<string, TestImpact>,
|
|
823
|
+
affectedScripts: Map<string, ImpactEvidence[]>,
|
|
824
|
+
evidence: ImpactEvidence[],
|
|
825
|
+
): boolean {
|
|
826
|
+
if (this.repositoryFiles?.has(removedPath)) return false;
|
|
827
|
+
const key = moduleKey(removedPath);
|
|
828
|
+
const names = new Set([posix.basename(removedPath), posix.basename(removedPath.replace(/\.[^./]+$/, "")), posix.basename(key)]);
|
|
829
|
+
// Conservative: any unresolved import whose last segment could name the file blocks, wherever it is.
|
|
830
|
+
const importer = this.unresolved.find((ref) => !ref.computed && names.has(posix.basename(ref.specifier.split(/[?#]/)[0]!)));
|
|
831
|
+
if (importer) {
|
|
832
|
+
evidence.push(makeEvidence("UNKNOWN_FILE", removedPath, `${importer.importer} imports ${importer.specifier}, which may have resolved to the removed ${removedPath}`));
|
|
833
|
+
return false;
|
|
834
|
+
}
|
|
835
|
+
if (!this.resolveByReference(removedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, { implicitReadersUnresolvable: true, removed: true })) return false;
|
|
836
|
+
for (const node of graph.nodes) {
|
|
837
|
+
if (node.path === removedPath || moduleKey(node.path) !== key) continue;
|
|
838
|
+
evidence.push(makeEvidence("DELETED_FILE_LEGACY_DEPENDENTS", removedPath, `${node.path} may now resolve imports of the removed ${removedPath}`, node.path));
|
|
839
|
+
this.processSourceChange(node.path, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
|
|
840
|
+
}
|
|
841
|
+
evidence.push(makeEvidence("DELETED_FILE_LEGACY_DEPENDENTS", removedPath, `No HEAD import can still reach the removed ${removedPath}; its former importers are changed files`));
|
|
842
|
+
return true;
|
|
843
|
+
}
|
|
844
|
+
|
|
720
845
|
/** Projects some test compiles (src/repo/compiled-projects.ts), computed once per analysis and only
|
|
721
846
|
* when file contents are available. */
|
|
722
847
|
private compiledProjectsFor(graph: DependencyGraph): CompiledProject[] {
|
|
@@ -763,7 +888,7 @@ export class ImpactAnalyzer {
|
|
|
763
888
|
affectedTests: Map<string, TestImpact>,
|
|
764
889
|
affectedScripts: Map<string, ImpactEvidence[]>,
|
|
765
890
|
evidence: ImpactEvidence[],
|
|
766
|
-
{ implicitReadersUnresolvable = false, allowNoReaders = false }: { implicitReadersUnresolvable?: boolean; allowNoReaders?: boolean } = {},
|
|
891
|
+
{ implicitReadersUnresolvable = false, allowNoReaders = false, removed = false }: { implicitReadersUnresolvable?: boolean; allowNoReaders?: boolean; removed?: boolean } = {},
|
|
767
892
|
): boolean {
|
|
768
893
|
if (!this.repositoryFiles || !this.readRepositoryFile) return false;
|
|
769
894
|
if (isImplicitlyLoadedFile(changedPath) && !(isWorkerConfig(changedPath) && this.workerConfigsOutsideSuite())) return false;
|
|
@@ -780,6 +905,7 @@ export class ImpactAnalyzer {
|
|
|
780
905
|
contentCleared: this.contentCleared,
|
|
781
906
|
implicitReadersUnresolvable,
|
|
782
907
|
allowNoReaders,
|
|
908
|
+
removed,
|
|
783
909
|
testPhases: this.selectTestPhases,
|
|
784
910
|
workerConfigsOutsideSuite: this.workerConfigsOutsideSuite(),
|
|
785
911
|
});
|