@diffci.com/diffci 0.3.54 → 0.3.56
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.d.ts +9 -2
- package/dist-client/src/client/agent-selection.js +20 -8
- package/dist-client/src/client/agent-setup.js +1 -1
- package/dist-client/src/client/cli.js +19 -7
- package/dist-client/src/client/command-batches.js +3 -2
- package/dist-client/src/client/context.d.ts +2 -0
- package/dist-client/src/client/context.js +51 -2
- package/dist-client/src/client/coverage-map.js +6 -1
- package/dist-client/src/client/full-command.js +22 -14
- package/dist-client/src/client/gate.js +24 -10
- package/dist-client/src/client/hook.d.ts +17 -0
- package/dist-client/src/client/hook.js +53 -1
- package/dist-client/src/client/install.d.ts +6 -0
- package/dist-client/src/client/install.js +29 -1
- package/dist-client/src/client/job-summary.d.ts +1 -1
- package/dist-client/src/client/job-summary.js +2 -1
- package/dist-client/src/client/mcp.js +4 -0
- package/dist-client/src/client/observe.js +4 -3
- package/dist-client/src/client/report.d.ts +8 -1
- package/dist-client/src/client/report.js +11 -0
- package/dist-client/src/client/shared-graph-cache.js +4 -2
- package/dist-client/src/client/telemetry.js +2 -1
- package/dist-client/src/client/usage-signal.d.ts +1 -1
- package/dist-client/src/client/verify-savings.d.ts +6 -0
- package/dist-client/src/client/verify-savings.js +15 -3
- package/dist-client/src/client/verify.js +124 -22
- package/dist-client/src/client/workflow-guard.js +27 -6
- package/dist-client/src/client/workflow-templates.d.ts +11 -1
- package/dist-client/src/client/workflow-templates.js +43 -2
- package/node_modules/@diffci.com/core/README.md +17 -10
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.js +38 -5
- package/node_modules/@diffci.com/core/dist/ci-inference/expression.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +26 -6
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.d.ts +2 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +7 -2
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js +15 -8
- package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +6 -2
- 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 +38 -5
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js +13 -1
- package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +5 -0
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +64 -31
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +22 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.d.ts +6 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js +14 -2
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/planner.js +65 -14
- package/node_modules/@diffci.com/core/dist/planner/planner.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/rust-command.js +43 -1
- package/node_modules/@diffci.com/core/dist/planner/rust-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js +5 -2
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/test-command.js +17 -2
- package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js +27 -1
- package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js +5 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +71 -9
- package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.d.ts +9 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +259 -18
- package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.d.ts +3 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js +44 -6
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.d.ts +1 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +338 -24
- package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +10 -0
- package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +16 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +76 -5
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/graph.js +101 -30
- package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +7 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +56 -9
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/layout.js +4 -1
- package/node_modules/@diffci.com/core/dist/repo/layout.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +10 -1
- package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
- 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/test-discovery.js +5 -1
- package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/types.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +3 -3
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.d.ts +11 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js +208 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.d.ts +3 -0
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js +2 -2
- package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +65 -13
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +47 -2
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
- package/node_modules/@diffci.com/core/package.json +1 -0
- package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +38 -5
- package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +21 -6
- package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +7 -2
- package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +15 -8
- package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +6 -2
- package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +37 -5
- package/node_modules/@diffci.com/core/src/git/ci-config-paths.ts +8 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +57 -32
- package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +22 -1
- package/node_modules/@diffci.com/core/src/planner/pipeline-steps.ts +13 -2
- package/node_modules/@diffci.com/core/src/planner/planner.ts +42 -14
- package/node_modules/@diffci.com/core/src/planner/rust-command.ts +37 -1
- package/node_modules/@diffci.com/core/src/planner/script-reads.ts +5 -1
- package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -2
- package/node_modules/@diffci.com/core/src/planner/type-program.ts +25 -1
- package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +5 -1
- package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +74 -9
- package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +209 -18
- package/node_modules/@diffci.com/core/src/repo/adapters/rust-invocation.ts +44 -6
- package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +264 -24
- package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +10 -1
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +70 -5
- package/node_modules/@diffci.com/core/src/repo/graph.ts +82 -21
- package/node_modules/@diffci.com/core/src/repo/impact.ts +57 -8
- package/node_modules/@diffci.com/core/src/repo/layout.ts +5 -1
- package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +11 -1
- package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +4 -1
- package/node_modules/@diffci.com/core/src/repo/types.ts +3 -1
- package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +3 -3
- package/node_modules/@diffci.com/core/src/repo/yarn-berry-lockfile.ts +178 -0
- package/node_modules/@diffci.com/core/src/repo/yarn-lockfile.ts +2 -2
- package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +43 -13
- package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +44 -2
- package/package.json +2 -2
|
@@ -5,6 +5,7 @@ import { dirname, extname, isAbsolute, join, normalize, posix, relative, resolve
|
|
|
5
5
|
import ts from "typescript";
|
|
6
6
|
import { adapterFiles, REPOSITORY_ADAPTERS } from "./adapters/index.js";
|
|
7
7
|
import { rustAdapter } from "./adapters/rust.js";
|
|
8
|
+
import type { AdapterContribution } from "./adapters/types.js";
|
|
8
9
|
import { rustTestInvocation } from "./adapters/rust-invocation.js";
|
|
9
10
|
import { pythonAdapter } from "./adapters/python.js";
|
|
10
11
|
import { analyzeRepository, type AnalyzeRepositoryOptions } from "./analyzer.js";
|
|
@@ -204,21 +205,30 @@ function globPattern(glob: string): NonNullable<ImportRef["patterns"]>[number] |
|
|
|
204
205
|
const firstWild = body.search(/[*?{[]/);
|
|
205
206
|
const cut = body.lastIndexOf("/", firstWild < 0 ? body.length : firstWild);
|
|
206
207
|
if (cut < 0 || body.includes("[")) return undefined;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
208
|
+
// Brace alternatives are globs too (`{index,*-icon}.ts`); escaping them as literals matched only the
|
|
209
|
+
// literal ones and dropped the rest. Nested braces are not translated and keep the load computed.
|
|
210
|
+
const translate = (text: string): string | undefined => {
|
|
211
|
+
let regex = "";
|
|
212
|
+
for (let i = 0; i < text.length; i++) {
|
|
213
|
+
const char = text[i]!;
|
|
214
|
+
if (text.startsWith("**/", i)) { regex += "(?:.*/)?"; i += 2; }
|
|
215
|
+
else if (text.startsWith("**", i)) { regex += ".*"; i += 1; }
|
|
216
|
+
else if (char === "*") regex += "[^/]*";
|
|
217
|
+
else if (char === "?") regex += "[^/]";
|
|
218
|
+
else if (char === "{") {
|
|
219
|
+
const close = text.indexOf("}", i);
|
|
220
|
+
if (close < 0 || text.slice(i + 1, close).includes("{")) return undefined;
|
|
221
|
+
const alternatives = text.slice(i + 1, close).split(",").map(translate);
|
|
222
|
+
if (alternatives.some((alternative) => alternative === undefined)) return undefined;
|
|
223
|
+
regex += `(?:${alternatives.join("|")})`;
|
|
224
|
+
i = close;
|
|
225
|
+
} else if (char === "}") return undefined;
|
|
226
|
+
else regex += escapeRegex(char);
|
|
227
|
+
}
|
|
228
|
+
return regex;
|
|
229
|
+
};
|
|
230
|
+
const regex = translate(body.slice(cut + 1));
|
|
231
|
+
if (regex === undefined) return undefined;
|
|
222
232
|
// Vite resolves a glob starting with "/" from its project root, not the filesystem root.
|
|
223
233
|
return { base: body.slice(0, cut + 1), regex, negated, ...(body.startsWith("/") ? { viteRoot: true } : {}) };
|
|
224
234
|
}
|
|
@@ -1085,8 +1095,12 @@ export async function buildDependencyGraph(
|
|
|
1085
1095
|
adapterBlockers.push("Mixed Go/JavaScript repositories require explicit cross-language dependencies; full validation required");
|
|
1086
1096
|
}
|
|
1087
1097
|
const rustModeled = contributions.some((item) => item.id === "rust");
|
|
1088
|
-
|
|
1089
|
-
|
|
1098
|
+
const rustScope = rustLanguageFileScope(contributions);
|
|
1099
|
+
const mixedRustFiles = rustModeled ? files.filter(file => /\.(?:[cm]?[jt]sx?|vue|go|py|java|kt|cs|svelte|astro|c|h|cpp|cc|cxx)$/.test(file)) : [];
|
|
1100
|
+
if (mixedRustFiles.length) {
|
|
1101
|
+
const reason = "Mixed Rust/language repositories require explicit cross-language dependencies; full validation required";
|
|
1102
|
+
adapterBlockers.push(reason);
|
|
1103
|
+
for (const file of mixedRustFiles) addScope(reason, rustScope(file));
|
|
1090
1104
|
}
|
|
1091
1105
|
const pythonModeled = contributions.some((item) => item.id === "python");
|
|
1092
1106
|
const unmodeledLanguageFiles = contributions.length ? files.filter((file) => (!pythonModeled && /\.py$/.test(file)) || (!rustModeled && /\.rs$/.test(file)) || /\.(?:cs|svelte|astro)$/.test(file) || !contributions.some((item) => item.id === "maven") && /\.(?:java|kt)$/.test(file)) : [];
|
|
@@ -1095,7 +1109,7 @@ export async function buildDependencyGraph(
|
|
|
1095
1109
|
adapterBlockers.push(reason);
|
|
1096
1110
|
// Files in a top-level dot-directory outside every package (agent skills, editor tooling) are confined
|
|
1097
1111
|
// to that directory: no package's sources or tests can load them.
|
|
1098
|
-
for (const file of unmodeledLanguageFiles) addScope(reason, packageScope(file) || (/^\.[^/]+\//.test(file) && !file.startsWith(".github/") ? file.slice(0, file.indexOf("/")) : ""));
|
|
1112
|
+
for (const file of unmodeledLanguageFiles) addScope(reason, packageScope(file) || (/^\.[^/]+\//.test(file) && !file.startsWith(".github/") ? file.slice(0, file.indexOf("/")) : "") || rustScope(file));
|
|
1099
1113
|
}
|
|
1100
1114
|
profile.adapters = contributions.map(({ id, version, blockers }) => ({ id, version, blockers }));
|
|
1101
1115
|
// Rust test targets are not Go packages; other adapters keep their existing routing here.
|
|
@@ -1113,7 +1127,7 @@ export async function buildDependencyGraph(
|
|
|
1113
1127
|
profile.rustTestTargets = { ...rustContribution.rustTestTargets };
|
|
1114
1128
|
profile.rustSources = [...new Set(rustContribution.sourcePaths)].sort();
|
|
1115
1129
|
profile.rustAssets = [...new Set(rustContribution.assetPaths)].sort();
|
|
1116
|
-
profile.rustTestInvocation = rustTestInvocation(repoPath, files);
|
|
1130
|
+
profile.rustTestInvocation = rustTestInvocation(repoPath, files, { allMembersTested: rustContribution.rustAllMembersTested });
|
|
1117
1131
|
if (rustContribution.rustFeatureCoverage) profile.rustFeatureCoverage = rustContribution.rustFeatureCoverage;
|
|
1118
1132
|
profile.rustDocumentationReaders = [...new Set(rustContribution.rustDocumentationReaders ?? [])].sort();
|
|
1119
1133
|
}
|
|
@@ -1127,7 +1141,10 @@ export async function buildDependencyGraph(
|
|
|
1127
1141
|
profile.testFilePaths = [...new Set([...profile.testFilePaths, ...adapterTests])].sort();
|
|
1128
1142
|
if (profile.testUniverse) {
|
|
1129
1143
|
profile.testUniverse.discoveredTestFiles = profile.testFilePaths.length;
|
|
1130
|
-
|
|
1144
|
+
const runners: Record<string, string> = { go: "go test", maven: "Maven", python: "pytest", rust: "cargo test" };
|
|
1145
|
+
const adapterRunners = contributions.flatMap((item) => runners[item.id] ? [runners[item.id]!] : []);
|
|
1146
|
+
if (adapterRunners.length) profile.testUniverse.adapterRunners = adapterRunners;
|
|
1147
|
+
profile.testUniverse.blindSpot = (profile.testUniverse.declaredFrameworks.length > 0 || adapterRunners.length > 0) && profile.testFilePaths.length === 0;
|
|
1131
1148
|
}
|
|
1132
1149
|
const entryPointPaths = new Set(profile.entryPoints.map((e) => e.path));
|
|
1133
1150
|
|
|
@@ -1378,6 +1395,19 @@ export async function buildDependencyGraph(
|
|
|
1378
1395
|
return undefined;
|
|
1379
1396
|
}
|
|
1380
1397
|
|
|
1398
|
+
/** The JavaScript file a repository declaration file describes, when it exists and is not excluded. */
|
|
1399
|
+
function declarationImplementation(declarationRel: string): string | undefined {
|
|
1400
|
+
const match = /^(.*)\.d\.([mc]?)ts$/.exec(declarationRel);
|
|
1401
|
+
if (!match) return undefined;
|
|
1402
|
+
const extensions = match[2] === "m" ? [".mjs"] : match[2] === "c" ? [".cjs"] : [".js", ".jsx"];
|
|
1403
|
+
for (const extension of extensions) {
|
|
1404
|
+
const candidate = match[1] + extension;
|
|
1405
|
+
if (isExcludedPath(candidate, options.excludeDirs ?? []) || candidate.split("/").includes("node_modules")) continue;
|
|
1406
|
+
if (internalSourcePaths.has(candidate) || existsSync(join(repoPath, candidate))) return candidate;
|
|
1407
|
+
}
|
|
1408
|
+
return undefined;
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1381
1411
|
/** Parses an implementation file an import reaches outside the initial walk, rather than silently dropping
|
|
1382
1412
|
* the edge or loading every TypeScript declaration library again; false, with a blocker, past the budget. */
|
|
1383
1413
|
function followImplementation(absolute: string, rel: string): boolean {
|
|
@@ -1468,7 +1498,11 @@ export async function buildDependencyGraph(
|
|
|
1468
1498
|
// TypeScript may resolve a Vue import to a declaration shim. Preserve the actual SFC edge.
|
|
1469
1499
|
if (resolvableSpecifier.endsWith(".vue")) {
|
|
1470
1500
|
const compilerAliases = Object.entries(importerOptions.paths ?? {}).map(([pattern, substitutions]) => ({ pattern, substitutions }));
|
|
1471
|
-
|
|
1501
|
+
// `paths` resolve against `baseUrl`, or without one against the declaring tsconfig's directory
|
|
1502
|
+
// (TypeScript's pathsBasePath), never the importer's. Root aliases are repo-relative, as for assets.
|
|
1503
|
+
const candidate = compilerAliases.length
|
|
1504
|
+
? findAssetCandidate(sf.fileName, resolvableSpecifier, compilerAliases, importerOptions.baseUrl ?? (importerOptions as { pathsBasePath?: string }).pathsBasePath ?? dirname(sf.fileName))
|
|
1505
|
+
: findAssetCandidate(sf.fileName, resolvableSpecifier, profile.pathAliases, profile.tsconfig?.baseUrl ? resolve(repoPath, profile.tsconfig.baseUrl) : repoPath);
|
|
1472
1506
|
const target = candidate && toRelativeInternal(repoPath, candidate);
|
|
1473
1507
|
if (target && internalSourcePaths.has(target)) {
|
|
1474
1508
|
addEdge(importerRel, target, ref.kind, ref);
|
|
@@ -1576,6 +1610,11 @@ export async function buildDependencyGraph(
|
|
|
1576
1610
|
if (!resolved.endsWith(".d.ts") && !followImplementation(resolved, targetRel)) continue;
|
|
1577
1611
|
internalSourcePaths.add(targetRel);
|
|
1578
1612
|
addEdge(importerRel, targetRel, ref.kind, ref);
|
|
1613
|
+
// A hand-written declaration beside its JavaScript (`foo.d.ts` next to `foo.js`) is what TypeScript
|
|
1614
|
+
// resolves to, but the runner loads the JavaScript. Without this edge a change to `foo.js` reached
|
|
1615
|
+
// no importer and selected nothing.
|
|
1616
|
+
const implementation = declarationImplementation(targetRel);
|
|
1617
|
+
if (implementation && followImplementation(join(repoPath, implementation), implementation)) addEdge(importerRel, implementation, ref.kind, ref);
|
|
1579
1618
|
recordReference("internal-source", importerRel, ref);
|
|
1580
1619
|
continue;
|
|
1581
1620
|
}
|
|
@@ -2218,6 +2257,28 @@ function confinedConfigScope(repoPath: string, configRel: string, config: unknow
|
|
|
2218
2257
|
return directory;
|
|
2219
2258
|
}
|
|
2220
2259
|
|
|
2260
|
+
/** In a Cargo-only repository, the directory a helper script or native source is confined to: the
|
|
2261
|
+
* deepest member crate that contains it, or its top-level directory outside every crate of a virtual
|
|
2262
|
+
* workspace. Cargo can reach such a file only through code in that crate (a build script, which already
|
|
2263
|
+
* depends on every crate, or an `include!`, which falls back), and a change to the file itself keeps the
|
|
2264
|
+
* full suite, so only changes that reach the directory need full validation. "" (global) when another
|
|
2265
|
+
* adapter is active, when Rust code starts external programs that could run the file from anywhere, for
|
|
2266
|
+
* languages another engine could test (JavaScript, Go, Java and so on), for files that look like
|
|
2267
|
+
* Python tests, and inside a root package. */
|
|
2268
|
+
function rustLanguageFileScope(contributions: readonly AdapterContribution[]): (file: string) => string {
|
|
2269
|
+
const rust = contributions.length === 1 && contributions[0]!.id === "rust" ? contributions[0]! : undefined;
|
|
2270
|
+
const crates = rust?.rustCrateDirectories;
|
|
2271
|
+
if (!rust || !crates || rust.rustRunsPrograms !== false) return () => "";
|
|
2272
|
+
return (file: string) => {
|
|
2273
|
+
if (!/\.(?:py|c|h|cc|cpp|cxx)$/.test(file)) return "";
|
|
2274
|
+
const name = file.slice(file.lastIndexOf("/") + 1);
|
|
2275
|
+
if (/^(?:test_.*|.*_test|conftest)\.py$/.test(name)) return "";
|
|
2276
|
+
const crate = crates.filter(directory => directory === "" || file.startsWith(`${directory}/`)).sort((a, b) => b.length - a.length)[0];
|
|
2277
|
+
if (crate !== undefined) return crate;
|
|
2278
|
+
return file.includes("/") ? file.slice(0, file.indexOf("/")) : "";
|
|
2279
|
+
};
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2221
2282
|
/** Moves blockers confined to directories out of `adapterBlockers` and returns them scoped to those
|
|
2222
2283
|
* directories (2026-11-08: Sentry's JavaScript SDK keeps 19 Nuxt, SvelteKit and Vue E2E applications whose
|
|
2223
2284
|
* tsconfig extends generated `.nuxt/`/`.svelte-kit/` files; they made every change in its SDK packages fall
|
|
@@ -8,7 +8,7 @@ import { refineConfidenceForDelta, relevantScopedAdapterBlockers } from "./graph
|
|
|
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 { compilerConfigNames, contentNamesPath, directoryWalkers, DIRECTING_EXTENSIONS, infrastructureRole, isAgentConfigurationPath, listsDirectories, loadsWithoutNaming, isImplicitlyLoadedFile, isWorkerConfig, referencePattern, referenceTokens, resolveFileReferences, suiteMayRunWorkers, testScriptClosure } from "./file-references.js";
|
|
11
|
+
import { compilerConfigNames, contentNamesPath, directoryWalkers, DIRECTING_EXTENSIONS, infrastructureRole, isAgentConfigurationPath, listsDirectories, loadsWithoutNaming, isImplicitlyLoadedFile, isWorkerConfig, referencePattern, referenceTokens, resolveFileReferences, suiteMayRunWorkers, testScriptClosure, testScriptPrograms } 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";
|
|
@@ -66,6 +66,7 @@ function toolConfigurationSubject(filePath: string): string | undefined {
|
|
|
66
66
|
if (base === ".nvmrc" || base === ".node-version") return "Node version";
|
|
67
67
|
if (base === ".npmrc") return "package manager settings";
|
|
68
68
|
if (/^tsconfig\.[^/]+\.json$/.test(base) || /^jsconfig\.[^/]+\.json$/.test(base)) return "TypeScript configuration";
|
|
69
|
+
if (base === ".mocharc" || base.startsWith(".mocharc.")) return "Mocha settings";
|
|
69
70
|
return undefined;
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -358,10 +359,10 @@ export class ImpactAnalyzer {
|
|
|
358
359
|
private knownTestPaths(profile: RepositoryProfile, graph: DependencyGraph): string[] {
|
|
359
360
|
if (this.knownTests) return this.knownTests;
|
|
360
361
|
const known = new Set<string>();
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
362
|
+
// Adapter repositories (pytest, Maven) declare no JavaScript test locations, so the matcher must not
|
|
363
|
+
// depend on profile.tests being non-empty.
|
|
364
|
+
for (const node of graph.nodes) {
|
|
365
|
+
if (this.isTestFile(node.path) || profile.tests.some((testLocation) => matchesTestGlob(node.path, testLocation.glob))) known.add(node.path);
|
|
365
366
|
}
|
|
366
367
|
this.knownTests = [...known].sort();
|
|
367
368
|
return this.knownTests;
|
|
@@ -707,7 +708,8 @@ export class ImpactAnalyzer {
|
|
|
707
708
|
// whose entire `__tests__/` suite was invisible: graph confidence COMPLETE, 5 of 5 commits
|
|
708
709
|
// SELECTIVE, zero tests. Fails closed to FULL instead.
|
|
709
710
|
if (profile.testUniverse?.blindSpot === true) {
|
|
710
|
-
|
|
711
|
+
// A language adapter (Go, Maven, pytest, Cargo) declares its runner without a package.json framework.
|
|
712
|
+
const declared = [...profile.testUniverse.declaredFrameworks, ...(profile.testUniverse.adapterRunners ?? [])].join(", ");
|
|
711
713
|
const message = `Repository declares ${declared} but no test files were discovered; full validation required`;
|
|
712
714
|
riskSignals.push({ level: "critical", reason: "TEST_UNIVERSE_EMPTY", message });
|
|
713
715
|
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
@@ -933,7 +935,7 @@ export class ImpactAnalyzer {
|
|
|
933
935
|
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]!;
|
|
934
936
|
};
|
|
935
937
|
if (yarnCandidates) {
|
|
936
|
-
//
|
|
938
|
+
// Yarn's node-modules linkers can hoist packages that repository code imports without declaring them.
|
|
937
939
|
// All-root widening covers peers, but cannot attribute these additional importers to a root.
|
|
938
940
|
const undeclared = [...new Set(graphResult.references.filter((ref) => ref.resolution === "external-package")
|
|
939
941
|
.map((ref) => packageRoot(ref.specifier)).filter((name) => !packages.includes(name)))].sort();
|
|
@@ -947,6 +949,14 @@ export class ImpactAnalyzer {
|
|
|
947
949
|
.map((ref) => packageRoot(ref.specifier)).filter((name) => !declared.has(name)))].sort();
|
|
948
950
|
if (undeclared.length) fail(`pnpm lockfile changed and repository imports undeclared dependencies (${undeclared.join(", ")}); full validation required`);
|
|
949
951
|
}
|
|
952
|
+
if (!delta.analysis.dependencyLockfile && delta.files.some((file) => file.path === "package-lock.json")) {
|
|
953
|
+
// npm hoists transitive packages to the root node_modules, where repository code can import them
|
|
954
|
+
// without declaring them. Attribution reaches only declared roots, so such an import is not covered.
|
|
955
|
+
const declared = new Set([...profile.packageJson.dependencies, ...profile.packageJson.devDependencies, ...packages]);
|
|
956
|
+
const undeclared = [...new Set(graphResult.references.filter((ref) => ref.resolution === "external-package")
|
|
957
|
+
.map((ref) => packageRoot(ref.specifier)).filter((name) => !declared.has(name)))].sort();
|
|
958
|
+
if (undeclared.length) fail(`npm lockfile changed and repository imports undeclared dependencies (${undeclared.join(", ")}); full validation required`);
|
|
959
|
+
}
|
|
950
960
|
const scripts = profile.packageJson.scripts;
|
|
951
961
|
const closureBodies = [...testScriptClosure(scripts)].map((name) => scripts[name] ?? "");
|
|
952
962
|
for (const name of packages) {
|
|
@@ -1255,6 +1265,7 @@ export class ImpactAnalyzer {
|
|
|
1255
1265
|
if (changedPath.endsWith(".py") && profile.pythonSources?.includes(changedPath)) {
|
|
1256
1266
|
this.resolveByReference(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence, { allowNoReaders: true });
|
|
1257
1267
|
}
|
|
1268
|
+
this.coverTestScriptPrograms(changedPath, graph, profile, evidence, riskSignals, fallbackReasons);
|
|
1258
1269
|
this.processSourceChange(changedPath, graph, profile, affectedSources, affectedEntryPoints, affectedTests, affectedScripts, evidence);
|
|
1259
1270
|
this.failToolLoadedOrphan(changedPath, changedImpact, graph, affectedTests, evidence, riskSignals, fallbackReasons, covered);
|
|
1260
1271
|
}
|
|
@@ -1267,6 +1278,41 @@ export class ImpactAnalyzer {
|
|
|
1267
1278
|
* name anywhere, or any one at the repository root, that no file imports and that reached no test.
|
|
1268
1279
|
* An unused module elsewhere (`src/unused.ts`) still selects nothing: no tool loads it by name.
|
|
1269
1280
|
*/
|
|
1281
|
+
/**
|
|
1282
|
+
* A program the root test script runs itself (`node scripts/check.mjs && node --test`) is part of the
|
|
1283
|
+
* suite although no test imports it: the graph saw only an entry point, so a change to it, or to code it
|
|
1284
|
+
* imports, selected nothing for it and `verify` passed while `npm test` failed (2026-11-18). Callers
|
|
1285
|
+
* that run test-script phases run the phase; everyone else gets the full suite.
|
|
1286
|
+
*/
|
|
1287
|
+
private coverTestScriptPrograms(
|
|
1288
|
+
changedPath: string,
|
|
1289
|
+
graph: DependencyGraph,
|
|
1290
|
+
profile: RepositoryProfile,
|
|
1291
|
+
evidence: ImpactEvidence[],
|
|
1292
|
+
riskSignals: ImpactRiskSignal[],
|
|
1293
|
+
fallbackReasons: string[],
|
|
1294
|
+
): void {
|
|
1295
|
+
if (!JS_TS_CODE.test(changedPath) || this.isTestFile(changedPath)) return;
|
|
1296
|
+
const programs = testScriptPrograms(profile.packageJson.scripts);
|
|
1297
|
+
if (programs.size === 0) return;
|
|
1298
|
+
const reached = [changedPath, ...(hasNode(graph, changedPath) ? graph.transitiveDependentsOf(changedPath) : [])];
|
|
1299
|
+
for (const path of reached) {
|
|
1300
|
+
const program = programs.get(path);
|
|
1301
|
+
if (!program || this.isTestFile(path)) continue;
|
|
1302
|
+
if (this.selectTestPhases && program.direct) {
|
|
1303
|
+
for (const phase of program.phases) {
|
|
1304
|
+
this.testPhases.add(phase);
|
|
1305
|
+
evidence.push(makeEvidence("FILE_REFERENCE", changedPath, `the test script runs \`${phase}\`, which ${path === changedPath ? "is" : "imports"} ${changedPath}`));
|
|
1306
|
+
}
|
|
1307
|
+
continue;
|
|
1308
|
+
}
|
|
1309
|
+
const message = path === changedPath ? `The test script runs ${path}; full validation required` : `The test script runs ${path}, which imports ${changedPath}; full validation required`;
|
|
1310
|
+
evidence.push(makeEvidence("CONFIG_GLOBAL", changedPath, message));
|
|
1311
|
+
riskSignals.push({ level: "critical", reason: "CONFIG_GLOBAL", message, paths: [changedPath] });
|
|
1312
|
+
if (!fallbackReasons.includes(message)) fallbackReasons.push(message);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1270
1316
|
private failToolLoadedOrphan(
|
|
1271
1317
|
changedPath: string,
|
|
1272
1318
|
changedImpact: ChangedImpact,
|
|
@@ -1402,13 +1448,16 @@ export class ImpactAnalyzer {
|
|
|
1402
1448
|
}
|
|
1403
1449
|
const layout = this.layout;
|
|
1404
1450
|
const scripts = profile.packageJson.scripts;
|
|
1451
|
+
// A .py file the Python adapter modelled is code like a .js file: pytest runs a test that reads the
|
|
1452
|
+
// changed file without anything naming the test, so it must not be followed as a script.
|
|
1453
|
+
const pythonSources = new Set(profile.pythonSources ?? []);
|
|
1405
1454
|
const resolution = resolveFileReferences(changedPath, {
|
|
1406
1455
|
files: this.sortedRepositoryFiles,
|
|
1407
1456
|
read: this.readRepositoryFile,
|
|
1408
1457
|
isTestFile: this.isTestFile,
|
|
1409
1458
|
isDocumentation: (path) => layout.isDocumentationPath(path) || isAgentConfigurationPath(path),
|
|
1410
1459
|
inGraph: (path) => hasNode(graph, path),
|
|
1411
|
-
isCodeFile: isSourceFilePath,
|
|
1460
|
+
isCodeFile: (path) => isSourceFilePath(path) || pythonSources.has(path),
|
|
1412
1461
|
workflowFeedsTests: (content, names) => workflowFeedsTests(content, names, scripts),
|
|
1413
1462
|
contentCleared: this.contentCleared,
|
|
1414
1463
|
implicitReadersUnresolvable,
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
import { extname } from "node:path";
|
|
28
28
|
import type { RepositoryProfile } from "./types.js";
|
|
29
29
|
|
|
30
|
+
/** Trailing slashes. The lookbehind starts a match only at the first slash of a run; `/\/+$/` alone retries from every
|
|
31
|
+
* slash of a run that is not at the end, which is quadratic on long runs (CodeQL alerts 16, 17). */
|
|
32
|
+
const TRAILING_SLASHES = /(?<!\/)\/+$/;
|
|
33
|
+
|
|
30
34
|
/**
|
|
31
35
|
* Directory names that mean "documentation" across the ecosystem. Deliberately short: a name earns a
|
|
32
36
|
* place here by being a convention many projects share, not by appearing in one repository.
|
|
@@ -47,7 +51,7 @@ export interface RepositoryLayout {
|
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
function normalizeRoot(root: string): string {
|
|
50
|
-
return root.replace(/\\/g, "/").replace(/^\.\//, "").replace(
|
|
54
|
+
return root.replace(/\\/g, "/").replace(/^\.\//, "").replace(TRAILING_SLASHES, "");
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
function isUnder(path: string, root: string): boolean {
|
|
@@ -38,6 +38,16 @@ function stripRootDir(value: string): string {
|
|
|
38
38
|
return value.startsWith(ROOT_DIR) ? value.slice(ROOT_DIR.length).replace(/^\//, "") : value;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Jest replaces a leading `<rootDir>` in `testPathIgnorePatterns` with the absolute root directory.
|
|
43
|
+
* Ignore sources are matched against "/" + the repo-relative path, so the root becomes an anchored
|
|
44
|
+
* "^/". Anchoring keeps `<rootDir>/e2e/` from also ignoring `packages/a/e2e/`. A `<rootDir>` that
|
|
45
|
+
* is not at the front stays literal, as it does in jest.
|
|
46
|
+
*/
|
|
47
|
+
function rootDirIgnoreSource(source: string): string {
|
|
48
|
+
return source.startsWith(ROOT_DIR) ? `^/${source.slice(ROOT_DIR.length).replace(/^\/+/, "")}` : source;
|
|
49
|
+
}
|
|
50
|
+
|
|
41
51
|
export interface ExtractedTestPatterns {
|
|
42
52
|
/** Declared test globs, `<rootDir>/` stripped. */
|
|
43
53
|
includes: string[];
|
|
@@ -232,7 +242,7 @@ export function extractTestPatterns(source: string): ExtractedTestPatterns {
|
|
|
232
242
|
return {
|
|
233
243
|
includes: Array.from(new Set(includes)),
|
|
234
244
|
excludeGlobs: Array.from(new Set((readKey("exclude") ?? []).map(stripRootDir).filter((g) => g.length > 0 && !g.includes(ROOT_DIR)))),
|
|
235
|
-
ignoreRegexSources: Array.from(new Set(readKey("testPathIgnorePatterns") ?? [])),
|
|
245
|
+
ignoreRegexSources: Array.from(new Set((readKey("testPathIgnorePatterns") ?? []).map(rootDirIgnoreSource))),
|
|
236
246
|
roots,
|
|
237
247
|
declaresTests,
|
|
238
248
|
complete,
|
|
@@ -64,7 +64,7 @@ function expandScript(name: string, scripts: Readonly<Record<string, string>>, d
|
|
|
64
64
|
const phases: string[] = [];
|
|
65
65
|
for (const hook of [`pre${name}`, name, `post${name}`]) {
|
|
66
66
|
if (hook !== name && typeof scripts[hook] !== "string") continue;
|
|
67
|
-
for (const phase of (hook === name ? body : scripts[hook]!).split(
|
|
67
|
+
for (const phase of (hook === name ? body : scripts[hook]!).split("&&")) {
|
|
68
68
|
const words = shellWords(phase.trim());
|
|
69
69
|
const nested = words && /^(?:npm|pnpm|yarn|bun)$/.test(words[0] ?? "")
|
|
70
70
|
? (words[1] === "run" || words[1] === "run-script" ? words[2] : words[1] === "test" || words[1] === "t" ? "test" : undefined)
|
|
@@ -584,7 +584,10 @@ function globToRegex(pattern: string): RegExp {
|
|
|
584
584
|
return `\0X${groups.length - 1}\0`;
|
|
585
585
|
});
|
|
586
586
|
|
|
587
|
-
|
|
587
|
+
// `+`, `$` and `^` (outside a `[^...]` class) are literal in globs, as in picomatch: Remix route files
|
|
588
|
+
// (`users.$id.tsx`) and remix-flat-routes folders (`_auth+/`) use them. A bare `**` matches every path.
|
|
589
|
+
working = working.replace(/\\/g, "\\\\").replace(/\./g, "\\.").replace(/[+$]|(?<!\[)\^/g, "\\$&");
|
|
590
|
+
if (working === "**") return /^.*$/;
|
|
588
591
|
working = working
|
|
589
592
|
.replace(/\*\*\//g, "\0GS\0")
|
|
590
593
|
.replace(/\/\*\*/g, "\0SG\0")
|
|
@@ -53,7 +53,7 @@ export interface RepositoryProfile {
|
|
|
53
53
|
mavenTestModules?: Record<string, string>;
|
|
54
54
|
/** Cargo target source to owning package name and target, verified by metadata. */
|
|
55
55
|
rustTestPackages?: Record<string, string>;
|
|
56
|
-
rustTestTargets?: Record<string, { name: string; kind: "lib" | "bin" | "test" | "bench" | "example" }>;
|
|
56
|
+
rustTestTargets?: Record<string, { name: string; kind: "lib" | "bin" | "test" | "bench" | "example"; requiredFeatures?: string[] }>;
|
|
57
57
|
rustSources?: string[];
|
|
58
58
|
/** Rust files that may read documentation (adapters/rust.ts). While one exists, documentation
|
|
59
59
|
* changes keep the full suite; otherwise they follow the shared documentation classification. */
|
|
@@ -133,6 +133,8 @@ export interface RepositoryProfile {
|
|
|
133
133
|
/** How each framework was detected - "dependency:<pkg>" or "script:<name>". */
|
|
134
134
|
frameworkEvidence: Record<string, string>;
|
|
135
135
|
discoveredTestFiles: number;
|
|
136
|
+
/** Runners that language adapters found sources for (`go test`, `Maven`, `pytest`, `cargo test`). */
|
|
137
|
+
adapterRunners?: string[];
|
|
136
138
|
/** True when the repository declares a test framework and zero test files were discovered - the
|
|
137
139
|
* engine does not understand this repository's test layout, and must not propose a selection
|
|
138
140
|
* against an empty universe. */
|
|
@@ -32,17 +32,17 @@ const NON_TEST_ACTIONS = [
|
|
|
32
32
|
/** DiffCI subcommands that run no tests. `verify`, `check`, `pilot` and `enforce-misses` do, so `diffci`
|
|
33
33
|
* followed by anything else stays a test runner (2026-10-29: DiffCI's own observation workflows were
|
|
34
34
|
* 60 of 65 workflow-triggered fallbacks in one dogfood repository's telemetry). */
|
|
35
|
-
const DIFFCI_NON_TEST_COMMAND = /\bdiffci["']?(?:\s
|
|
35
|
+
const DIFFCI_NON_TEST_COMMAND = /\bdiffci["']?(?:\s+-\S*)*\s+(?:observe|init|version|telemetry|pilot-packet|verify-workflow|validate-specs|mcp)\b/g;
|
|
36
36
|
|
|
37
37
|
/** `diffci` invoked with a subcommand still present after removing the non-test ones. */
|
|
38
|
-
const DIFFCI_COMMAND = /\bdiffci["']?(?:\s
|
|
38
|
+
const DIFFCI_COMMAND = /\bdiffci["']?(?:\s+-\S*)*\s+[a-z][\w-]*/;
|
|
39
39
|
|
|
40
40
|
/** A job whose `if` is the literal false never runs (a retired workflow kept for its history). */
|
|
41
41
|
function jobDisabled(job: object): boolean {
|
|
42
42
|
const condition = (job as { if?: unknown }).if;
|
|
43
43
|
return condition === false || (typeof condition === "string" && /^\s*(?:\$\{\{\s*)?false(?:\s*\}\})?\s*$/.test(condition));
|
|
44
44
|
}
|
|
45
|
-
const TEST_RUNNERS = /(?:^|[\s/"'`(;&|])(?:vitest|jest|mocha|ava|tap|playwright|cypress|karma|jasmine|pytest|tox|nox|phpunit|rspec|ctest)(?=$|[\s"'`);&|])|(?:node|tsx|bun|deno)(?:\s
|
|
45
|
+
const TEST_RUNNERS = /(?:^|[\s/"'`(;&|])(?:vitest|jest|mocha|ava|tap|playwright|cypress|karma|jasmine|pytest|tox|nox|phpunit|rspec|ctest)(?=$|[\s"'`);&|])|(?:node|tsx|bun|deno)(?:\s+-\S*)*\s+--?test\b|\b(?:go|cargo|dotnet|swift|mix|zig)\s+test\b|\b(?:mvn|mvnw|gradle|gradlew|sbt|bazel|make|just)\b/;
|
|
46
46
|
const PACKAGE_SCRIPT = /\b(?:npm|pnpm|yarn|bun)\s+(?:(?:run|run-script|-w\s+\S+|--workspace[= ]\S+|--prefix[= ]\S+|--if-present|-r|--recursive|--silent|-s)\s+)*([\w:.-]+)/g;
|
|
47
47
|
const INTERPRETER_FILE = /\b(?:node|tsx|ts-node|bash|sh|zsh|pwsh|powershell|python3?|ruby|perl|deno\s+run|bun(?:\s+run)?|npx\s+(?:--\S+\s+)*tsx)\s+(?:-{1,2}[\w-]+(?:=\S+)?\s+)*\.{0,2}\/?[\w./-]+\.(?:m?[jt]s|c[jt]s|sh|ps1|py|rb|pl)\b|(?:^|[\s;&|])\.{1,2}\/[\w./-]+/;
|
|
48
48
|
const PACKAGE_MANAGER_BUILTINS = new Set(["ci", "install", "i", "add", "remove", "uninstall", "publish", "pack", "version", "view", "info", "whoami", "login", "config", "cache", "audit", "outdated", "ls", "list", "exec", "dlx", "init", "create", "link", "prune", "dedupe", "rebuild", "set-script", "pkg", "fund", "doctor", "help", "--version", "-v"]);
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
/**
|
|
3
|
+
* Conservative Berry npm candidates, gated separately on an explicit node-modules linker.
|
|
4
|
+
* Like Classic, a semantic change widens to every direct dependency: the lockfile does not record
|
|
5
|
+
* the installed hoisting layout. Unknown formats, protocols, fields and missing edges fail closed.
|
|
6
|
+
* A lone workspace:. record describes the project itself, not a workspace dependency; when present
|
|
7
|
+
* it must agree with the manifest. All other workspace records and edges are unsupported.
|
|
8
|
+
*/
|
|
9
|
+
import { parseDocument, visit } from "yaml";
|
|
10
|
+
import { lstatSync, readFileSync, realpathSync } from "node:fs";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { isExactVersion, isRegistryRequest } from "./yarn-lockfile.js";
|
|
14
|
+
|
|
15
|
+
type Direct = Readonly<Record<string, string>>;
|
|
16
|
+
type RecordMap = Map<string, unknown>;
|
|
17
|
+
interface Entry { edges: string[]; fingerprint: string }
|
|
18
|
+
interface Lock { entries: Map<string, Entry>; metadata: string; project?: string }
|
|
19
|
+
const NAME = /^(?:@[a-zA-Z0-9][a-zA-Z0-9._-]*\/)?[a-zA-Z0-9][a-zA-Z0-9._-]*$/;
|
|
20
|
+
const record = (value: unknown): value is RecordMap => value instanceof Map && [...value.keys()].every((key) => typeof key === "string");
|
|
21
|
+
|
|
22
|
+
function yaml(content: string | undefined): RecordMap | undefined {
|
|
23
|
+
if (!content || content.length > 8 * 1024 * 1024) return undefined;
|
|
24
|
+
const lines = content.split(/\r?\n/);
|
|
25
|
+
if (lines.length > 100_000 || lines.some((line) => line.length > 16_384)) return undefined;
|
|
26
|
+
try {
|
|
27
|
+
const doc = parseDocument(content, { uniqueKeys: true });
|
|
28
|
+
if (doc.errors.length || doc.warnings.length) return undefined;
|
|
29
|
+
let unsupported = false;
|
|
30
|
+
visit(doc, { Node(_key, node, path) { if (node.anchor || node.tag || path.length > 20) unsupported = true; }, Alias() { unsupported = true; } });
|
|
31
|
+
if (unsupported) return undefined;
|
|
32
|
+
const value: unknown = doc.toJS({ mapAsMap: true, maxAliasCount: 0 });
|
|
33
|
+
return record(value) ? value : undefined;
|
|
34
|
+
} catch { return undefined; }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Do not interpolate environment-dependent settings or silently ignore additional configuration.
|
|
38
|
+
* Yarn reads environment keys case-insensitively, including YARN_RC_FILENAME and plugin overrides.
|
|
39
|
+
* The caller must analyze in the environment in which the selected tests will run. */
|
|
40
|
+
export function berryNodeModulesConfig(content: string | undefined, env: NodeJS.ProcessEnv = process.env): boolean {
|
|
41
|
+
if (Object.keys(env).some((key) => /^yarn_/i.test(key) && env[key] !== undefined)) return false;
|
|
42
|
+
const config = yaml(content);
|
|
43
|
+
return !!config && config.size === 1 && config.get("nodeLinker") === "node-modules";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The project file overrides the linker, but inherited config can still inject plugins or change
|
|
47
|
+
* resolution. This first subset requires a standalone checkout without those additional inputs. */
|
|
48
|
+
export function berryRuntimeConfig(repoPath: string | undefined): boolean {
|
|
49
|
+
try {
|
|
50
|
+
const root = realpathSync(repoPath ?? process.cwd());
|
|
51
|
+
const configPath = join(root, ".yarnrc.yml");
|
|
52
|
+
const configStat = lstatSync(configPath);
|
|
53
|
+
if (!configStat.isFile() || configStat.size > 65_536 || !berryNodeModulesConfig(readFileSync(configPath, "utf8"))) return false;
|
|
54
|
+
const extra = new Set([join(root, ".env.yarn"), join(homedir(), ".yarnrc.yml")]);
|
|
55
|
+
let parent = dirname(root);
|
|
56
|
+
while (true) {
|
|
57
|
+
extra.add(join(parent, ".yarnrc.yml"));
|
|
58
|
+
if (dirname(parent) === parent) break;
|
|
59
|
+
parent = dirname(parent);
|
|
60
|
+
}
|
|
61
|
+
extra.delete(join(root, ".yarnrc.yml"));
|
|
62
|
+
for (const path of extra) {
|
|
63
|
+
try { lstatSync(path); return false; }
|
|
64
|
+
catch (error) { if ((error as NodeJS.ErrnoException).code !== "ENOENT") return false; }
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
} catch { return false; }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function descriptor(name: string, request: string): string | undefined {
|
|
71
|
+
const range = request.startsWith("npm:") ? request.slice(4) : request;
|
|
72
|
+
return NAME.test(name) && isRegistryRequest(range) ? `${name}@npm:${range}` : undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function selectors(key: string): string[] | undefined {
|
|
76
|
+
const values = key.split(/, */);
|
|
77
|
+
let packageName: string | undefined;
|
|
78
|
+
for (const value of values) {
|
|
79
|
+
const separator = value.indexOf("@", value.startsWith("@") ? 1 : 0);
|
|
80
|
+
const name = value.slice(0, separator);
|
|
81
|
+
const request = value.slice(separator + 1);
|
|
82
|
+
if (separator < 1 || !request.startsWith("npm:") || descriptor(name, request) !== value || (packageName !== undefined && packageName !== name)) return undefined;
|
|
83
|
+
packageName = name;
|
|
84
|
+
}
|
|
85
|
+
return values;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function dependencies(value: unknown): Map<string, string> | undefined {
|
|
89
|
+
if (value === undefined) return new Map();
|
|
90
|
+
if (!record(value)) return undefined;
|
|
91
|
+
const result = new Map<string, string>();
|
|
92
|
+
for (const [name, request] of value) {
|
|
93
|
+
if (typeof request !== "string") return undefined;
|
|
94
|
+
const key = descriptor(name, request);
|
|
95
|
+
if (!key) return undefined;
|
|
96
|
+
result.set(name, key);
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const sorted = (map: Map<string, unknown>) => [...map].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
102
|
+
function parse(content: string | undefined, direct: Direct, projectName?: string): Lock | undefined {
|
|
103
|
+
const raw = yaml(content);
|
|
104
|
+
if (!raw) return undefined;
|
|
105
|
+
const metadata = raw.get("__metadata");
|
|
106
|
+
const cacheKey = record(metadata) ? metadata.get("cacheKey") : undefined;
|
|
107
|
+
// Known Berry formats only; a future serializer needs a separate review.
|
|
108
|
+
if (!record(metadata) || ![4, 6, 8].includes(metadata.get("version") as number)
|
|
109
|
+
|| [...metadata.keys()].some((key) => key !== "version" && key !== "cacheKey")
|
|
110
|
+
|| (metadata.has("cacheKey") && !["string", "number"].includes(typeof metadata.get("cacheKey")))
|
|
111
|
+
|| (typeof cacheKey === "number" && (!Number.isSafeInteger(cacheKey) || cacheKey < 0))
|
|
112
|
+
|| (metadata.has("cacheKey") && !/^[a-zA-Z0-9]+$/.test(String(metadata.get("cacheKey"))))) return undefined;
|
|
113
|
+
const entries = new Map<string, Entry>();
|
|
114
|
+
let project: string | undefined;
|
|
115
|
+
for (const [key, value] of raw) {
|
|
116
|
+
if (key === "__metadata") continue;
|
|
117
|
+
if (!record(value) || [...value.keys()].some((field) => !["version", "resolution", "checksum", "languageName", "linkType", "dependencies", "bin"].includes(field))) return undefined;
|
|
118
|
+
const deps = dependencies(value.get("dependencies"));
|
|
119
|
+
if (!deps) return undefined;
|
|
120
|
+
if (key.endsWith("@workspace:.")) {
|
|
121
|
+
if (project || !projectName || !NAME.test(projectName) || key !== `${projectName}@workspace:.`
|
|
122
|
+
|| value.get("resolution") !== key || value.get("version") !== "0.0.0-use.local" || value.get("linkType") !== "soft"
|
|
123
|
+
|| value.has("checksum") || value.has("bin")
|
|
124
|
+
|| (value.has("languageName") && !["node", "unknown"].includes(value.get("languageName") as string))
|
|
125
|
+
|| deps.size !== Object.keys(direct).length
|
|
126
|
+
|| Object.entries(direct).some(([name, request]) => deps.get(name) !== descriptor(name, request))) return undefined;
|
|
127
|
+
project = JSON.stringify([key, value.get("languageName")]);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
const keys = selectors(key);
|
|
131
|
+
const version = value.get("version");
|
|
132
|
+
if (!keys || typeof version !== "string" || !isExactVersion(version) || value.get("languageName") !== "node" || value.get("linkType") !== "hard") return undefined;
|
|
133
|
+
const name = keys[0]!.slice(0, keys[0]!.indexOf("@", keys[0]!.startsWith("@") ? 1 : 0));
|
|
134
|
+
if (value.get("resolution") !== `${name}@npm:${version}`) return undefined;
|
|
135
|
+
const checksum = value.get("checksum");
|
|
136
|
+
if (checksum !== undefined && (typeof checksum !== "string" || !/^(?:[a-zA-Z0-9]+\/)?[a-f0-9]{128}$/.test(checksum))) return undefined;
|
|
137
|
+
const bin = value.get("bin");
|
|
138
|
+
if (bin !== undefined && (!record(bin) || [...bin.values()].some((path) => typeof path !== "string"))) return undefined;
|
|
139
|
+
const entry: Entry = { edges: [...deps.values()], fingerprint: JSON.stringify([version, value.get("resolution"), checksum ?? null, sorted(deps), bin ? sorted(bin as RecordMap) : null]) };
|
|
140
|
+
for (const selector of keys) {
|
|
141
|
+
if (entries.has(selector) || entries.size >= 100_000) return undefined;
|
|
142
|
+
entries.set(selector, entry);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if ([...entries.values()].some((entry) => entry.edges.some((edge) => !entries.has(edge)))) return undefined;
|
|
146
|
+
return { entries, metadata: JSON.stringify(sorted(metadata)), project };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function reachable(lock: Lock, direct: Direct): Set<Entry> | undefined {
|
|
150
|
+
const queue: Entry[] = [];
|
|
151
|
+
for (const [name, request] of Object.entries(direct)) {
|
|
152
|
+
const key = descriptor(name, request);
|
|
153
|
+
const entry = key ? lock.entries.get(key) : undefined;
|
|
154
|
+
if (!entry) return undefined;
|
|
155
|
+
queue.push(entry);
|
|
156
|
+
}
|
|
157
|
+
const seen = new Set<Entry>();
|
|
158
|
+
while (queue.length) {
|
|
159
|
+
const entry = queue.pop()!;
|
|
160
|
+
if (seen.has(entry)) continue;
|
|
161
|
+
seen.add(entry);
|
|
162
|
+
for (const key of entry.edges) queue.push(lock.entries.get(key)!);
|
|
163
|
+
}
|
|
164
|
+
return seen;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Possible affected roots, or undefined to retain full validation. Call only after linker proof. */
|
|
168
|
+
export function berryLockAffectedDependencies(oldContent: string | undefined, newContent: string | undefined, beforeDirect: Direct, afterDirect: Direct, beforeName?: string, afterName?: string): string[] | undefined {
|
|
169
|
+
const before = parse(oldContent, beforeDirect, beforeName);
|
|
170
|
+
const after = parse(newContent, afterDirect, afterName);
|
|
171
|
+
if (!before || !after || before.metadata !== after.metadata || before.project !== after.project) return undefined;
|
|
172
|
+
const oldReachable = reachable(before, beforeDirect);
|
|
173
|
+
const newReachable = reachable(after, afterDirect);
|
|
174
|
+
if (!oldReachable || !newReachable) return undefined;
|
|
175
|
+
const changed = [...new Set([...before.entries.keys(), ...after.entries.keys()])].filter((key) => before.entries.get(key)?.fingerprint !== after.entries.get(key)?.fingerprint);
|
|
176
|
+
if (changed.some((key) => !oldReachable.has(before.entries.get(key)!) && !newReachable.has(after.entries.get(key)!))) return undefined;
|
|
177
|
+
return changed.length ? [...new Set([...Object.keys(beforeDirect), ...Object.keys(afterDirect)])].sort() : [];
|
|
178
|
+
}
|
|
@@ -39,7 +39,7 @@ const IDENTIFIERS = "[0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*";
|
|
|
39
39
|
const EXACT_VERSION = new RegExp(`^${NUMERIC_PART}\\.${NUMERIC_PART}\\.${NUMERIC_PART}(?:-${IDENTIFIERS})?(?:\\+${IDENTIFIERS})?$`);
|
|
40
40
|
const RANGE_VERSION = new RegExp(`^v?(?:${NUMERIC_PART}|[xX*])(?:\\.(?:${NUMERIC_PART}|[xX*])){0,2}$`);
|
|
41
41
|
|
|
42
|
-
function isExactVersion(value: string): boolean {
|
|
42
|
+
export function isExactVersion(value: string): boolean {
|
|
43
43
|
if (!EXACT_VERSION.test(value)) return false;
|
|
44
44
|
const prerelease = /^[^-]+-([^+]+)/.exec(value)?.[1];
|
|
45
45
|
return !prerelease || prerelease.split(".").every((part) => !/^0[0-9]+$/.test(part));
|
|
@@ -56,7 +56,7 @@ function isRangeVersion(value: string): boolean {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/** A deliberately limited registry semver grammar; tags and protocol requests remain unsupported. */
|
|
59
|
-
function isRegistryRequest(value: string): boolean {
|
|
59
|
+
export function isRegistryRequest(value: string): boolean {
|
|
60
60
|
if (!value || value.length > 512 || value !== value.trim()) return false;
|
|
61
61
|
return value.split("||").every((alternative) => {
|
|
62
62
|
const range = alternative.trim();
|