@diffci.com/diffci 0.3.54 → 0.3.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist-client/src/client/agent-selection.d.ts +9 -2
  2. package/dist-client/src/client/agent-selection.js +20 -8
  3. package/dist-client/src/client/agent-setup.js +1 -1
  4. package/dist-client/src/client/cli.js +19 -7
  5. package/dist-client/src/client/command-batches.js +3 -2
  6. package/dist-client/src/client/context.d.ts +2 -0
  7. package/dist-client/src/client/context.js +51 -2
  8. package/dist-client/src/client/coverage-map.js +6 -1
  9. package/dist-client/src/client/full-command.js +22 -14
  10. package/dist-client/src/client/gate.js +24 -10
  11. package/dist-client/src/client/hook.d.ts +17 -0
  12. package/dist-client/src/client/hook.js +53 -1
  13. package/dist-client/src/client/install.d.ts +6 -0
  14. package/dist-client/src/client/install.js +29 -1
  15. package/dist-client/src/client/job-summary.d.ts +1 -1
  16. package/dist-client/src/client/job-summary.js +2 -1
  17. package/dist-client/src/client/mcp.js +4 -0
  18. package/dist-client/src/client/observe.js +4 -3
  19. package/dist-client/src/client/report.d.ts +8 -1
  20. package/dist-client/src/client/report.js +11 -0
  21. package/dist-client/src/client/shared-graph-cache.js +4 -2
  22. package/dist-client/src/client/telemetry.js +2 -1
  23. package/dist-client/src/client/usage-signal.d.ts +1 -1
  24. package/dist-client/src/client/verify-savings.d.ts +6 -0
  25. package/dist-client/src/client/verify-savings.js +15 -3
  26. package/dist-client/src/client/verify.js +124 -22
  27. package/dist-client/src/client/workflow-guard.js +27 -6
  28. package/dist-client/src/client/workflow-templates.d.ts +11 -1
  29. package/dist-client/src/client/workflow-templates.js +43 -2
  30. package/node_modules/@diffci.com/core/README.md +17 -10
  31. package/node_modules/@diffci.com/core/dist/ci-inference/expression.d.ts +5 -0
  32. package/node_modules/@diffci.com/core/dist/ci-inference/expression.js +38 -5
  33. package/node_modules/@diffci.com/core/dist/ci-inference/expression.js.map +1 -1
  34. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js +26 -6
  35. package/node_modules/@diffci.com/core/dist/ci-inference/infer.js.map +1 -1
  36. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.d.ts +2 -1
  37. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js +7 -2
  38. package/node_modules/@diffci.com/core/dist/ci-inference/jobs.js.map +1 -1
  39. package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js +15 -8
  40. package/node_modules/@diffci.com/core/dist/ci-inference/matrix.js.map +1 -1
  41. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js +6 -2
  42. package/node_modules/@diffci.com/core/dist/ci-inference/purpose.js.map +1 -1
  43. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js +38 -5
  44. package/node_modules/@diffci.com/core/dist/ci-inference/resolve.js.map +1 -1
  45. package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js +13 -1
  46. package/node_modules/@diffci.com/core/dist/git/ci-config-paths.js.map +1 -1
  47. package/node_modules/@diffci.com/core/dist/git/git-diff.d.ts +5 -0
  48. package/node_modules/@diffci.com/core/dist/git/git-diff.js +64 -31
  49. package/node_modules/@diffci.com/core/dist/git/git-diff.js.map +1 -1
  50. package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js +22 -1
  51. package/node_modules/@diffci.com/core/dist/planner/check-narrowing.js.map +1 -1
  52. package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.d.ts +6 -0
  53. package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js +14 -2
  54. package/node_modules/@diffci.com/core/dist/planner/pipeline-steps.js.map +1 -1
  55. package/node_modules/@diffci.com/core/dist/planner/planner.js +65 -14
  56. package/node_modules/@diffci.com/core/dist/planner/planner.js.map +1 -1
  57. package/node_modules/@diffci.com/core/dist/planner/rust-command.js +43 -1
  58. package/node_modules/@diffci.com/core/dist/planner/rust-command.js.map +1 -1
  59. package/node_modules/@diffci.com/core/dist/planner/script-reads.js +5 -2
  60. package/node_modules/@diffci.com/core/dist/planner/script-reads.js.map +1 -1
  61. package/node_modules/@diffci.com/core/dist/planner/test-command.js +17 -2
  62. package/node_modules/@diffci.com/core/dist/planner/test-command.js.map +1 -1
  63. package/node_modules/@diffci.com/core/dist/planner/type-program.js +27 -1
  64. package/node_modules/@diffci.com/core/dist/planner/type-program.js.map +1 -1
  65. package/node_modules/@diffci.com/core/dist/repo/adapters/go.js +5 -1
  66. package/node_modules/@diffci.com/core/dist/repo/adapters/go.js.map +1 -1
  67. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js +71 -9
  68. package/node_modules/@diffci.com/core/dist/repo/adapters/maven.js.map +1 -1
  69. package/node_modules/@diffci.com/core/dist/repo/adapters/python.d.ts +9 -1
  70. package/node_modules/@diffci.com/core/dist/repo/adapters/python.js +259 -18
  71. package/node_modules/@diffci.com/core/dist/repo/adapters/python.js.map +1 -1
  72. package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.d.ts +3 -1
  73. package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js +44 -6
  74. package/node_modules/@diffci.com/core/dist/repo/adapters/rust-invocation.js.map +1 -1
  75. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.d.ts +1 -0
  76. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js +338 -24
  77. package/node_modules/@diffci.com/core/dist/repo/adapters/rust.js.map +1 -1
  78. package/node_modules/@diffci.com/core/dist/repo/adapters/types.d.ts +10 -0
  79. package/node_modules/@diffci.com/core/dist/repo/adapters/types.js.map +1 -1
  80. package/node_modules/@diffci.com/core/dist/repo/file-references.d.ts +16 -0
  81. package/node_modules/@diffci.com/core/dist/repo/file-references.js +76 -5
  82. package/node_modules/@diffci.com/core/dist/repo/file-references.js.map +1 -1
  83. package/node_modules/@diffci.com/core/dist/repo/graph.js +101 -30
  84. package/node_modules/@diffci.com/core/dist/repo/graph.js.map +1 -1
  85. package/node_modules/@diffci.com/core/dist/repo/impact.d.ts +7 -0
  86. package/node_modules/@diffci.com/core/dist/repo/impact.js +56 -9
  87. package/node_modules/@diffci.com/core/dist/repo/impact.js.map +1 -1
  88. package/node_modules/@diffci.com/core/dist/repo/layout.js +4 -1
  89. package/node_modules/@diffci.com/core/dist/repo/layout.js.map +1 -1
  90. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js +10 -1
  91. package/node_modules/@diffci.com/core/dist/repo/runner-universe.js.map +1 -1
  92. package/node_modules/@diffci.com/core/dist/repo/script-universe.js +1 -1
  93. package/node_modules/@diffci.com/core/dist/repo/script-universe.js.map +1 -1
  94. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js +5 -1
  95. package/node_modules/@diffci.com/core/dist/repo/test-discovery.js.map +1 -1
  96. package/node_modules/@diffci.com/core/dist/repo/types.d.ts +3 -0
  97. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js +3 -3
  98. package/node_modules/@diffci.com/core/dist/repo/workflow-test-steps.js.map +1 -1
  99. package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.d.ts +11 -0
  100. package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js +208 -0
  101. package/node_modules/@diffci.com/core/dist/repo/yarn-berry-lockfile.js.map +1 -0
  102. package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.d.ts +3 -0
  103. package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js +2 -2
  104. package/node_modules/@diffci.com/core/dist/repo/yarn-lockfile.js.map +1 -1
  105. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js +65 -13
  106. package/node_modules/@diffci.com/core/dist/research/baseline/matcher.js.map +1 -1
  107. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js +47 -2
  108. package/node_modules/@diffci.com/core/dist/research/baseline/workflow-parser.js.map +1 -1
  109. package/node_modules/@diffci.com/core/package.json +1 -0
  110. package/node_modules/@diffci.com/core/src/ci-inference/expression.ts +38 -5
  111. package/node_modules/@diffci.com/core/src/ci-inference/infer.ts +21 -6
  112. package/node_modules/@diffci.com/core/src/ci-inference/jobs.ts +7 -2
  113. package/node_modules/@diffci.com/core/src/ci-inference/matrix.ts +15 -8
  114. package/node_modules/@diffci.com/core/src/ci-inference/purpose.ts +6 -2
  115. package/node_modules/@diffci.com/core/src/ci-inference/resolve.ts +37 -5
  116. package/node_modules/@diffci.com/core/src/git/ci-config-paths.ts +8 -1
  117. package/node_modules/@diffci.com/core/src/git/git-diff.ts +57 -32
  118. package/node_modules/@diffci.com/core/src/planner/check-narrowing.ts +22 -1
  119. package/node_modules/@diffci.com/core/src/planner/pipeline-steps.ts +13 -2
  120. package/node_modules/@diffci.com/core/src/planner/planner.ts +42 -14
  121. package/node_modules/@diffci.com/core/src/planner/rust-command.ts +37 -1
  122. package/node_modules/@diffci.com/core/src/planner/script-reads.ts +5 -1
  123. package/node_modules/@diffci.com/core/src/planner/test-command.ts +17 -2
  124. package/node_modules/@diffci.com/core/src/planner/type-program.ts +25 -1
  125. package/node_modules/@diffci.com/core/src/repo/adapters/go.ts +5 -1
  126. package/node_modules/@diffci.com/core/src/repo/adapters/maven.ts +74 -9
  127. package/node_modules/@diffci.com/core/src/repo/adapters/python.ts +209 -18
  128. package/node_modules/@diffci.com/core/src/repo/adapters/rust-invocation.ts +44 -6
  129. package/node_modules/@diffci.com/core/src/repo/adapters/rust.ts +264 -24
  130. package/node_modules/@diffci.com/core/src/repo/adapters/types.ts +10 -1
  131. package/node_modules/@diffci.com/core/src/repo/file-references.ts +70 -5
  132. package/node_modules/@diffci.com/core/src/repo/graph.ts +82 -21
  133. package/node_modules/@diffci.com/core/src/repo/impact.ts +57 -8
  134. package/node_modules/@diffci.com/core/src/repo/layout.ts +5 -1
  135. package/node_modules/@diffci.com/core/src/repo/runner-universe.ts +11 -1
  136. package/node_modules/@diffci.com/core/src/repo/script-universe.ts +1 -1
  137. package/node_modules/@diffci.com/core/src/repo/test-discovery.ts +4 -1
  138. package/node_modules/@diffci.com/core/src/repo/types.ts +3 -1
  139. package/node_modules/@diffci.com/core/src/repo/workflow-test-steps.ts +3 -3
  140. package/node_modules/@diffci.com/core/src/repo/yarn-berry-lockfile.ts +178 -0
  141. package/node_modules/@diffci.com/core/src/repo/yarn-lockfile.ts +2 -2
  142. package/node_modules/@diffci.com/core/src/research/baseline/matcher.ts +43 -13
  143. package/node_modules/@diffci.com/core/src/research/baseline/workflow-parser.ts +44 -2
  144. package/package.json +2 -2
@@ -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) {
@@ -227,6 +227,10 @@ async function handle(request) {
227
227
  return;
228
228
  case "notifications/initialized":
229
229
  return;
230
+ // Either side may ping at any time, before or after initialization; the answer is an empty result.
231
+ case "ping":
232
+ success(id, {});
233
+ return;
230
234
  case "tools/list":
231
235
  success(id, { tools });
232
236
  return;
@@ -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
  }
@@ -91,7 +91,8 @@ export async function observe(options) {
91
91
  const repoPath = resolve(options.repoPath);
92
92
  const git = options.git ?? makeGitRunner(repoPath);
93
93
  const ci = readCiEnvironment(options.env);
94
- const [owner, name] = (ci.ownerName ?? "").split("/");
94
+ // GitLab's CI_PROJECT_PATH may name subgroups (group/sub/project): keep every segment, not the first two.
95
+ const ownerName = ci.ownerName && /^[^/]+(?:\/[^/]+)+$/.test(ci.ownerName) ? ci.ownerName : undefined;
95
96
  const before = { head: headSha(git), worktree: worktreeDigest(git) };
96
97
  const hashPath = (path) => (options.redactPaths ? redactPath(path, sha256) : path);
97
98
  // Declared before `finish` closes over it: the range is part of every report, including the reports
@@ -124,7 +125,7 @@ export async function observe(options) {
124
125
  },
125
126
  repository: {
126
127
  provider: ci.provider === "github-actions" ? "github" : ci.provider === "gitlab-ci" ? "gitlab" : "unknown",
127
- ownerName: owner && name ? `${owner}/${name}` : undefined,
128
+ ownerName,
128
129
  defaultBranch: ci.defaultBranch,
129
130
  providerRepositoryId: ci.providerRepositoryId,
130
131
  },
@@ -37,7 +37,7 @@ export interface ObservationCommitRange {
37
37
  }
38
38
  export interface ObservationRepository {
39
39
  provider: "github" | "gitlab" | "unknown";
40
- /** "owner/name". The only repository identifier sent; never a URL carrying a token. */
40
+ /** "owner/name", or GitLab's full "group/subgroup/name" path. The only repository identifier sent; never a URL carrying a token. */
41
41
  ownerName?: string;
42
42
  defaultBranch?: string;
43
43
  /** GitHub's numeric repository id when the environment supplies it - survives a rename. */
@@ -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))
@@ -327,14 +327,16 @@ export function configureGraphCache(input) {
327
327
  if (input.shared) {
328
328
  const baseUrl = resolveSharedGraphCacheBaseUrl({ cacheUrl: input.cacheUrl, apiUrl: input.apiUrl });
329
329
  const secret = input.secret && input.secret.length >= 16 ? input.secret : undefined;
330
- if (input.secret && !secret)
331
- notes.push("DIFFCI_GRAPH_CACHE_SECRET ignored: it must be at least 16 characters");
332
330
  if (input.noSend)
333
331
  notes.push("shared graph cache off: --no-send");
334
332
  else if (!baseUrl)
335
333
  notes.push("shared graph cache off: no https api-url or graph-cache-url");
336
334
  else if (!input.token)
337
335
  notes.push("shared graph cache off: no api-token");
336
+ // A secret that is set asks for encryption: one too short to use must not fall back to plaintext uploads.
337
+ // An empty value counts as set: `DIFFCI_GRAPH_CACHE_SECRET: ${{ secrets.X }}` is empty when X is missing.
338
+ else if (input.secret !== undefined && !secret)
339
+ notes.push("shared graph cache off: DIFFCI_GRAPH_CACHE_SECRET must be at least 16 characters");
338
340
  else if (input.redactPaths && !secret)
339
341
  notes.push("shared graph cache off: --redact-paths needs DIFFCI_GRAPH_CACHE_SECRET, because the graph carries file paths");
340
342
  else
@@ -96,7 +96,8 @@ export function repositoryName(repoPath, env) {
96
96
  function surfaceOf(env) {
97
97
  if (env.DIFFCI_MCP === "1")
98
98
  return "local-mcp";
99
- if (env.DIFFCI_SURFACE === "github-action" || env.DIFFCI_SURFACE === "gitlab-component")
99
+ // Each CI wrapper sets its own value: action/, integrations/gitlab and integrations/azure-devops (#303).
100
+ if (env.DIFFCI_SURFACE === "github-action" || env.DIFFCI_SURFACE === "gitlab-component" || env.DIFFCI_SURFACE === "azure-devops-task")
100
101
  return env.DIFFCI_SURFACE;
101
102
  return "cli";
102
103
  }
@@ -1,7 +1,7 @@
1
1
  /** Best-effort usage signal. Carries a repository name only when given one; never content, paths or machine details. */
2
2
  export type UsageCommand = "check" | "observe" | "verify" | "plan";
3
3
  export type UsageOutcome = "observed" | "refused" | "error" | "passed" | "failed" | "blocked" | "selective" | "full";
4
- export type UsageSurface = "cli" | "local-mcp" | "github-action" | "gitlab-component";
4
+ export type UsageSurface = "cli" | "local-mcp" | "github-action" | "gitlab-component" | "azure-devops-task";
5
5
  export interface UsageSignal {
6
6
  command: UsageCommand;
7
7
  outcome: UsageOutcome;
@@ -165,6 +165,12 @@ interface ResolvedSelection {
165
165
  observationSha256?: string;
166
166
  observerVersion?: string;
167
167
  }
168
+ /**
169
+ * At most the last `bytes` bytes of `value`, cut at a character boundary. `bytes` 0 keeps nothing:
170
+ * `value.slice(-0)` is the whole string, so `--tail-bytes 0` used to keep the entire output, and a
171
+ * multi-byte tail was cut by characters, not bytes.
172
+ */
173
+ export declare function tail(value: string, bytes: number): string;
168
174
  export declare function measureCommand(command: string, options: Pick<VerifySavingsOptions, "cwd" | "timeoutMs" | "tailBytes"> & {
169
175
  env?: Record<string, string>;
170
176
  }): CommandMeasurement;
@@ -8,10 +8,22 @@ import { windowsLaunch, withPathEntry } from "./node-bin-launch.js";
8
8
  import { runnerTestCount } from "./selected-coverage.js";
9
9
  import { parseTestFileResults } from "./test-results.js";
10
10
  import { classifyFailureFromEvidence, computeFailureFingerprint } from "../preflight/fingerprint.js";
11
- function tail(value, bytes) {
12
- if (Buffer.byteLength(value, "utf8") <= bytes)
11
+ /**
12
+ * At most the last `bytes` bytes of `value`, cut at a character boundary. `bytes` 0 keeps nothing:
13
+ * `value.slice(-0)` is the whole string, so `--tail-bytes 0` used to keep the entire output, and a
14
+ * multi-byte tail was cut by characters, not bytes.
15
+ */
16
+ export function tail(value, bytes) {
17
+ if (!(bytes > 0))
18
+ return "";
19
+ const buffer = Buffer.from(value, "utf8");
20
+ if (buffer.length <= bytes)
13
21
  return value;
14
- return value.slice(-bytes);
22
+ let start = buffer.length - Math.floor(bytes);
23
+ // Skip UTF-8 continuation bytes so the tail never starts inside a character.
24
+ while (start < buffer.length && (buffer[start] & 0xc0) === 0x80)
25
+ start++;
26
+ return buffer.subarray(start).toString("utf8");
15
27
  }
16
28
  function readSelectionFromObservation(path, override) {
17
29
  const absolutePath = resolve(path);
@@ -1,4 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { commandSpecToString, nodeTestGlobForPath } from "@diffci.com/core/planner/test-command";
2
3
  import { mkdtempSync, rmSync } from "node:fs";
3
4
  import { tmpdir } from "node:os";
4
5
  import { join, resolve } from "node:path";
@@ -8,7 +9,7 @@ import { checkAtBaseline, compareWithBaseline } from "./failure-baseline.js";
8
9
  import { collectEnforcementContext, evaluateEnforcement } from "./enforce-policy.js";
9
10
  import { inferFullCommand, inferPlannedCommands, inferSelectedCommand, inferSelectedCommands } from "./full-command.js";
10
11
  import { plannedChecks, runChecks } from "./gate-checks.js";
11
- import { makeGitRunner, observe } from "./observe.js";
12
+ import { makeGitRunner, observe, separateProjectReason } from "./observe.js";
12
13
  import { redactPath } from "./report.js";
13
14
  import { createIsolatedWorktree } from "./isolated-worktree.js";
14
15
  import { selectedNodeTests, traceNodeTestFiles, unmatchedNodeTests, unstartedNodeTests } from "./selected-coverage.js";
@@ -61,10 +62,13 @@ function unknownSnapshot() {
61
62
  return { baseSha: "unknown", treeSha: "unknown", commitSha: "unknown", changed: true };
62
63
  }
63
64
  async function executeObservation(options, scope, before, observation) {
64
- const enforcement = options.policy === "enforce"
65
- ? evaluateEnforcement(collectEnforcementContext(makeGitRunner(options.repoPath), options.env, observation), observation)
65
+ // The analysis sees real paths, but under --redact-paths enforce keeps treating the paths as redacted.
66
+ const context = options.policy === "enforce" ? collectEnforcementContext(makeGitRunner(options.repoPath), options.env, observation) : undefined;
67
+ const enforcement = context
68
+ ? evaluateEnforcement(options.redactPaths ? { ...context, pathsRedacted: true } : context, observation)
66
69
  : undefined;
67
- const report = await executeWithPolicy(options, scope, before, observation, enforcement);
70
+ const executed = await executeWithPolicy(options, scope, before, observation, enforcement);
71
+ const report = options.redactPaths ? redactReceipt(executed, observation.result, options.repoPath) : executed;
68
72
  if (!enforcement)
69
73
  return report;
70
74
  return { ...report, enforcement: { ...enforcement, applied: enforcement.fired_fallback === null && report.selection === "selected" } };
@@ -224,11 +228,22 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
224
228
  };
225
229
  }
226
230
  const checkBaseline = options.baselineOnFailure && checkBase && checkHead
227
- ? (check, remainingMs) => checkAtBaseline({ repoPath: options.repoPath, baseSha: checkBase, headSha: checkHead, command: check.command, timeoutMs: Math.max(remainingMs, 0) })
231
+ // With no time left the base rerun would get a 0ms limit, which means none: report it as unknown instead.
232
+ ? (check, remainingMs) => remainingMs <= 0
233
+ ? { status: "unknown", base_sha: checkBase, reason: "the time limit ran out before the base run" }
234
+ : checkAtBaseline({ repoPath: options.repoPath, baseSha: checkBase, headSha: checkHead, command: check.command, timeoutMs: remainingMs })
228
235
  : undefined;
229
236
  const checkRun = options.skipChecks ? undefined : runChecks(planned, { cwd: options.repoPath, timeoutMs: options.timeoutMs, tailBytes: options.tailBytes, baseline: checkBaseline });
230
237
  const checks = checkRun?.results.length ? checkRun.results : undefined;
231
238
  const failedCheck = checkRun?.failure?.check;
239
+ // Checks the time limit left no room for were never run, so the tests must not run (with no limit) either.
240
+ const unrunChecks = checkRun?.outOfTime ? checkRun.results.filter((check) => check.status === "not_run") : [];
241
+ // Every check can run and still use the whole budget (a slow last check, or a base rerun after a
242
+ // failure that also fails at the base). The tests would then get a 0ms limit, which means none.
243
+ const testBudgetMs = options.timeoutMs - (checkRun?.wallMs ?? 0);
244
+ const budgetUsedByChecks = Boolean(checkRun && !checkRun.failure && !unrunChecks.length && testBudgetMs <= 0
245
+ && checkRun.results.some((check) => check.status !== "skipped" && check.status !== "not_run"));
246
+ const testsOutOfTime = unrunChecks.length > 0 || budgetUsedByChecks;
232
247
  // Checks that also fail at the base: still a failed verdict (required CI fails either way), but they
233
248
  // no longer stop the run before the change's own failures.
234
249
  const preexistingChecks = checkRun?.preexisting ?? [];
@@ -238,13 +253,15 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
238
253
  // Every test run goes under a probe that records which `node --test` files started (selected ones must)
239
254
  // and each one's duration and result for the outcome log (2026-11-06). Outside node:test it does nothing.
240
255
  const expectedNodeTests = selection === "selected" && result ? selectedNodeTests(command, result.selectedTests) : [];
241
- const trace = !checkRun?.failure ? traceNodeTestFiles(options.repoPath) : undefined;
256
+ const trace = !checkRun?.failure && !testsOutOfTime ? traceNodeTestFiles(options.repoPath) : undefined;
242
257
  let startedNodeTests;
243
258
  let execution;
244
259
  try {
245
260
  execution = checkRun?.failure
246
261
  ? checkRun.failure.measurement
247
- : measureCommands(runCommands, { cwd: options.repoPath, timeoutMs: Math.max(options.timeoutMs - (checkRun?.wallMs ?? 0), 0), tailBytes: options.tailBytes, env: trace?.env, stopOnFailure: options.failFast, stopOnFailureWithin: firstPass?.parts.length });
262
+ : testsOutOfTime
263
+ ? checksOutOfTime(command, checkRun?.wallMs ?? 0)
264
+ : measureCommands(runCommands, { cwd: options.repoPath, timeoutMs: testBudgetMs, tailBytes: options.tailBytes, env: trace?.env, stopOnFailure: options.failFast, stopOnFailureWithin: firstPass?.parts.length });
248
265
  startedNodeTests = trace?.read();
249
266
  const nodeResults = trace?.results() ?? [];
250
267
  if (nodeResults.length)
@@ -310,15 +327,19 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
310
327
  ? `the runner reported ${String(execution.runnerTestCount)} test(s) for ${selectedCount} selected test file(s), so some selected tests did not run; run the full test command instead`
311
328
  : succeeded
312
329
  ? checks ? `${reason}; ${checkSummary(checks)}` : reason
313
- : failedCheck
314
- ? `gate check ${failedCheck.id} ${failedCheck.status === "timed_out" ? "timed out" : `failed with exit code ${String(failedCheck.exit_code)}`}; tests were not run (${failedCheck.command})`
315
- : execution.timedOut
316
- ? `verification timed out after ${options.timeoutMs}ms${preexistingNote}`
317
- : testsPassed
318
- ? `${preexistingChecks.length} gate check(s) failed that also fail at the base commit; nothing this change introduced failed (${preexistingChecks.map((check) => check.id).join(", ")})`
319
- : `verification command failed with exit code ${String(execution.exitCode)}${preexistingNote}`;
330
+ : unrunChecks.length
331
+ ? `gate check(s) ${unrunChecks.map((check) => check.id).join(", ")} did not run within the ${options.timeoutMs}ms time limit; tests were not run`
332
+ : budgetUsedByChecks
333
+ ? `gate checks used the whole ${options.timeoutMs}ms time limit (${String(checkRun?.wallMs ?? 0)}ms); tests were not run`
334
+ : failedCheck
335
+ ? `gate check ${failedCheck.id} ${failedCheck.status === "timed_out" ? "timed out" : `failed with exit code ${String(failedCheck.exit_code)}`}; tests were not run (${failedCheck.command})`
336
+ : execution.timedOut
337
+ ? `verification timed out after ${options.timeoutMs}ms${preexistingNote}`
338
+ : testsPassed
339
+ ? `${preexistingChecks.length} gate check(s) failed that also fail at the base commit; nothing this change introduced failed (${preexistingChecks.map((check) => check.id).join(", ")})`
340
+ : `verification command failed with exit code ${String(execution.exitCode)}${preexistingNote}`;
320
341
  const baselineSha = scope === "commit-range" ? range?.baseSha : before.baseSha;
321
- const failureBaseline = verification === "failed" && !failedCheck && !execution.timedOut && options.baselineOnFailure && baselineSha
342
+ const failureBaseline = verification === "failed" && !failedCheck && !testsOutOfTime && !execution.timedOut && options.baselineOnFailure && baselineSha
322
343
  // The base reruns only the parts that ran here: a first-pass failure is compared without the full suite.
323
344
  ? compareWithBaseline({ repoPath: options.repoPath, baseSha: baselineSha, headSha: scope === "commit-range" ? before.baseSha : before.commitSha, commands: stoppedInFirstPass ? firstPass.parts : commands, headFailures: execution.failingTests ?? [], timeoutMs: options.timeoutMs })
324
345
  : undefined;
@@ -357,13 +378,13 @@ async function executeWithPolicy(options, scope, before, observation, enforcemen
357
378
  ...coverageField,
358
379
  };
359
380
  }
360
- function stamped(report, version) {
381
+ function stamped(report, version, redactPaths) {
361
382
  const { schema, schema_version, produced_at, ...rest } = report;
362
- return { schema, schema_version, produced_at, diffci_version: version, ...rest };
383
+ return { schema, schema_version, produced_at, diffci_version: version, ...rest, ...(redactPaths ? { snapshot: redactSnapshot(report.snapshot) } : {}) };
363
384
  }
364
385
  /** Verify exactly the staged, unstaged, and non-ignored untracked content currently on disk. */
365
386
  export async function verifyChanged(options) {
366
- return stamped(await verifyChangedSnapshot(options), options.version);
387
+ return stamped(await verifyChangedSnapshot(options), options.version, options.redactPaths);
367
388
  }
368
389
  async function verifyChangedSnapshot(options) {
369
390
  const repoPath = resolve(options.repoPath);
@@ -404,7 +425,7 @@ async function verifyChangedSnapshot(options) {
404
425
  engineSha: options.engineSha,
405
426
  baseOverride: before.baseSha,
406
427
  headOverride: before.commitSha,
407
- redactPaths: options.redactPaths,
428
+ // Planned with real paths so the selected tests can run; only the receipt is redacted (redactReceipt).
408
429
  reportPath: join(temporaryDirectory, "observation.json"),
409
430
  selectTestPhases: true,
410
431
  ...(options.onGraph ? { onGraph: options.onGraph } : {}),
@@ -435,7 +456,7 @@ export function scopedChanges(repoPath, scope) {
435
456
  };
436
457
  }
437
458
  export async function verifyScoped(options) {
438
- return stamped(await verifyScopedTree(options), options.version);
459
+ return stamped(await verifyScopedTree(options), options.version, options.redactPaths);
439
460
  }
440
461
  async function verifyScopedTree(options) {
441
462
  const repoPath = resolve(options.repoPath);
@@ -524,7 +545,7 @@ async function verifyScopedTree(options) {
524
545
  }
525
546
  /** Verify a real commit range and bind the receipt to the clean commit that was actually executed. */
526
547
  export async function verifyRange(options) {
527
- return stamped(await verifyCommitRange(options), options.version);
548
+ return stamped(await verifyCommitRange(options), options.version, options.redactPaths);
528
549
  }
529
550
  async function verifyCommitRange(options) {
530
551
  const repoPath = resolve(options.repoPath);
@@ -549,7 +570,7 @@ async function verifyCommitRange(options) {
549
570
  engineSha: options.engineSha,
550
571
  baseOverride: options.baseOverride,
551
572
  headOverride: options.headOverride,
552
- redactPaths: options.redactPaths,
573
+ // Planned with real paths so the selected tests can run; only the receipt is redacted (redactReceipt).
553
574
  reportPath: join(temporaryDirectory, "observation.json"),
554
575
  selectTestPhases: true,
555
576
  });
@@ -559,12 +580,93 @@ async function verifyCommitRange(options) {
559
580
  rmSync(temporaryDirectory, { recursive: true, force: true });
560
581
  }
561
582
  }
583
+ /**
584
+ * Under --redact-paths the analysis plans with real paths, so the selected tests can run, and the receipt
585
+ * carries digests instead (the same sha256-12 as the observation report): the selected tests and their
586
+ * reasons, and those paths wherever the command and reason text name them. The text also names the files
587
+ * the snapshot lists (a file the run changed); `stamped` digests the lists themselves (redactSnapshot).
588
+ */
589
+ function redactReceipt(report, result, repoPath) {
590
+ const digest = (path) => redactPath(path, (input) => createHash("sha256").update(input).digest("hex"));
591
+ const snapshot = report.snapshot;
592
+ const known = [...new Set([
593
+ ...(result?.selectedTests ?? []), ...(result?.testsOutsideFullSuite ?? []), ...(result?.changedFiles ?? []),
594
+ ...(snapshot.written_during_verification ?? []), ...(snapshot.changed_during_verification ?? []).map((change) => change.path),
595
+ ...(snapshot.line_ending_only_changes ?? []),
596
+ ])].filter((path) => path.length > 0);
597
+ // A command names a path as written, or as the `node --test` glob that matches only it, either one
598
+ // shell-escaped when it holds glob characters: `d[1].test.js` runs as "d@([[])1@([]]).test.js".
599
+ const shellForm = (text) => commandSpecToString({ executable: "", args: [text] }).slice(1);
600
+ const forms = known.flatMap((path) => {
601
+ const glob = nodeTestGlobForPath(path);
602
+ return [...new Set([path, shellForm(path), ...(glob ? [glob, shellForm(glob)] : [])])].map((form) => [form, digest(path)]);
603
+ });
604
+ // The outside-suite reason names the separate project's directory, which is no file the run knows.
605
+ const outside = result?.testsOutsideFullSuite ?? [];
606
+ const projectReason = outside.length ? separateProjectReason(repoPath, outside) : undefined;
607
+ if (projectReason)
608
+ forms.push([projectReason, separateProjectReason(repoPath, outside, digest)]);
609
+ forms.sort((left, right) => right[0].length - left[0].length);
610
+ const scrub = (text) => forms.reduce((current, [form, hidden]) => current.split(form).join(hidden), text);
611
+ return {
612
+ ...report,
613
+ reason: scrub(report.reason),
614
+ required_actions: report.required_actions.map(scrub),
615
+ ...(report.selected_tests ? { selected_tests: report.selected_tests.map(digest) } : {}),
616
+ ...(report.selection_reasons ? {
617
+ selection_reasons: Object.fromEntries(Object.entries(report.selection_reasons).map(([test, why]) => [digest(test), { ...why, changed_file: digest(why.changed_file) }])),
618
+ } : {}),
619
+ ...(report.command !== undefined ? { command: scrub(report.command) } : {}),
620
+ ...(report.commands ? { commands: report.commands.map(scrub) } : {}),
621
+ ...(report.first_pass ? { first_pass: { ...report.first_pass, commands: report.first_pass.commands.map(scrub) } } : {}),
622
+ ...(report.execution ? { execution: redactMeasurement(report.execution, scrub) } : {}),
623
+ // Gate checks name the changed files in their reasons, and a NARROWED check's command lists them.
624
+ ...(report.checks ? { checks: report.checks.map((check) => ({ ...check, command: scrub(check.command), reason: scrub(check.reason) })) } : {}),
625
+ ...(report.failure_baseline ? {
626
+ failure_baseline: {
627
+ ...report.failure_baseline,
628
+ reason: scrub(report.failure_baseline.reason),
629
+ preexisting: report.failure_baseline.preexisting.map(scrub),
630
+ introduced: report.failure_baseline.introduced.map(scrub),
631
+ },
632
+ } : {}),
633
+ };
634
+ }
635
+ /**
636
+ * The snapshot's file lists under --redact-paths: the files the run wrote or changed, and the files that
637
+ * differ only by line endings. Applied to every receipt, including the ones that return before the run.
638
+ */
639
+ function redactSnapshot(snapshot) {
640
+ const digest = (path) => redactPath(path, (input) => createHash("sha256").update(input).digest("hex"));
641
+ return {
642
+ ...snapshot,
643
+ ...(snapshot.written_during_verification ? { written_during_verification: snapshot.written_during_verification.map(digest) } : {}),
644
+ ...(snapshot.changed_during_verification ? { changed_during_verification: snapshot.changed_during_verification.map((change) => ({ ...change, path: digest(change.path) })) } : {}),
645
+ ...(snapshot.line_ending_only_changes ? { line_ending_only_changes: snapshot.line_ending_only_changes.map(digest) } : {}),
646
+ };
647
+ }
648
+ /** The run's command, output tails, failing test names and per-file results, with the known paths as digests. */
649
+ function redactMeasurement(execution, scrub) {
650
+ return {
651
+ ...execution,
652
+ command: scrub(execution.command),
653
+ stdoutTail: scrub(execution.stdoutTail),
654
+ stderrTail: scrub(execution.stderrTail),
655
+ ...(execution.failingTests ? { failingTests: execution.failingTests.map(scrub) } : {}),
656
+ ...(execution.testResults ? { testResults: execution.testResults.map((result) => ({ ...result, file: scrub(result.file) })) } : {}),
657
+ };
658
+ }
562
659
  function checkSummary(checks) {
563
660
  const ran = checks.filter((check) => check.status === "passed").length;
564
661
  const narrowed = checks.filter((check) => check.status === "passed" && check.decision === "NARROWED").length;
565
662
  const skipped = checks.length - ran;
566
663
  return `ran ${ran} gate check(s) first${narrowed ? ` (${narrowed} narrowed to changed files)` : ""}${skipped ? `, skipped ${skipped} the change does not affect` : ""}`;
567
664
  }
665
+ /** The measurement recorded when the time limit ran out during the gate checks, before the tests started. */
666
+ function checksOutOfTime(command, wallMs) {
667
+ const now = new Date().toISOString();
668
+ return { command, exitCode: null, signal: null, timedOut: true, startedAt: now, finishedAt: now, wallMs: 0, stdoutTail: "", stderrTail: `gate checks used the time limit (${wallMs}ms); tests were not run` };
669
+ }
568
670
  export function verificationExitCode(report) {
569
671
  if (report.verification === "passed")
570
672
  return 0;
@@ -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()