@futurelastic/colab-handbook 1.12.0-rc.36 → 1.12.0-rc.37

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/package.json CHANGED
@@ -27,5 +27,5 @@
27
27
  "engines": {
28
28
  "node": ">=18"
29
29
  },
30
- "version": "1.12.0-rc.36"
30
+ "version": "1.12.0-rc.37"
31
31
  }
@@ -91,6 +91,23 @@
91
91
  # run still concludes on the `release` job. EDIT: on this route, a cron more frequent than daily
92
92
  # tags a head that release.final-spacing held back sooner.
93
93
  #
94
+ # DRY RUN ON A FIX BRANCH (#474). This workflow never runs on a branch by itself, so a fix to it
95
+ # (a moved runner label, a HANDBOOK_REF naming a missing branch) had no run to prove it, and the
96
+ # cure rule (CONVENTIONS.md §4) could only refuse it — a human ci-grant was the one door. Dispatch
97
+ # it on the fix branch instead:
98
+ #
99
+ # gh workflow run release-auto.yml --ref <fix-branch> -f dry_run=true
100
+ #
101
+ # (`colab ship` dispatches it for you when a red in this workflow is what stands between the branch
102
+ # and trunk). A dispatch on any ref other than main is ALWAYS dry, input or not. A dry run checks out
103
+ # the branch, runs every step with `--dry` — the same decisions, nothing promoted, tagged, released,
104
+ # pushed or dispatched — and skips only the steps whose names end in `[publish]`. The step
105
+ # "Dry run — nothing is tagged, released or published" runs only then; it is how the cure rule
106
+ # recognises the run. Keep both names as they are: the cure rule matches steps BY NAME, and accepts
107
+ # a dry run only if every step that ran in trunk's red run passed in it and every step it skipped
108
+ # ends in `[publish]`. So a red INSIDE a `[publish]` step, or in the npm or deploy jobs (which never
109
+ # run without a tag), cannot be cured by a dry run — that stays a human ci-grant.
110
+ #
94
111
  # IT READS TAGS AND CREATES TAGS. IT NEVER WRITES A COMMIT. No step here commits; the refs
95
112
  # pushed are the tags `colab release cut` / `colab release finalize` create (annotated, their
96
113
  # checks recorded in the tag message) and — only on a repo granting unattended promotion — the
@@ -154,12 +171,21 @@ on:
154
171
  # hour is when scheduled runs queue longest.
155
172
  - cron: "17 3 * * *"
156
173
  workflow_dispatch:
174
+ # #474: a DRY RUN for a fix branch — see "DRY RUN ON A FIX BRANCH" in the header. A dispatch on
175
+ # any ref other than main is dry whether or not this is set; on main it is opt-in.
176
+ inputs:
177
+ dry_run:
178
+ description: "Dry run: decide everything, write nothing (no promotion, tag, Release or publish)"
179
+ type: boolean
180
+ default: false
157
181
 
158
182
  # One release run at a time; a second one waits rather than racing the first for the same
159
183
  # candidate number. Never cancelled mid-run: a half-finished run may have pushed a tag
160
184
  # without publishing it.
161
185
  concurrency:
162
- group: release-auto
186
+ # A dry run (#474) gets a group of its own: GitHub cancels an older PENDING run in the same group,
187
+ # so a shared one could let a branch's dry run displace a real release run waiting on main.
188
+ group: release-auto${{ github.event_name == 'workflow_dispatch' && (inputs.dry_run || github.ref_name != 'main') && format('-dry-{0}', github.ref_name) || '' }}
163
189
  cancel-in-progress: false
164
190
 
165
191
  permissions: {}
@@ -230,16 +256,34 @@ jobs:
230
256
  health-url: ${{ steps.cut.outputs.health-url }}
231
257
  env:
232
258
  GH_TOKEN: ${{ github.token }}
259
+ # #474: 'true' on a dry run — a dispatch on any ref other than main, or one with dry_run set.
260
+ # Never on workflow_run or schedule. Every write below is off when it is.
261
+ # EDIT: if your trunk is not `main`, name it here too (the same branch as `ref:` below).
262
+ DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && (inputs.dry_run || github.ref_name != 'main') }}
233
263
  steps:
234
264
  - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
235
265
  with:
236
- ref: main
266
+ # A dry run checks out the ref it was dispatched on — the fix being proven; every other run, main.
267
+ ref: ${{ env.DRY_RUN == 'true' && github.sha || 'main' }}
237
268
  # Full history plus tags: versions, bumps and "previous final" are all read from
238
269
  # git, and the on-trunk check refuses a shallow checkout outright.
239
270
  fetch-depth: 0
240
271
  # Left on deliberately: `colab release cut` / `finalize` push their tag over the
241
- # checkout's origin. The token is this job's, scoped by `permissions:` above.
242
- persist-credentials: true
272
+ # checkout's origin. The token is this job's, scoped by `permissions:` above. Off on a dry
273
+ # run (#474): nothing is pushed, so nothing should be able to push.
274
+ persist-credentials: ${{ env.DRY_RUN != 'true' }}
275
+
276
+ # #474: the marker ci-cure reads to recognise a dry run — its name must stay byte-identical to
277
+ # DRY_RUN_STEP in the handbook's tools/lib/ci-cure.js. Skipped on every ordinary run.
278
+ - name: Dry run — nothing is tagged, released or published
279
+ if: env.DRY_RUN == 'true'
280
+ run: |
281
+ {
282
+ echo "#### Dry run (#474)"
283
+ echo
284
+ echo "Dispatched on \`$GITHUB_REF_NAME\` @ \`$GITHUB_SHA\`. Every decision below runs with \`--dry\`; steps marked \`[publish]\` are skipped. Nothing is promoted, tagged, released or published."
285
+ echo
286
+ } >> "$GITHUB_STEP_SUMMARY"
243
287
 
244
288
  # A red CI run on main is not a candidate. Gated here rather than by a job-level `if:` so
245
289
  # this run concludes success, never `skipped` (#435; the comment on the job above).
@@ -285,7 +329,8 @@ jobs:
285
329
  eval "$RETRY_TRANSIENT"
286
330
  OUT="$RUNNER_TEMP/promote.json"
287
331
  rc=0
288
- retry_transient node "$COLAB" promote --auto --json > "$OUT" || rc=$?
332
+ DRY=(); [ "${DRY_RUN:-false}" = "true" ] && DRY=(--dry)
333
+ retry_transient node "$COLAB" promote --auto ${DRY[@]+"${DRY[@]}"} --json > "$OUT" || rc=$?
289
334
  if ! jq -e 'has("promoted")' "$OUT" > /dev/null 2>&1; then
290
335
  echo "::warning::colab promote --auto gave no verdict (exit $rc; a HANDBOOK_REF older than #440?) — nothing was promoted"
291
336
  exit 0
@@ -296,7 +341,10 @@ jobs:
296
341
  jq -r '.checks[]? | "- \(if .ok then "✓" else "✗" end) **\(.condition)** — \(.detail)"' "$OUT"
297
342
  echo
298
343
  } >> "$GITHUB_STEP_SUMMARY"
299
- if [ "$(jq -r '.promoted' "$OUT")" = "true" ]; then
344
+ if [ "${DRY_RUN:-false}" = "true" ]; then
345
+ # #474: a dry run promotes nothing and dispatches nothing, whatever the verdict says.
346
+ echo "Dry run — promote: $(jq -r 'if .promoted then "would promote" elif .noop then "no-op: \(.reason)" else "would refuse: \(.reason)" end' "$OUT")" | tee -a "$GITHUB_STEP_SUMMARY"
347
+ elif [ "$(jq -r '.promoted' "$OUT")" = "true" ]; then
300
348
  echo "promoted=true" >> "$GITHUB_OUTPUT"
301
349
  echo "Promoted to main @ $(jq -r '.sha' "$OUT")" | tee -a "$GITHUB_STEP_SUMMARY"
302
350
  if retry_transient gh workflow run "$CI_WORKFLOW" --ref main; then
@@ -322,7 +370,8 @@ jobs:
322
370
  eval "$RETRY_TRANSIENT"
323
371
  OUT="$RUNNER_TEMP/cut.json"
324
372
  rc=0
325
- retry_transient node "$COLAB" release cut --auto --json > "$OUT" || rc=$?
373
+ DRY=(); [ "${DRY_RUN:-false}" = "true" ] && DRY=(--dry)
374
+ retry_transient node "$COLAB" release cut --auto ${DRY[@]+"${DRY[@]}"} --json > "$OUT" || rc=$?
326
375
  # A verdict is JSON carrying `ok`; anything else is a run that never decided.
327
376
  if ! jq -e 'has("ok")' "$OUT" > /dev/null 2>&1; then
328
377
  echo "::error::colab release cut produced no verdict (exit $rc)"
@@ -336,7 +385,10 @@ jobs:
336
385
  jq -r '.checks[]? | "- \(if .ok then "✓" else "✗" end) **\(.condition)** — \(.detail)"' "$OUT"
337
386
  echo
338
387
  } >> "$GITHUB_STEP_SUMMARY"
339
- if [ "$(jq -r '.created' "$OUT")" = "true" ]; then
388
+ if [ "${DRY_RUN:-false}" = "true" ]; then
389
+ # #474: a dry run never hands a tag to the publishing steps, whatever the verdict says.
390
+ echo "Dry run — would cut: $(jq -r '.tag // "nothing"' "$OUT") (created: $(jq -r '.created' "$OUT"))" | tee -a "$GITHUB_STEP_SUMMARY"
391
+ elif [ "$(jq -r '.created' "$OUT")" = "true" ]; then
340
392
  TAG="$(jq -r '.tag' "$OUT")"
341
393
  echo "tag=$TAG" >> "$GITHUB_OUTPUT"
342
394
  echo "Cut $TAG" | tee -a "$GITHUB_STEP_SUMMARY"
@@ -376,7 +428,8 @@ jobs:
376
428
  eval "$RETRY_TRANSIENT"
377
429
  OUT="$RUNNER_TEMP/finalize.json"
378
430
  rc=0
379
- retry_transient node "$COLAB" release finalize --auto --json > "$OUT" || rc=$?
431
+ DRY=(); [ "${DRY_RUN:-false}" = "true" ] && DRY=(--dry)
432
+ retry_transient node "$COLAB" release finalize --auto ${DRY[@]+"${DRY[@]}"} --json > "$OUT" || rc=$?
380
433
  if ! jq -e 'has("state")' "$OUT" > /dev/null 2>&1; then
381
434
  echo "::error::colab release finalize produced no verdict (exit $rc)"
382
435
  echo "colab release finalize produced no verdict (exit $rc) — the reason is in this step's log." >> "$GITHUB_STEP_SUMMARY"
@@ -400,7 +453,9 @@ jobs:
400
453
  echo
401
454
  fi
402
455
  } >> "$GITHUB_STEP_SUMMARY"
403
- if [ "$(jq -r '.tagged' "$OUT")" = "true" ]; then
456
+ if [ "${DRY_RUN:-false}" = "true" ]; then
457
+ echo "Dry run — finalize: $STATE (would tag: $(jq -r '.finalTag // "nothing"' "$OUT"))" | tee -a "$GITHUB_STEP_SUMMARY"
458
+ elif [ "$(jq -r '.tagged' "$OUT")" = "true" ]; then
404
459
  TAG="$(jq -r '.finalTag' "$OUT")"
405
460
  echo "tag=$TAG" >> "$GITHUB_OUTPUT"
406
461
  echo "Finalized $TAG" | tee -a "$GITHUB_STEP_SUMMARY"
@@ -414,9 +469,9 @@ jobs:
414
469
  # Whether the npm job publishes what this run tagged — `colab release npm` reads the
415
470
  # release: block (one reading, the same as cut/finalize). A CLI older than #433 gives no
416
471
  # verdict; that is a warning and no npm publish, never a failed release.
417
- - name: Read the npm target (colab release npm)
472
+ - name: Read the npm target (colab release npm) [publish]
418
473
  id: npm-target
419
- if: steps.cut.outputs.tag != '' || steps.finalize.outputs.tag != ''
474
+ if: env.DRY_RUN != 'true' && (steps.cut.outputs.tag != '' || steps.finalize.outputs.tag != '')
420
475
  env:
421
476
  TAGS: ${{ steps.cut.outputs.tag }} ${{ steps.finalize.outputs.tag }}
422
477
  run: |
@@ -445,8 +500,8 @@ jobs:
445
500
 
446
501
  # Publishes every tag THIS run created. In this run, never via a tag-push workflow:
447
502
  # see "PUBLISHING HAPPENS IN THIS RUN" in the header.
448
- - name: Publish GitHub Release (same run)
449
- if: steps.cut.outputs.tag != '' || steps.finalize.outputs.tag != ''
503
+ - name: Publish GitHub Release (same run) [publish]
504
+ if: env.DRY_RUN != 'true' && (steps.cut.outputs.tag != '' || steps.finalize.outputs.tag != '')
450
505
  env:
451
506
  TAGS: ${{ steps.cut.outputs.tag }} ${{ steps.finalize.outputs.tag }}
452
507
  run: |
package/tools/colab CHANGED
@@ -9450,9 +9450,9 @@ function ciGrantTrailerLine(grantVerdict, branch, trunk) {
9450
9450
  */
9451
9451
  function ciCureTrailerLine(cureVerdict, branch, trunk) {
9452
9452
  if (!cureVerdict || !cureVerdict.ok) return null;
9453
- const via = cureVerdict.carveOut
9453
+ const via = (cureVerdict.carveOut
9454
9454
  ? ` via workflow-carve-out jobs ${cureVerdict.carveOut.jobs.map((j) => j.name).join(',')}`
9455
- : '';
9455
+ : '') + (cureVerdict.dryRun ? ` via dry-run jobs ${cureVerdict.dryRun.jobs.join(',')}` : '');
9456
9456
  return `CI-Cure: branch ${branch} over-red ${trunk}@${shortSha(cureVerdict.redSha)} evidence ${shortSha(cureVerdict.evidenceSha)}${via}`;
9457
9457
  }
9458
9458
 
@@ -10426,9 +10426,10 @@ function applyRedTrunkExemptions(raw, target, trunk, redSha, grantThunk, cureThu
10426
10426
  const via = cureVerdict.carveOut
10427
10427
  ? ` THROUGH THE #321 WORKFLOW CARVE-OUT — every job red on trunk ran to success here: ${cureVerdict.carveOut.jobs.map((j) => `${j.name} (${j.redMs}ms red, ${j.branchMs}ms passing)`).join(', ')}`
10428
10428
  : '';
10429
+ const viaDry = cureVerdict.dryRun ? ` — main-only job(s) ${cureVerdict.dryRun.jobs.join(', ')} proven by a DRY RUN on the branch (#474)` : '';
10429
10430
  return {
10430
10431
  name: raw.name, ok: true, class: null,
10431
- detail: `PRECONDITION OVERRIDDEN by the cure rule (#281) — branch contains red ${shortSha(redSha)} and is green at its own head${via} (raw: ${raw.detail})`,
10432
+ detail: `PRECONDITION OVERRIDDEN by the cure rule (#281) — branch contains red ${shortSha(redSha)} and is green at its own head${via}${viaDry} (raw: ${raw.detail})`,
10432
10433
  grantVerdict: null, cureVerdict,
10433
10434
  };
10434
10435
  }
@@ -10548,11 +10549,23 @@ function shipCiCure(repoAbs, gh, target, trunk, redSha, branch) {
10548
10549
  // so a branch that cannot cure pays no job-level `gh` calls for it.
10549
10550
  const jobEvidence = (containsRedSha && evidence && evidence.ok)
10550
10551
  ? shipCureJobEvidence(repoAbs, trunk, redSha, branch, evRun) : null;
10552
+ // #474: which workflows at the branch head offer a dry run — a static read (git show), read only
10553
+ // when job evidence exists, so a branch that already refuses on containment or 2a pays nothing.
10554
+ const capable = jobEvidence && evidence ? dryRunCapableWorkflows(repoAbs, evidence.sha) : [];
10551
10555
  const verdict = ciCure.cureVerdict({ containsRedSha, evidence, redSha, stacking, jobEvidence,
10552
10556
  workflowsTouched: diff.workflowsTouched,
10553
10557
  manifestScriptsTouched: diff.manifestScriptsTouched, manifestPaths: diff.manifestPaths,
10554
- pythonManifestTouched: diff.pythonManifestTouched, pythonManifestPaths: diff.pythonManifestPaths });
10555
- return { ...verdict, redSha, evidenceSha: evidence ? evidence.sha : null };
10558
+ pythonManifestTouched: diff.pythonManifestTouched, pythonManifestPaths: diff.pythonManifestPaths,
10559
+ dryRunCapable: capable.map((w) => w.name) });
10560
+ // The dispatch plan carries the FILE and the exact command, so the refusal can name it and the
10561
+ // real ship path can run it — measurement only here; nothing is dispatched by this function.
10562
+ const dryRunDispatch = verdict.dryRunWanted
10563
+ ? verdict.dryRunWanted.map((name) => {
10564
+ const w = capable.find((c) => c.name === name);
10565
+ return { workflow: name, file: w.file, command: `gh workflow run ${w.file} --ref ${branch} -f ${DRY_RUN_INPUT}=true` };
10566
+ })
10567
+ : null;
10568
+ return { ...verdict, ...(dryRunDispatch ? { dryRunDispatch } : {}), redSha, evidenceSha: evidence ? evidence.sha : null };
10556
10569
  }
10557
10570
 
10558
10571
  /**
@@ -10630,9 +10643,71 @@ function ciCurePayload(ciResult) {
10630
10643
  carveOut: c.carveOut
10631
10644
  ? { jobs: c.carveOut.jobs.map((j) => ({ name: j.name, redDurationMs: j.redMs, branchDurationMs: j.branchMs })) }
10632
10645
  : null,
10646
+ // #474: the red job(s) proven only by a dry run of a main-only workflow — null otherwise.
10647
+ dryRun: c.dryRun ? { jobs: c.dryRun.jobs.slice() } : null,
10648
+ // #474: on a refusal, the dry run(s) that would supply the missing 2b evidence — what the real
10649
+ // ship dispatches; `--dry --json` only reports it. null when none would help.
10650
+ dryRunWanted: c.dryRunDispatch ? c.dryRunDispatch.map((d) => ({ ...d })) : null,
10633
10651
  };
10634
10652
  }
10635
10653
 
10654
+ /** The dispatch input a dry-run-capable workflow declares (#474, templates/release-auto.yml). */
10655
+ const DRY_RUN_INPUT = 'dry_run';
10656
+
10657
+ /**
10658
+ * The workflows at `treeish` that offer a dry run (#474): a top-level `name:`, a `workflow_dispatch`
10659
+ * input named `dry_run`, and ci-cure's sentinel step text. All three, read statically at the BRANCH's
10660
+ * head — the copy a dispatch on that ref would run. A pre-#474 copy has no forced-dry mode and would
10661
+ * really publish if dispatched, which is exactly why this read gates every dispatch. `[]` on any
10662
+ * failed read: no capability is ever assumed.
10663
+ */
10664
+ function dryRunCapableWorkflows(repoAbs, treeish) {
10665
+ const ls = git.git(['ls-tree', '--name-only', `${treeish}:.github/workflows`], repoAbs);
10666
+ if (!ls.ok) return [];
10667
+ const out = [];
10668
+ for (const f of ls.stdout.split('\n').map((x) => x.trim()).filter((x) => /\.ya?ml$/.test(x))) {
10669
+ const r = git.git(['show', `${treeish}:.github/workflows/${f}`], repoAbs);
10670
+ if (!r.ok) continue;
10671
+ const name = workflowTriggers.workflowNameOf(r.stdout);
10672
+ if (!name || !r.stdout.includes(ciCure.DRY_RUN_STEP)) continue;
10673
+ if (!workflowTriggers.workflowDispatchInputs(r.stdout).includes(DRY_RUN_INPUT)) continue;
10674
+ out.push({ name, file: f });
10675
+ }
10676
+ return out;
10677
+ }
10678
+
10679
+ /**
10680
+ * Dispatch the dry run(s) a refused cure asked for (#474) — the REAL ship path only, never `--dry`,
10681
+ * never `--dry --json`, never from the measurement above (which runs up to three times per ship).
10682
+ * Skips a workflow that already has ANY run at the branch head, whatever its status: a queued run has
10683
+ * no jobs yet, so "job absent" alone would dispatch it twice. Never waits — the caller re-runs ship
10684
+ * once the run completes (code-ship B1a's bounded wait), the same no-polling stance as every other
10685
+ * read here.
10686
+ */
10687
+ function shipDispatchDryRuns(repoAbs, branch, plan) {
10688
+ const head = git.git(['rev-parse', branch], repoAbs);
10689
+ const runs = head.ok ? git.ghRunsForCommit(repoAbs, branch, head.stdout.trim(), 30) : null;
10690
+ for (const p of plan) {
10691
+ const existing = runs ? runs.filter((r) => r.workflowName === p.workflow) : null;
10692
+ if (existing === null) {
10693
+ warn(` dry run for ${p.workflow} NOT dispatched: the runs at ${branch}'s head could not be read — run it yourself: ${p.command}`);
10694
+ continue;
10695
+ }
10696
+ if (existing.length) {
10697
+ const r = existing[0];
10698
+ warn(` dry run for ${p.workflow} already exists at ${branch}'s head (run ${r.databaseId}, ${r.status}${r.conclusion ? '/' + r.conclusion : ''}) — not dispatched again; re-run \`colab ship\` once it completes.`);
10699
+ continue;
10700
+ }
10701
+ const d = git.ghWorkflowDispatch(repoAbs, p.file, branch, { [DRY_RUN_INPUT]: 'true' });
10702
+ if (d.ok) {
10703
+ warn(` ↻ dispatched a dry run of ${p.workflow} on ${branch} (#474)${d.withInputs ? '' : ' — without the input, which GitHub refused; the ref forces dry mode'}. ` +
10704
+ 'Re-run `colab ship` once it completes (code-ship B1a\'s bounded wait) — it is the evidence this cure is missing.');
10705
+ } else {
10706
+ warn(` dry run for ${p.workflow} could NOT be dispatched (${d.detail}) — run it yourself: ${p.command}`);
10707
+ }
10708
+ }
10709
+ }
10710
+
10636
10711
  /**
10637
10712
  * Previews whether B0's merge (target INTO the branch) would conflict — WITHOUT touching the real
10638
10713
  * worktree, the branch, or the network beyond a fetch — so `ship --dry --json`'s "no hand-merge
@@ -12065,6 +12140,11 @@ function cmdShip(argv) {
12065
12140
  }
12066
12141
  const dryOk = preOk && dryClosingConflicts.length === 0;
12067
12142
  print(dryOk ? '→ READY: preconditions pass. Re-run without --dry to ship.' : '→ NOT READY: fix the ✗ rows above.');
12143
+ if (!ciOk && ciResult.cureVerdict && ciResult.cureVerdict.dryRunDispatch) {
12144
+ for (const d of ciResult.cureVerdict.dryRunDispatch) {
12145
+ print(` Dry run wanted (#474): ${d.workflow} has no run on this branch — a real \`colab ship\` dispatches \`${d.command}\` and refuses until it completes.`);
12146
+ }
12147
+ }
12068
12148
  if (mode.evidenceClose) {
12069
12149
  print(' Plan: no merge, no commit, no push · post evidence comment + CLOSE each issue · ' +
12070
12150
  (opts.keepWorktree ? 'keep worktree' : 'worktree rm') + ' (releases claims)');
@@ -12095,7 +12175,14 @@ function cmdShip(argv) {
12095
12175
  if (refsIssues.length) print(` Refs (kept open, NOT closed): ${refsIssues.map((n) => '#' + n).join(' ')}`);
12096
12176
  return dryOk ? 0 : 1;
12097
12177
  }
12098
- if (!preOk) { process.stderr.write('✗ Aborting: one or more preconditions failed (see ✗ above). Nothing was pushed.\n'); return 1; }
12178
+ if (!preOk) {
12179
+ // #474: the cure is missing only a main-only workflow's run, and that workflow offers a dry run —
12180
+ // dispatch it now (once), so the re-run has the evidence. Never on --dry: that returned above.
12181
+ if (!ciOk && ciResult.cureVerdict && ciResult.cureVerdict.dryRunDispatch && gh) {
12182
+ shipDispatchDryRuns(repoAbs, sess.branch, ciResult.cureVerdict.dryRunDispatch);
12183
+ }
12184
+ process.stderr.write('✗ Aborting: one or more preconditions failed (see ✗ above). Nothing was pushed.\n'); return 1;
12185
+ }
12099
12186
 
12100
12187
  // ---- (b3) evidence-close: the whole B0–B2 sequence is skipped, because there is nothing to merge ----
12101
12188
  if (mode.evidenceClose) return shipEvidenceClose({
@@ -126,6 +126,33 @@
126
126
  * is the obvious first follow-up the moment that refusal is observed in the field, but adding it
127
127
  * unmeasured is precisely the speculative loosening condition 4 exists to resist.
128
128
  *
129
+ * DRY-RUN EVIDENCE FOR A MAIN-ONLY WORKFLOW (#474). Some checks never run on a branch at all:
130
+ * `release-auto.yml` fires on `workflow_run` after trunk CI, or on a schedule. 2b then refuses every
131
+ * fix for a red in it (the job is absent on the branch), and a human ci-grant was the only door,
132
+ * even for a mechanical defect. The workflow template therefore offers a DRY RUN: dispatched on the
133
+ * fix branch, it runs the same job and the same steps, but with every external write turned off. Steps
134
+ * that would publish are skipped, and their names end in `PUBLISH_STEP_MARKER`. A sentinel step named
135
+ * `DRY_RUN_STEP` runs only in that mode, and is how a job instance is recognised as a dry run here.
136
+ * Such an instance counts as the job's evidence for 2b (and hence 4a) only when, on top of 2b:
137
+ *
138
+ * D1. both step lists are measurable — trunk's ran-steps and the dry run's steps;
139
+ * D2. every step that RAN on trunk, the failing one included, concluded `success` in the dry run.
140
+ * This is the not-a-back-door proof: a red INSIDE a publishing step can never be cured this way,
141
+ * because the dry run skips exactly that step. It is 4b, applied to dry-run instances on every
142
+ * path, not only the carve-out's;
143
+ * D3. every step the dry run did NOT run to success is a skipped publishing step. A dry run that
144
+ * also skipped some ordinary step past trunk's failure point has not run the job, it has run
145
+ * part of it.
146
+ *
147
+ * Why a NAME marker and not a list declared in the workflow: steps are matched by exact name (D2/4b),
148
+ * so marking the very step that failed on trunk renames it, and D2 then reads it as absent and
149
+ * refuses. A list inside the workflow would be read from the branch, which is the party being graded.
150
+ *
151
+ * Limit, stated: a red in a publishing step, or in a later job that only runs after a tag (npm,
152
+ * deploy), cannot be cured by a dry run. That stays a ci-grant. So does a red job that ran ZERO steps
153
+ * (a runner that never picked it up) on the carve-out path: 4c has no usable duration for it and
154
+ * refuses, which is the safe direction and a deliberately unmade loosening, like the timeout case.
155
+ *
129
156
  * PURE BY CONSTRUCTION, identical posture to ci-grant.js / migration-grant.js / readiness.js /
130
157
  * shipguard.js: signals in, verdict out. No git, no network, no `gh`. The caller (tools/colab)
131
158
  * measures containment, evidence, anti-stacking and the workflow-file diff, and hands them in.
@@ -177,6 +204,25 @@ const PYTHON_MANIFEST_REFUSAL =
177
204
  * never ran is not a job that failed. */
178
205
  const NOT_RED_CONCLUSIONS = new Set(['success', 'cancelled', 'skipped']);
179
206
 
207
+ /** The suffix a step name carries when the dry run skips it because it writes outside the run (#474).
208
+ * The template names its publishing steps with it; D3 admits no other skipped step. */
209
+ const PUBLISH_STEP_MARKER = '[publish]';
210
+
211
+ /** The sentinel step a dry-run job instance runs and an ordinary one skips (#474). Its successful
212
+ * presence is the only thing that marks an instance as a dry run here. Must match the template's
213
+ * step name byte for byte. */
214
+ const DRY_RUN_STEP = 'Dry run — nothing is tagged, released or published';
215
+
216
+ function isPublishStepName(name) {
217
+ return typeof name === 'string' && name.trimEnd().endsWith(PUBLISH_STEP_MARKER);
218
+ }
219
+
220
+ /** A job instance is a dry run iff its sentinel step concluded `success`. A skipped sentinel is an
221
+ * ordinary run (the template's `if:` was false), never a dry one. */
222
+ function isDryRunSteps(steps) {
223
+ return Array.isArray(steps) && steps.some((s) => s && s.name === DRY_RUN_STEP && s.conclusion === 'success');
224
+ }
225
+
180
226
  /** A step "ran" on trunk iff it reached a terminal conclusion that is not `skipped`/`cancelled`.
181
227
  * Steps after the failing one are skipped by GitHub, and a skipped step constrains nothing. */
182
228
  function stepRan(s) {
@@ -245,6 +291,7 @@ function shapeJobEvidence({ redRunJobs, branchRunJobs } = {}) {
245
291
  conclusion: j && j.conclusion,
246
292
  durationMs: j ? durationMs(j.startedAt, j.completedAt) : null,
247
293
  steps: j && Array.isArray(j.steps) ? j.steps.map((s) => ({ name: s && s.name, conclusion: s && s.conclusion })) : null,
294
+ dryRun: !!j && isDryRunSteps(j.steps),
248
295
  }));
249
296
 
250
297
  return { redJobs, branchJobs };
@@ -279,13 +326,46 @@ function indexBranchJobs(branchJobs) {
279
326
  const isRed = j.status === 'completed' && !NOT_RED_CONCLUSIONS.has(j.conclusion);
280
327
  const isPending = j.status !== 'completed';
281
328
  if (!prev) { idx.set(k, { job: j, hasRed: isRed, hasPending: isPending }); continue; }
282
- const better = j.status === 'completed' && j.conclusion === 'success'
283
- && !(prev.job.status === 'completed' && prev.job.conclusion === 'success');
329
+ const ok = (x) => x.status === 'completed' && x.conclusion === 'success';
330
+ // A green ORDINARY instance outranks a green dry run (#474): the dry-run rules only apply when
331
+ // a dry run is the sole evidence the branch has for that job.
332
+ const better = ok(j) && (!ok(prev.job) || (prev.job.dryRun && !j.dryRun));
284
333
  idx.set(k, { job: better ? j : prev.job, hasRed: prev.hasRed || isRed, hasPending: prev.hasPending || isPending });
285
334
  }
286
335
  return idx;
287
336
  }
288
337
 
338
+ /**
339
+ * The dry-run rules (#474), D1–D3 — see the module header. `red` is a trunk red job (with
340
+ * `ranSteps`), `mine` the branch's dry-run instance of the same job (with `steps`). Returns a refusal
341
+ * reason, or '' when the dry run is admissible evidence for this job.
342
+ */
343
+ function dryRunEvidence(red, mine) {
344
+ const label = jobLabel(red);
345
+ if (!Array.isArray(red.ranSteps) || !Array.isArray(mine.steps)) {
346
+ return `job \`${label}\` is proven only by a dry run, and its step lists could not be read — a dry run is admissible only step by step`;
347
+ }
348
+ const mySteps = new Map();
349
+ for (const s of mine.steps) if (s && s.name) mySteps.set(s.name, s);
350
+ for (const stepName of red.ranSteps) {
351
+ const s = mySteps.get(stepName);
352
+ if (!s) {
353
+ return `step \`${stepName}\` RAN in job \`${label}\` on trunk and is absent from the branch's dry run — a dry run proves only the steps it executes`;
354
+ }
355
+ if (s.conclusion !== 'success') {
356
+ return `step \`${stepName}\` RAN in job \`${label}\` on trunk and concluded \`${s.conclusion}\` in the branch's dry run — ` +
357
+ 'a dry run cannot cure a red in a step it does not execute (a red in a publishing step stays a ci-grant)';
358
+ }
359
+ }
360
+ for (const s of mine.steps) {
361
+ if (!s || s.conclusion === 'success') continue;
362
+ if (s.conclusion === 'skipped' && isPublishStepName(s.name)) continue;
363
+ return `step \`${s && s.name}\` concluded \`${s && s.conclusion}\` in the branch's dry run of job \`${label}\` and is not a publishing step ` +
364
+ `(name ending \`${PUBLISH_STEP_MARKER}\`) — a dry run may skip only the steps that write outside the run`;
365
+ }
366
+ return '';
367
+ }
368
+
289
369
  /**
290
370
  * Sub-test 4a (#321), and — since #297 — condition 2b of EVERY cure: every job RED on trunk exists
291
371
  * on the branch's runs at its own head, completed and successful.
@@ -299,7 +379,8 @@ function indexBranchJobs(branchJobs) {
299
379
  * that exists only on the branch: this certifies that the branch cures trunk's red, not that the
300
380
  * branch is spotless.
301
381
  *
302
- * Returns `{ok, reason, jobs}` — `jobs` is the list of red job names proven on the branch.
382
+ * Returns `{ok, reason, jobs, dryRunJobs}` — `jobs` is the list of red job names proven on the branch,
383
+ * `dryRunJobs` the subset proven only by a dry run (#474), each having passed D1–D3.
303
384
  * Every unmeasurable input is a refusal, never a pass.
304
385
  */
305
386
  function redJobsProvenOnBranch(jobEvidence) {
@@ -317,6 +398,7 @@ function redJobsProvenOnBranch(jobEvidence) {
317
398
  return { ok: false, jobs: [], reason: "the branch's own run reported no jobs to compare against" };
318
399
  }
319
400
  const idx = indexBranchJobs(branchJobs);
401
+ const dryRunJobs = [];
320
402
 
321
403
  for (const red of redJobs) {
322
404
  if (!red || !red.name) {
@@ -341,8 +423,13 @@ function redJobsProvenOnBranch(jobEvidence) {
341
423
  return { ok: false, jobs: [],
342
424
  reason: `job \`${label}\` is red on trunk and failed in another run at the branch's own head — a job that both passed and failed at one sha has proven nothing` };
343
425
  }
426
+ if (mine.dryRun) {
427
+ const why = dryRunEvidence(red, mine);
428
+ if (why) return { ok: false, jobs: [], reason: why };
429
+ dryRunJobs.push(red.name);
430
+ }
344
431
  }
345
- return { ok: true, jobs: redJobs.map((r) => r.name), reason: '' };
432
+ return { ok: true, jobs: redJobs.map((r) => r.name), ...(dryRunJobs.length ? { dryRunJobs } : {}), reason: '' };
346
433
  }
347
434
 
348
435
  /**
@@ -402,6 +489,34 @@ function workflowCarveOut(jobEvidence) {
402
489
  return { ok: true, jobs, reason: '' };
403
490
  }
404
491
 
492
+ /**
493
+ * Would a dry run on the branch supply the evidence 2b is missing (#474)? PURE. Returns the sorted
494
+ * workflow names to dispatch, or `[]`. Non-empty only when EVERY red job is either already passing
495
+ * on the branch (completed `success`, nothing red or pending beside it) or ABSENT from the branch's
496
+ * runs in a workflow listed in `dryRunCapable` — and at least one is absent. A red job that is
497
+ * present-but-failing, pending, or absent in a workflow without a dry-run mode means no dispatch
498
+ * would help, so none is asked for. Whether the dry run, once it exists, passes D1–D3 is decided
499
+ * then, not predicted now.
500
+ */
501
+ function dryRunDispatchPlan(jobEvidence, dryRunCapable) {
502
+ const capable = new Set(Array.isArray(dryRunCapable) ? dryRunCapable : dryRunCapable instanceof Set ? [...dryRunCapable] : []);
503
+ if (!capable.size || !jobEvidence || !Array.isArray(jobEvidence.redJobs) || !jobEvidence.redJobs.length) return [];
504
+ const idx = indexBranchJobs(Array.isArray(jobEvidence.branchJobs) ? jobEvidence.branchJobs : []);
505
+ const want = new Set();
506
+ for (const red of jobEvidence.redJobs) {
507
+ if (!red || !red.name) return [];
508
+ const entry = idx.get(jobKey(red));
509
+ if (!entry) {
510
+ if (!red.workflowName || !capable.has(red.workflowName)) return [];
511
+ want.add(red.workflowName);
512
+ continue;
513
+ }
514
+ const mine = entry.job;
515
+ if (mine.status !== 'completed' || entry.hasPending || mine.conclusion !== 'success' || entry.hasRed) return [];
516
+ }
517
+ return [...want].sort();
518
+ }
519
+
405
520
  /**
406
521
  * The cure verdict for one branch's attempt to ship into a red trunk.
407
522
  *
@@ -453,7 +568,7 @@ function workflowCarveOut(jobEvidence) {
453
568
  * the presence of `carveOut` rather than by re-deriving it.
454
569
  */
455
570
  function cureVerdict({ containsRedSha, evidence, redSha, stacking, workflowsTouched, jobEvidence,
456
- manifestScriptsTouched, manifestPaths, pythonManifestTouched, pythonManifestPaths }) {
571
+ manifestScriptsTouched, manifestPaths, pythonManifestTouched, pythonManifestPaths, dryRunCapable }) {
457
572
  if (!containsRedSha) {
458
573
  return { ok: false,
459
574
  reason: `branch does not contain trunk's current red head \`${redSha}\` as an ancestor — ` +
@@ -473,10 +588,20 @@ function cureVerdict({ containsRedSha, evidence, redSha, stacking, workflowsTouc
473
588
  }
474
589
  const proven = redJobsProvenOnBranch(jobEvidence);
475
590
  if (!proven.ok) {
476
- return { ok: false,
591
+ const out = { ok: false,
477
592
  reason: `branch's run is green, but the check trunk is red on is not proven here: ${proven.reason} — ` +
478
593
  'a cure must pass the named failing job(s), not merely produce a green run (#297)' };
594
+ // #474: say which dry run would supply the missing evidence — only when every LATER condition
595
+ // already holds, so a dispatch is never asked for on a branch that would refuse anyway.
596
+ const wanted = dryRunDispatchPlan(jobEvidence, dryRunCapable);
597
+ if (wanted.length && stacking && stacking.ok && manifestScriptsTouched === false && pythonManifestTouched === false
598
+ && typeof workflowsTouched === 'boolean') {
599
+ out.dryRunWanted = wanted;
600
+ }
601
+ return out;
479
602
  }
603
+ const dry = proven.dryRunJobs && proven.dryRunJobs.length ? { jobs: proven.dryRunJobs } : null;
604
+ const drySuffix = dry ? ` — the main-only job(s) ${dry.jobs.map((n) => `\`${n}\``).join(', ')} proven by a dry run on the branch (#474)` : '';
480
605
  if (!stacking || !stacking.ok) {
481
606
  return { ok: false, reason: (stacking && stacking.reason) || 'anti-stacking verdict unavailable' };
482
607
  }
@@ -500,13 +625,13 @@ function cureVerdict({ containsRedSha, evidence, redSha, stacking, workflowsTouc
500
625
  return { ok: false, reason: `${WORKFLOW_REFUSAL}. The #321 carve-out does not admit it either: ${carve.reason}` };
501
626
  }
502
627
  const detail = carve.jobs.map((j) => `\`${j.name}\` (${j.redMs}ms red on trunk, ${j.branchMs}ms passing here)`).join(', ');
503
- return { ok: true, provenJobs: proven.jobs, carveOut: { jobs: carve.jobs },
628
+ return { ok: true, provenJobs: proven.jobs, carveOut: { jobs: carve.jobs }, ...(dry ? { dryRun: dry } : {}),
504
629
  reason: `branch contains red \`${redSha}\` as an ancestor AND is green at its own current head (\`${evidence.sha}\`) — proven cure, ` +
505
- `admitted through the #321 workflow carve-out: every job red on trunk ran to success here with every step it took on trunk — ${detail}` };
630
+ `admitted through the #321 workflow carve-out: every job red on trunk ran to success here with every step it took on trunk — ${detail}${drySuffix}` };
506
631
  }
507
- return { ok: true, provenJobs: proven.jobs,
508
- reason: `branch contains red \`${redSha}\` as an ancestor AND is green at its own current head (\`${evidence.sha}\`) — proven cure` };
632
+ return { ok: true, provenJobs: proven.jobs, ...(dry ? { dryRun: dry } : {}),
633
+ reason: `branch contains red \`${redSha}\` as an ancestor AND is green at its own current head (\`${evidence.sha}\`) — proven cure${drySuffix}` };
509
634
  }
510
635
 
511
- module.exports = { cureVerdict, redJobsProvenOnBranch, workflowCarveOut, shapeJobEvidence, WORKFLOW_REFUSAL, MANIFEST_SCRIPTS_REFUSAL,
512
- PYTHON_MANIFEST_REFUSAL };
636
+ module.exports = { cureVerdict, redJobsProvenOnBranch, workflowCarveOut, shapeJobEvidence, dryRunDispatchPlan, WORKFLOW_REFUSAL,
637
+ MANIFEST_SCRIPTS_REFUSAL, PYTHON_MANIFEST_REFUSAL, PUBLISH_STEP_MARKER, DRY_RUN_STEP };
package/tools/lib/git.js CHANGED
@@ -1157,6 +1157,25 @@ function ghRunJobs(repo, runDatabaseId) {
1157
1157
  }));
1158
1158
  }
1159
1159
 
1160
+ /**
1161
+ * Dispatch `workflowFile` on `ref` (#474) — `gh workflow run <file> --ref <ref> -f k=v…`. Returns
1162
+ * `{ok, withInputs, detail}`. If the call with inputs is refused (GitHub can validate inputs against
1163
+ * a workflow file that does not declare them yet), it is retried ONCE without them: the release-auto
1164
+ * template forces dry mode on any ref other than main, so an input-less dispatch of a capable file is
1165
+ * still a dry run. The caller only ever dispatches a file it read as dry-run capable at that ref.
1166
+ * Never waits for the run.
1167
+ */
1168
+ function ghWorkflowDispatch(repo, workflowFile, ref, inputs = {}) {
1169
+ const flags = [];
1170
+ for (const [k, v] of Object.entries(inputs)) flags.push('-f', `${k}=${v}`);
1171
+ const first = run('gh', ['workflow', 'run', workflowFile, '--ref', ref, ...flags], { cwd: repo });
1172
+ if (first.ok) return { ok: true, withInputs: true, detail: '' };
1173
+ if (!flags.length) return { ok: false, withInputs: false, detail: (first.stderr || first.stdout || '').trim().split('\n')[0] || 'gh workflow run failed' };
1174
+ const second = run('gh', ['workflow', 'run', workflowFile, '--ref', ref], { cwd: repo });
1175
+ if (second.ok) return { ok: true, withInputs: false, detail: (first.stderr || '').trim().split('\n')[0] || '' };
1176
+ return { ok: false, withInputs: false, detail: (second.stderr || second.stdout || '').trim().split('\n')[0] || 'gh workflow run failed' };
1177
+ }
1178
+
1160
1179
  /**
1161
1180
  * Issues claimed by the current gh user in a repo = assigned to @me AND labeled in-progress
1162
1181
  * (that pairing is exactly what `colab claim` writes). Returns array of numbers, or null on failure.
@@ -1177,7 +1196,7 @@ module.exports = {
1177
1196
  dirtyTracked, dirtyUntracked, dirtyAny,
1178
1197
  ghAvailable, ghState, ghIssueEdit, ghListLabels, ghOpenIssueNumbersByLabel, ghAssignedIssues,
1179
1198
  ghCurrentLogin, ghIssueView, ghIssueComment, ghRunForSha, ghRunForCommit, ghRunsForCommit, ghRunsForRef, ghRunsAtCommit, ghRunForCommitAnyRef, commitTimeMs, ghRunsSince, summarizeRunsForCommit, isRepoOwnedRun,
1180
- ghRunJobCount, ghRunJobs,
1199
+ ghRunJobCount, ghRunJobs, ghWorkflowDispatch,
1181
1200
  ghIssueListByLabel, ghLabelDelete, ghLabelCreate, ghListLabelsDetailed, ghLabelEditDescription,
1182
1201
  ghApi, isGraphqlRateLimit, ghIssueRelease, ghClaimHolder, ghIssueLabelEvents, ghIssueLabelActors,
1183
1202
  ghPrForBranch, ghPrCreate, ghPrClose, ghRepoVisibility,
@@ -265,9 +265,57 @@ function prereleaseTagTriggers({ readFile, workflows, deploy }) {
265
265
  return out;
266
266
  }
267
267
 
268
+ // --------------------------------------------------- workflow_dispatch inputs (#474)
269
+ //
270
+ // The names declared under `on: workflow_dispatch: inputs:`, in order. `[]` for a bare
271
+ // `workflow_dispatch:` (or one with no inputs), and for a workflow with no dispatch trigger at all —
272
+ // a caller asking "can this be dispatched with dry_run?" needs the same answer for both. Same
273
+ // pragmatic, indentation-aware scan as parseWorkflowOn; the inline `on:` forms carry no inputs.
274
+ function workflowDispatchInputs(text) {
275
+ if (!text) return [];
276
+ const all = text.split(/\r?\n/);
277
+ const start = all.findIndex((l) => /^(on|["']on["'])\s*:\s*(#.*)?$/.test(l));
278
+ if (start === -1) return [];
279
+ const body = [];
280
+ for (let i = start + 1; i < all.length; i++) {
281
+ if (/^\S/.test(all[i])) break;
282
+ body.push(all[i]);
283
+ }
284
+ const indentOf = (l) => l.match(/^(\s*)/)[1].length;
285
+ const meaningful = (l) => l.trim() && !/^\s*#/.test(l);
286
+ const block = (from, parentIndent) => {
287
+ const out = [];
288
+ for (let j = from; j < body.length; j++) {
289
+ if (!meaningful(body[j])) continue;
290
+ if (indentOf(body[j]) <= parentIndent) break;
291
+ out.push(j);
292
+ }
293
+ return out;
294
+ };
295
+ const wd = body.findIndex((l) => /^\s*workflow_dispatch\s*:/.test(l));
296
+ if (wd === -1) return [];
297
+ const wdIndent = indentOf(body[wd]);
298
+ const inp = block(wd + 1, wdIndent).find((j) => /^\s*inputs\s*:\s*(#.*)?$/.test(body[j]));
299
+ if (inp === undefined) return [];
300
+ const lines = block(inp + 1, indentOf(body[inp]));
301
+ if (!lines.length) return [];
302
+ const keyIndent = Math.min(...lines.map((j) => indentOf(body[j])));
303
+ return lines.filter((j) => indentOf(body[j]) === keyIndent)
304
+ .map((j) => (body[j].match(/^\s*([A-Za-z_][\w-]*)\s*:/) || [])[1]).filter(Boolean);
305
+ }
306
+
307
+ // A workflow's top-level `name:` — what the runs API reports as `workflowName` — or null.
308
+ function workflowNameOf(text) {
309
+ if (!text) return null;
310
+ const m = text.match(/^name:\s*(.+?)\s*$/m);
311
+ if (!m) return null;
312
+ return m[1].replace(/\s+#.*$/, '').replace(/^["']|["']$/g, '').trim() || null;
313
+ }
314
+
268
315
  module.exports = {
269
316
  PRERELEASE_TAG_PROBE,
270
317
  parseWorkflowOn, listField, githubFilterRegex, githubFilterMatches, workflowFiresOnTag,
271
318
  workflowFiresOnBranchPush, workflowsFiringOnBranchPush,
272
319
  isDeployWorkflow, isReleaseTagTemplateCopy, prereleaseTagTriggers,
320
+ workflowDispatchInputs, workflowNameOf,
273
321
  };