@diffci.com/diffci 0.3.55 → 0.3.57

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 (57) hide show
  1. package/dist-client/src/client/cli.js +4 -3
  2. package/dist-client/src/client/context.d.ts +2 -0
  3. package/dist-client/src/client/context.js +19 -0
  4. package/dist-client/src/client/full-command.js +5 -2
  5. package/dist-client/src/client/gate-checks.d.ts +5 -2
  6. package/dist-client/src/client/gate-checks.js +60 -5
  7. package/dist-client/src/client/gate.js +24 -10
  8. package/dist-client/src/client/job-summary.d.ts +1 -1
  9. package/dist-client/src/client/job-summary.js +2 -1
  10. package/dist-client/src/client/observe.js +1 -1
  11. package/dist-client/src/client/report.d.ts +7 -0
  12. package/dist-client/src/client/report.js +11 -0
  13. package/dist-client/src/client/workflow-guard.js +27 -6
  14. package/dist-client/src/client/workflow-templates.d.ts +11 -1
  15. package/dist-client/src/client/workflow-templates.js +43 -2
  16. package/node_modules/@diffci.com/core/README.md +6 -6
  17. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +20 -2
  18. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
  19. package/node_modules/@diffci.com/core/dist/git/git-diff.js +49 -12
  20. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  21. package/node_modules/@diffci.com/core/dist/planner/python-checks.d.ts +55 -0
  22. package/node_modules/@diffci.com/core/dist/planner/python-checks.js +258 -0
  23. package/node_modules/@diffci.com/core/dist/planner/python-checks.js.map +1 -0
  24. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +51 -8
  25. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
  26. package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +111 -14
  27. package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
  28. package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.d.ts +3 -1
  29. package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js +44 -6
  30. package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js.map +1 -1
  31. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +158 -9
  32. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -1
  33. package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +3 -0
  34. package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
  35. package/node_modules/@diffci.com/core/dist/repo/graph.js +1 -1
  36. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  37. package/node_modules/@diffci.com/core/dist/repo/impact.js +5 -1
  38. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  39. package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.d.ts +11 -0
  40. package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js +208 -0
  41. package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js.map +1 -0
  42. package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.d.ts +3 -0
  43. package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js +2 -2
  44. package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js.map +1 -1
  45. package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +20 -2
  46. package/node_modules/@diffci.com/core/src/git/git-diff.ts +44 -12
  47. package/node_modules/@diffci.com/core/src/planner/python-checks.ts +244 -0
  48. package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +55 -8
  49. package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +86 -14
  50. package/node_modules/@diffci.com/core/src/repo/adapters/rust-invocation.ts +44 -6
  51. package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +129 -9
  52. package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +3 -0
  53. package/node_modules/@diffci.com/core/src/repo/graph.ts +1 -1
  54. package/node_modules/@diffci.com/core/src/repo/impact.ts +3 -1
  55. package/node_modules/@diffci.com/core/src/repo/yarn-berry-lockfile.ts +178 -0
  56. package/node_modules/@diffci.com/core/src/repo/yarn-lockfile.ts +2 -2
  57. package/package.json +2 -2
@@ -48,6 +48,7 @@ import { inferFullCommand, inferComparableSelectedCommand, inferWorkspaceCompari
48
48
  import { addDiffciPackageScripts, detectPackageManager, installDiffci } from "./install.js";
49
49
  import { hookCommand, installPrePushHook, isGitRepository, refreshPrePushHook } from "./hook.js";
50
50
  import { AGENT_HOOK_TIMEOUT_SECONDS, ignoredWrites, MCP_CONFIG_PATHS, SKILL_PATHS, writeAgentStopHook, writeMcpConfig, writeSkill } from "./agent-setup.js";
51
+ import { worktreeChangeSuspected } from "./report.js";
51
52
  import { submitObservation } from "./submit.js";
52
53
  import { configureGraphCache } from "./shared-graph-cache.js";
53
54
  import { GraphCache } from "@diffci.com/core/cache/graph-cache";
@@ -65,7 +66,7 @@ import { formatGrowthPrompt, formatVerifySavingsSummary, measureCommand, runVeri
65
66
  import { auditEnforceWorkflows, auditWorkflows, isNonInterfering } from "./workflow-guard.js";
66
67
  import { renderPilotPacket } from "./pilot-packet.js";
67
68
  import { observerIdentity } from "./package-identity.js";
68
- import { buildPilotWorkflow, diffciVerificationWorkflow, diffciWorkflow } from "./workflow-templates.js";
69
+ import { buildPilotWorkflow, diffciVerificationWorkflow, diffciWorkflow, verificationInstallCommands } from "./workflow-templates.js";
69
70
  import { buildMissReport, formatMissReportMarkdown, parseJunit } from "./enforce-misses.js";
70
71
  import { appendOutcome, formatOutcomeSummary, outcomeLogPath, readOutcomes, summarizeOutcomes } from "./outcome-log.js";
71
72
  import { checkPlan } from "./check-plan.js";
@@ -435,7 +436,7 @@ function runInit(flags, env) {
435
436
  if (includeWorkflow)
436
437
  writes.push(writeInitFile(repoPath, ".github/workflows/diffci.yml", diffciWorkflow(identity.version), force));
437
438
  if (includeVerificationWorkflow) {
438
- writes.push(writeInitFile(repoPath, ".github/workflows/diffci-verify.yml", diffciVerificationWorkflow(identity.version), force));
439
+ writes.push(writeInitFile(repoPath, ".github/workflows/diffci-verify.yml", diffciVerificationWorkflow(identity.version, verificationInstallCommands(repoPath)), force));
439
440
  }
440
441
  // The hook, MCP server and skill are on by default so an agent meets DiffCI without being told to.
441
442
  const skipped = [];
@@ -938,7 +939,7 @@ function summarise(report, executionFollows = false) {
938
939
  lines.push(" blind spot: this repository declares a test framework and DiffCI discovered none of its tests");
939
940
  }
940
941
  }
941
- lines.push(` non-interference${executionFollows ? " (analysis phase)" : ""}: worktree ${report.nonInterference.worktreeUnchanged ? "unchanged" : "CHANGED - report this"}, report written ${report.nonInterference.reportWrittenOutsideRepository ? "outside" : "INSIDE"} the checkout`);
942
+ lines.push(` non-interference${executionFollows ? " (analysis phase)" : ""}: worktree ${report.nonInterference.worktreeUnchanged ? "unchanged" : worktreeChangeSuspected(report.nonInterference) ? "CHANGED - report this" : "not a git checkout, nothing to compare"}, report written ${report.nonInterference.reportWrittenOutsideRepository ? "outside" : "INSIDE"} the checkout`);
942
943
  const blocking = report.nonInterference.workflowFindings.filter((f) => f.severity === "BLOCKING");
943
944
  // `check` is a local trial, not an installation, so it names the count and where to look; `observe`
944
945
  // runs inside the installation being judged and keeps every finding in its log.
@@ -1,10 +1,12 @@
1
1
  /** Injected so tests can drive this without a real repository. Returns stdout, or a failure. */
2
+ /** `stderr` is only inspected, never reported: a failed fetch can print a remote URL with credentials. */
2
3
  export type GitRunner = (args: string[]) => {
3
4
  ok: true;
4
5
  stdout: string;
5
6
  } | {
6
7
  ok: false;
7
8
  error: string;
9
+ stderr?: string;
8
10
  };
9
11
  export interface ObservationEnvironment {
10
12
  [key: string]: string | undefined;
@@ -153,6 +153,17 @@ const DEEPEN_HINT = "the commit is not in this checkout - add `fetch-depth: 0` t
153
153
  const GITLAB_DEEPEN_HINT = "the commit is not in this checkout - set `GIT_DEPTH: \"0\"` in the variables of the job that runs DiffCI (this does not affect any other job)";
154
154
  /** Azure Pipelines checks out shallow (`fetchDepth: 1`) by default in pipelines created since 2022. */
155
155
  const AZURE_DEEPEN_HINT = "the commit is not in this checkout - set `fetchDepth: 0` on the `checkout` step of the job that runs DiffCI (this does not affect any other job)";
156
+ /** For a path that is not a git checkout: where the checkout is, not how deep it is (#278). */
157
+ function notACheckoutHint(env) {
158
+ if (env.GITHUB_ACTIONS === "true") {
159
+ return "set the DiffCI Action's `repository-path` (or `--repo`) to the directory actions/checkout cloned into - its `path:` when the checkout step sets one";
160
+ }
161
+ if (env.GITLAB_CI === "true")
162
+ return "run DiffCI in the cloned project directory, or pass `--repo` with that directory";
163
+ if (isAzurePipelines(env))
164
+ return "set the DiffCIObserve task's `repositoryPath` (or `--repo`) to the directory the `checkout` step cloned into - its `path:` when it sets one";
165
+ return "pass `--repo` with the directory of a git checkout";
166
+ }
156
167
  function deepenHint(env) {
157
168
  if (env.GITLAB_CI === "true")
158
169
  return GITLAB_DEEPEN_HINT;
@@ -290,6 +301,14 @@ export function resolveCommitRangeFetchingHistory(options) {
290
301
  if (first.ok)
291
302
  return first;
292
303
  const { env, git } = options;
304
+ // A path that is not a git checkout at all (#278): no history depth fixes that, so the deepen hint
305
+ // would send the user the wrong way. Name the setting that points DiffCI at the checkout instead.
306
+ const inside = git(["rev-parse", "--is-inside-work-tree"]);
307
+ // Only git saying so means "not a checkout": dubious ownership or a missing git binary fail differently.
308
+ if (!inside.ok && !/not a git repository/i.test(inside.stderr ?? ""))
309
+ return first;
310
+ if (!inside.ok || inside.stdout.trim() !== "true")
311
+ return { ok: false, reason: `this path is not a git checkout: ${notACheckoutHint(env)}` };
293
312
  if (env.GITHUB_ACTIONS !== "true" && env.GITLAB_CI !== "true" && !isAzurePipelines(env))
294
313
  return first;
295
314
  const shallow = git(["rev-parse", "--is-shallow-repository"]);
@@ -160,7 +160,10 @@ export function inferFullCommand(repoPath) {
160
160
  }
161
161
  else {
162
162
  const manager = typeof pkg.packageManager === "string" ? pkg.packageManager.split("@")[0] : undefined;
163
- if (manager === "pnpm" || manager === "yarn" || manager === "bun") {
163
+ // `bun test` is Bun's own test runner and ignores scripts.test; `bun run test` runs the script.
164
+ if (manager === "bun")
165
+ return { command: "bun run test", reason: "package.json test script via bun" };
166
+ if (manager === "pnpm" || manager === "yarn") {
164
167
  return { command: `${manager} test`, reason: `package.json test script via ${manager}` };
165
168
  }
166
169
  if (manager && manager !== "npm")
@@ -170,7 +173,7 @@ export function inferFullCommand(repoPath) {
170
173
  if (existsSync(join(repoPath, "yarn.lock")))
171
174
  return { command: "yarn test", reason: "package.json test script with Yarn lockfile" };
172
175
  if (existsSync(join(repoPath, "bun.lock")) || existsSync(join(repoPath, "bun.lockb")))
173
- return { command: "bun test", reason: "package.json test script with Bun lockfile" };
176
+ return { command: "bun run test", reason: "package.json test script with Bun lockfile" };
174
177
  return { command: "npm test", reason: "package.json test script" };
175
178
  }
176
179
  }
@@ -22,13 +22,16 @@ export interface CheckChange {
22
22
  baseSha: string;
23
23
  headSha: string;
24
24
  }
25
+ /** True when `command` names a program on PATH (with PATHEXT on Windows). */
26
+ export declare function onPath(command: string, env?: NodeJS.ProcessEnv, platform?: NodeJS.Platform): boolean;
25
27
  /**
26
28
  * The checks the repository's gate runs besides its tests (2026-10-29, docs/design/pipeline-impact.md).
27
29
  * Agents ran the tests DiffCI selected and then failed `npm run check` after push; these are the rest of
28
30
  * the gate. With a change, per-file lint and format checks are narrowed to its files or skipped
29
31
  * (check-narrowing.ts); if the change cannot be read, every check runs. No package.json, or one that
30
- * cannot be read, has none. `extraRoots` replaces the scripts CI workflows add to the gate, for a caller
31
- * that knows exactly which scripts its build runs (`diffci gate --script`).
32
+ * cannot be read, has no package checks. Python checks that CI workflows run follow them (pythonChecks).
33
+ * `extraRoots` replaces the scripts CI workflows add to the gate, for a caller
34
+ * that knows exactly which scripts its build runs (`diffci gate --script`); it also leaves Python checks out.
32
35
  */
33
36
  export declare function plannedChecks(repoPath: string, change?: CheckChange, options?: {
34
37
  extraRoots?: readonly string[];
@@ -1,22 +1,44 @@
1
1
  import { execFileSync } from "node:child_process";
2
- import { existsSync, readdirSync, readFileSync } from "node:fs";
2
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
3
3
  import { join } from "node:path";
4
4
  import { narrowGateChecks } from "@diffci.com/core/planner/check-narrowing";
5
5
  import { discoverGateChecks, workflowGateScripts } from "@diffci.com/core/planner/pipeline-steps";
6
+ import { discoverPythonChecks, narrowPythonChecks } from "@diffci.com/core/planner/python-checks";
6
7
  import { measureCommand } from "./verify-savings.js";
7
- function workflowTexts(repoPath) {
8
+ function workflowFiles(repoPath) {
8
9
  const dir = join(repoPath, ".github", "workflows");
9
10
  if (!existsSync(dir))
10
11
  return [];
11
12
  return readdirSync(dir).filter((name) => /\.ya?ml$/.test(name)).sort().flatMap((name) => {
12
13
  try {
13
- return [readFileSync(join(dir, name), "utf8")];
14
+ return [{ path: `.github/workflows/${name}`, text: readFileSync(join(dir, name), "utf8") }];
14
15
  }
15
16
  catch {
16
17
  return [];
17
18
  }
18
19
  });
19
20
  }
21
+ function workflowTexts(repoPath) {
22
+ return workflowFiles(repoPath).map((file) => file.text);
23
+ }
24
+ /** True when `command` names a program on PATH (with PATHEXT on Windows). */
25
+ export function onPath(command, env = process.env, platform = process.platform) {
26
+ if (/[\\/]/.test(command))
27
+ return false;
28
+ const windows = platform === "win32";
29
+ const extensions = windows ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean) : [""];
30
+ const pathValue = env.PATH ?? env.Path ?? "";
31
+ for (const dir of pathValue.split(windows ? ";" : ":").filter(Boolean)) {
32
+ for (const extension of windows && !/\.\w+$/.test(command) ? ["", ...extensions] : [""]) {
33
+ try {
34
+ if (statSync(join(dir, command + extension)).isFile())
35
+ return true;
36
+ }
37
+ catch { /* not here */ }
38
+ }
39
+ }
40
+ return false;
41
+ }
20
42
  function packageManager(repoPath, declared) {
21
43
  const name = typeof declared === "string" ? declared.split("@")[0] : undefined;
22
44
  if (name === "pnpm" || name === "yarn" || name === "bun")
@@ -55,10 +77,16 @@ function readRepositoryFile(repoPath, path) {
55
77
  * Agents ran the tests DiffCI selected and then failed `npm run check` after push; these are the rest of
56
78
  * the gate. With a change, per-file lint and format checks are narrowed to its files or skipped
57
79
  * (check-narrowing.ts); if the change cannot be read, every check runs. No package.json, or one that
58
- * cannot be read, has none. `extraRoots` replaces the scripts CI workflows add to the gate, for a caller
59
- * that knows exactly which scripts its build runs (`diffci gate --script`).
80
+ * cannot be read, has no package checks. Python checks that CI workflows run follow them (pythonChecks).
81
+ * `extraRoots` replaces the scripts CI workflows add to the gate, for a caller
82
+ * that knows exactly which scripts its build runs (`diffci gate --script`); it also leaves Python checks out.
60
83
  */
61
84
  export function plannedChecks(repoPath, change, options = {}) {
85
+ const checks = packageChecks(repoPath, change, options);
86
+ // `extraRoots` names exactly the scripts the caller's build runs; workflow-read Python checks would add others.
87
+ return options.extraRoots ? checks : [...checks, ...pythonChecks(repoPath, change)];
88
+ }
89
+ function packageChecks(repoPath, change, options) {
62
90
  const path = join(repoPath, "package.json");
63
91
  if (!existsSync(path))
64
92
  return [];
@@ -94,6 +122,33 @@ export function plannedChecks(repoPath, change, options = {}) {
94
122
  reason: check.reason,
95
123
  }));
96
124
  }
125
+ /**
126
+ * Python checks CI workflows run (`make type-check-core`, `uv run mypy src`; Core python-checks.ts). With a
127
+ * change, Python-only checks are skipped when no Python file or configuration changed. A check whose
128
+ * program is not installed here is skipped with that reason rather than failed: CI still runs it.
129
+ */
130
+ function pythonChecks(repoPath, change) {
131
+ let checks = discoverPythonChecks(workflowFiles(repoPath), (file) => readRepositoryFile(repoPath, file));
132
+ if (checks.length === 0)
133
+ return [];
134
+ if (change) {
135
+ try {
136
+ checks = narrowPythonChecks(checks, changedPaths(repoPath, change));
137
+ }
138
+ catch { /* The change could not be read: every check runs as discovered. */ }
139
+ }
140
+ return checks.map((check) => {
141
+ const program = check.command.split(" ")[0];
142
+ const missing = check.decision !== "SKIP" && !onPath(program);
143
+ return {
144
+ id: check.id,
145
+ kind: check.kind,
146
+ decision: missing ? "SKIP" : check.decision,
147
+ command: check.command,
148
+ reason: missing ? `${check.reason}; \`${program}\` is not installed here, so CI runs it` : check.reason,
149
+ };
150
+ });
151
+ }
97
152
  /** Runs checks in order and stops at the first failure, as the gate's `&&` chain would. SKIP checks
98
153
  * are recorded as skipped and not run. `baseline` reruns a failed check at the base commit; one that
99
154
  * fails there too is recorded in `preexisting` and the run goes on, so a check that was already red
@@ -90,12 +90,19 @@ export async function runGate(options) {
90
90
  const repoPath = resolve(options.repoPath);
91
91
  const run = options.run ?? measureCommand;
92
92
  const started = Date.now();
93
- const remaining = () => Math.max(options.timeoutMs - (Date.now() - started), 0);
94
- const execute = (command) => run(command, { cwd: repoPath, timeoutMs: remaining(), tailBytes: options.tailBytes });
93
+ // The step budget starts after the analysis: a slow analysis must not leave the full gate unrun.
94
+ let stepsStarted = started;
95
+ // A step that would start with no time left is not run: a 0ms timeout would mean no limit at all.
96
+ const execute = (command) => {
97
+ const remaining = options.timeoutMs - (Date.now() - stepsStarted);
98
+ return remaining > 0 ? run(command, { cwd: repoPath, timeoutMs: remaining, tailBytes: options.tailBytes }) : undefined;
99
+ };
100
+ const step = (measurement) => measurement ? stepRun(measurement) : { status: "not_run" };
95
101
  // 1. What DiffCI would do: a plan made elsewhere, or an analysis here. Never fatal: the full gate runs
96
102
  // whatever happens here.
97
103
  const supplied = options.plan !== undefined ? usablePlan(options.plan, options.expectHead) : undefined;
98
104
  const plan = supplied ? supplied.plan : await planGate(options);
105
+ stepsStarted = Date.now();
99
106
  const analysis = plan?.analysis ?? { status: "PLAN_UNUSABLE", reason: supplied?.reason, fallback_reasons: [] };
100
107
  const unplanned = analysis.reason ?? "the change could not be analysed";
101
108
  const analysisMs = supplied?.plan ? 0 : plan?.analysis.duration_ms ?? 0;
@@ -105,7 +112,7 @@ export async function runGate(options) {
105
112
  // 2. The full gate, every leaf, continuing past failures so each one is attributed.
106
113
  const checks = full.map((check) => {
107
114
  const decided = decisionOf.get(check.id);
108
- const measured = stepRun(execute(check.command));
115
+ const measured = step(execute(check.command));
109
116
  return {
110
117
  id: check.id, kind: check.kind,
111
118
  decision: decided?.decision ?? "UNPLANNED",
@@ -119,7 +126,7 @@ export async function runGate(options) {
119
126
  let tests;
120
127
  if (testCommand) {
121
128
  const measurement = execute(testCommand);
122
- const fullRun = { ...stepRun(measurement), ...(measurement.failingTests?.length ? { failing_tests: measurement.failingTests } : {}) };
129
+ const fullRun = { ...step(measurement), ...(measurement?.failingTests?.length ? { failing_tests: measurement.failingTests } : {}) };
123
130
  tests = {
124
131
  command: testCommand, full: fullRun,
125
132
  selection: plan?.tests.selection ?? "unavailable",
@@ -134,27 +141,31 @@ export async function runGate(options) {
134
141
  for (const check of checks) {
135
142
  if (check.full.status === "passed" && !options.measureSelected)
136
143
  continue;
144
+ // A step the time limit left unrun has no result, so it cannot be a miss.
145
+ if (check.full.status === "not_run")
146
+ continue;
137
147
  if (check.decision === "SKIP") {
138
148
  check.missed = check.full.status !== "passed";
139
149
  continue;
140
150
  }
141
151
  if (check.decision !== "NARROWED" || !check.narrowed_command)
142
152
  continue;
143
- check.narrowed = stepRun(execute(check.narrowed_command));
153
+ check.narrowed = step(execute(check.narrowed_command));
144
154
  if (check.full.status !== "passed")
145
155
  check.missed = check.narrowed.status === "passed";
146
156
  }
147
157
  if (tests?.selected_commands && (tests.full.status !== "passed" || options.measureSelected)) {
148
158
  const runs = tests.selected_commands.map((command) => execute(command));
149
- const failed = runs.find((measurement) => stepRun(measurement).status !== "passed");
150
- tests.selected = { ...stepRun(failed ?? runs[runs.length - 1]), wall_ms: runs.reduce((sum, measurement) => sum + measurement.wallMs, 0) };
159
+ const failed = runs.findIndex((measurement) => step(measurement).status !== "passed");
160
+ tests.selected = { ...step(runs[failed >= 0 ? failed : runs.length - 1]), wall_ms: runs.reduce((sum, measurement) => sum + (measurement?.wallMs ?? 0), 0) };
151
161
  if (tests.full.status !== "passed")
152
162
  tests.missed = tests.selected.status === "passed";
153
163
  }
154
164
  // 4. Summary. The build's result is the full gate's, never DiffCI's.
155
165
  const failedSteps = [...checks.filter((check) => check.full.status !== "passed").map((check) => check.id), ...(tests && tests.full.status !== "passed" ? ["tests"] : [])];
156
166
  const fullMs = checks.reduce((sum, check) => sum + (check.full.wall_ms ?? 0), 0) + (tests?.full.wall_ms ?? 0);
157
- let estimated = false;
167
+ // A step the time limit left unrun has no time in either total, so the comparison is not fully measured.
168
+ let estimated = checks.some((check) => check.full.status === "not_run") || tests?.full.status === "not_run";
158
169
  let diffciMs = analysisMs;
159
170
  for (const check of checks) {
160
171
  if (check.decision === "SKIP")
@@ -201,6 +212,9 @@ export function gateExitCode(report) {
201
212
  return report.gate.status === "passed" ? 0 : 1;
202
213
  }
203
214
  const seconds = (ms) => `${(ms / 1000).toFixed(1)}s`;
215
+ /** A step the time limit left unrun did not fail; it reads as not run, and the gate's reason says it failed. */
216
+ const stepLabel = (status) => status === "passed" ? "ok " : status === "not_run" ? "-- " : "FAIL";
217
+ const notRun = (status) => status === "not_run" ? " (not run)" : "";
204
218
  export function formatGateSummary(report) {
205
219
  const lines = [
206
220
  `DiffCI gate (observe): ${report.gate.status.toUpperCase()} - ${report.gate.reason}`,
@@ -208,12 +222,12 @@ export function formatGateSummary(report) {
208
222
  ` analysis: ${report.analysis.status}${report.analysis.mode ? ` (${report.analysis.mode})` : ""}${report.analysis.reason ? ` - ${report.analysis.reason}` : ""}`,
209
223
  ];
210
224
  for (const check of report.checks) {
211
- lines.push(` ${check.full.status === "passed" ? "ok " : "FAIL"} ${check.id} ${seconds(check.full.wall_ms ?? 0)} - DiffCI: ${check.decision}${check.missed ? " (MISSED)" : ""}`);
225
+ lines.push(` ${stepLabel(check.full.status)} ${check.id} ${seconds(check.full.wall_ms ?? 0)}${notRun(check.full.status)} - DiffCI: ${check.decision}${check.missed ? " (MISSED)" : ""}`);
212
226
  }
213
227
  if (report.tests) {
214
228
  const t = report.tests;
215
229
  const scope = t.selection === "selected" ? `${t.tests_selected}/${t.tests_available} test files` : t.selection;
216
- lines.push(` ${t.full.status === "passed" ? "ok " : "FAIL"} tests ${seconds(t.full.wall_ms ?? 0)} - DiffCI: ${scope}${t.missed ? " (MISSED)" : ""}`);
230
+ lines.push(` ${stepLabel(t.full.status)} tests ${seconds(t.full.wall_ms ?? 0)}${notRun(t.full.status)} - DiffCI: ${scope}${t.missed ? " (MISSED)" : ""}`);
217
231
  }
218
232
  const s = report.summary;
219
233
  lines.push(` full gate ${seconds(s.full_ms)}, DiffCI ${seconds(s.diffci_ms)} (${s.basis}), would save ${seconds(s.saved_ms)}`);
@@ -1,4 +1,4 @@
1
- import type { ObservationReport } from "./report.js";
1
+ import { type ObservationReport } from "./report.js";
2
2
  /**
3
3
  * The GitHub job summary for `diffci observe`: the place most people will ever read a report, so it
4
4
  * leads with the answer (what this change affects) and keeps the full text summary one click away.
@@ -1,3 +1,4 @@
1
+ import { worktreeChangeSuspected } from "./report.js";
1
2
  /** Selected tests listed by name before the rest collapse into a count. */
2
3
  const MAX_LISTED_TESTS = 20;
3
4
  /** Inline code that survives any path: no backticks to close it early, no pipes to split a table cell. */
@@ -65,7 +66,7 @@ export function formatJobSummary(report, textSummary, delivery) {
65
66
  }
66
67
  // A broken promise of non-interference is the one thing that must never hide in a collapsed block.
67
68
  const blocking = report.nonInterference.workflowFindings.filter((finding) => finding.severity === "BLOCKING");
68
- if (!report.nonInterference.worktreeUnchanged) {
69
+ if (worktreeChangeSuspected(report.nonInterference)) {
69
70
  lines.push("", "> [!WARNING]", "> The working tree changed while DiffCI observed it. Please report this at https://github.com/DiffCI/core/issues.");
70
71
  }
71
72
  if (blocking.length > 0) {
@@ -43,7 +43,7 @@ export function makeGitRunner(repoPath) {
43
43
  return { ok: true, stdout };
44
44
  }
45
45
  catch (error) {
46
- return { ok: false, error: error.message.split("\n")[0] ?? "git failed" };
46
+ return { ok: false, error: error.message.split("\n")[0] ?? "git failed", stderr: String(error.stderr ?? "") };
47
47
  }
48
48
  };
49
49
  }
@@ -93,6 +93,13 @@ export interface NonInterferenceEvidence {
93
93
  /** Findings from the workflow guard (src/client/workflow-guard.ts), embedded on every run. */
94
94
  workflowFindings: WorkflowFinding[];
95
95
  }
96
+ /**
97
+ * Whether the evidence shows the observer may have changed the checkout: a before/after pair differs,
98
+ * or evidence captured before is missing after. With no evidence at all - the path is not a git
99
+ * checkout, so the observation refused - there was nothing to change and nothing to report (#278).
100
+ * This only decides what is shown; `worktreeUnchanged` stays false, so such a run never narrows.
101
+ */
102
+ export declare function worktreeChangeSuspected(evidence: Pick<NonInterferenceEvidence, "headShaBefore" | "headShaAfter" | "worktreeDigestBefore" | "worktreeDigestAfter" | "worktreeUnchanged">): boolean;
96
103
  export type WorkflowFindingSeverity = "BLOCKING" | "WARNING" | "INFO";
97
104
  export interface WorkflowFinding {
98
105
  severity: WorkflowFindingSeverity;
@@ -19,6 +19,17 @@
19
19
  */
20
20
  /** Wire identifier. Consumers MUST reject a document whose `schema` they do not recognise. */
21
21
  export const OBSERVATION_SCHEMA = "diffci.observation.v1";
22
+ /**
23
+ * Whether the evidence shows the observer may have changed the checkout: a before/after pair differs,
24
+ * or evidence captured before is missing after. With no evidence at all - the path is not a git
25
+ * checkout, so the observation refused - there was nothing to change and nothing to report (#278).
26
+ * This only decides what is shown; `worktreeUnchanged` stays false, so such a run never narrows.
27
+ */
28
+ export function worktreeChangeSuspected(evidence) {
29
+ if (evidence.worktreeUnchanged)
30
+ return false;
31
+ return [evidence.headShaBefore, evidence.headShaAfter, evidence.worktreeDigestBefore, evidence.worktreeDigestAfter].some((value) => value !== undefined);
32
+ }
22
33
  /** Optional, additive metrics; unknown or incomplete core telemetry stays absent. */
23
34
  export function readTypeScriptProgramMetrics(value) {
24
35
  if (!value || typeof value !== "object" || Array.isArray(value))
@@ -366,13 +366,33 @@ const ENFORCE_VARIABLE_EXPRESSION = /^\$\{\{\s*vars\.DIFFCI_ENFORCE\s*\}\}$/;
366
366
  function runInvokesEnforcePolicy(run) {
367
367
  return runInvokesDiffCiVerification(run) && /--policy[=\s]+["']?enforce\b/.test(commandText(run));
368
368
  }
369
- /** `npm run test` and `npm test` are the same command; so are the pnpm/yarn/bun pairs. */
369
+ /**
370
+ * `npm run test` and `npm test` are the same command; so are the pnpm and yarn pairs. Bun's are not:
371
+ * `bun test` starts Bun's own test runner and never reads scripts.test, so only `bun run test` is the
372
+ * test script.
373
+ */
370
374
  function normalizeTestCommand(command) {
371
- return command.trim().replace(/\s+/g, " ").replace(/^(npm|pnpm|yarn|bun) run test$/, "$1 test");
375
+ return command.trim().replace(/\s+/g, " ").replace(/^(npm|pnpm|yarn) run test$/, "$1 test");
376
+ }
377
+ function runInvokesFullCommand(run, fullCommands) {
378
+ const targets = new Set(fullCommands.map(normalizeTestCommand));
379
+ return commandText(run).split("\n").some((line) => targets.has(normalizeTestCommand(line)));
372
380
  }
373
- function runInvokesFullCommand(run, fullCommand) {
374
- const target = normalizeTestCommand(fullCommand);
375
- return commandText(run).split("\n").some((line) => normalizeTestCommand(line) === target);
381
+ /**
382
+ * `bun run test` runs scripts.test. When that script is exactly `bun test`, a workflow step that runs
383
+ * `bun test` directly runs the same suite, so it counts as the full command too.
384
+ */
385
+ function bunScriptEquivalents(repoPath, fullCommand) {
386
+ if (normalizeTestCommand(fullCommand) !== "bun run test")
387
+ return [];
388
+ try {
389
+ const pkg = JSON.parse(readFileSync(join(repoPath, "package.json"), "utf8"));
390
+ const script = pkg.scripts?.test;
391
+ return typeof script === "string" && normalizeTestCommand(script) === "bun test" ? ["bun test"] : [];
392
+ }
393
+ catch {
394
+ return [];
395
+ }
376
396
  }
377
397
  function globToRegExp(glob) {
378
398
  const pattern = glob
@@ -523,6 +543,7 @@ export function auditEnforceWorkflows(repoPath, options = {}) {
523
543
  const unprovable = [];
524
544
  const inferred = options.fullCommand ? { command: options.fullCommand, reason: "--full-command" } : inferFullCommand(repoPath);
525
545
  const fullCommand = inferred.command;
546
+ const fullCommands = fullCommand ? [fullCommand, ...bunScriptEquivalents(repoPath, fullCommand)] : [];
526
547
  if (!fullCommand) {
527
548
  findings.push({
528
549
  severity: "BLOCKING",
@@ -577,7 +598,7 @@ export function auditEnforceWorkflows(repoPath, options = {}) {
577
598
  if (jobCondition === "FALSE")
578
599
  continue;
579
600
  for (const step of steps) {
580
- if (typeof step.run !== "string" || !runInvokesFullCommand(step.run, fullCommand))
601
+ if (typeof step.run !== "string" || !runInvokesFullCommand(step.run, fullCommands))
581
602
  continue;
582
603
  if (step["working-directory"] !== undefined && step["working-directory"] !== ".")
583
604
  continue;
@@ -1,8 +1,18 @@
1
+ import { type SupportedPackageManager } from "./install.js";
1
2
  /** GitHub-hosted runner and Node 24 action pins shared by every workflow the CLI generates. */
2
3
  export declare const RUNNER = "ubuntu-26.04";
3
4
  export declare const CHECKOUT_SHA = "3d3c42e5aac5ba805825da76410c181273ba90b1";
4
5
  export declare const SETUP_NODE_SHA = "949feb2413d6458794dcd2491c4babbbce0c15c1";
5
6
  export declare const UPLOAD_ARTIFACT_SHA = "cf430e030ddbb5b0abf93d22962f4752f3646cd9";
6
7
  export declare function diffciWorkflow(version: string): string;
7
- export declare function diffciVerificationWorkflow(version: string): string;
8
+ /**
9
+ * The commands that install a JavaScript repository's dependencies in CI, for the verification workflow:
10
+ * verify runs the repository's tests, which a fresh checkout cannot run before its dependencies are
11
+ * installed (every receipt then fails, 2026-11-18). Empty when the package manager is not known, or is
12
+ * Bun, which needs a setup action this template does not pin.
13
+ */
14
+ export declare function dependencyInstallCommands(manager: SupportedPackageManager | undefined, hasLockfile: boolean, yarnBerry?: boolean): string[];
15
+ /** How the verification workflow installs `repoPath`'s dependencies before verify runs its tests. */
16
+ export declare function verificationInstallCommands(repoPath: string): string[];
17
+ export declare function diffciVerificationWorkflow(version: string, installCommands?: readonly string[]): string;
8
18
  export declare function buildPilotWorkflow(version: string): string;
@@ -1,3 +1,6 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { detectPackageManager } from "./install.js";
1
4
  /** GitHub-hosted runner and Node 24 action pins shared by every workflow the CLI generates. */
2
5
  export const RUNNER = "ubuntu-26.04";
3
6
  export const CHECKOUT_SHA = "3d3c42e5aac5ba805825da76410c181273ba90b1"; // actions/checkout v7.0.1
@@ -22,7 +25,45 @@ jobs:
22
25
  - run: npx "@diffci.com/diffci@${version}" observe --no-send
23
26
  `;
24
27
  }
25
- export function diffciVerificationWorkflow(version) {
28
+ /**
29
+ * The commands that install a JavaScript repository's dependencies in CI, for the verification workflow:
30
+ * verify runs the repository's tests, which a fresh checkout cannot run before its dependencies are
31
+ * installed (every receipt then fails, 2026-11-18). Empty when the package manager is not known, or is
32
+ * Bun, which needs a setup action this template does not pin.
33
+ */
34
+ export function dependencyInstallCommands(manager, hasLockfile, yarnBerry = false) {
35
+ // pnpm and Yarn 2+ install frozen by default in CI, which fails without a lockfile; Yarn 2+ spells it --immutable.
36
+ switch (manager) {
37
+ case "npm": return [hasLockfile ? "npm ci" : "npm install"];
38
+ case "pnpm": return ["corepack enable", hasLockfile ? "pnpm install --frozen-lockfile" : "pnpm install --no-frozen-lockfile"];
39
+ case "yarn": return ["corepack enable", yarnBerry ? (hasLockfile ? "yarn install --immutable" : "yarn install --no-immutable") : hasLockfile ? "yarn install --frozen-lockfile" : "yarn install"];
40
+ default: return [];
41
+ }
42
+ }
43
+ /** How the verification workflow installs `repoPath`'s dependencies before verify runs its tests. */
44
+ export function verificationInstallCommands(repoPath) {
45
+ if (!existsSync(join(repoPath, "package.json")))
46
+ return [];
47
+ let manager;
48
+ try {
49
+ manager = detectPackageManager(repoPath);
50
+ }
51
+ catch {
52
+ return [];
53
+ }
54
+ const lockfiles = manager === "pnpm" ? ["pnpm-lock.yaml"] : manager === "yarn" ? ["yarn.lock"] : ["package-lock.json", "npm-shrinkwrap.json"];
55
+ const hasLockfile = lockfiles.some((name) => existsSync(join(repoPath, name)));
56
+ const yarnBerry = existsSync(join(repoPath, ".yarnrc.yml")) || /"packageManager"\s*:\s*"yarn@(?!1\.)/.test(readFileSync(join(repoPath, "package.json"), "utf8"));
57
+ return dependencyInstallCommands(manager, hasLockfile, yarnBerry);
58
+ }
59
+ function installStep(commands) {
60
+ if (commands.length === 0) {
61
+ return " # Install the repository's dependencies here: verify runs its tests.\n";
62
+ }
63
+ const run = commands.length === 1 ? ` ${commands[0]}` : ` |\n${commands.map((command) => ` ${command}`).join("\n")}`;
64
+ return ` - name: Install dependencies\n run:${run}\n`;
65
+ }
66
+ export function diffciVerificationWorkflow(version, installCommands = []) {
26
67
  return `name: DiffCI verification
27
68
  on: [push, pull_request]
28
69
  permissions:
@@ -39,7 +80,7 @@ jobs:
39
80
  - uses: actions/setup-node@${SETUP_NODE_SHA} # immutable setup-node pin
40
81
  with:
41
82
  node-version: 22
42
- - name: Verify changed code
83
+ ${installStep(installCommands)} - name: Verify changed code
43
84
  run: npx "@diffci.com/diffci@${version}" verify --json --out "$RUNNER_TEMP/diffci-verification.json"
44
85
  - name: Upload verification receipt
45
86
  if: always()