@diffci.com/diffci 0.3.15 → 0.3.17
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.js +30 -0
- package/dist-client/src/client/cli.js +21 -2
- package/dist-client/src/client/gate-checks.js +120 -0
- package/dist-client/src/client/hook.js +94 -0
- package/dist-client/src/client/mcp.js +11 -3
- package/dist-client/src/client/observe.js +7 -2
- package/dist-client/src/client/verify.js +49 -8
- package/node_modules/@diffci.com/core/LICENSE +21 -661
- package/node_modules/@diffci.com/core/NOTICE +2 -2
- package/node_modules/@diffci.com/core/README.md +21 -3
- package/node_modules/@diffci.com/core/dist/analyze.js +1 -1
- package/node_modules/@diffci.com/core/dist/analyze.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js +1 -1
- package/node_modules/@diffci.com/core/dist/cache/graph-cache.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/evidence.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +1 -1
- 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 +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/schema.js +1 -1
- package/node_modules/@diffci.com/core/dist/ci-inference/schema.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/cli.js +1 -1
- package/node_modules/@diffci.com/core/dist/cli.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +29 -4
- package/node_modules/@diffci.com/core/dist/git/git-diff.js +136 -22
- package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/git/types.d.ts +7 -0
- package/node_modules/@diffci.com/core/dist/index.js +1 -1
- package/node_modules/@diffci.com/core/dist/index.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/measurement.js +1 -1
- package/node_modules/@diffci.com/core/dist/measurement.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.d.ts +45 -0
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +252 -0
- package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.d.ts +60 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js +241 -0
- package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/planner/script-reads.d.ts +31 -0
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js +197 -0
- package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/planner/type-program.d.ts +33 -0
- package/node_modules/@diffci.com/core/dist/planner/type-program.js +106 -0
- package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -0
- package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/compiled-projects.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +32 -0
- package/node_modules/@diffci.com/core/dist/repo/file-references.js +180 -9
- package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/impact-types.d.ts +4 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +19 -0
- package/node_modules/@diffci.com/core/dist/repo/impact.js +105 -3
- package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.d.ts +27 -0
- package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.js +116 -0
- package/node_modules/@diffci.com/core/dist/repo/npm-lockfile.js.map +1 -0
- 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/workflow-test-steps.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/repo/workspaces.js +1 -1
- package/node_modules/@diffci.com/core/dist/repo/workspaces.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/test-activity.js +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/test-activity.js.map +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +1 -1
- package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
- package/node_modules/@diffci.com/core/package.json +1 -1
- package/node_modules/@diffci.com/core/src/analyze.ts +1 -1
- package/node_modules/@diffci.com/core/src/cache/graph-cache.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/causal.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/evidence.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/reference-graph.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +1 -1
- package/node_modules/@diffci.com/core/src/ci-inference/schema.ts +1 -1
- package/node_modules/@diffci.com/core/src/cli.ts +1 -1
- package/node_modules/@diffci.com/core/src/git/git-diff.ts +127 -21
- package/node_modules/@diffci.com/core/src/git/types.ts +7 -0
- package/node_modules/@diffci.com/core/src/index.ts +1 -1
- package/node_modules/@diffci.com/core/src/measurement.ts +1 -1
- package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +269 -0
- package/node_modules/@diffci.com/core/src/planner/pipeline-steps.ts +243 -0
- package/node_modules/@diffci.com/core/src/planner/script-reads.ts +174 -0
- package/node_modules/@diffci.com/core/src/planner/type-program.ts +103 -0
- package/node_modules/@diffci.com/core/src/repo/compiled-projects.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/file-references.ts +170 -9
- package/node_modules/@diffci.com/core/src/repo/impact-types.ts +4 -0
- package/node_modules/@diffci.com/core/src/repo/impact.ts +115 -2
- package/node_modules/@diffci.com/core/src/repo/npm-lockfile.ts +109 -0
- package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +1 -1
- package/node_modules/@diffci.com/core/src/repo/workspaces.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/path-baseline.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/registry.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/test-activity.ts +1 -1
- package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { observe } from "./observe.js";
|
|
4
|
+
import { plannedChecks } from "./gate-checks.js";
|
|
4
5
|
import { executableSelection } from "./verify.js";
|
|
5
6
|
import { captureWorkingTreeSnapshot } from "./working-tree.js";
|
|
6
7
|
function changedPaths(repoPath, snapshot) {
|
|
@@ -31,6 +32,8 @@ export async function agentSelection(repoInput) {
|
|
|
31
32
|
const observation = before.changed ? await observe({
|
|
32
33
|
repoPath, env: process.env, version: "agent-selection-v1",
|
|
33
34
|
baseOverride: before.baseSha, headOverride: before.commitSha,
|
|
35
|
+
// The returned commands include any test-script phases (executableSelection).
|
|
36
|
+
selectTestPhases: true,
|
|
34
37
|
}) : undefined;
|
|
35
38
|
const result = observation?.result;
|
|
36
39
|
const after = captureWorkingTreeSnapshot(repoPath);
|
|
@@ -48,6 +51,8 @@ export async function agentSelection(repoInput) {
|
|
|
48
51
|
}
|
|
49
52
|
}
|
|
50
53
|
const ready = unchanged && (!before.changed || Boolean(command));
|
|
54
|
+
const planned = ready && before.changed ? plannedChecks(repoPath, { baseSha: before.baseSha, headSha: before.commitSha }) : [];
|
|
55
|
+
const checks = planned.filter((check) => check.decision !== "SKIP");
|
|
51
56
|
return {
|
|
52
57
|
schema: "diffci.agent-selection.v1", scope: "working-tree",
|
|
53
58
|
status: ready ? "planned" : "blocked", tests_executed: false,
|
|
@@ -59,6 +64,9 @@ export async function agentSelection(repoInput) {
|
|
|
59
64
|
command: ready ? command : undefined,
|
|
60
65
|
// Run these one after another when present: the joined command exceeds the shell's limit.
|
|
61
66
|
...(ready && commands.length > 1 ? { commands } : {}),
|
|
67
|
+
// The rest of the repository's gate (lint, typecheck, check scripts), to run before the tests.
|
|
68
|
+
checks,
|
|
69
|
+
skipped_checks: planned.filter((check) => check.decision === "SKIP").map(({ id, reason }) => ({ id, reason })),
|
|
62
70
|
reason: unchanged ? reason : "working tree changed during analysis; reanalyze",
|
|
63
71
|
fallback_reasons: result?.fallbackReasons ?? [],
|
|
64
72
|
analysis_status: observation?.status ?? "not_needed",
|
|
@@ -68,3 +76,25 @@ export async function agentSelection(repoInput) {
|
|
|
68
76
|
required_ci_authoritative: true,
|
|
69
77
|
};
|
|
70
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* One plain sentence ahead of the JSON, naming the exact command to run (2026-10-28). Agents given only
|
|
81
|
+
* the JSON plan mostly went on to pick their own test files or run the whole suite; the first line is
|
|
82
|
+
* what they act on, so it says what to run and nothing else.
|
|
83
|
+
*/
|
|
84
|
+
export function selectionInstruction(plan) {
|
|
85
|
+
if (plan.status === "blocked")
|
|
86
|
+
return `DiffCI could not plan this change: ${plan.reason}. Run the repository's normal verification and report this.`;
|
|
87
|
+
if (plan.selection === "none")
|
|
88
|
+
return `Nothing to verify: ${plan.reason}.`;
|
|
89
|
+
const scope = plan.selection === "selected"
|
|
90
|
+
? `DiffCI selected ${plan.tests_selected} of ${plan.tests_available} test files`
|
|
91
|
+
: `DiffCI requires the full suite (${plan.reason})`;
|
|
92
|
+
const testCommands = plan.commands && plan.commands.length > 1 ? plan.commands : [plan.command];
|
|
93
|
+
const all = [...plan.checks.map((check) => check.command), ...testCommands];
|
|
94
|
+
const skipped = plan.skipped_checks?.length ? ` ${plan.skipped_checks.length} other gate check(s) are not affected by this change.` : "";
|
|
95
|
+
const gate = plan.checks.length ? ` The repository's gate also runs ${plan.checks.length} check(s) (${plan.checks.map((check) => check.id).join(", ")}); run them first.${skipped}` : skipped;
|
|
96
|
+
const run = all.length > 1
|
|
97
|
+
? `Run these commands in order, exactly as given:\n${all.join("\n")}`
|
|
98
|
+
: `Run exactly:\n${all[0]}`;
|
|
99
|
+
return `${scope}.${gate} ${run}\nDo not substitute your own test files, checks or the full suite.`;
|
|
100
|
+
}
|
|
@@ -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)
|
|
@@ -328,6 +340,8 @@ async function runVerifyCommand(flags, env) {
|
|
|
328
340
|
tailBytes: numberFlag(flags, "tail-bytes") ?? 12_000,
|
|
329
341
|
redactPaths: flags["redact-paths"] === true,
|
|
330
342
|
baselineOnFailure: flags["baseline-on-failure"] === true || env.DIFFCI_BASELINE_ON_FAILURE === "1",
|
|
343
|
+
// Gate checks are for before push; in CI the repository's own check jobs already run them.
|
|
344
|
+
skipChecks: flags["no-checks"] === true || env.DIFFCI_CHECKS === "0" || (Boolean(env.CI) && env.CI !== "false" && flags.checks !== true),
|
|
331
345
|
};
|
|
332
346
|
const report = changed
|
|
333
347
|
? await verifyChanged(common)
|
|
@@ -908,10 +922,11 @@ Open-source engine: https://github.com/DiffCI/core
|
|
|
908
922
|
Pilot a repository: https://diffci.com/#pilot
|
|
909
923
|
|
|
910
924
|
Usage:
|
|
911
|
-
diffci init [--repo <path>] [--workflow] [--verification-workflow] [--install] [--force]
|
|
925
|
+
diffci init [--repo <path>] [--workflow] [--verification-workflow] [--install] [--hook] [--force]
|
|
912
926
|
diffci mcp
|
|
913
927
|
diffci verify [--changed | --base <sha> --head <sha>] [--policy enforce] [--repo <path>] [--out <file>] [--json]
|
|
914
|
-
[--redact-paths] [--timeout-ms <ms>] [--baseline-on-failure] [--
|
|
928
|
+
[--redact-paths] [--timeout-ms <ms>] [--baseline-on-failure] [--no-checks | --checks]
|
|
929
|
+
[--share-usage] [--no-send]
|
|
915
930
|
diffci telemetry [--mode off|anonymous|installations] [--internal-usage]
|
|
916
931
|
diffci check [--repo <path>] [--out <file>] [--base <sha> --head <sha>]
|
|
917
932
|
[--redact-paths] [--json] [--quiet] [--fail-on-error] [--timeout-ms <ms>] [--share-usage]
|
|
@@ -937,9 +952,13 @@ init writes AGENTS.md, CLAUDE.md, Cursor rules, Copilot instructions, and diffci
|
|
|
937
952
|
or Bun, installs this DiffCI version as an exact dev dependency, updates the manager's lockfile,
|
|
938
953
|
and adds diffci:verify, diffci:check, and diffci:observe package scripts without replacing existing scripts.
|
|
939
954
|
--verification-workflow adds a blocking GitHub check that uploads a commit-bound verification receipt.
|
|
955
|
+
--hook installs a Git pre-push hook that runs diffci verify on the commits being pushed and blocks the push
|
|
956
|
+
when verification fails (git push --no-verify skips it; DIFFCI_HOOK_STRICT=1 also blocks when it cannot verify).
|
|
940
957
|
mcp runs the stdio MCP server for native agent integrations.
|
|
941
958
|
verify --changed snapshots staged, unstaged, and non-ignored untracked changes, runs the minimum
|
|
942
959
|
executable verification (or full fallback), and exits zero only when that exact snapshot passes.
|
|
960
|
+
verify first runs the rest of the repository's gate (the check script's lint, typecheck and check-script
|
|
961
|
+
leaves) and stops at the first failure; --no-checks skips them, and they are skipped in CI unless --checks.
|
|
943
962
|
verify without --changed resolves the CI event range (or HEAD^..HEAD locally), requires a clean checkout,
|
|
944
963
|
and exits zero only when the analyzed head is the commit that actually passed verification.
|
|
945
964
|
check analyzes the change, runs inferred full and selected commands, and shows measured savings.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { narrowGateChecks } from "@diffci.com/core/planner/check-narrowing";
|
|
5
|
+
import { discoverGateChecks, workflowGateScripts } from "@diffci.com/core/planner/pipeline-steps";
|
|
6
|
+
import { measureCommand } from "./verify-savings.js";
|
|
7
|
+
function workflowTexts(repoPath) {
|
|
8
|
+
const dir = join(repoPath, ".github", "workflows");
|
|
9
|
+
if (!existsSync(dir))
|
|
10
|
+
return [];
|
|
11
|
+
return readdirSync(dir).filter((name) => /\.ya?ml$/.test(name)).sort().flatMap((name) => {
|
|
12
|
+
try {
|
|
13
|
+
return [readFileSync(join(dir, name), "utf8")];
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function packageManager(repoPath, declared) {
|
|
21
|
+
const name = typeof declared === "string" ? declared.split("@")[0] : undefined;
|
|
22
|
+
if (name === "pnpm" || name === "yarn" || name === "bun")
|
|
23
|
+
return name;
|
|
24
|
+
if (existsSync(join(repoPath, "pnpm-lock.yaml")))
|
|
25
|
+
return "pnpm";
|
|
26
|
+
if (existsSync(join(repoPath, "yarn.lock")))
|
|
27
|
+
return "yarn";
|
|
28
|
+
if (existsSync(join(repoPath, "bun.lock")) || existsSync(join(repoPath, "bun.lockb")))
|
|
29
|
+
return "bun";
|
|
30
|
+
return "npm";
|
|
31
|
+
}
|
|
32
|
+
function git(repoPath, args) {
|
|
33
|
+
return execFileSync("git", args, { cwd: repoPath, encoding: "utf8", windowsHide: true, maxBuffer: 64 * 1024 * 1024 });
|
|
34
|
+
}
|
|
35
|
+
/** Renames count as a deletion plus an addition: a deleted path can break an import elsewhere. */
|
|
36
|
+
function changedPaths(repoPath, change) {
|
|
37
|
+
const fields = git(repoPath, ["diff", "--name-status", "--no-renames", "-z", change.baseSha, change.headSha]).split("\0").filter(Boolean);
|
|
38
|
+
const changes = [];
|
|
39
|
+
for (let i = 0; i + 1 < fields.length; i += 2) {
|
|
40
|
+
const status = fields[i];
|
|
41
|
+
changes.push({ path: fields[i + 1], status: status === "A" ? "added" : status === "D" ? "deleted" : "modified" });
|
|
42
|
+
}
|
|
43
|
+
return changes;
|
|
44
|
+
}
|
|
45
|
+
function readRepositoryFile(repoPath, path) {
|
|
46
|
+
try {
|
|
47
|
+
return readFileSync(join(repoPath, path), "utf8");
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The checks the repository's gate runs besides its tests (2026-10-29, docs/design/pipeline-impact.md).
|
|
55
|
+
* Agents ran the tests DiffCI selected and then failed `npm run check` after push; these are the rest of
|
|
56
|
+
* the gate. With a change, per-file lint and format checks are narrowed to its files or skipped
|
|
57
|
+
* (check-narrowing.ts); if the change cannot be read, every check runs. No package.json, or one that
|
|
58
|
+
* cannot be read, has none.
|
|
59
|
+
*/
|
|
60
|
+
export function plannedChecks(repoPath, change) {
|
|
61
|
+
const path = join(repoPath, "package.json");
|
|
62
|
+
if (!existsSync(path))
|
|
63
|
+
return [];
|
|
64
|
+
let pkg;
|
|
65
|
+
try {
|
|
66
|
+
pkg = JSON.parse(readFileSync(path, "utf8"));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
if (!pkg.scripts || typeof pkg.scripts !== "object")
|
|
72
|
+
return [];
|
|
73
|
+
const scripts = Object.fromEntries(Object.entries(pkg.scripts).filter((entry) => typeof entry[1] === "string"));
|
|
74
|
+
const manager = packageManager(repoPath, pkg.packageManager);
|
|
75
|
+
const lifecycleHooks = manager !== "pnpm";
|
|
76
|
+
let { checks } = discoverGateChecks(scripts, { lifecycleHooks, workflowScripts: workflowGateScripts(workflowTexts(repoPath), scripts) });
|
|
77
|
+
if (change) {
|
|
78
|
+
try {
|
|
79
|
+
const changes = changedPaths(repoPath, change);
|
|
80
|
+
const files = git(repoPath, ["ls-files", "-z"]).split("\0").filter(Boolean);
|
|
81
|
+
checks = narrowGateChecks(checks, { scripts, changes, files, lifecycleHooks, read: (file) => readRepositoryFile(repoPath, file) });
|
|
82
|
+
}
|
|
83
|
+
catch { /* The change could not be read: every check runs as discovered. */ }
|
|
84
|
+
}
|
|
85
|
+
return checks.map((check) => ({
|
|
86
|
+
id: check.id,
|
|
87
|
+
kind: check.kind,
|
|
88
|
+
decision: check.decision,
|
|
89
|
+
command: check.runsScript
|
|
90
|
+
? `${manager} run ${check.script}`
|
|
91
|
+
: /^(?:npm|pnpm|yarn|bun|npx|node)\s/.test(check.command) ? check.command : `npx --no-install ${check.command}`,
|
|
92
|
+
reason: check.reason,
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
95
|
+
/** Runs checks in order and stops at the first failure, as the gate's `&&` chain would. SKIP checks
|
|
96
|
+
* are recorded as skipped and not run. */
|
|
97
|
+
export function runChecks(checks, options) {
|
|
98
|
+
const started = Date.now();
|
|
99
|
+
const results = [];
|
|
100
|
+
let failure;
|
|
101
|
+
for (const check of checks) {
|
|
102
|
+
if (check.decision === "SKIP") {
|
|
103
|
+
results.push({ ...check, status: "skipped" });
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const remaining = options.timeoutMs - (Date.now() - started);
|
|
107
|
+
if (failure || remaining <= 0) {
|
|
108
|
+
results.push({ ...check, status: "not_run" });
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const measurement = measureCommand(check.command, { ...options, timeoutMs: remaining });
|
|
112
|
+
const status = measurement.timedOut ? "timed_out" : measurement.exitCode === 0 && measurement.signal === null ? "passed" : "failed";
|
|
113
|
+
const result = { ...check, status, exit_code: measurement.exitCode, wall_ms: measurement.wallMs };
|
|
114
|
+
results.push(result);
|
|
115
|
+
if (status !== "passed")
|
|
116
|
+
failure = { check: result, measurement };
|
|
117
|
+
}
|
|
118
|
+
const outOfTime = !failure && results.some((result) => result.status === "not_run");
|
|
119
|
+
return { results, failure, outOfTime, wallMs: Date.now() - started };
|
|
120
|
+
}
|
|
@@ -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
|
-
|
|
243
|
-
|
|
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
|
-
|
|
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,
|
|
@@ -5,6 +5,7 @@ import { batchCommand, measureCommands } from "./command-batches.js";
|
|
|
5
5
|
import { compareWithBaseline } from "./failure-baseline.js";
|
|
6
6
|
import { collectEnforcementContext, evaluateEnforcement } from "./enforce-policy.js";
|
|
7
7
|
import { inferFullCommand, inferSelectedCommand } from "./full-command.js";
|
|
8
|
+
import { plannedChecks, runChecks } from "./gate-checks.js";
|
|
8
9
|
import { makeGitRunner, observe } from "./observe.js";
|
|
9
10
|
import { captureWorkingTreeSnapshot } from "./working-tree.js";
|
|
10
11
|
export const VERIFICATION_SCHEMA = "diffci.verification.v1";
|
|
@@ -110,7 +111,17 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
110
111
|
const inferred = inferFullCommand(options.repoPath);
|
|
111
112
|
return blocked(before, scope, `no executable verification command is available: ${inferred.reason}`, analysis, counts, boundRange);
|
|
112
113
|
}
|
|
113
|
-
|
|
114
|
+
// The gate's other checks run first and stop at the first failure, as `npm run check && npm test` would:
|
|
115
|
+
// these are the failures agents met only after push (docs/design/pipeline-impact.md).
|
|
116
|
+
const checkBase = scope === "commit-range" ? range?.baseSha : before.baseSha;
|
|
117
|
+
const checkHead = scope === "commit-range" ? range?.headSha : before.commitSha;
|
|
118
|
+
const planned = options.skipChecks ? [] : plannedChecks(options.repoPath, checkBase && checkHead ? { baseSha: checkBase, headSha: checkHead } : undefined);
|
|
119
|
+
const checkRun = options.skipChecks ? undefined : runChecks(planned, { cwd: options.repoPath, timeoutMs: options.timeoutMs, tailBytes: options.tailBytes });
|
|
120
|
+
const checks = checkRun?.results.length ? checkRun.results : undefined;
|
|
121
|
+
const failedCheck = checkRun?.failure?.check;
|
|
122
|
+
const execution = checkRun?.failure
|
|
123
|
+
? checkRun.failure.measurement
|
|
124
|
+
: measureCommands(commands, { cwd: options.repoPath, timeoutMs: Math.max(options.timeoutMs - (checkRun?.wallMs ?? 0), 0), tailBytes: options.tailBytes });
|
|
114
125
|
let after;
|
|
115
126
|
try {
|
|
116
127
|
after = captureWorkingTreeSnapshot(options.repoPath);
|
|
@@ -123,20 +134,23 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
123
134
|
command,
|
|
124
135
|
...(commands.length > 1 ? { commands } : {}),
|
|
125
136
|
execution,
|
|
137
|
+
...(checks ? { checks } : {}),
|
|
126
138
|
};
|
|
127
139
|
}
|
|
128
140
|
const unchanged = before.baseSha === after.baseSha && before.treeSha === after.treeSha;
|
|
129
|
-
const succeeded = execution.exitCode === 0 && !execution.timedOut;
|
|
141
|
+
const succeeded = !failedCheck && execution.exitCode === 0 && !execution.timedOut;
|
|
130
142
|
const verification = !unchanged ? "blocked" : succeeded ? "passed" : "failed";
|
|
131
143
|
const finalReason = !unchanged
|
|
132
144
|
? "the working tree changed while verification was running; rerun DiffCI for the new snapshot"
|
|
133
145
|
: succeeded
|
|
134
|
-
? reason
|
|
135
|
-
:
|
|
136
|
-
? `
|
|
137
|
-
:
|
|
146
|
+
? checks ? `${reason}; ${checkSummary(checks)}` : reason
|
|
147
|
+
: failedCheck
|
|
148
|
+
? `gate check ${failedCheck.id} ${failedCheck.status === "timed_out" ? "timed out" : `failed with exit code ${String(failedCheck.exit_code)}`}; tests were not run (${failedCheck.command})`
|
|
149
|
+
: execution.timedOut
|
|
150
|
+
? `verification timed out after ${options.timeoutMs}ms`
|
|
151
|
+
: `verification command failed with exit code ${String(execution.exitCode)}`;
|
|
138
152
|
const baselineSha = scope === "commit-range" ? range?.baseSha : before.baseSha;
|
|
139
|
-
const failureBaseline = verification === "failed" && !execution.timedOut && options.baselineOnFailure && baselineSha
|
|
153
|
+
const failureBaseline = verification === "failed" && !failedCheck && !execution.timedOut && options.baselineOnFailure && baselineSha
|
|
140
154
|
? compareWithBaseline({ repoPath: options.repoPath, baseSha: baselineSha, headSha: scope === "commit-range" ? before.baseSha : before.commitSha, commands, headFailures: execution.failingTests ?? [], timeoutMs: options.timeoutMs })
|
|
141
155
|
: undefined;
|
|
142
156
|
const baselineNote = failureBaseline && failureBaseline.status !== "unknown"
|
|
@@ -156,6 +170,7 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
|
|
|
156
170
|
command,
|
|
157
171
|
...(commands.length > 1 ? { commands } : {}),
|
|
158
172
|
execution,
|
|
173
|
+
...(checks ? { checks } : {}),
|
|
159
174
|
snapshot: {
|
|
160
175
|
...baseReport(before, scope, boundRange).snapshot,
|
|
161
176
|
after_base_sha: after.baseSha,
|
|
@@ -216,6 +231,7 @@ async function verifyChangedSnapshot(options) {
|
|
|
216
231
|
headOverride: before.commitSha,
|
|
217
232
|
redactPaths: options.redactPaths,
|
|
218
233
|
reportPath: join(temporaryDirectory, "observation.json"),
|
|
234
|
+
selectTestPhases: true,
|
|
219
235
|
});
|
|
220
236
|
return await executeObservation({ ...options, repoPath }, "working-tree", before, observation);
|
|
221
237
|
}
|
|
@@ -251,6 +267,7 @@ async function verifyCommitRange(options) {
|
|
|
251
267
|
headOverride: options.headOverride,
|
|
252
268
|
redactPaths: options.redactPaths,
|
|
253
269
|
reportPath: join(temporaryDirectory, "observation.json"),
|
|
270
|
+
selectTestPhases: true,
|
|
254
271
|
});
|
|
255
272
|
return await executeObservation({ ...options, repoPath }, "commit-range", before, observation);
|
|
256
273
|
}
|
|
@@ -258,6 +275,12 @@ async function verifyCommitRange(options) {
|
|
|
258
275
|
rmSync(temporaryDirectory, { recursive: true, force: true });
|
|
259
276
|
}
|
|
260
277
|
}
|
|
278
|
+
function checkSummary(checks) {
|
|
279
|
+
const ran = checks.filter((check) => check.status === "passed").length;
|
|
280
|
+
const narrowed = checks.filter((check) => check.status === "passed" && check.decision === "NARROWED").length;
|
|
281
|
+
const skipped = checks.length - ran;
|
|
282
|
+
return `ran ${ran} gate check(s) first${narrowed ? ` (${narrowed} narrowed to changed files)` : ""}${skipped ? `, skipped ${skipped} the change does not affect` : ""}`;
|
|
283
|
+
}
|
|
261
284
|
export function verificationExitCode(report) {
|
|
262
285
|
if (report.verification === "passed")
|
|
263
286
|
return 0;
|
|
@@ -276,6 +299,8 @@ export function formatVerificationSummary(report) {
|
|
|
276
299
|
];
|
|
277
300
|
if (report.commit_range)
|
|
278
301
|
lines.splice(2, 0, ` range: ${report.commit_range.base_sha.slice(0, 12)}..${report.commit_range.head_sha.slice(0, 12)}`);
|
|
302
|
+
if (report.checks)
|
|
303
|
+
lines.push(` checks: ${report.checks.map((check) => `${check.id} ${check.status}`).join(", ")}`);
|
|
279
304
|
if (report.command)
|
|
280
305
|
lines.push(` command: ${report.command}`);
|
|
281
306
|
if (report.enforcement) {
|
|
@@ -293,9 +318,19 @@ export function executableSelection(repoPath, result) {
|
|
|
293
318
|
let selection;
|
|
294
319
|
let command;
|
|
295
320
|
let reason;
|
|
321
|
+
let primaryPhases = [];
|
|
296
322
|
if (result.mode === "SELECTIVE" && !result.commandRefusalReason && result.proposedCommands.length === 1) {
|
|
297
323
|
const selected = inferSelectedCommand(repoPath, result.proposedCommands[0], result.selectedTests);
|
|
298
|
-
|
|
324
|
+
const phases = result.testPhases ?? [];
|
|
325
|
+
if (selected.command && phases.length) {
|
|
326
|
+
// The selection covers some changed files only through these test-script phases, so they run
|
|
327
|
+
// after the selected files, as the test script would run them (2026-10-28).
|
|
328
|
+
selection = "selected";
|
|
329
|
+
primaryPhases = phases.map(phaseCommand);
|
|
330
|
+
command = selected.command;
|
|
331
|
+
reason = `dependency impact; also ran ${phases.length} test-script phase(s) that read changed files: ${phases.join("; ")}`;
|
|
332
|
+
}
|
|
333
|
+
else if (selected.command) {
|
|
299
334
|
selection = "selected";
|
|
300
335
|
command = selected.command;
|
|
301
336
|
reason = "dependency impact";
|
|
@@ -336,7 +371,13 @@ export function executableSelection(repoPath, result) {
|
|
|
336
371
|
// Each part stays within the shell's command-line limit (cmd.exe stops at 8,191 characters).
|
|
337
372
|
const commands = command ? [
|
|
338
373
|
...batchCommand(primary ?? command, selection === "selected" ? result.selectedTests : []),
|
|
374
|
+
...primaryPhases,
|
|
339
375
|
...(auxiliaryCommand ? batchCommand(auxiliaryCommand, outside) : []),
|
|
340
376
|
] : [];
|
|
341
377
|
return { selection, command: commands.length ? commands.join(" && ") : command, commands, reason, outsideSuite };
|
|
342
378
|
}
|
|
379
|
+
/** A test-script phase as a standalone command. `npm test` puts `node_modules/.bin` on PATH; outside
|
|
380
|
+
* it a repository-local runner such as tsx is reached the way selected TypeScript tests are. */
|
|
381
|
+
export function phaseCommand(phase) {
|
|
382
|
+
return /^node\s/.test(phase) ? phase : `npx --no-install ${phase}`;
|
|
383
|
+
}
|