@diffci.com/diffci 0.3.13 → 0.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist-client/src/client/agent-selection.js +4 -1
  2. package/dist-client/src/client/cli.js +4 -49
  3. package/dist-client/src/client/command-batches.js +80 -0
  4. package/dist-client/src/client/failure-baseline.js +99 -0
  5. package/dist-client/src/client/observe.js +11 -3
  6. package/dist-client/src/client/pilot-packet.js +0 -31
  7. package/dist-client/src/client/verify-savings.js +12 -1
  8. package/dist-client/src/client/verify.js +53 -5
  9. package/dist-client/src/client/workflow-templates.js +80 -0
  10. package/node_modules/@diffci.com/core/README.md +13 -7
  11. package/node_modules/@diffci.com/core/dist/analyze.js +2 -1
  12. package/node_modules/@diffci.com/core/dist/analyze.js.map +1 -1
  13. package/node_modules/@diffci.com/core/dist/cache/graph-cache.d.ts +1 -1
  14. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +1 -1
  15. package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +9 -0
  16. package/node_modules/@diffci.com/core/dist/git/git-diff.js +122 -19
  17. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  18. package/node_modules/@diffci.com/core/dist/git/types.d.ts +9 -0
  19. package/node_modules/@diffci.com/core/dist/planner/test-command.js +16 -3
  20. package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
  21. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +99 -42
  22. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
  23. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.d.ts +16 -0
  24. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js +101 -0
  25. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js.map +1 -0
  26. package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +68 -0
  27. package/node_modules/@diffci.com/core/dist/repo/file-references.js +278 -0
  28. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -0
  29. package/node_modules/@diffci.com/core/dist/repo/graph.d.ts +4 -2
  30. package/node_modules/@diffci.com/core/dist/repo/graph.js +107 -31
  31. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  32. package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +7 -1
  33. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +32 -0
  34. package/node_modules/@diffci.com/core/dist/repo/impact.js +241 -20
  35. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  36. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +9 -3
  37. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
  38. package/node_modules/@diffci.com/core/dist/repo/script-universe.d.ts +16 -0
  39. package/node_modules/@diffci.com/core/dist/repo/script-universe.js +173 -0
  40. package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -0
  41. package/node_modules/@diffci.com/core/dist/repo/test-discovery.d.ts +12 -0
  42. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +54 -7
  43. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
  44. package/node_modules/@diffci.com/core/dist/repo/types.d.ts +8 -0
  45. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.d.ts +15 -0
  46. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +157 -0
  47. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -0
  48. package/node_modules/@diffci.com/core/package.json +5 -0
  49. package/node_modules/@diffci.com/core/src/analyze.ts +2 -1
  50. package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +1 -1
  51. package/node_modules/@diffci.com/core/src/git/git-diff.ts +106 -20
  52. package/node_modules/@diffci.com/core/src/git/types.ts +9 -0
  53. package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -3
  54. package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +120 -30
  55. package/node_modules/@diffci.com/core/src/repo/compiled-projects.ts +108 -0
  56. package/node_modules/@diffci.com/core/src/repo/file-references.ts +275 -0
  57. package/node_modules/@diffci.com/core/src/repo/graph.ts +104 -31
  58. package/node_modules/@diffci.com/core/src/repo/impact-types.ts +10 -0
  59. package/node_modules/@diffci.com/core/src/repo/impact.ts +243 -18
  60. package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +6 -3
  61. package/node_modules/@diffci.com/core/src/repo/script-universe.ts +158 -0
  62. package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +62 -7
  63. package/node_modules/@diffci.com/core/src/repo/types.ts +5 -0
  64. package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +117 -0
  65. package/package.json +2 -2
@@ -0,0 +1,157 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ /**
3
+ * Can this GitHub Actions workflow run the repository's tests? (2026-10-21.)
4
+ *
5
+ * WHY. Any change under `.github/workflows/` forced full validation: 48 of 132 verification receipts in one
6
+ * dogfood repository and 25 of 124 in the other. A workflow that runs tests defines the environment the suite
7
+ * runs in, so a change to it can affect every test and full validation is right. A workflow that only
8
+ * deploys, publishes, scans or labels cannot change a test outcome; tests observe it only by reading the
9
+ * file, which the reference resolver (src/repo/file-references.ts) handles like any other data file.
10
+ *
11
+ * THE QUESTION ANSWERED HERE IS ONE-SIDED. `true` means "may run tests" and is the answer whenever the
12
+ * file cannot be read with confidence: unparseable YAML, a reusable workflow, a local or unrecognised
13
+ * action, a test runner anywhere on a command line, an npm script whose closure reaches tests, or an
14
+ * interpreter executing a repository file (which may itself run tests). Only a workflow made entirely
15
+ * of recognised non-test steps answers `false`.
16
+ */
17
+ import { parse } from "yaml";
18
+ /** Actions known not to execute repository tests. Anything else is assumed to. */
19
+ const NON_TEST_ACTIONS = [
20
+ "actions/checkout", "actions/setup-node", "actions/setup-go", "actions/setup-java", "actions/setup-python",
21
+ "actions/cache", "actions/upload-artifact", "actions/download-artifact", "actions/configure-pages",
22
+ "actions/upload-pages-artifact", "actions/deploy-pages", "actions/attest-build-provenance", "actions/labeler",
23
+ "actions/create-github-app-token", "actions/stale", "actions/first-interaction", "github/codeql-action/",
24
+ "pnpm/action-setup", "oven-sh/setup-bun", "softprops/action-gh-release", "peter-evans/create-pull-request",
25
+ "peter-evans/create-or-update-comment", "aws-actions/configure-aws-credentials", "google-github-actions/auth",
26
+ "google-github-actions/setup-gcloud", "azure/login", "dependabot/fetch-metadata", "cloudflare/wrangler-action",
27
+ ];
28
+ const TEST_RUNNERS = /(?:^|[\s/"'`(;&|])(?:vitest|jest|mocha|ava|tap|playwright|cypress|karma|jasmine|pytest|tox|nox|phpunit|rspec|diffci|ctest)(?=$|[\s"'`);&|])|(?:node|tsx|bun|deno)(?:\s+--?[\w-]+(?:=\S+)?)*\s+--?test\b|\b(?:go|cargo|dotnet|swift|mix|zig)\s+test\b|\b(?:mvn|mvnw|gradle|gradlew|sbt|bazel|make|just)\b/;
29
+ 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;
30
+ 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./-]+/;
31
+ 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"]);
32
+ /** `strict` asks only whether the command runs a test runner or the test script; otherwise running any
33
+ * repository file also counts, because that file may run tests itself. */
34
+ function commandRunsTests(text, scripts, seen = new Set(), strict = false) {
35
+ if (TEST_RUNNERS.test(text) || (!strict && INTERPRETER_FILE.test(text)))
36
+ return true;
37
+ for (const match of text.matchAll(PACKAGE_SCRIPT)) {
38
+ const name = match[1] ?? "";
39
+ if (!name || seen.has(name) || PACKAGE_MANAGER_BUILTINS.has(name))
40
+ continue;
41
+ if (name === "test" || name === "t" || name.startsWith("test:"))
42
+ return true;
43
+ if (typeof scripts[name] !== "string")
44
+ return true;
45
+ seen.add(name);
46
+ if (commandRunsTests(scripts[name] ?? "", scripts, seen, strict))
47
+ return true;
48
+ for (const hook of [`pre${name}`, `post${name}`])
49
+ if (typeof scripts[hook] === "string" && commandRunsTests(scripts[hook] ?? "", scripts, seen, strict))
50
+ return true;
51
+ }
52
+ return false;
53
+ }
54
+ /**
55
+ * Can something a workflow names reach the test suite through that workflow? (2026-10-21.)
56
+ *
57
+ * A workflow step that names a file can only influence test results by preparing what a LATER step in
58
+ * the same job runs tests against. A check script run as its own CI step is required CI, which stays
59
+ * authoritative, not part of the suite DiffCI selects from. One dogfood repository's deploy workflow runs two such
60
+ * checks, and counting them blocked every site HTML change in its replayed history.
61
+ *
62
+ * So the answer is true when a job step matching `names` is, or precedes, a step that runs the test
63
+ * command or a test runner, or an action not known to be test-free; when a reusable-workflow job or
64
+ * job-level configuration names it in a job that runs tests; and whenever the YAML cannot be read.
65
+ */
66
+ export function workflowFeedsTests(workflowText, names, scripts = {}) {
67
+ let document;
68
+ try {
69
+ document = parse(workflowText);
70
+ }
71
+ catch {
72
+ return true;
73
+ }
74
+ if (!document || typeof document !== "object")
75
+ return true;
76
+ const jobs = document.jobs;
77
+ if (!jobs || typeof jobs !== "object")
78
+ return names.test(workflowText);
79
+ const testStep = (step) => {
80
+ if (!step || typeof step !== "object")
81
+ return true;
82
+ const { uses, run } = step;
83
+ if (typeof uses === "string") {
84
+ const action = uses.split("@")[0].toLowerCase();
85
+ if (!NON_TEST_ACTIONS.some((known) => known.endsWith("/") ? action.startsWith(known) : action === known))
86
+ return true;
87
+ }
88
+ else if (uses !== undefined)
89
+ return true;
90
+ if (run !== undefined && typeof run !== "string")
91
+ return true;
92
+ return typeof run === "string" && commandRunsTests(run, scripts, new Set(), true);
93
+ };
94
+ for (const job of Object.values(jobs)) {
95
+ if (!job || typeof job !== "object")
96
+ return true;
97
+ const { steps, uses, ...configuration } = job;
98
+ if (uses !== undefined) {
99
+ if (names.test(JSON.stringify(job)))
100
+ return true;
101
+ continue;
102
+ }
103
+ if (!Array.isArray(steps))
104
+ return true;
105
+ const firstNaming = steps.findIndex((step) => names.test(JSON.stringify(step)));
106
+ const jobRunsTests = steps.some(testStep);
107
+ if (jobRunsTests && names.test(JSON.stringify(configuration)))
108
+ return true;
109
+ if (firstNaming !== -1 && steps.slice(firstNaming).some(testStep))
110
+ return true;
111
+ }
112
+ return false;
113
+ }
114
+ /** True unless every job in `workflowText` is made of recognised non-test steps. */
115
+ export function workflowMayRunTests(workflowText, scripts = {}) {
116
+ if (workflowText === undefined)
117
+ return true;
118
+ let document;
119
+ try {
120
+ document = parse(workflowText);
121
+ }
122
+ catch {
123
+ return true;
124
+ }
125
+ if (!document || typeof document !== "object")
126
+ return true;
127
+ const jobs = document.jobs;
128
+ if (!jobs || typeof jobs !== "object")
129
+ return true;
130
+ for (const job of Object.values(jobs)) {
131
+ if (!job || typeof job !== "object")
132
+ return true;
133
+ const record = job;
134
+ if (record.uses !== undefined)
135
+ return true;
136
+ if (!Array.isArray(record.steps))
137
+ return true;
138
+ for (const step of record.steps) {
139
+ if (!step || typeof step !== "object")
140
+ return true;
141
+ const { uses, run } = step;
142
+ if (typeof uses === "string") {
143
+ const action = uses.split("@")[0].toLowerCase();
144
+ if (!NON_TEST_ACTIONS.some((known) => known.endsWith("/") ? action.startsWith(known) : action === known))
145
+ return true;
146
+ }
147
+ else if (uses !== undefined)
148
+ return true;
149
+ if (typeof run === "string" && commandRunsTests(run, scripts))
150
+ return true;
151
+ if (run !== undefined && typeof run !== "string")
152
+ return true;
153
+ }
154
+ }
155
+ return false;
156
+ }
157
+ //# sourceMappingURL=workflow-test-steps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-test-steps.js","sourceRoot":"","sources":["../../src/repo/workflow-test-steps.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAG7B,kFAAkF;AAClF,MAAM,gBAAgB,GAAG;IACvB,kBAAkB,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,sBAAsB;IAC1G,eAAe,EAAE,yBAAyB,EAAE,2BAA2B,EAAE,yBAAyB;IAClG,+BAA+B,EAAE,sBAAsB,EAAE,iCAAiC,EAAE,iBAAiB;IAC7G,iCAAiC,EAAE,eAAe,EAAE,2BAA2B,EAAE,uBAAuB;IACxG,mBAAmB,EAAE,mBAAmB,EAAE,6BAA6B,EAAE,iCAAiC;IAC1G,sCAAsC,EAAE,uCAAuC,EAAE,4BAA4B;IAC7G,oCAAoC,EAAE,aAAa,EAAE,2BAA2B,EAAE,4BAA4B;CAC/G,CAAC;AACF,MAAM,YAAY,GAAG,0SAA0S,CAAC;AAChU,MAAM,cAAc,GAAG,qJAAqJ,CAAC;AAC7K,MAAM,gBAAgB,GAAG,+OAA+O,CAAC;AACzQ,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,E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WAAW,EAAE,CAAC;gBACjD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,KAAK,CAAC;oBAAE,OAAO,IAAI,CAAC;YACxH,CAAC;iBAAM,IAAI,IAAI,KAAK,SAAS;gBAAE,OAAO,IAAI,CAAC;YAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,gBAAgB,CAAC,GAAG,EAAE,OAAO,CAAC;gBAAE,OAAO,IAAI,CAAC;YAC3E,IAAI,GAAG,KAAK,SAAS,IAAI,OAAO,GAAG,KAAK,QAAQ;gBAAE,OAAO,IAAI,CAAC;QAChE,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -36,6 +36,11 @@
36
36
  "test": "node scripts/run-tests.mjs",
37
37
  "benchmark": "node --import tsx scripts/benchmark.ts",
38
38
  "audit:boundary": "node scripts/audit-boundary.mjs",
39
+ "agent:check": "node scripts/check-agent-packaging.mjs",
40
+ "agent:muse:check": "node scripts/check-muse-plugin-integrity.mjs",
41
+ "agent:muse:sync": "node scripts/check-muse-plugin-integrity.mjs --write",
42
+ "registry:verify": "node scripts/verify-mcp-registry.mjs",
43
+ "release:verify": "node scripts/verify-release.mjs",
39
44
  "prepack": "npm run build",
40
45
  "prepare": "npm run build"
41
46
  },
@@ -5,6 +5,7 @@ import { realpathSync } from "node:fs";
5
5
  import { analyzeGitDelta } from "./git/git-diff.js";
6
6
  import { buildDependencyGraph } from "./repo/graph.js";
7
7
  import { ImpactAnalyzer } from "./repo/impact.js";
8
+ import { repositoryFileReader } from "./repo/file-references.js";
8
9
  import { DefaultCIPlanner } from "./planner/planner.js";
9
10
  import { buildGenericTaskRegistry } from "./research/baseline/registry.js";
10
11
  import { parseRepositoryWorkflows } from "./research/baseline/workflow-parser.js";
@@ -25,7 +26,7 @@ export async function analyzeCheckout(options: { repoPath: string; base: string;
25
26
  const delta = await analyzeGitDelta({ repoPath, baseSha: base, headSha: head });
26
27
  if (!delta.success) throw new Error(JSON.stringify(delta.error));
27
28
  const graph = await buildDependencyGraph({ repoPath, excludeDirs: ["node_modules", ".git", "dist", "build", ".next", "coverage"] });
28
- const impact = new ImpactAnalyzer().analyze(delta.delta, graph, graph.profile, { repositoryFiles: delta.inventory?.files });
29
+ const impact = new ImpactAnalyzer().analyze(delta.delta, graph, graph.profile, { repositoryFiles: delta.inventory?.files, readRepositoryFile: repositoryFileReader(repoPath) });
29
30
  const registry = buildGenericTaskRegistry(graph.profile, "typescript", parseRepositoryWorkflows(graph.profile, repoPath));
30
31
  const plan = new DefaultCIPlanner(registry).plan({ delta: delta.delta, impact, profile: graph.profile });
31
32
  return { advisoryOnly: true, base, head, plan, impact };
@@ -4,7 +4,7 @@ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
4
  import { resolve } from "node:path";
5
5
  import type { DependencyGraphResult } from "../repo/types.js";
6
6
 
7
- export const GRAPH_CACHE_SCHEMA_VERSION = "2";
7
+ export const GRAPH_CACHE_SCHEMA_VERSION = "3";
8
8
 
9
9
  export interface GraphCacheKeyInputs {
10
10
  commitSha: string;
@@ -10,6 +10,8 @@ import {
10
10
  type GitDeltaSummary,
11
11
  type RepositoryInventory,
12
12
  } from "./types.js";
13
+ import { infrastructureRole, testScriptClosure } from "../repo/file-references.js";
14
+ import { workflowMayRunTests } from "../repo/workflow-test-steps.js";
13
15
 
14
16
  export const EMPTY_TREE_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
15
17
  export const ZERO_SHA = "0000000000000000000000000000000000000000";
@@ -205,12 +207,14 @@ const CONFIG_PATTERNS = [
205
207
  /^webpack\.config\./,
206
208
  /^rollup\.config\./,
207
209
  /^esbuild\.config\./,
208
- /^\.github\//,
210
+ // Only workflows and composite actions configure CI. Issue templates, CODEOWNERS and agent
211
+ // instructions under .github/ do not (2026-10-21).
212
+ /^\.github\/(?:workflows|actions)\//,
209
213
  /^\.docker/,
210
214
  /^Dockerfile/,
211
215
  /^docker-compose/,
212
- /^ops\//,
213
- /^database\//,
216
+ // ops/ and database/ are reported by their own signals below, not a second time as configuration
217
+ // (2026-10-21).
214
218
  /^package\.json$/,
215
219
  /^package-lock\.json$/,
216
220
  /^yarn\.lock$/,
@@ -252,6 +256,57 @@ export function hasRelevantPackageJsonChange(oldContent: string | undefined, new
252
256
  !PACKAGE_JSON_METADATA_FIELDS.has(field) && JSON.stringify(oldJson[field]) !== JSON.stringify(newJson[field]));
253
257
  }
254
258
 
259
+ /**
260
+ * Fields whose change cannot alter how `npm test` runs, but which a test may read (a release test
261
+ * asserting `version`, a packaging test reading `files`). 2026-10-21 telemetry: `version` alone was the
262
+ * only package.json change in 18 of one dogfood repository's 84 full runs, and non-test scripts in 15 more.
263
+ */
264
+ const PACKAGE_JSON_DATA_FIELDS = new Set(["version", "files", "private", "publishConfig", "funding", "mcpName"]);
265
+
266
+ function parsePackageScripts(content: string | undefined): unknown {
267
+ if (content === undefined) return undefined;
268
+ try { return (JSON.parse(content) as { scripts?: unknown } | null)?.scripts; } catch { return undefined; }
269
+ }
270
+
271
+ function scriptRecord(value: unknown): Record<string, string> | undefined {
272
+ if (value === undefined) return {};
273
+ if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
274
+ return Object.fromEntries(Object.entries(value).filter((entry): entry is [string, string] => typeof entry[1] === "string"));
275
+ }
276
+
277
+ /**
278
+ * How a modified package.json changed:
279
+ * - `metadata`: only descriptive fields (hasRelevantPackageJsonChange is false);
280
+ * - `data`: only PACKAGE_JSON_DATA_FIELDS and scripts outside the test closure (`test`, its
281
+ * lifecycle hooks, install hooks, and every script they name) on either side - tests may read the
282
+ * file, so it is resolved by reference rather than ignored;
283
+ * - `behavioral`: anything else, including dependencies, engines, type, exports and unparseable JSON.
284
+ */
285
+ export function packageJsonChangeKind(oldContent: string | undefined, newContent: string | undefined): "metadata" | "data" | "behavioral" {
286
+ if (!hasRelevantPackageJsonChange(oldContent, newContent)) return "metadata";
287
+ let oldJson: Record<string, unknown>;
288
+ let newJson: Record<string, unknown>;
289
+ try {
290
+ oldJson = JSON.parse(oldContent!);
291
+ newJson = JSON.parse(newContent!);
292
+ } catch {
293
+ return "behavioral";
294
+ }
295
+ const oldScripts = scriptRecord(oldJson.scripts);
296
+ const newScripts = scriptRecord(newJson.scripts);
297
+ if (!oldScripts || !newScripts) return "behavioral";
298
+ const closure = new Set([...testScriptClosure(oldScripts), ...testScriptClosure(newScripts)]);
299
+ for (const field of new Set([...Object.keys(oldJson), ...Object.keys(newJson)])) {
300
+ if (PACKAGE_JSON_METADATA_FIELDS.has(field) || PACKAGE_JSON_DATA_FIELDS.has(field)) continue;
301
+ if (JSON.stringify(oldJson[field]) === JSON.stringify(newJson[field])) continue;
302
+ if (field !== "scripts") return "behavioral";
303
+ for (const name of new Set([...Object.keys(oldScripts), ...Object.keys(newScripts)])) {
304
+ if (oldScripts[name] !== newScripts[name] && closure.has(name)) return "behavioral";
305
+ }
306
+ }
307
+ return "data";
308
+ }
309
+
255
310
  /** Reads a file's content at a specific commit via `git show <sha>:<path>`, without touching the
256
311
  * working tree (safe to call regardless of what's currently checked out). Returns undefined - not an
257
312
  * error - when the file doesn't exist at that commit (a newly-added or since-deleted file), which is
@@ -267,20 +322,25 @@ export function computeAnalysis(files: ChangedFile[]): GitDeltaAnalysis {
267
322
  f.oldPath ? [f.path, f.oldPath] : [f.path],
268
323
  );
269
324
 
270
- const matches = (pattern: RegExp) => paths.some((p) => pattern.test(p));
325
+ const matching = (test: (p: string) => boolean) => [...new Set(paths.filter(test))].sort();
326
+ const signalPaths: NonNullable<GitDeltaAnalysis["signalPaths"]> = {
327
+ config: matching((p) => CONFIG_PATTERNS.some((pattern) => pattern.test(p))),
328
+ dependencyManifest: matching((p) => p === "package.json"),
329
+ lockfile: matching((p) => /^(?:package-lock\.json|yarn\.lock|pnpm-lock\.yaml|bun\.lockb)$/.test(p)),
330
+ workflow: matching((p) => p.startsWith(".github/workflows/")),
331
+ infrastructure: matching((p) => infrastructureRole(p) === "definition"),
332
+ database: matching((p) => p.startsWith("database/")),
333
+ };
271
334
 
272
335
  return {
273
336
  empty: files.length === 0,
274
- configChanged: CONFIG_PATTERNS.some(matches),
275
- dependencyManifestChanged: matches(/^package\.json$/),
276
- lockfileChanged:
277
- matches(/^package-lock\.json$/) ||
278
- matches(/^yarn\.lock$/) ||
279
- matches(/^pnpm-lock\.yaml$/) ||
280
- matches(/^bun\.lockb$/),
281
- workflowChanged: matches(/^\.github\/workflows\//),
282
- infrastructureChanged: matches(/^ops\//),
283
- databaseChanged: matches(/^database\//),
337
+ configChanged: signalPaths.config!.length > 0,
338
+ dependencyManifestChanged: signalPaths.dependencyManifest!.length > 0,
339
+ lockfileChanged: signalPaths.lockfile!.length > 0,
340
+ workflowChanged: signalPaths.workflow!.length > 0,
341
+ infrastructureChanged: signalPaths.infrastructure!.length > 0,
342
+ databaseChanged: signalPaths.database!.length > 0,
343
+ signalPaths,
284
344
  };
285
345
  }
286
346
 
@@ -426,19 +486,45 @@ export async function analyzeGitDelta(
426
486
  // behaviorally-relevant field actually changed - only attempted when the root package.json itself
427
487
  // was modified (not added/deleted/renamed, which stay unambiguously true - see
428
488
  // hasRelevantPackageJsonChange()'s own doc comment) and only ever narrows true -> false.
489
+ const narrowed = new Set<ChangedFile>();
490
+ const referenceResolvedPaths: string[] = [];
429
491
  if (analysis.dependencyManifestChanged) {
430
492
  const changedPackageJson = filesWithBinary.find((f) => f.path === "package.json" && f.changeType === "modified");
431
493
  if (changedPackageJson) {
432
494
  const oldContent = readFileAtSha(baseSha, "package.json", repoPath);
433
495
  const newContent = readFileAtSha(headSha, "package.json", repoPath);
434
- analysis.dependencyManifestChanged = hasRelevantPackageJsonChange(oldContent, newContent);
435
- if (!analysis.dependencyManifestChanged) {
436
- // Do not let the generic path rule undo the content-level narrowing. Other config
437
- // changes in the same delta must still force full validation.
438
- analysis.configChanged = computeAnalysis(filesWithBinary.filter((f) => f !== changedPackageJson)).configChanged;
439
- }
496
+ const kind = packageJsonChangeKind(oldContent, newContent);
497
+ analysis.dependencyManifestChanged = kind === "behavioral";
498
+ if (kind !== "behavioral") narrowed.add(changedPackageJson);
499
+ if (kind === "data") referenceResolvedPaths.push("package.json");
440
500
  }
441
501
  }
502
+ // 2026-10-21: a workflow that cannot run tests (deploy, publish, scan) cannot change a test
503
+ // outcome. Both sides of the change are inspected, since removing a test step changes CI too.
504
+ if (analysis.workflowChanged) {
505
+ const headScripts = scriptRecord(parsePackageScripts(readFileAtSha(headSha, "package.json", repoPath))) ?? {};
506
+ const baseScripts = scriptRecord(parsePackageScripts(readFileAtSha(baseSha, "package.json", repoPath))) ?? {};
507
+ for (const file of filesWithBinary) {
508
+ const sides = file.oldPath ? [file.path, file.oldPath] : [file.path];
509
+ if (!sides.every((p) => /^\.github\/workflows\/[^/]+\.ya?ml$/.test(p))) continue;
510
+ const before = file.changeType === "added" ? "" : readFileAtSha(baseSha, file.oldPath ?? file.path, repoPath);
511
+ const after = file.changeType === "deleted" ? "" : readFileAtSha(headSha, file.path, repoPath);
512
+ const mayRunTests = (text: string | undefined, scripts: Record<string, string>) => text !== "" && workflowMayRunTests(text, scripts);
513
+ if (mayRunTests(before, baseScripts) || mayRunTests(after, headScripts)) continue;
514
+ narrowed.add(file);
515
+ referenceResolvedPaths.push(file.path);
516
+ }
517
+ }
518
+ if (narrowed.size > 0) {
519
+ // Do not let the generic path rules undo the content-level narrowing. Other changes in the same
520
+ // delta must still force full validation.
521
+ const remaining = computeAnalysis(filesWithBinary.filter((f) => !narrowed.has(f)));
522
+ analysis.configChanged = remaining.configChanged;
523
+ analysis.workflowChanged = remaining.workflowChanged;
524
+ analysis.signalPaths = { ...analysis.signalPaths, config: remaining.signalPaths?.config, workflow: remaining.signalPaths?.workflow,
525
+ ...(analysis.dependencyManifestChanged ? {} : { dependencyManifest: [] }) };
526
+ }
527
+ if (referenceResolvedPaths.length > 0) analysis.referenceResolvedPaths = referenceResolvedPaths.sort();
442
528
 
443
529
  const delta: GitDelta = {
444
530
  baseSha,
@@ -39,6 +39,15 @@ export interface GitDeltaAnalysis {
39
39
  workflowChanged: boolean;
40
40
  infrastructureChanged: boolean;
41
41
  databaseChanged: boolean;
42
+ /** Changed files whose content shows they cannot change how tests run - a workflow with no test
43
+ * step, a package.json edit limited to fields outside the test script closure - and which therefore
44
+ * did not set a global flag above. Tests may still read them, so ImpactAnalyzer resolves their
45
+ * readers by reference and falls back to full validation when it cannot (2026-10-21). */
46
+ referenceResolvedPaths?: string[];
47
+ /** The changed paths behind each flag above, so a fallback reason can name its files (2026-10-21:
48
+ * "Configuration file(s) changed" was the most frequent reason in both telemetry cohorts and never
49
+ * said which file). Absent on analyses produced before this field existed. */
50
+ signalPaths?: Partial<Record<"config" | "dependencyManifest" | "lockfile" | "workflow" | "infrastructure" | "database", string[]>>;
42
51
  }
43
52
 
44
53
  export interface GitDelta extends GitCommitRange {
@@ -26,7 +26,8 @@
26
26
  */
27
27
  import type { PackageManager, RepositoryProfile } from "../repo/types.js";
28
28
  import type { TestRunnerConfig } from "../repo/test-discovery.js";
29
- import { matchesGlob } from "../repo/test-discovery.js";
29
+ import { matchesGlob, testDiscoveryErrors } from "../repo/test-discovery.js";
30
+ import { compileIgnoreRegexes, isIgnoredPath, isUnderRoots } from "../repo/runner-universe.js";
30
31
  import { END_TO_END_FRAMEWORKS, type KnownTestFramework } from "../repo/test-framework.js";
31
32
  import type { CommandSpec } from "./types.js";
32
33
 
@@ -103,6 +104,12 @@ function frameworkOfConfig(config: TestRunnerConfig): KnownTestFramework {
103
104
  return config.runner;
104
105
  }
105
106
 
107
+ function configAllowsPath(config: TestRunnerConfig, path: string): boolean {
108
+ return !config.excludeGlobs.some(glob => matchesGlob(path, glob))
109
+ && !isIgnoredPath(path, compileIgnoreRegexes(config.ignoreRegexSources))
110
+ && isUnderRoots(path, config.roots);
111
+ }
112
+
106
113
  function buildCommand(
107
114
  framework: KnownTestFramework,
108
115
  packageManager: PackageManager,
@@ -131,7 +138,7 @@ export function planSelectiveTestCommands(
131
138
  profile: RepositoryProfile,
132
139
  selectedPaths: readonly string[],
133
140
  ): SelectiveTestCommandPlan {
134
- const blockers = profile.adapterBlockers ?? profile.adapters?.flatMap((adapter) => adapter.blockers) ?? [];
141
+ const blockers = [...(profile.adapterBlockers ?? profile.adapters?.flatMap((adapter) => adapter.blockers) ?? []), ...testDiscoveryErrors(profile)];
135
142
  if (blockers.length) return { commands: [], groups: [], unroutedPaths: [...selectedPaths], refusalReason: blockers.join("; ") };
136
143
  if (profile.workspaceTestPackages?.length) {
137
144
  const suites = profile.workspaceTestPackages;
@@ -261,7 +268,9 @@ export function planSelectiveTestCommands(
261
268
  // command runs which files, so those claims are honoured first.
262
269
  for (const config of configs) {
263
270
  if (config.includes.length === 0) continue;
264
- const claimed = paths.filter((p) => remaining.has(p) && config.includes.some((glob) => matchesGlob(p, glob)));
271
+ // A file may execute under several configurations with different environments.
272
+ // Retain every applicable invocation; an earlier include is not exclusive ownership.
273
+ const claimed = paths.filter((p) => configAllowsPath(config, p) && config.includes.some((glob) => matchesGlob(p, glob)));
265
274
  if (claimed.length === 0) continue;
266
275
  for (const p of claimed) remaining.delete(p);
267
276
  const framework = frameworkOfConfig(config);
@@ -290,6 +299,11 @@ export function planSelectiveTestCommands(
290
299
  };
291
300
  }
292
301
  const rest = Array.from(remaining).sort();
302
+ const defaultConfigs = configs.filter(config => config.runner === primary && config.isDefault);
303
+ if (defaultConfigs.some(config => rest.some(path => !configAllowsPath(config, path)
304
+ || config.authoritative && !config.includes.some(glob => matchesGlob(path, glob))))) {
305
+ return { commands: [], groups: [], unroutedPaths: rest, refusalReason: "Selected tests are outside the default runner configuration" };
306
+ }
293
307
  groups.push({
294
308
  runnerId: primary,
295
309
  label: `${primary} (default configuration)`,
@@ -1,38 +1,128 @@
1
1
  import { readFileSync } from "node:fs";
2
- import { dirname, posix } from "node:path";
2
+ import { posix } from "node:path";
3
3
  import { contribution, type AdapterContext, type AdapterContribution, type RepositoryAdapter } from "./types.js";
4
4
 
5
- interface Pom { path:string; dir:string; groupId?:string; artifactId?:string; modules:string[]; dependencies:Array<{groupId:string;artifactId:string}>; }
5
+ interface Coordinates { groupId: string; artifactId: string; }
6
+ interface Pom {
7
+ path: string;
8
+ dir: string;
9
+ groupId?: string;
10
+ artifactId?: string;
11
+ parent?: Coordinates;
12
+ dependencies: Coordinates[];
13
+ customSourceRoots: boolean;
14
+ }
15
+
16
+ function tags(xml: string, name: string): string[] {
17
+ const re = new RegExp(`<${name}\\b[^>]*>([\\s\\S]*?)<\\/${name}>`, "g");
18
+ const out: string[] = [];
19
+ let match: RegExpExecArray | null;
20
+ while ((match = re.exec(xml))) out.push((match[1] ?? "").trim());
21
+ return out;
22
+ }
23
+
24
+ function first(xml: string, name: string): string | undefined { return tags(xml, name)[0]; }
25
+
26
+ function parsePom(path: string, xml: string): Pom {
27
+ const dir = posix.dirname(path) === "." ? "" : posix.dirname(path);
28
+ const parent = first(xml, "parent");
29
+ const own = xml.replace(/<parent\b[^>]*>[\s\S]*?<\/parent>/, "");
30
+ // Nested plugin/dependency coordinates are not the project's own identity. In
31
+ // particular, a dependency's ${project.groupId} must not shadow an inherited ID.
32
+ const identity = own.replace(/<(dependencies|dependencyManagement|build|profiles|reporting|properties)\b[^>]*>[\s\S]*?<\/\1>/g, "");
33
+ const dependencies = tags(xml, "dependency")
34
+ .map(value => ({ groupId: first(value, "groupId") ?? "", artifactId: first(value, "artifactId") ?? "" }))
35
+ .filter(value => value.artifactId);
36
+ return {
37
+ path, dir,
38
+ groupId: first(identity, "groupId") ?? first(parent ?? "", "groupId"),
39
+ artifactId: first(identity, "artifactId"),
40
+ parent: parent === undefined ? undefined : { groupId: first(parent, "groupId") ?? "", artifactId: first(parent, "artifactId") ?? "" },
41
+ dependencies,
42
+ customSourceRoots: tags(xml, "sourceDirectory").some(root => root !== "src/main/java") ||
43
+ tags(xml, "testSourceDirectory").some(root => root !== "src/test/java"),
44
+ };
45
+ }
6
46
 
7
- function tags(xml:string, name:string): string[] {
8
- const re=new RegExp(`<${name}\\b[^>]*>([\\s\\S]*?)<\\/${name}>`,"g"); const out:string[]=[]; let m:RegExpExecArray|null;
9
- while((m=re.exec(xml))) out.push((m[1]??"").trim()); return out;
47
+ function under(dir: string, path: string): boolean { return !dir || path === dir || path.startsWith(dir + "/"); }
48
+ function owningPom(poms: Pom[], file: string): Pom | undefined {
49
+ return poms.filter(pom => under(pom.dir, file)).sort((a, b) => b.dir.length - a.dir.length)[0];
10
50
  }
11
- function first(xml:string,name:string):string|undefined { return tags(xml,name)[0]; }
12
- function parsePom(path:string, xml:string):Pom {
13
- const dir=posix.dirname(path)==="."?"":posix.dirname(path);
14
- const parent=first(xml,"parent")??"";
15
- const own=xml.replace(/<parent\b[^>]*>[\s\S]*?<\/parent>/,"");
16
- const deps=tags(xml,"dependency").map(x=>({groupId:first(x,"groupId")??"",artifactId:first(x,"artifactId")??""})).filter(x=>x.artifactId);
17
- return {path,dir,groupId:first(own,"groupId")??first(parent,"groupId"),artifactId:first(own,"artifactId"),modules:tags(first(xml,"modules")??"","module"),dependencies:deps};
51
+ function isTest(path: string): boolean {
52
+ return /\/src\/test\/(?:java|kotlin)\//.test("/" + path) &&
53
+ /^(?:Test.*|.*(?:Test|Tests|TestCase|IT))\.(?:java|kt)$/.test(posix.basename(path));
18
54
  }
19
- function under(dir:string,path:string){return !dir||path===dir||path.startsWith(dir+"/");}
20
- function owningPom(poms:Pom[], file:string):Pom|undefined { return poms.filter(p=>under(p.dir,file)).sort((a,b)=>b.dir.length-a.dir.length)[0]; }
21
- function javaFiles(context:AdapterContext, poms:Pom[], pom:Pom){return context.files.filter(f=>owningPom(poms,f)===pom&&/\/src\/(?:main|test)\/(?:java|kotlin)\/.*\.(?:java|kt)$/.test("/"+f));}
22
- function isTest(path:string){return /\/src\/test\/(?:java|kotlin)\//.test("/"+path)&&/(?:Test|Tests|TestCase|IT)\.(?:java|kt)$/.test(path);}
23
-
24
- export function analyzeMaven(context:AdapterContext):AdapterContribution {
25
- const r=contribution(mavenAdapter);
26
- const poms=context.files.filter(f=>f==="pom.xml"||f.endsWith("/pom.xml")).map(path=>parsePom(path,readFileSync(context.repoPath+"/"+path,"utf8")));
27
- if(!poms.length){r.blockers.push("Maven analysis found no pom.xml");return r;}
28
- const byGA=new Map(poms.filter(p=>p.artifactId).map(p=>[`${p.groupId??""}:${p.artifactId}`,p]));
29
- const byArtifact=new Map(poms.filter(p=>p.artifactId).map(p=>[p.artifactId!,p]));
30
- const members=new Map<Pom,string[]>(), anchors=new Map<Pom,string>();
31
- for(const p of poms){const files=javaFiles(context,poms,p); if(!files.length) continue; members.set(p,files); anchors.set(p,files[0]!); r.sourcePaths.push(...files); for(const f of files) if(isTest(f)){r.testFiles.push(f);r.testPackages[f]=p.dir||".";}}
32
- for(const [p,files] of members){const a=anchors.get(p)!; for(const f of files) if(f!==a) r.edges.push({from:a,to:f,kind:"import"},{from:f,to:a,kind:"import"});
33
- for(const d of p.dependencies){const normalizedGroup=d.groupId.replace(/\$\{project\.groupId\}/g,p.groupId??"").replace(/\$\{pom\.groupId\}/g,p.groupId??""); const target=byGA.get(`${normalizedGroup}:${d.artifactId}`)??byArtifact.get(d.artifactId); const ta=target&&anchors.get(target); if(ta&&ta!==a) r.edges.push({from:a,to:ta,kind:"import"});}
55
+
56
+ export function analyzeMaven(context: AdapterContext): AdapterContribution {
57
+ const result = contribution(mavenAdapter);
58
+ const poms = context.files.filter(file => file === "pom.xml" || file.endsWith("/pom.xml"))
59
+ .map(path => parsePom(path, readFileSync(context.repoPath + "/" + path, "utf8")));
60
+ if (!poms.length) { result.blockers.push("Maven analysis found no pom.xml"); return result; }
61
+ const byGA = new Map(poms.filter(pom => pom.artifactId).map(pom => [`${pom.groupId ?? ""}:${pom.artifactId}`, pom]));
62
+ const byArtifact = new Map(poms.filter(pom => pom.artifactId).map(pom => [pom.artifactId!, pom]));
63
+ const findPom = (coordinates: Coordinates) => byGA.get(`${coordinates.groupId}:${coordinates.artifactId}`) ?? byArtifact.get(coordinates.artifactId);
64
+ const members = new Map<Pom, string[]>();
65
+ const resources = new Map<Pom, string[]>();
66
+ const anchors = new Map<Pom, string>();
67
+
68
+ for (const pom of poms) {
69
+ if (pom.customSourceRoots) result.blockers.push(`Maven ${pom.path}: custom source roots require full validation`);
70
+ // This static adapter does not construct Maven's effective model. A local parent's
71
+ // dependency declarations cannot safely be treated as belonging only to that POM.
72
+ const visited = new Set<Pom>([pom]);
73
+ let parent = pom.parent && findPom(pom.parent);
74
+ while (parent && !visited.has(parent)) {
75
+ if (parent.dependencies.length) {
76
+ result.blockers.push(`Maven ${pom.path}: parent dependency inheritance requires full validation`);
77
+ break;
78
+ }
79
+ visited.add(parent);
80
+ parent = parent.parent && findPom(parent.parent);
81
+ }
82
+
83
+ const owned = context.files.filter(file => owningPom(poms, file) === pom);
84
+ const sources = owned.filter(file => /\/src\/(?:main|test)\/(?:java|kotlin)\/.*\.(?:java|kt)$/.test("/" + file));
85
+ const assets = owned.filter(file => /\/src\/(?:main|test)\/resources\//.test("/" + file));
86
+ members.set(pom, sources);
87
+ resources.set(pom, assets);
88
+ const anchor = sources[0] ?? assets[0];
89
+ if (anchor) anchors.set(pom, anchor);
90
+ result.sourcePaths.push(...sources);
91
+ result.assetPaths.push(...assets);
92
+ for (const file of sources) {
93
+ if (isTest(file)) { result.testFiles.push(file); result.testPackages[file] = pom.dir || "."; }
94
+ }
34
95
  }
35
- if(!r.sourcePaths.length) r.blockers.push("Maven reactor contains no Java sources");
36
- return r;
96
+
97
+ for (const pom of poms) {
98
+ const anchor = anchors.get(pom);
99
+ if (anchor) {
100
+ for (const file of members.get(pom) ?? []) {
101
+ if (file !== anchor) result.edges.push({ from: anchor, to: file, kind: "import" }, { from: file, to: anchor, kind: "import" });
102
+ }
103
+ // Resources are inputs to the entire module. Resource-only JARs also need an
104
+ // anchor so changes can reach tests in modules that depend on them.
105
+ for (const file of resources.get(pom) ?? []) {
106
+ if (file !== anchor) result.edges.push({ from: anchor, to: file, kind: "asset" });
107
+ }
108
+ }
109
+ for (const dependency of pom.dependencies) {
110
+ const groupId = dependency.groupId.replace(/\$\{project\.groupId\}/g, pom.groupId ?? "").replace(/\$\{pom\.groupId\}/g, pom.groupId ?? "");
111
+ if (/\$\{/.test(groupId) || /\$\{/.test(dependency.artifactId)) {
112
+ result.blockers.push(`Maven ${pom.path}: unresolved dependency coordinates require full validation`);
113
+ continue;
114
+ }
115
+ const target = findPom({ groupId, artifactId: dependency.artifactId });
116
+ const targetAnchor = target && anchors.get(target);
117
+ if (anchor && targetAnchor && targetAnchor !== anchor) result.edges.push({ from: anchor, to: targetAnchor, kind: "import" });
118
+ }
119
+ }
120
+ if (!result.sourcePaths.length) result.blockers.push("Maven reactor contains no Java sources");
121
+ return result;
37
122
  }
38
- export const mavenAdapter:RepositoryAdapter={id:"maven",version:"1",kind:"language",detect:({files})=>files.includes("pom.xml")&&files.some(f=>f.endsWith(".java")||f.endsWith(".kt")),analyze:analyzeMaven};
123
+
124
+ export const mavenAdapter: RepositoryAdapter = {
125
+ id: "maven", version: "2", kind: "language",
126
+ detect: ({ files }) => files.includes("pom.xml") && files.some(file => file.endsWith(".java") || file.endsWith(".kt")),
127
+ analyze: analyzeMaven,
128
+ };