@patronage/factory-ci 1.0.0-alpha.46 → 1.0.0-alpha.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { t as bundleAlchemyEntry } from "./bundle-alchemy-entry-Ba1Ebp91.js";
2
- import { a as localPreviewStage, c as assertAlchemyBaseline, i as isLocalPreviewStage, n as executeAlchemyEntry, o as parseLocalPreviewStage, s as ALCHEMY_BASELINE, t as EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER } from "./execute-alchemy-entry-CxQrjSg8.js";
3
- import { createRequire } from "node:module";
4
- import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
5
- import path from "node:path";
1
+ import { a as localPreviewStage, c as assertAlchemyBaseline, i as isLocalPreviewStage, n as executeAlchemyEntry, o as parseLocalPreviewStage, s as ALCHEMY_BASELINE, t as EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER } from "./execute-alchemy-entry-D-dMPvaC.js";
2
+ import { t as bundleAlchemyEntry } from "./bundle-alchemy-entry-CcxZTIqt.js";
6
3
  import { createSign, randomUUID } from "node:crypto";
7
4
  import { readFileSync } from "node:fs";
8
5
  import { setTimeout as setTimeout$1 } from "node:timers/promises";
9
6
  import { execFileSync, spawn } from "node:child_process";
10
7
  import { once } from "node:events";
8
+ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
9
+ import { createRequire } from "node:module";
11
10
  import { arch, availableParallelism, cpus, platform, release, totalmem } from "node:os";
11
+ import path from "node:path";
12
12
  import { performance } from "node:perf_hooks";
13
13
  // src/actions.ts
14
14
  /**
@@ -400,9 +400,14 @@ const mintInstallationToken = async (input, options = {}) => {
400
400
  *
401
401
  * It answers one question, before checkout and before install: may this job
402
402
  * reuse the local verification the factory already published for *this exact
403
- * head*? It asks that only on a pull request, so every default-branch push
404
- * executes the full hosted suite (#863). Refusing runs hosted CI; it never
405
- * fails the candidate.
403
+ * head*? On a pull request the head is the PR branch tip. On a push to the
404
+ * default branch, a **merge fallback** extends "this exact head" to "this
405
+ * exact tree": a merge whose tree is byte-identical to the producing pull
406
+ * request's proven head tree reuses that head's proof, but only when the proof
407
+ * is a whole-tree run that *executed* every command the surface requires
408
+ * (#1658). Impact-stamp releases and diff-scoped runs never count on a push,
409
+ * because a merge target is owed the whole tree (#931). Refusing runs hosted
410
+ * CI; it never fails the candidate.
406
411
  *
407
412
  * What a consumer chooses is only *what its guarded surface requires*: the
408
413
  * plain profile command objects that surface selects. Everything else below is
@@ -490,26 +495,43 @@ const FACTORY_PROOF_GATE_MODE_OUTPUT = "mode";
490
495
  /** Exact Checks API URL of the proof generation selected by the gate. */
491
496
  const FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT = "source-check-url";
492
497
  /**
498
+ * The commit whose proof was reused, when the gate reused one. On a pull
499
+ * request it is the head itself; on a merge-target push it is the producing
500
+ * pull request's head, a different commit than the pushed one (#1658). Empty
501
+ * on every refusal.
502
+ */
503
+ const FACTORY_PROOF_GATE_SOURCE_HEAD_OUTPUT = "source-head";
504
+ /**
493
505
  * Guard for every step the gate protects. Deliberately `!= 'true'` and not
494
506
  * `== 'false'`: an unset, empty, or garbled output must run the suite.
495
507
  */
496
508
  const FACTORY_PROOF_GATE_GUARD = `steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_OUTPUT} != 'true'`;
497
509
  /**
498
- * Pull requests only — the gate's single condition (#873, default since #863,
499
- * the only mode since the merge-target opt-out was deleted).
510
+ * Pull requests, plus pushes to the default branch (#611, #1658) — the gate's
511
+ * single condition.
512
+ *
513
+ * A merge target's guarantee is about the whole tree, not the diff. A squash
514
+ * merge mints a new commit, so no proof is ever written for the merged SHA;
515
+ * the push path exists only for the merge fallback, which reuses the
516
+ * producing pull request's head proof when the merge tree *is* that head's
517
+ * tree and the proof's whole-tree run executed every command the surface
518
+ * requires.
500
519
  *
501
- * A merge target's guarantee is about the whole tree, not the diff. A
502
- * candidate proof only ever binds the diff the candidate was scoped to, so
503
- * reusing it on the merged commit proves less than the merge target needs.
504
- * #931 is that defect observed — a `main` push reused a candidate proof,
505
- * executed no command, and left a red package unnoticed for three days. Every
506
- * default-branch push therefore executes the full hosted suite, whatever
507
- * proof exists.
520
+ * #931 is why both conditions are load-bearing. A `main` push once reused an
521
+ * impact-scoped candidate proof, executed no command for an untouched
522
+ * package, and left that package red for three days. An impact-scoped proof
523
+ * is a sound gate for the candidate and an unsound one for the merge target,
524
+ * so a push credits no `notRequiredCommands` release. The same holds for a
525
+ * command that ran but scoped itself to the diff through the run context
526
+ * (`psf affected`): only a proof recording `runScope: "whole-tree"` counts.
527
+ * Anything else runs the full battery.
508
528
  *
509
- * Which branches trigger the workflow at all stays repository-owned. This
510
- * condition only keeps the gate from consulting proof outside a pull request.
529
+ * The push side is deliberately the default branch only. Which branches
530
+ * trigger a workflow at all stays repository-owned; this condition only keeps
531
+ * the gate from consulting proof on pushes that are not merges into the
532
+ * default branch.
511
533
  */
512
- const FACTORY_PROOF_GATE_IF = "github.event_name == 'pull_request'";
534
+ const FACTORY_PROOF_GATE_IF = "github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch))";
513
535
  /**
514
536
  * The complete refusal vocabulary: the only distinctions the gate can make
515
537
  * from its Checks API reads.
@@ -630,6 +652,15 @@ const resolveProofReuseCommands = (catalog, names, selectionLabel) => names.map(
630
652
  * jq program: every page of the Checks API result in, four sanitized lines
631
653
  * (`reason`, `mode`, uncovered commands, source URL) out.
632
654
  *
655
+ * `$creditReleases` is `true` on a pull request and `false` on any push,
656
+ * the merge fallback included. With it `false`, a validated
657
+ * `notRequiredCommands` release still covers nothing, and the proof must
658
+ * also record `runScope: "whole-tree"`: `pr:verify` hands each command the
659
+ * diff, and a command may scope itself to it (`psf affected`), so a command
660
+ * name in `executedCommands` says the command ran, not that it covered the
661
+ * tree. Only a whole-tree run's executed commands are what a merge target is
662
+ * owed (#931, #1658). Without it, `whole-tree run` is reported missing.
663
+ *
633
664
  * The input is what `gh api --paginate` actually writes: the pages
634
665
  * *concatenated* as a stream of top-level response objects, not merged into
635
666
  * one document and not wrapped in an array. That is why the script invokes
@@ -977,8 +1008,13 @@ def releaseAuthorized($release; $commands; $stamp):
977
1008
  and (([$releases[].name] - $executed | length) == ($releases | length))
978
1009
  and ($releases | all(.[]; releaseAuthorized(.; $commands; $stamp)))
979
1010
  end) as $releasesValid
980
- | (if $releasesValid then [$releases[].name] else [] end) as $released
981
- | ($required - $executed - $released) as $missing
1011
+ | (if $releasesValid and $creditReleases
1012
+ then [$releases[].name]
1013
+ else []
1014
+ end) as $released
1015
+ | ($creditReleases or ($proof.runScope == "whole-tree")) as $wholeTree
1016
+ | ( ($required - $executed - $released)
1017
+ + (if $wholeTree then [] else ["whole-tree run"] end) ) as $missing
982
1018
  | (if $run.status != "completed" then "pending"
983
1019
  elif $run.conclusion != "success" then "failed"
984
1020
  elif ($run | bound | not) then "unreadable"
@@ -1010,6 +1046,108 @@ const safeLabel$1 = (surface) => {
1010
1046
  const cleaned = (typeof surface === "string" ? surface : "").replaceAll(/[^\w -]/gu, "").trim().slice(0, 60);
1011
1047
  return cleaned.length > 0 ? cleaned : "verification";
1012
1048
  };
1049
+ /**
1050
+ * The push-event merge fallback (#611, restored with executed-only coverage
1051
+ * by #1658). Emitted into every gate script; on a pull request event it is
1052
+ * inert.
1053
+ */
1054
+ const MERGE_FALLBACK_BLOCK = String.raw`# Merge fallback (#611, #1658). A squash merge mints a new commit, so the
1055
+ # direct read at a pushed merge-target head finds nothing even when the
1056
+ # factory proved the producing pull request head. Only when the direct read
1057
+ # found no generation at all on a push event, look up the producing pull
1058
+ # request and reuse its head proof, and only when:
1059
+ #
1060
+ # - the merge commit's TREE id equals the proven head's tree id, which makes
1061
+ # the pushed content byte-identical to what was verified. That is a clean
1062
+ # squash of a head that already contained the previous default-branch tip.
1063
+ # Patch identity was considered and rejected as the comparator: git
1064
+ # patch-id normalizes whitespace and ignores base motion, so an identical
1065
+ # patch can still produce an integrated tree that was never tested. Tree
1066
+ # identity also makes "no other merge landed in between" unnecessary to
1067
+ # check separately: if one had, the trees would differ.
1068
+ # - the proof EXECUTED every command this surface requires, in a run that
1069
+ # handed every command the whole tree (runScope "whole-tree"). Impact-stamp
1070
+ # releases are not credited here (gate_lookup ... false), and neither is a
1071
+ # diff-scoped run, whose commands may have scoped themselves to the diff:
1072
+ # both are weaker than the whole tree a merge target is owed (#931).
1073
+ #
1074
+ # Everything else -- no unique merged producing PR, an unreadable commit, a
1075
+ # proof that is anything but proven, an executed set that does not cover the
1076
+ # surface, or tree drift from a dirty or stale merge -- leaves the direct
1077
+ # "none" refusal standing, so the full suite runs (fail open).
1078
+ if [ "$reason" = 'none' ] && [ "${shellExpansion$1("GITHUB_EVENT_NAME:-")}" = 'push' ]; then
1079
+ producing_head=''
1080
+ producing_number=''
1081
+ producing_row=''
1082
+ merge_tree=''
1083
+ head_tree=''
1084
+ if ! producing_pulls=$(gh api --method GET --paginate \
1085
+ "repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA/pulls" \
1086
+ -f per_page=100 2>&1); then
1087
+ detail="producing pull request unreadable: $producing_pulls"
1088
+ elif ! producing_row=$(jq -r -s \
1089
+ --arg sha "$HEAD_SHA" \
1090
+ '[ add[]?
1091
+ | select((.merged_at // null) != null)
1092
+ | select((.merge_commit_sha // "") == $sha)
1093
+ | [((.head.sha // "") | tostring), ((.number // "") | tostring)]
1094
+ | join(" ") ]
1095
+ | if length == 1 then .[0] else "" end' 2>&1 <<< "$producing_pulls"); then
1096
+ detail="producing pull request unreadable: $producing_row"
1097
+ producing_row=''
1098
+ fi
1099
+ if [ -n "$producing_row" ]; then
1100
+ read -r producing_head producing_number <<< "$producing_row" || :
1101
+ fi
1102
+ if [ -n "$detail" ]; then
1103
+ :
1104
+ elif ! [[ "$producing_head" =~ ^[0-9a-f]{40}$ ]] \
1105
+ || ! [[ "$producing_number" =~ ^[0-9]+$ ]]; then
1106
+ detail='no single merged producing pull request at this commit'
1107
+ producing_head=''
1108
+ elif ! merge_commit=$(gh api --method GET \
1109
+ "repos/$GITHUB_REPOSITORY/commits/$HEAD_SHA" 2>&1); then
1110
+ detail="merge commit unreadable: $merge_commit"
1111
+ elif ! merge_tree=$(jq -r \
1112
+ '(.commit.tree.sha // "") | tostring' 2>&1 <<< "$merge_commit"); then
1113
+ detail="merge commit unreadable: $merge_tree"
1114
+ merge_tree=''
1115
+ elif ! [[ "$merge_tree" =~ ^[0-9a-f]{40}$ ]]; then
1116
+ detail='merge commit carries no readable tree id'
1117
+ merge_tree=''
1118
+ elif ! head_commit=$(gh api --method GET \
1119
+ "repos/$GITHUB_REPOSITORY/commits/$producing_head" 2>&1); then
1120
+ detail="producing head commit unreadable: $head_commit"
1121
+ elif ! head_tree=$(jq -r \
1122
+ '(.commit.tree.sha // "") | tostring' 2>&1 <<< "$head_commit"); then
1123
+ detail="producing head commit unreadable: $head_tree"
1124
+ head_tree=''
1125
+ elif ! [[ "$head_tree" =~ ^[0-9a-f]{40}$ ]]; then
1126
+ detail='producing head commit carries no readable tree id'
1127
+ head_tree=''
1128
+ elif [ "$merge_tree" != "$head_tree" ]; then
1129
+ detail="tree drift: the merge result is not the tree proven at pull request #$producing_number head $producing_head"
1130
+ merge_tree=''
1131
+ fi
1132
+ if [ -z "$detail" ] \
1133
+ && [[ "$producing_head" =~ ^[0-9a-f]{40}$ ]] \
1134
+ && [[ "$merge_tree" =~ ^[0-9a-f]{40}$ ]] \
1135
+ && [ "$merge_tree" = "$head_tree" ]; then
1136
+ gate_lookup "$producing_head" false
1137
+ if [ "$lookup_reason" = 'proven' ]; then
1138
+ reason=proven
1139
+ mode="$lookup_mode"
1140
+ missing=''
1141
+ source_url="$lookup_url"
1142
+ proof_head="$producing_head"
1143
+ merge_note="pull request #$producing_number. The merge result's tree \`$merge_tree\` is byte-identical to the tree proven at its head \`$producing_head\`, and that proof's whole-tree run executed every command this surface requires"
1144
+ elif [ "$lookup_reason" = 'incomplete' ]; then
1145
+ detail="producing pull request #$producing_number proof not reusable (incomplete: a merge target counts only the commands a whole-tree run executed; missing: $lookup_missing)"
1146
+ else
1147
+ detail="producing pull request #$producing_number proof not reusable ($lookup_reason) $lookup_detail"
1148
+ fi
1149
+ fi
1150
+ fi`;
1013
1151
  const gateScript = (required, surface) => String.raw`
1014
1152
  set -uo pipefail
1015
1153
 
@@ -1023,12 +1161,19 @@ detail=''
1023
1161
  mode=''
1024
1162
  missing=''
1025
1163
  source_url=''
1164
+ proof_head=''
1165
+ merge_note=''
1026
1166
 
1027
1167
  # One proof lookup at one commit. Sets lookup_reason / lookup_mode /
1028
1168
  # lookup_missing / lookup_url, or lookup_detail when the read itself
1029
1169
  # failed. Always returns 0: every caller must reach the single
1030
1170
  # GITHUB_OUTPUT write below whatever this function meets.
1031
1171
  #
1172
+ # $2 is whether impact-stamp releases may cover a required command: 'true'
1173
+ # on a pull request, 'false' on any push, where only executed commands count
1174
+ # because a merge target is owed the whole tree (#931, #1658). Anything but
1175
+ # 'true' is false.
1176
+ #
1032
1177
  # filter=all with full pagination is load-bearing (ADR 0022). GitHub's
1033
1178
  # default "latest" filter is ordered by completion, so a newer generation
1034
1179
  # that is still running can be hidden behind an older completed one — the
@@ -1039,6 +1184,10 @@ gate_lookup() {
1039
1184
  lookup_missing=''
1040
1185
  lookup_url=''
1041
1186
  lookup_detail=''
1187
+ lookup_credit=false
1188
+ if [ "${shellExpansion$1("2:-")}" = 'true' ]; then
1189
+ lookup_credit=true
1190
+ fi
1042
1191
  if ! lookup_response=$(gh api --method GET --paginate \
1043
1192
  "repos/$GITHUB_REPOSITORY/commits/$1/check-runs" \
1044
1193
  -f "check_name=$CHECK_NAME" \
@@ -1055,6 +1204,7 @@ gate_lookup() {
1055
1204
  --arg sha "$1" \
1056
1205
  --arg repository "$GITHUB_REPOSITORY" \
1057
1206
  --argjson required "$REQUIRED_COMMANDS" \
1207
+ --argjson creditReleases "$lookup_credit" \
1058
1208
  '${GATE_JQ}' 2>&1 <<< "$lookup_response"); then
1059
1209
  lookup_detail="unreadable proof binding: $lookup_finding"
1060
1210
  return 0
@@ -1090,14 +1240,25 @@ if [ -z "${shellExpansion$1("HEAD_SHA:-")}" ]; then
1090
1240
  elif [ -z "${shellExpansion$1("GITHUB_REPOSITORY:-")}" ]; then
1091
1241
  detail='no repository name'
1092
1242
  else
1093
- gate_lookup "$HEAD_SHA"
1243
+ # A push is a merge target even when the pushed tip is a candidate's own
1244
+ # head (a fast-forward), so it credits executed commands only there too.
1245
+ direct_credit=true
1246
+ if [ "${shellExpansion$1("GITHUB_EVENT_NAME:-")}" = 'push' ]; then
1247
+ direct_credit=false
1248
+ fi
1249
+ gate_lookup "$HEAD_SHA" "$direct_credit"
1094
1250
  reason="$lookup_reason"
1095
1251
  detail="$lookup_detail"
1096
1252
  mode="$lookup_mode"
1097
1253
  missing="$lookup_missing"
1098
1254
  source_url="$lookup_url"
1255
+ if [ "$reason" = 'proven' ]; then
1256
+ proof_head="$HEAD_SHA"
1257
+ fi
1099
1258
  fi
1100
1259
 
1260
+ ${MERGE_FALLBACK_BLOCK}
1261
+
1101
1262
  # The binding is App-verified, but it still reaches markdown. Only a plain
1102
1263
  # lowercase token is quoted back; anything else is reported as unknown.
1103
1264
  case "$mode" in
@@ -1108,6 +1269,8 @@ esac
1108
1269
  verdict=false
1109
1270
  if [ "$reason" = 'proven' ]; then
1110
1271
  verdict=true
1272
+ else
1273
+ proof_head=''
1111
1274
  fi
1112
1275
 
1113
1276
  # detail can carry arbitrary gh or jq error text. Collapse it to one bounded
@@ -1131,7 +1294,7 @@ say ''
1131
1294
 
1132
1295
  case "$reason" in
1133
1296
  proven)
1134
- echo "Factory proof: reusing local verification of $HEAD_SHA; skipping the $SURFACE suite."
1297
+ echo "Factory proof: reusing local verification of $proof_head; skipping the $SURFACE suite."
1135
1298
  say "Skipped. The factory already verified this exact content, so this job did not run the $SURFACE suite a second time."
1136
1299
  say ''
1137
1300
  if [ -n "$source_url" ]; then
@@ -1139,13 +1302,20 @@ case "$reason" in
1139
1302
  else
1140
1303
  say "- Reused proof: the \`$CHECK_NAME\` check run published by the pinned factory GitHub App."
1141
1304
  fi
1142
- say "- Covers head: \`$HEAD_SHA\`"
1305
+ say "- Covers head: \`$proof_head\`"
1306
+ if [ -n "$merge_note" ]; then
1307
+ say "- Merge-target reuse: $merge_note."
1308
+ fi
1143
1309
  say "- Recorded mode: \`$mode\` (diagnostic only), outcome \`passed\`."
1144
1310
  ;;
1145
1311
  none)
1146
1312
  say 'Ran the full suite. No trusted factory proof covers this commit.'
1147
1313
  say ''
1148
1314
  say "The factory GitHub App has published no \`$CHECK_NAME\` check run at head \`$HEAD_SHA\`. Proof is keyed to the commit, so proof written for any other commit is not visible here. A pull request opened by hand carries no factory proof at all, which is normal."
1315
+ if [ -n "$detail" ]; then
1316
+ say ''
1317
+ say "- Merge fallback: $detail"
1318
+ fi
1149
1319
  say ''
1150
1320
  say '${CORRECTIVE_LINE}'
1151
1321
  ;;
@@ -1173,7 +1343,11 @@ case "$reason" in
1173
1343
  incomplete)
1174
1344
  say "Ran the full suite. The factory proof for this commit does not cover every command the $SURFACE surface requires."
1175
1345
  say ''
1176
- say "The newest \`$CHECK_NAME\` check run at head \`$HEAD_SHA\` passed, but its executed commands plus stamp-authorized \`notRequiredCommands\` do not cover this surface. Missing: \`$missing\`"
1346
+ if [ "${shellExpansion$1("GITHUB_EVENT_NAME:-")}" = 'push' ]; then
1347
+ say "The newest \`$CHECK_NAME\` check run at head \`$HEAD_SHA\` passed, but a merge target counts only the commands a whole-tree run executed, and those do not cover this surface. Missing: \`$missing\`"
1348
+ else
1349
+ say "The newest \`$CHECK_NAME\` check run at head \`$HEAD_SHA\` passed, but its executed commands plus stamp-authorized \`notRequiredCommands\` do not cover this surface. Missing: \`$missing\`"
1350
+ fi
1177
1351
  say ''
1178
1352
  say '${CORRECTIVE_LINE}'
1179
1353
  ;;
@@ -1205,6 +1379,7 @@ fi
1205
1379
  printf '${FACTORY_PROOF_GATE_REASON_OUTPUT}=%s\n' "$reason"
1206
1380
  printf '${FACTORY_PROOF_GATE_MODE_OUTPUT}=%s\n' "$mode"
1207
1381
  printf '${FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT}=%s\n' "$source_url"
1382
+ printf '${FACTORY_PROOF_GATE_SOURCE_HEAD_OUTPUT}=%s\n' "$proof_head"
1208
1383
  } >> "${shellExpansion$1("GITHUB_OUTPUT:-/dev/null")}"
1209
1384
  `.trim();
1210
1385
  /**
@@ -1227,8 +1402,11 @@ const factoryProofGateScript = ({ commands, surface }) => {
1227
1402
  * The step itself, structurally accepted by gagen's `step()` without adding a
1228
1403
  * gagen runtime dependency. It belongs first in the job it guards: a few API
1229
1404
  * reads with the default `GITHUB_TOKEN`, no checkout, no install, so a proven
1230
- * head costs a runner nothing beyond job startup. The step runs on pull
1231
- * requests only, so it needs only `checks: read` (#873, #863).
1405
+ * head costs a runner nothing beyond job startup. A pull request read needs
1406
+ * only `checks: read`. The merge fallback on a default-branch push also reads
1407
+ * the producing pull request (`pull-requests: read`) and the two commit
1408
+ * objects whose tree ids it compares (`contents: read`). A job that grants
1409
+ * less loses only the fallback: the failed read degrades to the full suite.
1232
1410
  *
1233
1411
  * A **step, not a job**, and that is not a style preference. A separate gate
1234
1412
  * job that errored would leave the guarded job `skipped`, and a summary job
@@ -1950,6 +2128,8 @@ say '## ${label} timing'
1950
2128
  say ''
1951
2129
 
1952
2130
  if [ "${shellExpansion("GITHUB_EVENT_NAME:-")}" = 'push' ] && [ -z "${shellExpansion("PROOF_REASON:-")}" ]; then
2131
+ # A push run with no recorded reason is one where the gate step's condition
2132
+ # kept it off entirely: a push to a ref other than the default branch.
1953
2133
  say '- Path: full execution, no proof consulted'
1954
2134
  say '- Proof-reuse gate: did not run on this ref; the full suite ran.'
1955
2135
  say "- Verified head: \`${shellExpansion("GITHUB_SHA:-unknown")}\`"
@@ -1959,9 +2139,18 @@ elif [ "${shellExpansion("PROOF_REUSED:-")}" = 'true' ]; then
1959
2139
  if [ -n "${shellExpansion("PROOF_SOURCE_URL:-")}" ]; then
1960
2140
  say "- Reused proof: [exact source check](${shellExpansion("PROOF_SOURCE_URL")})"
1961
2141
  fi
1962
- say "- Bound head: \`${shellExpansion("PROOF_HEAD_SHA:-unknown")}\`"
2142
+ # On a merge-target push the reused proof is the producing pull request
2143
+ # head's, a different commit than the pushed one (#1658).
2144
+ bound_head="${shellExpansion("PROOF_SOURCE_HEAD:-")}"
2145
+ if [ -z "$bound_head" ]; then
2146
+ bound_head="${shellExpansion("PROOF_HEAD_SHA:-unknown")}"
2147
+ fi
2148
+ say "- Bound head: \`$bound_head\`"
2149
+ if [ "$bound_head" != "${shellExpansion("PROOF_HEAD_SHA:-")}" ]; then
2150
+ say "- Merge target: \`${shellExpansion("PROOF_HEAD_SHA:-unknown")}\` has the same tree as the proven head"
2151
+ fi
1963
2152
  say "- Factory verification mode: ${shellExpansion("PROOF_MODE:-unavailable")} (diagnostic only)"
1964
- echo "::notice title=Factory proof reuse::Reused trusted local proof for ${label} at ${shellExpansion("PROOF_HEAD_SHA:-unknown")}."
2153
+ echo "::notice title=Factory proof reuse::Reused trusted local proof for ${label} at $bound_head."
1965
2154
  else
1966
2155
  say "- Path: full GitHub CI fallback (${shellExpansion("PROOF_REASON:-error")})"
1967
2156
  say "- Bound head: \`${shellExpansion("PROOF_HEAD_SHA:-unknown")}\`"
@@ -1984,6 +2173,7 @@ const factoryProofReuseSummaryStep = (options) => Object.freeze({
1984
2173
  PROOF_MODE: githubExpression(`steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_MODE_OUTPUT}`),
1985
2174
  PROOF_REASON: githubExpression(`steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_REASON_OUTPUT}`),
1986
2175
  PROOF_REUSED: githubExpression(`steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_OUTPUT}`),
2176
+ PROOF_SOURCE_HEAD: githubExpression(`steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_SOURCE_HEAD_OUTPUT}`),
1987
2177
  PROOF_SOURCE_URL: githubExpression(`steps.${FACTORY_PROOF_GATE_STEP_ID}.outputs.${FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT}`)
1988
2178
  }),
1989
2179
  if: "always()",
@@ -4307,4 +4497,4 @@ const assertWorkflowShellParses = (yaml, options) => {
4307
4497
  const detail = failures.map((failure) => ` - ${failure.step ?? "unnamed step"}: ${failure.stderr.replaceAll("\n", "\n ")}`).join("\n");
4308
4498
  throw new Error(`${options.source} emits shell bash cannot parse; the runner would treat it as a no-op:\n${detail}`);
4309
4499
  };
4310
- export { ALCHEMY_BASELINE, EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER, FACTORY_APP_BROKER_ORIGIN, FACTORY_APP_BROKER_PATH, FACTORY_APP_BROKER_TOKEN_PERMISSIONS, FACTORY_CANDIDATE_IMPACT_BASIS_OUTPUT, FACTORY_CANDIDATE_IMPACT_DECISION_OUTPUT, FACTORY_CANDIDATE_IMPACT_INERT_OUTPUT, FACTORY_CANDIDATE_IMPACT_STEP_ID, FACTORY_CANDIDATE_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_CANDIDATE_PULL_REQUEST_TYPES, FACTORY_CURSOR_OIDC_AUDIENCE, FACTORY_CURSOR_OIDC_ISSUER, FACTORY_CURSOR_OIDC_JWKS_URL, FACTORY_CURSOR_OIDC_MANAGED_RUNTIME, FACTORY_LIFECYCLE_CONTRACT_JOB_ID, FACTORY_LIFECYCLE_CONTRACT_JOB_NAME, FACTORY_MERGE_FREEZE_APP_TOKEN_STEP_ID, FACTORY_MERGE_FREEZE_CHECK_NAME, FACTORY_MERGE_FREEZE_IF, FACTORY_MERGE_FREEZE_JOB_ID, FACTORY_MERGE_FREEZE_JOB_NAME, FACTORY_MERGE_FREEZE_PERMISSIONS, FACTORY_MERGE_FREEZE_VERIFY_RESULT_EXPRESSION, FACTORY_MERGE_TARGET_REF_CONDITION, FACTORY_PREVIEW_CLEANUP_APP_TOKEN_STEP_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_NAME, FACTORY_PREVIEW_CLEANUP_CHECKOUT_REF, FACTORY_PREVIEW_CLEANUP_DEFAULT_SWEEP_CRON, FACTORY_PREVIEW_CLEANUP_DESTROY_STEP_ID, FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_ID, FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_NAME, FACTORY_PREVIEW_CLEANUP_DISCOVER_STEP_ID, FACTORY_PREVIEW_CLEANUP_PR_CLOSED_CONDITION, FACTORY_PREVIEW_CLEANUP_SWEEP_CONDITION, FACTORY_PRODUCTION_IMPACT_BASIS_OUTPUT, FACTORY_PRODUCTION_IMPACT_DECISION_OUTPUT, FACTORY_PRODUCTION_IMPACT_STEP_ID, FACTORY_PRODUCTION_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_PROOF_GATE_APP_ID, FACTORY_PROOF_GATE_CHECK_NAME, FACTORY_PROOF_GATE_GUARD, FACTORY_PROOF_GATE_IF, FACTORY_PROOF_GATE_MODE_OUTPUT, FACTORY_PROOF_GATE_OUTPUT, FACTORY_PROOF_GATE_REASONS, FACTORY_PROOF_GATE_REASON_OUTPUT, FACTORY_PROOF_GATE_SHELL, FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT, FACTORY_PROOF_GATE_STEP_ID, FACTORY_PROOF_GATE_STEP_NAME, FACTORY_PR_STATUS_HUD_APP_TOKEN_STEP_ID, FACTORY_PR_STATUS_HUD_CONCURRENCY, FACTORY_PR_STATUS_HUD_IF, FACTORY_PR_STATUS_HUD_JOB_ID, FACTORY_PR_STATUS_HUD_JOB_NAME, FACTORY_PR_STATUS_HUD_PERMISSIONS, FACTORY_PR_STATUS_HUD_PLAN_PATH, FACTORY_PUSH_IDENTITY_SCHEMA_VERSION, GitHubApiError, GitHubAppTokenTransportError, NODE_PNPM_ACTION_FAMILY_NODE24, PREVIEW_PROOF_INVENTORY_CHECK_NAME, PREVIEW_PROOF_INVENTORY_LIST_PERMISSIONS, PreviewProofTransportError, SETUP_STEP_ROLES, UPLOAD_ARTIFACT, VITEST_PROFILE_SCHEMA_VERSION, VITEST_PROFILE_TOOL, VitestProfileError, assertAlchemyBaseline, assertPreviewCleanupStackPolicy, assertPreviewCleanupTargetsAbsent, assertProofReuseCoverage, assertVerifyRunnerPolicy, assertWorkflowShellParses, bundleAlchemyEntry, captureVitestProfileEnvironment, discoverOrphanedPreviewCleanupTargets, discoverPreviewCleanupTargets, executeAlchemyEntry, factoryCandidateImpactWorkflow, factoryCandidateOrPushCondition, factoryLifecycleContractLane, factoryMergeFreezeJob, factoryMergeFreezeScript, factoryPrStatusHudWorkflow, factoryPreviewCleanupTopology, factoryPreviewCleanupWorkflow, factoryPreviewReceiptWorkflow, factoryProductionImpactWorkflow, factoryProofGateScript, factoryProofGateStep, factoryProofReuseSummaryStep, factoryProofTimingStartStep, factoryPushIdentityConsumer, factoryPushIdentityProducer, factoryVerifyRunner, factoryWorkflow, githubAppJwt, isLocalPreviewStage, localPreviewStage, mintInstallationToken, normalizeVitestProfileSample, parseHostedPreviewStage, parseLocalPreviewStage, parsePreviewCleanupResidue, parsePreviewCleanupTargets, previewCleanupDestroyJobId, previewCleanupGithubOutput, previewCleanupResiduePullRequests, previewCleanupStackOutputKey, previewProofInventory, previewProofLifecycle, productionImpactTargetOutput, proofReuseCoverage, proofReuseRequiredCommands, readPullRequestStates, readVitestProfileDocument, recordPreviewCleanupOutcome, resolveProofReuseCommands, runVitestProfile, setupStepsForRoles, verifyRunnerPolicy, workflowRunBlocks, workflowShellParseFailures, writeVitestProfile };
4500
+ export { ALCHEMY_BASELINE, EXECUTE_ALCHEMY_ENTRY_MAX_BUFFER, FACTORY_APP_BROKER_ORIGIN, FACTORY_APP_BROKER_PATH, FACTORY_APP_BROKER_TOKEN_PERMISSIONS, FACTORY_CANDIDATE_IMPACT_BASIS_OUTPUT, FACTORY_CANDIDATE_IMPACT_DECISION_OUTPUT, FACTORY_CANDIDATE_IMPACT_INERT_OUTPUT, FACTORY_CANDIDATE_IMPACT_STEP_ID, FACTORY_CANDIDATE_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_CANDIDATE_PULL_REQUEST_TYPES, FACTORY_CURSOR_OIDC_AUDIENCE, FACTORY_CURSOR_OIDC_ISSUER, FACTORY_CURSOR_OIDC_JWKS_URL, FACTORY_CURSOR_OIDC_MANAGED_RUNTIME, FACTORY_LIFECYCLE_CONTRACT_JOB_ID, FACTORY_LIFECYCLE_CONTRACT_JOB_NAME, FACTORY_MERGE_FREEZE_APP_TOKEN_STEP_ID, FACTORY_MERGE_FREEZE_CHECK_NAME, FACTORY_MERGE_FREEZE_IF, FACTORY_MERGE_FREEZE_JOB_ID, FACTORY_MERGE_FREEZE_JOB_NAME, FACTORY_MERGE_FREEZE_PERMISSIONS, FACTORY_MERGE_FREEZE_VERIFY_RESULT_EXPRESSION, FACTORY_MERGE_TARGET_REF_CONDITION, FACTORY_PREVIEW_CLEANUP_APP_TOKEN_STEP_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_ID, FACTORY_PREVIEW_CLEANUP_AUDIT_JOB_NAME, FACTORY_PREVIEW_CLEANUP_CHECKOUT_REF, FACTORY_PREVIEW_CLEANUP_DEFAULT_SWEEP_CRON, FACTORY_PREVIEW_CLEANUP_DESTROY_STEP_ID, FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_ID, FACTORY_PREVIEW_CLEANUP_DISCOVER_JOB_NAME, FACTORY_PREVIEW_CLEANUP_DISCOVER_STEP_ID, FACTORY_PREVIEW_CLEANUP_PR_CLOSED_CONDITION, FACTORY_PREVIEW_CLEANUP_SWEEP_CONDITION, FACTORY_PRODUCTION_IMPACT_BASIS_OUTPUT, FACTORY_PRODUCTION_IMPACT_DECISION_OUTPUT, FACTORY_PRODUCTION_IMPACT_STEP_ID, FACTORY_PRODUCTION_IMPACT_UNSUBSCRIBED_OUTPUT, FACTORY_PROOF_GATE_APP_ID, FACTORY_PROOF_GATE_CHECK_NAME, FACTORY_PROOF_GATE_GUARD, FACTORY_PROOF_GATE_IF, FACTORY_PROOF_GATE_MODE_OUTPUT, FACTORY_PROOF_GATE_OUTPUT, FACTORY_PROOF_GATE_REASONS, FACTORY_PROOF_GATE_REASON_OUTPUT, FACTORY_PROOF_GATE_SHELL, FACTORY_PROOF_GATE_SOURCE_HEAD_OUTPUT, FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT, FACTORY_PROOF_GATE_STEP_ID, FACTORY_PROOF_GATE_STEP_NAME, FACTORY_PR_STATUS_HUD_APP_TOKEN_STEP_ID, FACTORY_PR_STATUS_HUD_CONCURRENCY, FACTORY_PR_STATUS_HUD_IF, FACTORY_PR_STATUS_HUD_JOB_ID, FACTORY_PR_STATUS_HUD_JOB_NAME, FACTORY_PR_STATUS_HUD_PERMISSIONS, FACTORY_PR_STATUS_HUD_PLAN_PATH, FACTORY_PUSH_IDENTITY_SCHEMA_VERSION, GitHubApiError, GitHubAppTokenTransportError, NODE_PNPM_ACTION_FAMILY_NODE24, PREVIEW_PROOF_INVENTORY_CHECK_NAME, PREVIEW_PROOF_INVENTORY_LIST_PERMISSIONS, PreviewProofTransportError, SETUP_STEP_ROLES, UPLOAD_ARTIFACT, VITEST_PROFILE_SCHEMA_VERSION, VITEST_PROFILE_TOOL, VitestProfileError, assertAlchemyBaseline, assertPreviewCleanupStackPolicy, assertPreviewCleanupTargetsAbsent, assertProofReuseCoverage, assertVerifyRunnerPolicy, assertWorkflowShellParses, bundleAlchemyEntry, captureVitestProfileEnvironment, discoverOrphanedPreviewCleanupTargets, discoverPreviewCleanupTargets, executeAlchemyEntry, factoryCandidateImpactWorkflow, factoryCandidateOrPushCondition, factoryLifecycleContractLane, factoryMergeFreezeJob, factoryMergeFreezeScript, factoryPrStatusHudWorkflow, factoryPreviewCleanupTopology, factoryPreviewCleanupWorkflow, factoryPreviewReceiptWorkflow, factoryProductionImpactWorkflow, factoryProofGateScript, factoryProofGateStep, factoryProofReuseSummaryStep, factoryProofTimingStartStep, factoryPushIdentityConsumer, factoryPushIdentityProducer, factoryVerifyRunner, factoryWorkflow, githubAppJwt, isLocalPreviewStage, localPreviewStage, mintInstallationToken, normalizeVitestProfileSample, parseHostedPreviewStage, parseLocalPreviewStage, parsePreviewCleanupResidue, parsePreviewCleanupTargets, previewCleanupDestroyJobId, previewCleanupGithubOutput, previewCleanupResiduePullRequests, previewCleanupStackOutputKey, previewProofInventory, previewProofLifecycle, productionImpactTargetOutput, proofReuseCoverage, proofReuseRequiredCommands, readPullRequestStates, readVitestProfileDocument, recordPreviewCleanupOutcome, resolveProofReuseCommands, runVitestProfile, setupStepsForRoles, verifyRunnerPolicy, workflowRunBlocks, workflowShellParseFailures, writeVitestProfile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patronage/factory-ci",
3
- "version": "1.0.0-alpha.46",
3
+ "version": "1.0.0-alpha.48",
4
4
  "description": "Deep CI and deploy building blocks for Patronage factory projects: workflow source artifacts, hosted diff classification, Alchemy entry execution, and disposable-stage semantics",
5
5
  "keywords": [
6
6
  "alchemy",
@@ -39,18 +39,20 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@alchemy.run/cloudflare": "2.0.0-beta.84",
42
+ "@cloudflare/oxlint-config": "0.1.0",
42
43
  "@patronage/alchemy-d1-state": "0.4.0",
43
44
  "@types/node": "24.19.2",
44
- "@vitest/coverage-v8": "5.0.5",
45
+ "@vitest/coverage-v8": "5.1.1",
45
46
  "alchemy": "2.0.0-beta.84",
46
47
  "effect": "4.0.6",
47
- "knip": "6.43.0",
48
- "oxfmt": "0.75.0",
49
- "oxlint": "1.90.0",
50
- "tsdown": "0.23.2",
48
+ "knip": "6.46.1",
49
+ "oxfmt": "0.79.0",
50
+ "oxlint": "1.94.0",
51
+ "tsdown": "0.23.7",
52
+ "tsrs": "0.25.0-ts7.1.0-beta",
51
53
  "typescript": "7.1.0-beta",
52
- "ultracite": "8.1.0",
53
- "vitest": "5.0.5"
54
+ "ultracite": "8.3.1",
55
+ "vitest": "5.1.1"
54
56
  },
55
57
  "peerDependencies": {
56
58
  "alchemy": ">=2.0.0-beta.63 <3",
@@ -29,6 +29,17 @@ export interface AssertDestroyLeftNothingOptions extends StageStateTarget {
29
29
  readonly stateReader: StageStateReader;
30
30
  }
31
31
 
32
+ /**
33
+ * Whether a reader's answer is a list of resource identifiers. The reader's
34
+ * type promises one, but it is the project's code, so the postcondition
35
+ * checks the value it actually returned.
36
+ */
37
+ const isResourceIdList = (value: unknown): value is readonly string[] =>
38
+ Array.isArray(value) &&
39
+ value.every(
40
+ (resource) => typeof resource === "string" && resource.trim() !== ""
41
+ );
42
+
32
43
  /**
33
44
  * Read the state store through the project's reader.
34
45
  *
@@ -78,10 +89,7 @@ export const assertDestroyLeftNothing = async ({
78
89
  );
79
90
  }
80
91
  const listed = await readState(stateReader, { stack, stage });
81
- if (
82
- !Array.isArray(listed) ||
83
- listed.some((resource) => typeof resource !== "string" || !resource.trim())
84
- ) {
92
+ if (!isResourceIdList(listed)) {
85
93
  // Without this the check passes on `undefined`, which is the reading a
86
94
  // broken reader produces most often, and the assertion becomes vacuous.
87
95
  // A blank entry is the same failure: it is not a resource identifier, so
@@ -101,6 +101,10 @@ const upstreamOfProps = (
101
101
  return byProp;
102
102
  };
103
103
 
104
+ // Alchemy 2 beta types a plan's resources and binding rows as `any`. This
105
+ // mapper is where the evaluated plan becomes the typed `EvaluatedGraph`, so it
106
+ // is the parse boundary those reads cross.
107
+ /* oxlint-disable typescript/no-unsafe-assignment, typescript/no-unsafe-member-access, typescript/no-unsafe-argument */
104
108
  /** Map plan nodes to the graph. A binding row carries Alchemy's Worker shape, `{ bindings: [{ name, type }] }`. */
105
109
  const toGraph = (plan: Alchemy.Plan.Plan): EvaluatedGraph => ({
106
110
  bindings: Object.values(plan.resources).flatMap(({ bindings, resource }) =>
@@ -122,6 +126,7 @@ const toGraph = (plan: Alchemy.Plan.Plan): EvaluatedGraph => ({
122
126
  upstreamByProp: upstreamOfProps(resource.Props ?? {}),
123
127
  })),
124
128
  });
129
+ /* oxlint-enable typescript/no-unsafe-assignment, typescript/no-unsafe-member-access, typescript/no-unsafe-argument */
125
130
 
126
131
  /**
127
132
  * Run a stack program at `stage` and build the graph Alchemy would plan, with no state and no network:
@@ -350,6 +350,11 @@ const ownershipRefusal = (error: unknown): "held" | "lost" | undefined => {
350
350
  const isRecord = (value: unknown): value is Record<string, unknown> =>
351
351
  typeof value === "object" && value !== null && !Array.isArray(value);
352
352
 
353
+ /** Whether a stage view's `resources` is a list of non-empty FQNs. */
354
+ const isFqnList = (value: unknown): value is readonly string[] =>
355
+ Array.isArray(value) &&
356
+ value.every((fqn) => typeof fqn === "string" && fqn !== "");
357
+
353
358
  /**
354
359
  * The `version` of the `alchemy` manifest that owns `cliPath`: the nearest
355
360
  * `package.json` above it whose `name` is `alchemy`. Throws when none is
@@ -723,10 +728,7 @@ class LifecycleRun {
723
728
  phase,
724
729
  this.state.snapshotStage(this.target)
725
730
  );
726
- if (
727
- !Array.isArray(view.resources) ||
728
- view.resources.some((fqn) => typeof fqn !== "string" || fqn === "")
729
- ) {
731
+ if (!isFqnList(view.resources)) {
730
732
  throw this.fail("STATE_STORE_INVALID", phase);
731
733
  }
732
734
  const records = await Promise.all(
@@ -49,6 +49,11 @@ interface StageFilter {
49
49
  const isRecord = (value: unknown): value is Record<string, unknown> =>
50
50
  typeof value === "object" && value !== null;
51
51
 
52
+ /** Whether a stage view's `resources` is a list of non-empty FQNs. */
53
+ const isFqnList = (value: unknown): value is readonly string[] =>
54
+ Array.isArray(value) &&
55
+ value.every((fqn) => typeof fqn === "string" && fqn !== "");
56
+
52
57
  /**
53
58
  * Refuse a stack or stage name that does not address exactly one scope.
54
59
  *
@@ -124,10 +129,7 @@ export const readStageSnapshot = async (
124
129
  assertStageAddress("stage", target.stage);
125
130
  const scope = { stack: target.stack, stage: target.stage };
126
131
  const view = await Effect.runPromise(state.snapshotStage(scope));
127
- if (
128
- !Array.isArray(view.resources) ||
129
- view.resources.some((fqn) => typeof fqn !== "string" || fqn === "")
130
- ) {
132
+ if (!isFqnList(view.resources)) {
131
133
  throw new Error(
132
134
  `The state layer returned no resource list for ${target.stack} in ${target.stage}.`
133
135
  );
@@ -156,7 +156,7 @@ const githubJsonAttempt = async (
156
156
  }
157
157
 
158
158
  try {
159
- return { ok: true, value: (await response.json()) as unknown };
159
+ return { ok: true, value: await response.json() };
160
160
  } catch (error) {
161
161
  // A 2xx whose body dies mid-read is the transport failing, not GitHub
162
162
  // refusing: the EPIPE that motivated #830 lands exactly here.
package/src/index.ts CHANGED
@@ -108,6 +108,7 @@ export {
108
108
  FACTORY_PROOF_GATE_REASON_OUTPUT,
109
109
  FACTORY_PROOF_GATE_REASONS,
110
110
  FACTORY_PROOF_GATE_SHELL,
111
+ FACTORY_PROOF_GATE_SOURCE_HEAD_OUTPUT,
111
112
  FACTORY_PROOF_GATE_SOURCE_URL_OUTPUT,
112
113
  FACTORY_PROOF_GATE_STEP_ID,
113
114
  FACTORY_PROOF_GATE_STEP_NAME,