@diffci.com/diffci 0.3.15 → 0.3.16

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 (91) hide show
  1. package/dist-client/src/client/agent-selection.js +20 -0
  2. package/dist-client/src/client/cli.js +15 -1
  3. package/dist-client/src/client/hook.js +94 -0
  4. package/dist-client/src/client/mcp.js +11 -3
  5. package/dist-client/src/client/observe.js +7 -2
  6. package/dist-client/src/client/verify.js +19 -1
  7. package/node_modules/@diffci.com/core/LICENSE +21 -661
  8. package/node_modules/@diffci.com/core/NOTICE +2 -2
  9. package/node_modules/@diffci.com/core/README.md +21 -3
  10. package/node_modules/@diffci.com/core/dist/analyze.js +1 -1
  11. package/node_modules/@diffci.com/core/dist/analyze.js.map +1 -1
  12. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +1 -1
  13. package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
  14. package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js +1 -1
  15. package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js.map +1 -1
  16. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +1 -1
  17. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
  18. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +1 -1
  19. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
  20. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +1 -1
  21. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js.map +1 -1
  22. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +1 -1
  23. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
  24. package/node_modules/@diffci.com/core/dist/ci-inference/schema.js +1 -1
  25. package/node_modules/@diffci.com/core/dist/ci-inference/schema.js.map +1 -1
  26. package/node_modules/@diffci.com/core/dist/cli.js +1 -1
  27. package/node_modules/@diffci.com/core/dist/cli.js.map +1 -1
  28. package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +29 -4
  29. package/node_modules/@diffci.com/core/dist/git/git-diff.js +136 -22
  30. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  31. package/node_modules/@diffci.com/core/dist/git/types.d.ts +7 -0
  32. package/node_modules/@diffci.com/core/dist/index.js +1 -1
  33. package/node_modules/@diffci.com/core/dist/index.js.map +1 -1
  34. package/node_modules/@diffci.com/core/dist/measurement.js +1 -1
  35. package/node_modules/@diffci.com/core/dist/measurement.js.map +1 -1
  36. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js +1 -1
  37. package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js.map +1 -1
  38. package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +32 -0
  39. package/node_modules/@diffci.com/core/dist/repo/file-references.js +180 -9
  40. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
  41. package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +4 -0
  42. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +19 -0
  43. package/node_modules/@diffci.com/core/dist/repo/impact.js +105 -3
  44. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  45. package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.d.ts +27 -0
  46. package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.js +116 -0
  47. package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.js.map +1 -0
  48. package/node_modules/@diffci.com/core/dist/repo/script-universe.js +1 -1
  49. package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -1
  50. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +1 -1
  51. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
  52. package/node_modules/@diffci.com/core/dist/repo/workspaces.js +1 -1
  53. package/node_modules/@diffci.com/core/dist/repo/workspaces.js.map +1 -1
  54. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +1 -1
  55. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
  56. package/node_modules/@diffci.com/core/dist/research/baseline/test-activity.js +1 -1
  57. package/node_modules/@diffci.com/core/dist/research/baseline/test-activity.js.map +1 -1
  58. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +1 -1
  59. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
  60. package/node_modules/@diffci.com/core/package.json +1 -1
  61. package/node_modules/@diffci.com/core/src/analyze.ts +1 -1
  62. package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +1 -1
  63. package/node_modules/@diffci.com/core/src/ci-inference/causal.ts +1 -1
  64. package/node_modules/@diffci.com/core/src/ci-inference/evidence.ts +1 -1
  65. package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +1 -1
  66. package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +1 -1
  67. package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +1 -1
  68. package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +1 -1
  69. package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +1 -1
  70. package/node_modules/@diffci.com/core/src/ci-inference/reference-graph.ts +1 -1
  71. package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +1 -1
  72. package/node_modules/@diffci.com/core/src/ci-inference/schema.ts +1 -1
  73. package/node_modules/@diffci.com/core/src/cli.ts +1 -1
  74. package/node_modules/@diffci.com/core/src/git/git-diff.ts +127 -21
  75. package/node_modules/@diffci.com/core/src/git/types.ts +7 -0
  76. package/node_modules/@diffci.com/core/src/index.ts +1 -1
  77. package/node_modules/@diffci.com/core/src/measurement.ts +1 -1
  78. package/node_modules/@diffci.com/core/src/repo/compiled-projects.ts +1 -1
  79. package/node_modules/@diffci.com/core/src/repo/file-references.ts +170 -9
  80. package/node_modules/@diffci.com/core/src/repo/impact-types.ts +4 -0
  81. package/node_modules/@diffci.com/core/src/repo/impact.ts +115 -2
  82. package/node_modules/@diffci.com/core/src/repo/npm-lockfile.ts +109 -0
  83. package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
  84. package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +1 -1
  85. package/node_modules/@diffci.com/core/src/repo/workspaces.ts +1 -1
  86. package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +1 -1
  87. package/node_modules/@diffci.com/core/src/research/baseline/path-baseline.ts +1 -1
  88. package/node_modules/@diffci.com/core/src/research/baseline/registry.ts +1 -1
  89. package/node_modules/@diffci.com/core/src/research/baseline/test-activity.ts +1 -1
  90. package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +1 -1
  91. package/package.json +2 -2
@@ -31,6 +31,8 @@ export async function agentSelection(repoInput) {
31
31
  const observation = before.changed ? await observe({
32
32
  repoPath, env: process.env, version: "agent-selection-v1",
33
33
  baseOverride: before.baseSha, headOverride: before.commitSha,
34
+ // The returned commands include any test-script phases (executableSelection).
35
+ selectTestPhases: true,
34
36
  }) : undefined;
35
37
  const result = observation?.result;
36
38
  const after = captureWorkingTreeSnapshot(repoPath);
@@ -68,3 +70,21 @@ export async function agentSelection(repoInput) {
68
70
  required_ci_authoritative: true,
69
71
  };
70
72
  }
73
+ /**
74
+ * One plain sentence ahead of the JSON, naming the exact command to run (2026-10-28). Agents given only
75
+ * the JSON plan mostly went on to pick their own test files or run the whole suite; the first line is
76
+ * what they act on, so it says what to run and nothing else.
77
+ */
78
+ export function selectionInstruction(plan) {
79
+ if (plan.status === "blocked")
80
+ return `DiffCI could not plan this change: ${plan.reason}. Run the repository's normal verification and report this.`;
81
+ if (plan.selection === "none")
82
+ return `Nothing to verify: ${plan.reason}.`;
83
+ const scope = plan.selection === "selected"
84
+ ? `DiffCI selected ${plan.tests_selected} of ${plan.tests_available} test files`
85
+ : `DiffCI requires the full suite (${plan.reason})`;
86
+ const run = plan.commands && plan.commands.length > 1
87
+ ? `Run these commands in order, exactly as given:\n${plan.commands.join("\n")}`
88
+ : `Run exactly:\n${plan.command}`;
89
+ return `${scope}. ${run}\nDo not substitute your own test files or the full suite.`;
90
+ }
@@ -34,6 +34,7 @@ import { basename, dirname, join, resolve } from "node:path";
34
34
  import { observe, isInsideRepository } from "./observe.js";
35
35
  import { inferFullCommand, inferComparableSelectedCommand, inferWorkspaceComparison } from "./full-command.js";
36
36
  import { addDiffciPackageScripts, detectPackageManager, installDiffci } from "./install.js";
37
+ import { hookCommand, installPrePushHook } from "./hook.js";
37
38
  import { submitObservation } from "./submit.js";
38
39
  import { githubDeliveryWarning } from "./delivery-warning.js";
39
40
  import { configureTelemetry, readTelemetryPreference, recordUsage } from "./telemetry.js";
@@ -90,6 +91,12 @@ Default command:
90
91
  ${command}
91
92
  \`\`\`
92
93
 
94
+ Use it instead of choosing test files yourself and instead of re-running the full suite:
95
+
96
+ - Run it once after each change and before every commit. Do not pick individual test files to run instead; a hand-picked set misses tests that depend on your change through imports, fixtures and scripts.
97
+ - Do not run the full test suite to be safe. DiffCI already falls back to the full suite when it cannot prove a smaller set is enough, and says why in \`reason\`.
98
+ - When the MCP server is available, \`diffci_select_tests\` returns the one exact \`command\` to run; run that command as given.
99
+
93
100
  What this does:
94
101
 
95
102
  - snapshots staged, unstaged, and non-ignored untracked changes;
@@ -98,6 +105,7 @@ What this does:
98
105
  - emits a versioned machine-readable receipt and sends nothing.
99
106
 
100
107
  If verification changes generated files, review those changes and rerun DiffCI so the new snapshot is verified.
108
+ If the repository has the DiffCI pre-push hook (\`diffci init --hook\`), a push verifies the pushed commits again; do not bypass it with \`--no-verify\` unless the user asks.
101
109
  Use \`observe --no-send\` when analysis without test execution is needed.
102
110
 
103
111
  Do not propose, commit, push, or deploy when \`safe_to_continue\` is false. If DiffCI is blocked, run the repository's normal required verification and report the blocker; required project CI remains authoritative.
@@ -268,6 +276,8 @@ function runInit(flags, env) {
268
276
  if (includeVerificationWorkflow) {
269
277
  writes.push(writeInitFile(repoPath, ".github/workflows/diffci-verify.yml", diffciVerificationWorkflow(identity.version), force));
270
278
  }
279
+ if (flags.hook === true)
280
+ writes.push(installPrePushHook(repoPath, hookCommand(manager, identity.version), force));
271
281
  console.log(`DiffCI initialized for AI coding agents in ${repoPath}`);
272
282
  for (const write of writes)
273
283
  console.log(` ${write}`);
@@ -275,6 +285,8 @@ function runInit(flags, env) {
275
285
  console.log(` ${installed}`);
276
286
  else
277
287
  console.log(" skipped package installation (pass --install to add an exact dev dependency)");
288
+ if (flags.hook !== true)
289
+ console.log(" skipped the pre-push hook (pass --hook to verify pushed commits before every push)");
278
290
  if (!includeWorkflow)
279
291
  console.log(" skipped .github/workflows/diffci.yml (pass --workflow to add it)");
280
292
  if (!includeVerificationWorkflow)
@@ -908,7 +920,7 @@ Open-source engine: https://github.com/DiffCI/core
908
920
  Pilot a repository: https://diffci.com/#pilot
909
921
 
910
922
  Usage:
911
- diffci init [--repo <path>] [--workflow] [--verification-workflow] [--install] [--force]
923
+ diffci init [--repo <path>] [--workflow] [--verification-workflow] [--install] [--hook] [--force]
912
924
  diffci mcp
913
925
  diffci verify [--changed | --base <sha> --head <sha>] [--policy enforce] [--repo <path>] [--out <file>] [--json]
914
926
  [--redact-paths] [--timeout-ms <ms>] [--baseline-on-failure] [--share-usage] [--no-send]
@@ -937,6 +949,8 @@ init writes AGENTS.md, CLAUDE.md, Cursor rules, Copilot instructions, and diffci
937
949
  or Bun, installs this DiffCI version as an exact dev dependency, updates the manager's lockfile,
938
950
  and adds diffci:verify, diffci:check, and diffci:observe package scripts without replacing existing scripts.
939
951
  --verification-workflow adds a blocking GitHub check that uploads a commit-bound verification receipt.
952
+ --hook installs a Git pre-push hook that runs diffci verify on the commits being pushed and blocks the push
953
+ when verification fails (git push --no-verify skips it; DIFFCI_HOOK_STRICT=1 also blocks when it cannot verify).
940
954
  mcp runs the stdio MCP server for native agent integrations.
941
955
  verify --changed snapshots staged, unstaged, and non-ignored untracked changes, runs the minimum
942
956
  executable verification (or full fallback), and exits zero only when that exact snapshot passes.
@@ -0,0 +1,94 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { dirname, isAbsolute, join, relative } from "node:path";
4
+ /**
5
+ * The pre-push hook `diffci init --hook` installs (2026-10-28).
6
+ *
7
+ * WHY. In 449 agent sessions on DentalPresence, agents ran DiffCI in 24 of over 1,500 test commands:
8
+ * they picked test files themselves (928) or ran the whole suite (282), and 104 pushes then failed the
9
+ * repository gates in CI. Instructions alone did not make DiffCI the default. A hook does: every push,
10
+ * by an agent or a person, verifies the commits being pushed before they leave the machine.
11
+ *
12
+ * BEHAVIOUR. For each pushed ref that is the checked-out HEAD, the hook runs
13
+ * `diffci verify --base <remote sha> --head <local sha>` (a new branch uses its merge base with the
14
+ * remote's default branch). Failing verification (exit 1) blocks the push. When DiffCI cannot verify
15
+ * (exit 2: dirty checkout, unknown base, analysis refused) it says why and lets the push through,
16
+ * because required CI still runs; `DIFFCI_HOOK_STRICT=1` blocks instead. `git push --no-verify` skips it.
17
+ */
18
+ export const HOOK_MARKER = "# diffci:managed pre-push hook";
19
+ export function prePushHook(command) {
20
+ return `#!/bin/sh
21
+ ${HOOK_MARKER}
22
+ # Verifies the commits being pushed with DiffCI's affected tests. Skip once: git push --no-verify
23
+ # Block when DiffCI cannot verify, not only when tests fail: DIFFCI_HOOK_STRICT=1
24
+ remote="$1"
25
+ zero=0000000000000000000000000000000000000000
26
+ head=$(git rev-parse HEAD)
27
+ status=0
28
+ while read -r local_ref local_sha remote_ref remote_sha; do
29
+ [ "$local_sha" = "$zero" ] && continue
30
+ if [ "$local_sha" != "$head" ]; then
31
+ echo "diffci: $local_ref is not checked out; not verified here" >&2
32
+ continue
33
+ fi
34
+ base="$remote_sha"
35
+ if [ "$base" = "$zero" ] || ! git cat-file -e "$base^{commit}" 2>/dev/null; then
36
+ base=$(git merge-base HEAD "refs/remotes/$remote/HEAD" 2>/dev/null || true)
37
+ fi
38
+ if [ -z "$base" ] || [ "$base" = "$local_sha" ]; then
39
+ echo "diffci: no base commit for $local_ref; not verified" >&2
40
+ continue
41
+ fi
42
+ echo "diffci: verifying $base..$local_sha before push" >&2
43
+ ${command} verify --base "$base" --head "$local_sha" </dev/null
44
+ code=$?
45
+ if [ "$code" -eq 1 ]; then
46
+ echo "diffci: verification failed; push blocked. Fix it, or skip once with git push --no-verify" >&2
47
+ status=1
48
+ elif [ "$code" -ne 0 ]; then
49
+ if [ "$DIFFCI_HOOK_STRICT" = "1" ]; then
50
+ echo "diffci: could not verify (exit $code); push blocked because DIFFCI_HOOK_STRICT=1" >&2
51
+ status=1
52
+ else
53
+ echo "diffci: could not verify (exit $code); pushing anyway, required CI still runs" >&2
54
+ fi
55
+ fi
56
+ done
57
+ exit $status
58
+ `;
59
+ }
60
+ /** The command the hook runs: the installed binary when the repository has DiffCI as a dependency,
61
+ * otherwise a pinned npx invocation, so the hook never floats to a newer release. */
62
+ export function hookCommand(manager, version) {
63
+ switch (manager) {
64
+ case "npm": return "npx --no-install diffci";
65
+ case "pnpm": return "pnpm exec diffci";
66
+ case "yarn": return "yarn diffci";
67
+ case "bun": return "bunx diffci";
68
+ default: return `npx --yes "@diffci.com/diffci@${version}"`;
69
+ }
70
+ }
71
+ /** Writes the hook into the directory Git actually runs hooks from (`core.hooksPath` included, such as
72
+ * `.husky`). An existing hook DiffCI did not write is kept unless `force` is set. */
73
+ export function installPrePushHook(repoPath, command, force) {
74
+ const hooksDir = execFileSync("git", ["rev-parse", "--git-path", "hooks"], { cwd: repoPath, encoding: "utf8", windowsHide: true }).trim();
75
+ const absoluteDir = isAbsolute(hooksDir) ? hooksDir : join(repoPath, hooksDir);
76
+ const hookPath = join(absoluteDir, "pre-push");
77
+ const shown = relative(repoPath, hookPath).replace(/\\/g, "/") || hookPath;
78
+ const content = prePushHook(command);
79
+ if (existsSync(hookPath)) {
80
+ const existing = readFileSync(hookPath, "utf8");
81
+ if (existing === content)
82
+ return `kept ${shown} (current)`;
83
+ if (!existing.includes(HOOK_MARKER) && !force) {
84
+ return `kept ${shown} (existing hook not written by DiffCI; add \`${command} verify --base <remote-sha> --head <local-sha>\` to it, or pass --force)`;
85
+ }
86
+ }
87
+ mkdirSync(dirname(hookPath), { recursive: true });
88
+ writeFileSync(hookPath, content, "utf8");
89
+ try {
90
+ chmodSync(hookPath, 0o755);
91
+ }
92
+ catch { /* Git for Windows runs hooks through sh regardless of mode. */ }
93
+ return `wrote ${shown} (verifies pushed commits; skip once with git push --no-verify)`;
94
+ }
@@ -2,7 +2,7 @@
2
2
  import { execFile } from "node:child_process";
3
3
  import { dirname, join, resolve } from "node:path";
4
4
  import { StringDecoder } from "node:string_decoder";
5
- import { agentChangedFiles, agentSelection } from "./agent-selection.js";
5
+ import { agentChangedFiles, agentSelection, selectionInstruction } from "./agent-selection.js";
6
6
  import { requireDiffciPackageIdentity } from "./package-identity.js";
7
7
  const SERVER_INFO = { name: "diffci-mcp", version: requireDiffciPackageIdentity().version };
8
8
  const tools = [
@@ -76,6 +76,7 @@ const tools = [
76
76
  repo: { type: "string", description: "Repository path. Defaults to the MCP server working directory." },
77
77
  workflow: { type: "boolean", description: "Also add the non-blocking GitHub Actions observer workflow." },
78
78
  verificationWorkflow: { type: "boolean", description: "Also add the blocking GitHub Actions verification workflow." },
79
+ hook: { type: "boolean", description: "Also install a Git pre-push hook that verifies the commits being pushed." },
79
80
  force: { type: "boolean", description: "Overwrite existing instruction files." },
80
81
  },
81
82
  additionalProperties: false,
@@ -159,6 +160,8 @@ function commandForTool(name, args) {
159
160
  command.push("--workflow");
160
161
  if (booleanArg(args, "verificationWorkflow"))
161
162
  command.push("--verification-workflow");
163
+ if (booleanArg(args, "hook"))
164
+ command.push("--hook");
162
165
  if (booleanArg(args, "force"))
163
166
  command.push("--force");
164
167
  return command;
@@ -239,8 +242,13 @@ async function handle(request) {
239
242
  }
240
243
  if (["diffci_changed_files", "diffci_select_tests", "diffci_explain_selection"].includes(params.name)) {
241
244
  const repo = stringArg(args, "repo") ?? process.cwd();
242
- const plan = params.name === "diffci_changed_files" ? agentChangedFiles(repo) : await agentSelection(repo);
243
- success(id, { content: [{ type: "text", text: JSON.stringify(plan) }], structuredContent: plan, isError: plan.status === "blocked" });
245
+ if (params.name === "diffci_changed_files") {
246
+ const changes = agentChangedFiles(repo);
247
+ success(id, { content: [{ type: "text", text: JSON.stringify(changes) }], structuredContent: changes, isError: changes.status === "blocked" });
248
+ return;
249
+ }
250
+ const plan = await agentSelection(repo);
251
+ success(id, { content: [{ type: "text", text: `${selectionInstruction(plan)}\n\n${JSON.stringify(plan)}` }], structuredContent: plan, isError: plan.status === "blocked" });
244
252
  return;
245
253
  }
246
254
  const run = await runCli(commandForTool(params.name, args));
@@ -191,10 +191,14 @@ export async function observe(options) {
191
191
  });
192
192
  }
193
193
  const profile = graphResult.profile;
194
- const impact = new ImpactAnalyzer().analyze(delta, graphResult, profile, {
194
+ // `selectTestPhases` and `testPhases` are newer than some bundled engines; an engine without them
195
+ // ignores the option and never returns phases, so it keeps falling back.
196
+ const analyzeOptions = {
195
197
  repositoryFiles: deltaResult.inventory?.files,
196
198
  readRepositoryFile: repositoryFileReader(repoPath),
197
- });
199
+ selectTestPhases: options.selectTestPhases === true,
200
+ };
201
+ const impact = new ImpactAnalyzer().analyze(delta, graphResult, profile, analyzeOptions);
198
202
  const baseline = runPathBaseline(profile.testFilePaths, delta.files, profile);
199
203
  const selectedTests = impact.affectedTests.map((test) => test.path).sort();
200
204
  // The comparator's own identities, sorted and redacted identically so the two arms of an economics
@@ -221,6 +225,7 @@ export async function observe(options) {
221
225
  } : {}),
222
226
  fallbackReasons: impact.fallbackReasons,
223
227
  proposedCommands: (commandPlan?.commands ?? []).map(commandSpecToString),
228
+ ...(impact.testPhases?.length ? { testPhases: [...impact.testPhases] } : {}),
224
229
  workspaceCommands: Boolean(profile.workspaceTestPackages?.length),
225
230
  goScope: profile.diffciConfig?.go?.scope,
226
231
  vueScope: profile.vueScope ? { packageRoot: hashPath(profile.vueScope.packageRoot), testConfig: hashPath(profile.vueScope.testConfig) } : undefined,
@@ -216,6 +216,7 @@ async function verifyChangedSnapshot(options) {
216
216
  headOverride: before.commitSha,
217
217
  redactPaths: options.redactPaths,
218
218
  reportPath: join(temporaryDirectory, "observation.json"),
219
+ selectTestPhases: true,
219
220
  });
220
221
  return await executeObservation({ ...options, repoPath }, "working-tree", before, observation);
221
222
  }
@@ -251,6 +252,7 @@ async function verifyCommitRange(options) {
251
252
  headOverride: options.headOverride,
252
253
  redactPaths: options.redactPaths,
253
254
  reportPath: join(temporaryDirectory, "observation.json"),
255
+ selectTestPhases: true,
254
256
  });
255
257
  return await executeObservation({ ...options, repoPath }, "commit-range", before, observation);
256
258
  }
@@ -293,9 +295,19 @@ export function executableSelection(repoPath, result) {
293
295
  let selection;
294
296
  let command;
295
297
  let reason;
298
+ let primaryPhases = [];
296
299
  if (result.mode === "SELECTIVE" && !result.commandRefusalReason && result.proposedCommands.length === 1) {
297
300
  const selected = inferSelectedCommand(repoPath, result.proposedCommands[0], result.selectedTests);
298
- if (selected.command) {
301
+ const phases = result.testPhases ?? [];
302
+ if (selected.command && phases.length) {
303
+ // The selection covers some changed files only through these test-script phases, so they run
304
+ // after the selected files, as the test script would run them (2026-10-28).
305
+ selection = "selected";
306
+ primaryPhases = phases.map(phaseCommand);
307
+ command = selected.command;
308
+ reason = `dependency impact; also ran ${phases.length} test-script phase(s) that read changed files: ${phases.join("; ")}`;
309
+ }
310
+ else if (selected.command) {
299
311
  selection = "selected";
300
312
  command = selected.command;
301
313
  reason = "dependency impact";
@@ -336,7 +348,13 @@ export function executableSelection(repoPath, result) {
336
348
  // Each part stays within the shell's command-line limit (cmd.exe stops at 8,191 characters).
337
349
  const commands = command ? [
338
350
  ...batchCommand(primary ?? command, selection === "selected" ? result.selectedTests : []),
351
+ ...primaryPhases,
339
352
  ...(auxiliaryCommand ? batchCommand(auxiliaryCommand, outside) : []),
340
353
  ] : [];
341
354
  return { selection, command: commands.length ? commands.join(" && ") : command, commands, reason, outsideSuite };
342
355
  }
356
+ /** A test-script phase as a standalone command. `npm test` puts `node_modules/.bin` on PATH; outside
357
+ * it a repository-local runner such as tsx is reached the way selected TypeScript tests are. */
358
+ export function phaseCommand(phase) {
359
+ return /^node\s/.test(phase) ? phase : `npx --no-install ${phase}`;
360
+ }