@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
|
@@ -15,6 +15,7 @@ import { workflowMayRunTests } from "../repo/workflow-test-steps.js";
|
|
|
15
15
|
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
|
+
import { berryLockAffectedDependencies, berryNodeModulesConfig, berryRuntimeConfig } from "../repo/yarn-berry-lockfile.js";
|
|
18
19
|
import { LOCKFILE, LOCKFILE_NAMES } from "../repo/lockfiles.js";
|
|
19
20
|
import { ciConfigPredicate, gitlabLocalIncludes, isConventionalCiConfigPath } from "./ci-config-paths.js";
|
|
20
21
|
|
|
@@ -148,30 +149,25 @@ export function parseNameStatus(buffer: Buffer): ChangedFile[] {
|
|
|
148
149
|
return files;
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const isBinary = fields[0]?.trimStart().startsWith("-") ?? false;
|
|
158
|
-
const hasRename = fields.length >= 4;
|
|
159
|
-
const newPath = hasRename ? fields[fields.length - 1] : fields[2];
|
|
160
|
-
|
|
161
|
-
if (!newPath) return undefined;
|
|
162
|
-
return { path: newPath, isBinary };
|
|
163
|
-
}
|
|
164
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Parses `git diff-tree --numstat -z`. Each record is `added\tdeleted\tpath\0`, except a rename or copy:
|
|
154
|
+
* `added\tdeleted\t\0old\0new\0`, an empty path followed by both paths as their own fields (#175).
|
|
155
|
+
* `-z` leaves paths unquoted, so a path may itself contain a tab.
|
|
156
|
+
*/
|
|
165
157
|
export function parseNumstat(buffer: Buffer): Map<string, boolean> {
|
|
166
|
-
const
|
|
167
|
-
const records = text.split("\0");
|
|
158
|
+
const tokens = buffer.toString("utf8").split("\0");
|
|
168
159
|
const binaryByNewPath = new Map<string, boolean>();
|
|
169
160
|
|
|
170
|
-
for (
|
|
171
|
-
const
|
|
172
|
-
if (
|
|
173
|
-
|
|
161
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
162
|
+
const fields = tokens[i]!.split("\t");
|
|
163
|
+
if (fields.length < 3) continue;
|
|
164
|
+
const isBinary = fields[0]!.trimStart().startsWith("-");
|
|
165
|
+
let path = fields.slice(2).join("\t");
|
|
166
|
+
if (path === "") {
|
|
167
|
+
path = tokens[i + 2] ?? "";
|
|
168
|
+
i += 2;
|
|
174
169
|
}
|
|
170
|
+
if (path) binaryByNewPath.set(path, isBinary);
|
|
175
171
|
}
|
|
176
172
|
|
|
177
173
|
return binaryByNewPath;
|
|
@@ -239,7 +235,7 @@ export const CONFIG_PATTERNS = [
|
|
|
239
235
|
// Python projects (2026-11-06): what pytest, the interpreter and the installed packages are.
|
|
240
236
|
/^pyproject\.toml$/,
|
|
241
237
|
/^setup\.(?:py|cfg)$/,
|
|
242
|
-
|
|
238
|
+
/^\.?pytest\.(?:ini|toml)$/,
|
|
243
239
|
/^tox\.ini$/,
|
|
244
240
|
/^noxfile\.py$/,
|
|
245
241
|
/^requirements[^/]*\.(?:txt|in)$/,
|
|
@@ -252,6 +248,10 @@ export const CONFIG_PATTERNS = [
|
|
|
252
248
|
/^\.nvmrc$/,
|
|
253
249
|
/^\.node-version$/,
|
|
254
250
|
/^\.npmrc$/,
|
|
251
|
+
// Mocha's configuration (issue #142). `.mocharc.json` reads as an asset by extension and
|
|
252
|
+
// `.mocharc.js` as code with no importers, so neither reached the configuration signals; both
|
|
253
|
+
// decide how the suite runs.
|
|
254
|
+
/^\.mocharc(?:\.[^/]+)?$/,
|
|
255
255
|
];
|
|
256
256
|
|
|
257
257
|
// Stage 1B fix (2026-08-21, docs/research/2026-08-21-stage1b-*.md): root-caused in Stage 1A's fallback-
|
|
@@ -360,14 +360,17 @@ export function testListEdit(oldBody: string, newBody: string): { added: string[
|
|
|
360
360
|
|
|
361
361
|
const DEPENDENCY_FIELDS = new Set(["dependencies", "devDependencies", "optionalDependencies"]);
|
|
362
362
|
|
|
363
|
-
/** Exact root requests for the supported
|
|
363
|
+
/** Exact root requests for the supported Yarn layouts. Unlike scriptRecord, never discard an
|
|
364
364
|
* invalid dependency value: an omitted root would make the lockfile attribution incomplete. */
|
|
365
|
-
function yarnDirectDependencies(content: string | undefined): Record<string, string> | undefined {
|
|
365
|
+
function yarnDirectDependencies(content: string | undefined, berry = false): Record<string, string> | undefined {
|
|
366
366
|
let manifest: Record<string, unknown>;
|
|
367
367
|
try { manifest = JSON.parse(content ?? "") as Record<string, unknown>; } catch { return undefined; }
|
|
368
368
|
if (!manifest || typeof manifest !== "object" || Array.isArray(manifest)) return undefined;
|
|
369
|
+
if (berry && manifest.name !== undefined && typeof manifest.name !== "string") return undefined;
|
|
369
370
|
if (["workspaces", "resolutions", "flat", "installConfig", "peerDependencies", "bundledDependencies", "bundleDependencies"].some((field) => manifest[field] !== undefined)) return undefined;
|
|
370
|
-
if (
|
|
371
|
+
if (berry && ["dependenciesMeta", "peerDependenciesMeta"].some((field) => manifest[field] !== undefined)) return undefined;
|
|
372
|
+
if (berry && /yarn_/i.test(JSON.stringify(manifest.scripts ?? {}))) return undefined;
|
|
373
|
+
if (manifest.packageManager !== undefined && (typeof manifest.packageManager !== "string" || !(berry ? /^yarn@[234]\.\d+\.\d+(?:\+sha(?:224|512)\.[a-f0-9]+)?$/ : /^yarn@1\.\d+\.\d+$/).test(manifest.packageManager))) return undefined;
|
|
371
374
|
const direct: Record<string, string> = Object.create(null);
|
|
372
375
|
for (const field of DEPENDENCY_FIELDS) {
|
|
373
376
|
const record = manifest[field];
|
|
@@ -541,6 +544,21 @@ function readRootPathsAtSha(sha: string, repoPath: string | undefined): Readonly
|
|
|
541
544
|
return roots.size === paths.length ? roots : undefined;
|
|
542
545
|
}
|
|
543
546
|
|
|
547
|
+
/** Do not narrow Berry when tracked runtime setup advertises an override or a nested Yarn config.
|
|
548
|
+
* This supplements the actual process environment check; it does not execute CI or shell scripts. */
|
|
549
|
+
function berrySetupSupported(sha: string, repoPath: string | undefined): boolean {
|
|
550
|
+
const listing = runGit(["ls-tree", "-r", "--full-tree", "--name-only", "-z", sha], repoPath);
|
|
551
|
+
if (listing.status !== 0 || !listing.stdout.endsWith("\0")) return false;
|
|
552
|
+
const paths = listing.stdout.slice(0, -1).split("\0");
|
|
553
|
+
if (paths.some((path) => !path || (path !== ".yarnrc.yml" && /(?:^|\/)\.yarnrc(?:\.yml)?$/.test(path)))) return false;
|
|
554
|
+
const setup = paths.filter((path) => /\.(?:ya?ml|sh|bash|zsh)$/.test(path) || /(?:^|\/)(?:Dockerfile|Jenkinsfile|\.env[^/]*)$/.test(path));
|
|
555
|
+
if (setup.length > 500) return false;
|
|
556
|
+
return setup.every((path) => {
|
|
557
|
+
const content = readFileAtSha(sha, path, repoPath);
|
|
558
|
+
return content !== undefined && content.length <= 65_536 && !/yarn_/i.test(content);
|
|
559
|
+
});
|
|
560
|
+
}
|
|
561
|
+
|
|
544
562
|
/**
|
|
545
563
|
* Test-runner and transform configurations that apply to the tests of the directory that holds them, so
|
|
546
564
|
* a workspace package's copy configures that package's tests like a root one configures the root's
|
|
@@ -778,8 +796,8 @@ export async function analyzeGitDelta(
|
|
|
778
796
|
}
|
|
779
797
|
}
|
|
780
798
|
}
|
|
781
|
-
//
|
|
782
|
-
//
|
|
799
|
+
// Yarn does not record the installed hoisting layout. Both helpers validate exact manifest
|
|
800
|
+
// requests and widen meaningful changes to every direct dependency; Berry also proves its linker.
|
|
783
801
|
// Keep this separate from npm's installed-path model and resolve raw lockfile readers downstream.
|
|
784
802
|
const changedYarnLock = filesWithBinary.find((f) => f.path === "yarn.lock" && f.changeType === "modified");
|
|
785
803
|
// Path-level signals only cover some root configurations. Do not let narrowing this root lock
|
|
@@ -789,19 +807,26 @@ export async function analyzeGitDelta(
|
|
|
789
807
|
|| CONFIG_PATTERNS.some((pattern) => pattern.test(path) || pattern.test(posix.basename(path)))
|
|
790
808
|
|| isImplicitlyLoadedFile(path)));
|
|
791
809
|
if (dependencyEdit && changedYarnLock && !otherConfiguration && (!analysis.dependencyManifestChanged || changedPackageJson)) {
|
|
792
|
-
const
|
|
793
|
-
const
|
|
810
|
+
const oldYarnLock = readFileAtSha(baseSha, "yarn.lock", repoPath);
|
|
811
|
+
const newYarnLock = readFileAtSha(headSha, "yarn.lock", repoPath);
|
|
812
|
+
const berry = /^__metadata:/m.test(oldYarnLock ?? "") && /^__metadata:/m.test(newYarnLock ?? "");
|
|
813
|
+
const beforeDirect = yarnDirectDependencies(oldPackageJson, berry);
|
|
814
|
+
const afterDirect = yarnDirectDependencies(newPackageJson, berry);
|
|
794
815
|
// A second package manager or alternate Yarn install layout is outside this model, even when
|
|
795
816
|
// its configuration did not change in this delta.
|
|
796
|
-
const alternateLayouts = ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "bun.lock", "bun.lockb", ".yarnrc", ".
|
|
817
|
+
const alternateLayouts = ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "bun.lock", "bun.lockb", ".yarnrc", ".pnp.js", ".pnp.cjs", ...(berry ? [".pnp.loader.mjs", ".env.yarn"] : [".yarnrc.yml"])];
|
|
797
818
|
const unsupportedLayout = [baseSha, headSha].some((sha) => {
|
|
798
819
|
const roots = readRootPathsAtSha(sha, repoPath);
|
|
799
820
|
// Either revision can rule out narrowing, including a layout deleted before HEAD.
|
|
800
821
|
// An unavailable or malformed listing cannot prove that these paths are absent.
|
|
801
|
-
return !roots || alternateLayouts.some((path) => roots.has(path))
|
|
822
|
+
return !roots || alternateLayouts.some((path) => roots.has(path))
|
|
823
|
+
|| (berry && (!roots.has(".yarnrc.yml") || !berryNodeModulesConfig(readFileAtSha(sha, ".yarnrc.yml", repoPath))));
|
|
802
824
|
});
|
|
803
|
-
const
|
|
804
|
-
|
|
825
|
+
const berrySetup = !berry || (berryRuntimeConfig(repoPath) && [baseSha, headSha].every((sha) => berrySetupSupported(sha, repoPath)));
|
|
826
|
+
const affected = beforeDirect && afterDirect && !unsupportedLayout && berrySetup
|
|
827
|
+
? berry
|
|
828
|
+
? berryLockAffectedDependencies(oldYarnLock, newYarnLock, beforeDirect, afterDirect, JSON.parse(oldPackageJson!).name, JSON.parse(newPackageJson!).name)
|
|
829
|
+
: yarnLockAffectedDependencies(oldYarnLock, newYarnLock, beforeDirect, afterDirect)
|
|
805
830
|
: undefined;
|
|
806
831
|
if (affected && (packageChange?.changedDependencies ?? []).every((name) => affected.includes(name))) {
|
|
807
832
|
analysis.dependencyManifestChanged = false;
|
|
@@ -161,6 +161,26 @@ function covers(target: string, path: string, extensions: readonly string[]): bo
|
|
|
161
161
|
return inside && extensions.includes(posix.extname(path).slice(1));
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
+
/** Other names configuration uses for a file type: `@eslint/markdown` lints `.md`, `eslint-plugin-yml` `.yaml`. */
|
|
165
|
+
const EXTENSION_ALIASES: Readonly<Record<string, readonly string[]>> = { md: ["markdown"], yml: ["yaml"], yaml: ["yml"], jsonc: ["json"], json5: ["json"] };
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Extensions of changed files that the ESLint configuration names (2026-11-17). A directory target lints
|
|
169
|
+
* every file a flat config's `files` (or an eslintrc `overrides[].files`) reaches, not only JavaScript and
|
|
170
|
+
* TypeScript: `...vue.configs["flat/recommended"]` makes `eslint src` lint `src/App.vue`. A changed file's
|
|
171
|
+
* extension that appears in the configuration text, or a plugin named for it, therefore counts as linted.
|
|
172
|
+
*/
|
|
173
|
+
function configuredExtensions(changes: readonly ChangedPath[], texts: readonly string[]): string[] {
|
|
174
|
+
const found = new Set<string>();
|
|
175
|
+
for (const { path } of changes) {
|
|
176
|
+
const extension = posix.extname(path).slice(1).toLowerCase();
|
|
177
|
+
if (!/^\w+$/.test(extension) || ESLINT_EXTENSIONS.includes(extension) || found.has(extension)) continue;
|
|
178
|
+
const names = [extension, ...(EXTENSION_ALIASES[extension] ?? [])];
|
|
179
|
+
if (texts.some((text) => names.some((name) => new RegExp(`\\b${name}\\b`, "i").test(text)))) found.add(extension);
|
|
180
|
+
}
|
|
181
|
+
return [...found];
|
|
182
|
+
}
|
|
183
|
+
|
|
164
184
|
/** Root configuration files of the tool that exist, and the paths each one names relatively. */
|
|
165
185
|
function configReferences(tool: Tool, input: NarrowingInput, explicit: string | undefined): { texts: string[]; referenced: string[] } {
|
|
166
186
|
const candidates = explicit ? [posix.normalize(explicit)] : tool.name === "eslint"
|
|
@@ -224,7 +244,8 @@ function decide(check: GateCheck, input: NarrowingInput, cache: RootTextCache):
|
|
|
224
244
|
|
|
225
245
|
const extensions = tool.name === "eslint" && values.has("--ext")
|
|
226
246
|
? [...ESLINT_EXTENSIONS, ...values.get("--ext")!.split(",").map((ext) => ext.replace(/^\./, ""))]
|
|
227
|
-
: tool.
|
|
247
|
+
: tool.name === "eslint" ? [...ESLINT_EXTENSIONS, ...configuredExtensions(input.changes, texts)]
|
|
248
|
+
: tool.extensions;
|
|
228
249
|
if (tool.name === "eslint") {
|
|
229
250
|
const nested = input.files?.find((path) => path.includes("/") && ESLINT_CONFIG.test(posix.basename(path)) && !posix.basename(path).endsWith("ignore"));
|
|
230
251
|
const importRules = texts.some((text) => IMPORT_RULES.test(text));
|
|
@@ -64,7 +64,7 @@ const CONCURRENTLY = /^(?:npx\s+(?:--no-install\s+)?)?concurrently\b(.*)$/;
|
|
|
64
64
|
const REPO_RUNNER = /^(?:node|tsx|bun)\s+(\.{0,2}\/?[\w./-]+\.(?:m?[jt]s|c[jt]s))((?:\s+[\w:.@/-]+)+)$/;
|
|
65
65
|
/** Shell syntax whose meaning changes when the script is split into parts or run outside its shell. */
|
|
66
66
|
const UNSPLITTABLE = /\|\||[|<>`$()\\]|^\s*\w+=|\s\w+=\S/;
|
|
67
|
-
const TEST_RUNNER = /(?:^|[\s/])(?:vitest|jest|mocha|ava|tap|playwright|cypress|karma|jasmine)(?:\s|$)|(?:node|tsx|bun|deno)(?:\s
|
|
67
|
+
const TEST_RUNNER = /(?:^|[\s/])(?:vitest|jest|mocha|ava|tap|playwright|cypress|karma|jasmine)(?:\s|$)|(?:node|tsx|bun|deno)(?:\s+-\S*)*\s+--test\b|^(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?test(?:\s|$)/;
|
|
68
68
|
|
|
69
69
|
function kindOf(command: string): GateCheckKind {
|
|
70
70
|
if (/(?:^|[\s/])(?:tsc|vue-tsc|svelte-check|tsgo)(?:\s|$)/.test(command)) return "typecheck";
|
|
@@ -100,10 +100,21 @@ function splitParts(body: string): string[] | undefined {
|
|
|
100
100
|
parts.push(current.trim());
|
|
101
101
|
const unquoted = parts.map((part) => part.replace(/"[^"]*"|'[^']*'/g, "\"\""));
|
|
102
102
|
// A double-quoted `$` or backtick still expands in the shell.
|
|
103
|
-
if (parts.some((part) => !part ||
|
|
103
|
+
if (parts.some((part) => !part || expandsBetweenDoubleQuotes(part)) || unquoted.some((part) => UNSPLITTABLE.test(part))) return undefined;
|
|
104
104
|
return parts;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
/**
|
|
108
|
+
* True when a `$` or backtick sits between two double quotes, the answer `/"[^"]*[$`][^"]*"/` gives.
|
|
109
|
+
* That regex is quadratic on a `"` followed by a long run of backticks with no closing quote (#300);
|
|
110
|
+
* this is one linear pass: the text strictly between two consecutive `"` holds a `$` or backtick.
|
|
111
|
+
*/
|
|
112
|
+
export function expandsBetweenDoubleQuotes(part: string): boolean {
|
|
113
|
+
const segments = part.split("\"");
|
|
114
|
+
for (let i = 1; i < segments.length - 1; i++) if (/[$`]/.test(segments[i]!)) return true;
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
107
118
|
function globToRegExp(pattern: string): RegExp {
|
|
108
119
|
return new RegExp(`^${pattern.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*/g, ".*").replace(/\*/g, "[^:]*")}$`);
|
|
109
120
|
}
|
|
@@ -19,25 +19,53 @@ function expandBraces(pattern: string): string[] {
|
|
|
19
19
|
return result;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* A task input glob as an anchored regex, with the same reading as the research matcher (#178/#179). `**\/`
|
|
24
|
+
* is any number of leading directories, a trailing `/**` is anything below, and any other `**` (`**.js`, a
|
|
25
|
+
* bare `**`) is any run of characters including `/`, as in GitHub's path filters. `*` and `?` stay within one
|
|
26
|
+
* segment, `[...]`/`[!...]` is a character class, `\` escapes the next character, and every other character
|
|
27
|
+
* is literal, so route directories like `app/(marketing)`, `routes/$id.tsx` and `c++/` match themselves.
|
|
28
|
+
*/
|
|
22
29
|
function regexFrom(pattern: string): RegExp {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
const literal = (character: string): string => character.replace(/[.*+?^${}()|[\]\\/]/g, "\\$&");
|
|
31
|
+
let source = "";
|
|
32
|
+
for (let index = 0; index < pattern.length; index++) {
|
|
33
|
+
const character = pattern[index]!;
|
|
34
|
+
if (pattern.startsWith("**/", index)) { source += "(?:.*/)?"; index += 2; continue; }
|
|
35
|
+
if (pattern.startsWith("/**", index) && index + 3 === pattern.length) { source += "(?:/.*)?"; index += 2; continue; }
|
|
36
|
+
if (pattern.startsWith("**", index)) { source += ".*"; index += 1; continue; }
|
|
37
|
+
if (character === "*") { source += "[^/]*"; continue; }
|
|
38
|
+
if (character === "?") { source += "[^/]"; continue; }
|
|
39
|
+
if (character === "\\" && index + 1 < pattern.length) { source += literal(pattern[++index]!); continue; }
|
|
40
|
+
if (character === "[") {
|
|
41
|
+
const close = pattern.indexOf("]", index + 2);
|
|
42
|
+
if (close > index) {
|
|
43
|
+
let body = pattern.slice(index + 1, close);
|
|
44
|
+
const negated = body.startsWith("!") || body.startsWith("^");
|
|
45
|
+
if (negated) body = body.slice(1);
|
|
46
|
+
source += `[${negated ? "^/" : ""}${body.replace(/[\\\]^[]/g, "\\$&")}]`;
|
|
47
|
+
index = close;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
source += literal(character);
|
|
52
|
+
}
|
|
53
|
+
return new RegExp(`^${source}$`);
|
|
36
54
|
}
|
|
37
55
|
|
|
38
56
|
function matches(path: string, pattern: string): boolean {
|
|
39
57
|
const normalized = path.replace(/\\/g, "/");
|
|
40
|
-
return expandBraces(pattern).some((p) =>
|
|
58
|
+
return expandBraces(pattern).some((p) => {
|
|
59
|
+
let regex: RegExp;
|
|
60
|
+
try {
|
|
61
|
+
regex = regexFrom(p);
|
|
62
|
+
} catch {
|
|
63
|
+
// A pattern that is not a valid filter cannot rule a change out: count it as matching, so the
|
|
64
|
+
// task runs rather than the whole plan throwing.
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return regex.test(normalized);
|
|
68
|
+
});
|
|
41
69
|
}
|
|
42
70
|
|
|
43
71
|
function matchesAny(path: string, patterns: string[] | undefined): boolean {
|
|
@@ -4,6 +4,8 @@ import type { SelectiveTestCommandGroup, SelectiveTestCommandPlan } from "./test
|
|
|
4
4
|
|
|
5
5
|
/** Cargo target names are literal arguments, not paths, globs, package specs or shell fragments. */
|
|
6
6
|
const literalName = /^[A-Za-z0-9_][A-Za-z0-9_-]*$/;
|
|
7
|
+
/** A package is its name, or NAME@VERSION when a dependency shares the name (adapters/rust.ts). */
|
|
8
|
+
const packageSpec = /^[A-Za-z0-9_][A-Za-z0-9_-]*(?:@\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?)?$/;
|
|
7
9
|
|
|
8
10
|
/** Only the Rust adapter may attest that the repository's invocation is reproducible. Missing
|
|
9
11
|
* evidence (including old cached profiles) must never become a guessed default test command. */
|
|
@@ -31,16 +33,27 @@ export function planRustTestCommands(profile: RepositoryProfile, selectedPaths:
|
|
|
31
33
|
return refuse("Rust tests require verified Cargo package and target metadata");
|
|
32
34
|
}
|
|
33
35
|
const target = targets[path]!;
|
|
34
|
-
if (!
|
|
36
|
+
if (!packageSpec.test(packages[path]!) || !literalName.test(target.name)
|
|
35
37
|
|| !["lib", "bin", "test", "bench", "example"].includes(target.kind)) {
|
|
36
38
|
return refuse("Invalid Cargo package or test target");
|
|
37
39
|
}
|
|
38
40
|
}
|
|
41
|
+
// A target with `required-features` runs only when Cargo enables those features for its package.
|
|
42
|
+
// Naming it (`--test name`) makes Cargo fail instead of skipping it, so its package stays whole:
|
|
43
|
+
// `cargo test -p name` runs exactly the targets the full run runs for that package.
|
|
44
|
+
const gated = new Set(paths.filter(path => targets[path]!.requiredFeatures !== undefined).map(path => packages[path]!));
|
|
45
|
+
for (const path of paths) {
|
|
46
|
+
const required = targets[path]!.requiredFeatures;
|
|
47
|
+
if (required !== undefined && (!Array.isArray(required) || !required.length || required.some(feature => typeof feature !== "string"))) {
|
|
48
|
+
return refuse("Invalid Cargo package or test target");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
39
51
|
const groups: SelectiveTestCommandGroup[] = [];
|
|
40
52
|
const cratePackages: string[] = [];
|
|
41
53
|
const cratePaths: string[] = [];
|
|
42
54
|
for (const pkg of [...new Set(paths.map(path => packages[path]!))].sort()) {
|
|
43
55
|
const owned = paths.filter(path => packages[path] === pkg);
|
|
56
|
+
if (gated.has(pkg)) { cratePackages.push(pkg); cratePaths.push(...owned); continue; }
|
|
44
57
|
const ordinary = owned.filter(path => ["lib", "bin", "test"].includes(targets[path]!.kind));
|
|
45
58
|
if (ordinary.length) {
|
|
46
59
|
// A crate unit-test root represents the whole crate, including doctests. Do not narrow it to
|
|
@@ -74,6 +87,29 @@ export function planRustTestCommands(profile: RepositoryProfile, selectedPaths:
|
|
|
74
87
|
// as the full `cargo test` does (see rustFeatureCoverage in adapters/rust.ts).
|
|
75
88
|
const coverage = profile.rustFeatureCoverage;
|
|
76
89
|
if (!coverage) return refuse("Rust tests require verified Cargo feature resolution");
|
|
90
|
+
const uncovered = (selected: ReadonlySet<string>) => [...selected].sort().flatMap(pkg => coverage.deficits[pkg] ?? [])
|
|
91
|
+
.find(dependency => !coverage.units.some(unit => unit.covers.includes(dependency) && unit.crates.every(name => selected.has(name))));
|
|
92
|
+
const packageGroup = groups.find(group => group.runnerId === "cargo:test:packages");
|
|
93
|
+
if (packageGroup) {
|
|
94
|
+
// When testing only the selected crates would build a shared dependency with fewer features than
|
|
95
|
+
// the full run, add the tested crates of the smallest unit Cargo resolved with the full run's
|
|
96
|
+
// features. Features only grow with the crates selected and never exceed the full run's, so the
|
|
97
|
+
// larger command still builds that dependency exactly as the full run does; it runs more tests
|
|
98
|
+
// than selected, but fewer than the full run. Each round adds a crate, so this ends.
|
|
99
|
+
const selected = new Set(cratePackages);
|
|
100
|
+
for (let missing = uncovered(selected); missing !== undefined; missing = uncovered(selected)) {
|
|
101
|
+
const extra = (unit: { crates: string[] }) => unit.crates.filter(name => !selected.has(name)).length;
|
|
102
|
+
const unit = coverage.units.filter(candidate => candidate.covers.includes(missing!) && candidate.crates.every(name => packageSpec.test(name)))
|
|
103
|
+
.sort((a, b) => extra(a) - extra(b) || a.crates.join(" ").localeCompare(b.crates.join(" ")))[0];
|
|
104
|
+
if (!unit) break;
|
|
105
|
+
for (const name of unit.crates) selected.add(name);
|
|
106
|
+
}
|
|
107
|
+
const added = [...selected].filter(name => !cratePackages.includes(name)).sort();
|
|
108
|
+
if (added.length) {
|
|
109
|
+
packageGroup.commandSpec = { executable: "cargo", args: ["test", ...[...selected].sort().flatMap(pkg => ["-p", pkg])] };
|
|
110
|
+
packageGroup.label = `Cargo package tests (with ${added.join(", ")} for the full run's features)`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
77
113
|
for (const group of groups) {
|
|
78
114
|
const args = group.commandSpec.args;
|
|
79
115
|
const selected = new Set(args.flatMap((arg, index) => args[index - 1] === "-p" ? [arg] : []));
|
|
@@ -65,7 +65,11 @@ function scanModule(path: string, text: string): { literals: string[]; imports:
|
|
|
65
65
|
else computed = true;
|
|
66
66
|
}
|
|
67
67
|
if (ts.isStringLiteralLike(node)) literals.push(node.text);
|
|
68
|
-
else if (ts.isTemplateExpression(node))
|
|
68
|
+
else if (ts.isTemplateExpression(node)) {
|
|
69
|
+
// Text after a substitution is read too: `${process.cwd()}/data/schema.json` names data/schema.json, and
|
|
70
|
+
// the `/` that joins it to the substitution is not an absolute path.
|
|
71
|
+
literals.push(node.head.text, ...node.templateSpans.map((span) => span.literal.text.replace(/^\/+/, "")));
|
|
72
|
+
}
|
|
69
73
|
ts.forEachChild(node, visit);
|
|
70
74
|
};
|
|
71
75
|
visit(source);
|
|
@@ -141,9 +141,24 @@ function configAllowsPath(config: TestRunnerConfig, path: string): boolean {
|
|
|
141
141
|
const PATTERN_CHARACTERS = /[[\]*?{}()+^$|]/;
|
|
142
142
|
const LITERAL_PATH_FRAMEWORKS: ReadonlySet<KnownTestFramework> = new Set(["vitest", "bun:test"]);
|
|
143
143
|
|
|
144
|
+
/**
|
|
145
|
+
* Whether `path` has a `{...,...}` or `{...}` range with `..`, as `/\{[^}]*(?:,|\.\.)[^}]*\}/` tests, in linear
|
|
146
|
+
* time (that regex is quadratic on a long run of `{`, CodeQL alert 14). The widest candidate before each `}` starts
|
|
147
|
+
* at the first `{` after the previous `}`, so checking that one per segment is enough.
|
|
148
|
+
*/
|
|
149
|
+
function hasBraceExpansion(path: string): boolean {
|
|
150
|
+
const segments = path.split("}");
|
|
151
|
+
return segments.slice(0, -1).some((segment) => {
|
|
152
|
+
const open = segment.indexOf("{");
|
|
153
|
+
if (open === -1) return false;
|
|
154
|
+
const body = segment.slice(open + 1);
|
|
155
|
+
return body.includes(",") || body.includes("..");
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
144
159
|
/** `path` as a `node --test` glob that matches only itself, or undefined when none can. */
|
|
145
160
|
export function nodeTestGlobForPath(path: string): string | undefined {
|
|
146
|
-
if (
|
|
161
|
+
if (hasBraceExpansion(path)) return undefined;
|
|
147
162
|
return path.replace(/[[\]*?{}()]/g, (character) => `@([${character}])`);
|
|
148
163
|
}
|
|
149
164
|
|
|
@@ -234,7 +249,7 @@ function runsOnlyDefaultVitest(scripts: Readonly<Record<string, string>>, name =
|
|
|
234
249
|
const script = scripts[name];
|
|
235
250
|
if (script === undefined) return depth > 0;
|
|
236
251
|
if (depth > 5 || !script.trim() || scripts[`pre${name}`] || scripts[`post${name}`]) return false;
|
|
237
|
-
return script.split(
|
|
252
|
+
return script.split("&&").every((phase) => {
|
|
238
253
|
const run = /^(?:npm|pnpm|yarn|bun) (?:run )?([\w:-]+)$/.exec(phase.trim());
|
|
239
254
|
if (run) return runsOnlyDefaultVitest(scripts, run[1]!, depth + 1);
|
|
240
255
|
const words = phase.trim().split(/\s+/);
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
23
|
import { posix } from "node:path";
|
|
24
|
+
import ts from "typescript";
|
|
24
25
|
import { projectRoots } from "../repo/compiled-projects.js";
|
|
25
26
|
import { LOCKFILE } from "../repo/lockfiles.js";
|
|
26
27
|
import type { NarrowingInput } from "./check-narrowing.js";
|
|
@@ -40,6 +41,28 @@ function escape(text: string): string {
|
|
|
40
41
|
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
41
42
|
}
|
|
42
43
|
|
|
44
|
+
/** Repository files `config` extends by a relative path, transitively, whatever they are named
|
|
45
|
+
* (`"extends": "./config/base.json"`). Their compiler options are the program's own. */
|
|
46
|
+
function extendedConfigs(config: string, input: NarrowingInput): Set<string> {
|
|
47
|
+
const found = new Set<string>();
|
|
48
|
+
const queue = [config];
|
|
49
|
+
while (queue.length > 0 && found.size < 50) {
|
|
50
|
+
const current = queue.shift()!;
|
|
51
|
+
const text = input.read(current);
|
|
52
|
+
if (text === undefined) continue;
|
|
53
|
+
const extended: unknown = ts.parseConfigFileTextToJson(current, text).config?.extends;
|
|
54
|
+
for (const value of Array.isArray(extended) ? extended : [extended]) {
|
|
55
|
+
if (typeof value !== "string" || !value.startsWith(".")) continue;
|
|
56
|
+
const base = posix.normalize(posix.join(posix.dirname(current), value));
|
|
57
|
+
const path = [base, `${base}.json`].find((candidate) => input.read(candidate) !== undefined) ?? base;
|
|
58
|
+
if (found.has(path) || path === config) continue;
|
|
59
|
+
found.add(path);
|
|
60
|
+
queue.push(path);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return found;
|
|
64
|
+
}
|
|
65
|
+
|
|
43
66
|
/** The name an import of `path` would end with: its stem, or its directory for an index file. */
|
|
44
67
|
function importName(path: string): string {
|
|
45
68
|
const stem = posix.basename(path).replace(/\.(?:d\.)?[^.]+$/, "");
|
|
@@ -49,7 +72,8 @@ function importName(path: string): string {
|
|
|
49
72
|
export function programMembership(config: string, input: NarrowingInput, cache: RootTextCache = new Map()): ProgramMembership {
|
|
50
73
|
const configText = input.read(config);
|
|
51
74
|
if (configText === undefined) return { inProgram: true, reason: `${config} could not be read` };
|
|
52
|
-
const
|
|
75
|
+
const bases = extendedConfigs(config, input);
|
|
76
|
+
const global = input.changes.find(({ path }) => CONFIG.test(path) || bases.has(path) || path === "package.json" || LOCKFILE.test(posix.basename(path)) || path.endsWith(".d.ts"));
|
|
53
77
|
if (global) return { inProgram: true, reason: `${global.path} changed, which affects every file's types` };
|
|
54
78
|
|
|
55
79
|
// Added and deleted paths are matched too: they enter or leave the program.
|
|
@@ -134,7 +134,11 @@ export const goAdapter: RepositoryAdapter = {
|
|
|
134
134
|
detect: ({ files }) => files.some((file) => file === "go.mod" || file.endsWith(".go")),
|
|
135
135
|
analyze(context) {
|
|
136
136
|
const failure = contribution(this);
|
|
137
|
-
|
|
137
|
+
// With a root module, a go.mod under testdata/, _x/ or .x/ is a fixture: `go list ./...` never
|
|
138
|
+
// enters those directories, so it is not a nested module of the build.
|
|
139
|
+
const rooted = context.files.includes("go.mod");
|
|
140
|
+
const nestedRoots = context.files.filter(f => f.endsWith("/go.mod") && !(rooted && isGoDiscoveryIgnoredPath(f)))
|
|
141
|
+
.map(f => f.slice(0, -"go.mod".length));
|
|
138
142
|
const scoped = context.profile.diffciConfig?.go?.scope === "root-module";
|
|
139
143
|
// No root module and no workspace, and every Go file sits inside a nested module: those modules are
|
|
140
144
|
// tools beside a repository written in another language (Paperclip's tools/agent-shim, 2026-11-11).
|
|
@@ -11,6 +11,29 @@ interface Pom {
|
|
|
11
11
|
parent?: Coordinates;
|
|
12
12
|
dependencies: Coordinates[];
|
|
13
13
|
customSourceRoots: boolean;
|
|
14
|
+
/** The module's Java test root relative to the repository, or undefined when it can't be resolved for certain. */
|
|
15
|
+
testRoot?: string;
|
|
16
|
+
/** Every `<testSourceDirectory>` the POM declares, including those inside profiles. */
|
|
17
|
+
declaredTestRoots: string[];
|
|
18
|
+
/** Whether a `<testSourceDirectory>` sits inside a profile, which may or may not be active. */
|
|
19
|
+
profileTestRoot: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DEFAULT_TEST_ROOT = "src/test/java";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Resolves a `<testSourceDirectory>` to a repository path. Only a plain relative path inside the module
|
|
26
|
+
* resolves; a `${property}`, an absolute path, a path leaving the module, or several declarations (a
|
|
27
|
+
* profile can override the root) don't, so the caller falls back. Never guess (#163).
|
|
28
|
+
*/
|
|
29
|
+
function resolveTestRoot(dir: string, declared: string[]): string | undefined {
|
|
30
|
+
const roots = [...new Set(declared)];
|
|
31
|
+
if (roots.length > 1) return undefined;
|
|
32
|
+
const root = roots[0] ?? DEFAULT_TEST_ROOT;
|
|
33
|
+
if (!root || root.includes("${") || root.startsWith("/") || /^[A-Za-z]:/.test(root) || root.includes("\\")) return undefined;
|
|
34
|
+
const local = posix.normalize(root).replace(/\/+$/, "");
|
|
35
|
+
if (local === "." || local === ".." || local.startsWith("../")) return undefined;
|
|
36
|
+
return dir ? `${dir}/${local}` : local;
|
|
14
37
|
}
|
|
15
38
|
|
|
16
39
|
function tags(xml: string, name: string): string[] {
|
|
@@ -23,13 +46,34 @@ function tags(xml: string, name: string): string[] {
|
|
|
23
46
|
|
|
24
47
|
function first(xml: string, name: string): string | undefined { return tags(xml, name)[0]; }
|
|
25
48
|
|
|
26
|
-
|
|
49
|
+
/** Drops `<!-- ... -->` comments in one left-to-right pass. An unterminated comment is kept, as before. */
|
|
50
|
+
function stripXmlComments(source: string): string {
|
|
51
|
+
let out = "";
|
|
52
|
+
let i = 0;
|
|
53
|
+
for (;;) {
|
|
54
|
+
const start = source.indexOf("<!--", i);
|
|
55
|
+
if (start === -1) return out + source.slice(i);
|
|
56
|
+
const end = source.indexOf("-->", start + 4);
|
|
57
|
+
if (end === -1) return out + source.slice(start);
|
|
58
|
+
out += source.slice(i, start);
|
|
59
|
+
i = end + 3;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function parsePom(path: string, source: string): Pom {
|
|
64
|
+
// Commented-out elements are not part of the model: an old <artifactId> in a comment must not
|
|
65
|
+
// become the module's identity.
|
|
66
|
+
const xml = stripXmlComments(source);
|
|
27
67
|
const dir = posix.dirname(path) === "." ? "" : posix.dirname(path);
|
|
28
68
|
const parent = first(xml, "parent");
|
|
29
69
|
const own = xml.replace(/<parent\b[^>]*>[\s\S]*?<\/parent>/, "");
|
|
30
70
|
// Nested plugin/dependency coordinates are not the project's own identity. In
|
|
31
71
|
// particular, a dependency's ${project.groupId} must not shadow an inherited ID.
|
|
32
72
|
const identity = own.replace(/<(dependencies|dependencyManagement|build|profiles|reporting|properties)\b[^>]*>[\s\S]*?<\/\1>/g, "");
|
|
73
|
+
// A profile's <testSourceDirectory> applies only when that profile is active, which this static
|
|
74
|
+
// adapter can't tell, so such a POM falls back.
|
|
75
|
+
const declaredTestRoots = tags(xml, "testSourceDirectory");
|
|
76
|
+
const profileTestRoot = declaredTestRoots.length !== tags(xml.replace(/<profiles\b[^>]*>[\s\S]*?<\/profiles>/g, ""), "testSourceDirectory").length;
|
|
33
77
|
const dependencies = tags(xml, "dependency")
|
|
34
78
|
.map(value => ({ groupId: first(value, "groupId") ?? "", artifactId: first(value, "artifactId") ?? "" }))
|
|
35
79
|
.filter(value => value.artifactId);
|
|
@@ -39,8 +83,9 @@ function parsePom(path: string, xml: string): Pom {
|
|
|
39
83
|
artifactId: first(identity, "artifactId"),
|
|
40
84
|
parent: parent === undefined ? undefined : { groupId: first(parent, "groupId") ?? "", artifactId: first(parent, "artifactId") ?? "" },
|
|
41
85
|
dependencies,
|
|
42
|
-
customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java")
|
|
43
|
-
|
|
86
|
+
customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java"),
|
|
87
|
+
testRoot: profileTestRoot ? undefined : resolveTestRoot(dir, declaredTestRoots),
|
|
88
|
+
declaredTestRoots, profileTestRoot,
|
|
44
89
|
};
|
|
45
90
|
}
|
|
46
91
|
|
|
@@ -48,9 +93,14 @@ function under(dir: string, path: string): boolean { return !dir || path === dir
|
|
|
48
93
|
function owningPom(poms: Pom[], file: string): Pom | undefined {
|
|
49
94
|
return poms.filter(pom => under(pom.dir, file)).sort((a, b) => b.dir.length - a.dir.length)[0];
|
|
50
95
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Surefire's default includes (Test*, *Test, *Tests, *TestCase) and Failsafe's (IT*, *IT, *ITCase), under the
|
|
98
|
+
* module's Java test root or src/test/kotlin.
|
|
99
|
+
*/
|
|
100
|
+
function isTest(pom: Pom, path: string): boolean {
|
|
101
|
+
const roots = [pom.testRoot!, pom.dir ? `${pom.dir}/src/test/kotlin` : "src/test/kotlin"];
|
|
102
|
+
return roots.some(root => path.startsWith(root + "/")) &&
|
|
103
|
+
/^(?:Test.*|IT.*|.*(?:Test|Tests|TestCase|IT|ITCase))\.(?:java|kt)$/.test(posix.basename(path));
|
|
54
104
|
}
|
|
55
105
|
|
|
56
106
|
export function analyzeMaven(context: AdapterContext): AdapterContribution {
|
|
@@ -65,8 +115,22 @@ export function analyzeMaven(context: AdapterContext): AdapterContribution {
|
|
|
65
115
|
const resources = new Map<Pom, string[]>();
|
|
66
116
|
const anchors = new Map<Pom, string>();
|
|
67
117
|
|
|
118
|
+
// A module that declares no <testSourceDirectory> inherits the nearest local parent's. Unless that is
|
|
119
|
+
// the default root, fall back rather than assume src/test/java.
|
|
120
|
+
for (const pom of poms) {
|
|
121
|
+
if (pom.declaredTestRoots.length) continue;
|
|
122
|
+
const visited = new Set<Pom>([pom]);
|
|
123
|
+
let ancestor = pom.parent && findPom(pom.parent);
|
|
124
|
+
while (ancestor && !visited.has(ancestor) && !ancestor.declaredTestRoots.length) {
|
|
125
|
+
visited.add(ancestor);
|
|
126
|
+
ancestor = ancestor.parent && findPom(ancestor.parent);
|
|
127
|
+
}
|
|
128
|
+
if (ancestor && !visited.has(ancestor) &&
|
|
129
|
+
(ancestor.profileTestRoot || resolveTestRoot("", ancestor.declaredTestRoots) !== DEFAULT_TEST_ROOT)) pom.testRoot = undefined;
|
|
130
|
+
}
|
|
131
|
+
|
|
68
132
|
for (const pom of poms) {
|
|
69
|
-
if (pom.customSourceRoots) result.blockers.push(`Maven ${pom.path}: custom source roots require full validation`);
|
|
133
|
+
if (pom.customSourceRoots || pom.testRoot === undefined) result.blockers.push(`Maven ${pom.path}: custom source roots require full validation`);
|
|
70
134
|
// This static adapter does not construct Maven's effective model. A local parent's
|
|
71
135
|
// dependency declarations cannot safely be treated as belonging only to that POM.
|
|
72
136
|
const visited = new Set<Pom>([pom]);
|
|
@@ -81,7 +145,8 @@ export function analyzeMaven(context: AdapterContext): AdapterContribution {
|
|
|
81
145
|
}
|
|
82
146
|
|
|
83
147
|
const owned = context.files.filter(file => owningPom(poms, file) === pom);
|
|
84
|
-
const sources = owned.filter(file =>
|
|
148
|
+
const sources = owned.filter(file => /\.(?:java|kt)$/.test(file) &&
|
|
149
|
+
(/\/src\/(?:main|test)\/(?:java|kotlin)\//.test("/" + file) || (pom.testRoot !== undefined && file.startsWith(pom.testRoot + "/"))));
|
|
85
150
|
const assets = owned.filter(file => /\/src\/(?:main|test)\/resources\//.test("/" + file));
|
|
86
151
|
members.set(pom, sources);
|
|
87
152
|
resources.set(pom, assets);
|
|
@@ -90,7 +155,7 @@ export function analyzeMaven(context: AdapterContext): AdapterContribution {
|
|
|
90
155
|
result.sourcePaths.push(...sources);
|
|
91
156
|
result.assetPaths.push(...assets);
|
|
92
157
|
for (const file of sources) {
|
|
93
|
-
if (isTest(file)) { result.testFiles.push(file); result.testPackages[file] = pom.dir || "."; }
|
|
158
|
+
if (pom.testRoot !== undefined && isTest(pom, file)) { result.testFiles.push(file); result.testPackages[file] = pom.dir || "."; }
|
|
94
159
|
}
|
|
95
160
|
}
|
|
96
161
|
|