forgedock 1.52.0 → 1.53.0

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 (93) hide show
  1. package/bin/engine/outcome-codes.mjs +3 -0
  2. package/bin/engine/telemetry-seam.mjs +4 -2
  3. package/bin/engine-cli.mjs +53 -16
  4. package/bin/experiment.mjs +58 -6
  5. package/bin/forge-utils.mjs +6 -2
  6. package/bin/forgedock.mjs +15 -1
  7. package/bin/lean/account-watch.mjs +28 -0
  8. package/bin/lean/account-watch.test.mjs +30 -0
  9. package/bin/lean/activation.mjs +20 -0
  10. package/bin/lean/activation.test.mjs +14 -1
  11. package/bin/lean/basered.mjs +115 -0
  12. package/bin/lean/basered.test.mjs +66 -0
  13. package/bin/lean/batch-health.mjs +40 -6
  14. package/bin/lean/batch-health.test.mjs +34 -1
  15. package/bin/lean/batch.mjs +41 -2
  16. package/bin/lean/batch.test.mjs +104 -2
  17. package/bin/lean/checkpoint-reconcile.mjs +43 -0
  18. package/bin/lean/checkpoint-reconcile.test.mjs +95 -0
  19. package/bin/lean/conformance.e2e.test.mjs +1 -1
  20. package/bin/lean/conformance.mjs +195 -22
  21. package/bin/lean/conformance.test.mjs +152 -5
  22. package/bin/lean/effects.mjs +8 -4
  23. package/bin/lean/execution.mjs +19 -3
  24. package/bin/lean/execution.test.mjs +39 -0
  25. package/bin/lean/findinglabel.mjs +16 -0
  26. package/bin/lean/findinglabel.test.mjs +39 -0
  27. package/bin/lean/issuewatch-release.mjs +6 -2
  28. package/bin/lean/issuewatch-release.test.mjs +16 -0
  29. package/bin/lean/issuewatch.mjs +11 -1
  30. package/bin/lean/lanelock.mjs +14 -0
  31. package/bin/lean/lean.mjs +165 -34
  32. package/bin/lean/lean.test.mjs +289 -9
  33. package/bin/lean/light.mjs +48 -7
  34. package/bin/lean/light.test.mjs +37 -3
  35. package/bin/lean/limits.test.mjs +142 -9
  36. package/bin/lean/orchestrate-cancel.test.mjs +143 -0
  37. package/bin/lean/orchestrate.mjs +96 -26
  38. package/bin/lean/postdeploy-check.test.mjs +39 -0
  39. package/bin/lean/prompts.mjs +8 -7
  40. package/bin/lean/quota.mjs +39 -0
  41. package/bin/lean/recovery.test.mjs +10 -0
  42. package/bin/lean/relaxation.mjs +73 -0
  43. package/bin/lean/relaxation.test.mjs +54 -0
  44. package/bin/lean/release-postmerge.mjs +119 -0
  45. package/bin/lean/release-rehearsal.mjs +63 -0
  46. package/bin/lean/release-rehearsal.test.mjs +93 -0
  47. package/bin/lean/release-review.e2e.test.mjs +77 -0
  48. package/bin/lean/release-review.mjs +198 -0
  49. package/bin/lean/release-review.test.mjs +180 -0
  50. package/bin/lean/release.mjs +228 -0
  51. package/bin/lean/release.test.mjs +292 -0
  52. package/bin/lean/rotator.mjs +150 -31
  53. package/bin/lean/rotator.test.mjs +105 -2
  54. package/bin/lean/sandbox-remote.mjs +9 -2
  55. package/bin/lean/schedd.mjs +49 -4
  56. package/bin/lean/schedd.test.mjs +87 -6
  57. package/bin/lean/verifier.mjs +3 -2
  58. package/bin/lean/verify.mjs +2 -1
  59. package/bin/lean/verify.test.mjs +6 -0
  60. package/bin/pool/agent.mjs +18 -4
  61. package/bin/pool/router.mjs +66 -24
  62. package/bin/review-staging.mjs +23 -0
  63. package/bin/stats/conformance-outcomes.mjs +208 -0
  64. package/bin/stats/conformance-outcomes.test.mjs +188 -0
  65. package/bin/stats/depth.mjs +218 -0
  66. package/bin/stats/depth.test.mjs +133 -0
  67. package/bin/stats/experiment.mjs +7 -5
  68. package/bin/stats/github-source.mjs +2 -2
  69. package/bin/stats/index.mjs +64 -2
  70. package/bin/stats/local-source.mjs +11 -0
  71. package/bin/stats/query.mjs +69 -0
  72. package/bin/stats/selffiled.mjs +52 -0
  73. package/bin/stats/selffiled.test.mjs +71 -0
  74. package/commands/orchestrate.md +1 -1
  75. package/commands/review-pr-agents/security.md +4 -0
  76. package/commands/review-pr-staging.md +2 -0
  77. package/commands/work-on/build.md +4 -6
  78. package/docs/CONFIG.md +65 -8
  79. package/docs/ISSUE-WATCH.md +2 -0
  80. package/docs/OUTCOME-CODES.md +3 -0
  81. package/docs/STATS.md +44 -0
  82. package/docs/TELEMETRY.md +1 -1
  83. package/package.json +1 -1
  84. package/pool/README.md +1 -1
  85. package/pool/image/cs-cred +14 -1
  86. package/scripts/backfill-finding-labels.mjs +50 -0
  87. package/scripts/backfill-finding-labels.test.mjs +36 -0
  88. package/scripts/doctor-pipeline-state.sh +21 -6
  89. package/scripts/file-deferred-followups.sh +59 -251
  90. package/scripts/file-deferred-followups.test.sh +85 -206
  91. package/scripts/followup-route.mjs +12 -0
  92. package/scripts/owner-route-parity.test.sh +17 -1
  93. package/scripts/review-pr-side-effects.test.sh +40 -0
@@ -1,39 +1,37 @@
1
1
  #!/usr/bin/env bash
2
- # file-deferred-followups.sh — file the deferred out-of-scope items of one build as ONE follow-up issue per class.
2
+ # file-deferred-followups.sh — file the deferred out-of-lane items of one build into the batch AGGREGATES (never a per-parent issue).
3
3
  # SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
4
4
  # SPDX-License-Identifier: AGPL-3.0-or-later
5
5
  #
6
- # The builder decides fold-vs-defer (judgment, build.md B2.0); this script does the mechanics for the items
7
- # that stay deferred: trusted lookup (claim marker <!-- FORGE:DEFERRED_ISSUE: #M --> on the parent, then a state-all search) of a follow-up carrying
8
- # <!-- FORGE:DEFERRED_FROM: #N -->, append the missing items (exact path match; a closed one is reopened only if completed, not resolved by a person, and given new items), or create ONE issue
9
- # with a checklist, claim it on the parent and re-check once for a concurrent lower-numbered duplicate.
10
- # Items are grouped by class (engineering | post-deploy | external | ops | host, #4664/#5078): one follow-up per class per parent, each
11
- # labelled `followup:<class>`, carrying `<!-- FORGE:DEFERRED_CLASS: <class> -->` (absent = engineering, for older issues) and the
12
- # parent's milestone (a shipped/closed one: the next open milestone by due date, else FORGE_FOLLOWUPS_DEFAULT_MILESTONE).
6
+ # #5207: engineering work is never deferred. A row of class engineering or backlog (an explicit class, `[bucket:new-issue]`, or
7
+ # a why with no class prefix) is rejected (stderr `engineering deferral: build it in-lane (#5207)`, DEFERRED_TSV=INVALID, exit 2,
8
+ # nothing filed): the lane builds it. What remains goes to ONE of three aggregates, never to a per-parent follow-up:
9
+ # post-deploy (and verify-now, date, owner:orchestrator / owner:promote / post-promotion text) -> the release-lane rollup,
10
+ # found by `<!-- FORGE:POSTDEPLOY_ROLLUP: <lane> -->` (or the lowest open trusted issue labelled FORGE_ROLLUP_LABEL,
11
+ # forge.yaml followups.rollup_issue_label); env FORGE_RELEASE_LANE (default `default`), FORGE_RELEASE_SHA (informational).
12
+ # external and ops (credentials, spend, an account, a third party or a customer) -> ONE aggregate per batch, found by
13
+ # `<!-- FORGE:EXTERNAL_BATCH: <FORGE_BATCH_ID or adhoc> -->` (labels followup:external, external-prerequisite, needs-human).
14
+ # host (read-only production data or capture, work needed before promotion) -> ONE host aggregate per batch, found by
15
+ # `<!-- FORGE:HOST_BATCH: <batch> -->` (labels followup:host + host-task, never needs-human, #5078).
16
+ # Every lane appends its items under a `### #<root parent>` heading (a follow-up of a follow-up is filed under the root parent),
17
+ # deduplicated on normalized text across parents; the lowest open trusted aggregate is canonical (a concurrent duplicate is closed).
18
+ # Existing per-parent follow-ups (`FORGE:DEFERRED_FROM`) of older runs are never read, edited, reopened or closed here (no migration).
13
19
  #
14
20
  # Usage: file-deferred-followups.sh --parent N --repo OWNER/REPO [--items FILE|-] [--folded N]
15
21
  # items TSV, one per line: <path|-> TAB <why> TAB <known-flaw flag: known-flaw|1|yes|true, else empty> [TAB <class> [TAB <label>]]
16
22
  # Column 1 must look like a path (any legal path characters; spaced values need a `/` or extension) or be `-` (a requirement-level item): requirement text or an `R<n>:` prefix there is a usage
17
23
  # error (exit 2, DEFERRED_TSV=INVALID, nothing filed). The label (default: the path) is the item's identity in the checklist
18
24
  # and in the stdout rows; repeated `R<n>: R<m>:` prefixes in it collapse to the first. Class: column 4, else the why's
19
- # `post-deploy:|external:|ops:` prefix, else engineering.
25
+ # `post-deploy:|external:|ops:|host:` prefix, else engineering (rejected).
20
26
  # #4724 buckets: a why carrying `[bucket:<kind>]` is routed by it (#5078): `owner` is class external only for credentials, spend,
21
27
  # an account, a third party or a customer; `owner: orchestrator`, `owner: promote...` and post-promotion text join the rollup and
22
- # read-only production data or capture is class host. `host` (labels `followup:host` + `host-task`, never `needs-human`) joins
23
- # the parent's engineering follow-up when the run has one. External items go to ONE aggregate per batch, found by
24
- # `<!-- FORGE:EXTERNAL_BATCH: <FORGE_BATCH_ID or adhoc> -->` (an older per-parent external follow-up is still appended to).
25
- # The rollup may also be the lowest open trusted issue labelled FORGE_ROLLUP_LABEL (forge.yaml followups.rollup_issue_label).
26
- # `new-issue` engineering deferrals (class backlog, #5188) go to ONE issue per batch found by `<!-- FORGE:BACKLOG_BATCH: <batch> -->`
27
- # (labels `followup:engineering` + `followup:backlog`, sections per parent, deduplicated like the rollup); `verify-now` (the parent is already on the default branch) its own per-parent follow-up class
28
- # `verify-now` that the gate releases at once, and `post-deploy`/`date` go to the ONE open rollup of the release lane.
29
- # The rollup (class post-deploy) is found by `<!-- FORGE:POSTDEPLOY_ROLLUP: <lane> -->`, not by parent: every lane appends
30
- # its items under a `### #<root parent>` heading (a follow-up of a follow-up is filed under the root parent), deduplicated
31
- # on normalized text across parents. Env: FORGE_RELEASE_LANE (the deploy lane, default `default`), FORGE_RELEASE_SHA (informational).
28
+ # read-only production data or capture is class host; `host` post-promotion text joins the rollup (#5186).
32
29
  # A post-deploy why starts `post-deploy: [check:<id>] ...` (#4626); the token is kept verbatim in the checklist line.
33
30
  # Env: DRY_RUN (non-empty: no create/edit, issue number 0), FORGE_TRAIL_TRUSTED_ASSOCIATIONS (default
34
31
  # OWNER,MEMBER,COLLABORATOR), FORGE_TRAIL_TRUSTED_LOGINS (default empty), FORGE_DEFERRED_RETRY_SLEEP (secs),
35
32
  # FORGE_FOLLOWUP_MILESTONE (the parent's milestone title; default: read from the parent), FORGE_FOLLOWUPS_DEFAULT_MILESTONE
36
- # (forge.yaml followups.default_milestone), FORGE_EXTERNAL_PREREQ (issue number an external follow-up links to).
33
+ # (forge.yaml followups.default_milestone; a shipped milestone moves to the next open one), FORGE_EXTERNAL_PREREQ (issue number
34
+ # the external aggregate links to), FORGE_BATCH_ID.
37
35
  # Stdout: `identity<TAB>issue` per item, then DEFERRED_TELEMETRY deferred_items=N folded=N batched_into=#M[,#M2] filed=N classes=a,b buckets=kind:N,...
38
36
  # Exit: 0 ok | 2 usage or malformed TSV row | 3 lookup failed (DEFERRED_LOOKUP=FAILED) | 4 create/append failed (DEFERRED_FILE=FAILED).
39
37
  # A failed lookup is never "none found". bash 3.2 portable.
@@ -64,26 +62,21 @@ if [ "$ITEMS" = "-" ]; then cat > "$TMP/items.raw"; else cat "$ITEMS" > "$TMP/it
64
62
  # Fields: identity, why, flag, path (`-` when none), class.
65
63
  SEP=$(printf '\037')
66
64
  CLASSES="engineering post-deploy external ops verify-now host backlog"
67
- # #5078: an owner item is external only when it needs credentials, spend, an account, a third party or a customer. A
68
- # post-promotion action (owner:orchestrator, owner:promote:*, after promotion/release, rollout, purge) joins the rollup and
69
- # read-only production data or capture (obs-psql, *-monitor, a read-only prod query) is a host task. Mirrors
70
- # bin/lean/conformance.mjs ownerRoute; word boundaries spelled (^|[^[:alnum:]_]) / ([^[:alnum:]_]|$), no \b, for BSD grep (bash 3.2 hosts).
71
- POSTPROM_ERE='(after|post)[- ]?(promotion|release|deploy)|in production after|production[- ]verif|promot(e|ion)|rollout|purge|deploy[- ]time'
72
- ROPROD_ERE='ssh[[:space:]]+[[:alnum:]_.-]*-monitor([^[:alnum:]_]|$)|(^|[^[:alnum:]_])obs-psql([^[:alnum:]_]|$)|(^|[^[:alnum:]_])prod(uction)?[ _-]monitor([^[:alnum:]_]|$)|(^|[^[:alnum:]_])read[- ]only[^[:alnum:]_.]([^.]{0,38}[^[:alnum:]_.])?prod(uction)?([^[:alnum:]_]|$)|(^|[^[:alnum:]_])prod(uction)?[^[:alnum:]_.]([^.]{0,28}[^[:alnum:]_.])?(query|queries|capture|telemetry|logs?)([^[:alnum:]_]|$)'
73
- EXTNEED_ERE='credential|secret|api[- ]?key|token|password|passphrase|ssh[- ]?keys?([^[:alnum:]_]|$)|private[- ]key|(^|[^[:alnum:]_])login([^[:alnum:]_]|$)|(^|[^[:alnum:]_])sudo([^[:alnum:]_]|$)|spend|budget|purchase|payment|account|third[- ]party|vendor|customer|contract sign|legal|(^|[^[:alnum:]_])(delete|drop|truncate|wipe|destroy|modify|migrate|write|update|restart|rotate|remove|grant|alter)([^[:alnum:]_]|$)'
65
+ # #5078/#5186/#5197: routing of an owner or host item (post-deploy rollup, host task, external) has ONE source: ownerRoute and
66
+ # hostRoute in bin/lean/conformance.mjs, reached through scripts/followup-route.mjs. No regex is mirrored here. A missing node
67
+ # or route CLI aborts the run (exit 2) rather than guessing a route.
68
+ ROUTE_CLI="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/followup-route.mjs"
69
+ [ -f "$ROUTE_CLI" ] || { echo "file-deferred-followups: route helper not found: $ROUTE_CLI" >&2; exit 2; }
70
+ command -v node >/dev/null 2>&1 || { echo "file-deferred-followups: node is required for routing" >&2; exit 2; }
71
+ route() { # kind why -> route (aborts the run on failure)
72
+ local out; out=$(node "$ROUTE_CLI" "$1" "$2") || { echo "file-deferred-followups: routing failed for kind $1" >&2; exit 2; }
73
+ printf '%s' "$out"
74
+ }
74
75
  owner_route() { # why -> post-deploy | host | external
75
76
  case "$1" in "owner: orchestrator"*|"owner: promote"*) echo "post-deploy"; return 0 ;; esac
76
- if printf '%s' "$1" | grep -qiE "$POSTPROM_ERE" && ! printf '%s' "$1" | grep -qiE "$EXTNEED_ERE"; then echo "post-deploy"
77
- elif printf '%s' "$1" | grep -qiE "$ROPROD_ERE" && ! printf '%s' "$1" | grep -qiE "$EXTNEED_ERE"; then echo "host"
78
- else echo "external"; fi
79
- }
80
- # #5186: an explicit host item is post-promotion (the release rollup) when its text says so and needs nothing external; work
81
- # needed before promotion ("before promotion", "pre-release") stays a host task. Mirrors bin/lean/conformance.mjs hostRoute.
82
- PREPROM_ERE='(before|pre)[- ]?(promotion|release|deploy)'
83
- host_route() { # why -> post-deploy | host
84
- if printf '%s' "$1" | grep -qiE "$POSTPROM_ERE" && ! printf '%s' "$1" | grep -qiE "$PREPROM_ERE" && ! printf '%s' "$1" | grep -qiE "$EXTNEED_ERE"; then echo "post-deploy"
85
- else echo "host"; fi
77
+ route owner "$1"
86
78
  }
79
+ host_route() { route host "$1"; } # why -> post-deploy | host
87
80
  : > "$TMP/items"
88
81
  BAD=0; ROW=0
89
82
  bad_row() { BAD=$((BAD+1)); echo "file-deferred-followups: row $ROW: $1" >&2; }
@@ -114,28 +107,24 @@ while IFS= read -r line || [ -n "$line" ]; do
114
107
  if [ -z "$c" ]; then
115
108
  case "$w" in post-deploy:*) c="post-deploy" ;; external:*) c="external" ;; ops:*) c="ops" ;; host:*) c="host" ;; *) c="engineering" ;; esac
116
109
  fi
117
- case " $CLASSES " in *" $c "*) ;; *) bad_row "unknown class \`$c\` (engineering|post-deploy|external|ops|host|backlog)"; continue ;; esac
118
- # #4724: the bucket token decides the class: owner actions never join the post-deploy rollup, verify-now needs no release.
110
+ case " $CLASSES " in *" $c "*) ;; *) bad_row "unknown class \`$c\` (post-deploy|external|ops|host)"; continue ;; esac
111
+ # #4724: the bucket token decides the class: owner actions never join the post-deploy rollup.
119
112
  case "$w" in
120
- *"[bucket:owner]"*) [ "$c" = "ops" ] || c=$(owner_route "$w") ;;
121
- *"[bucket:host]"*) c=$(host_route "$w") ;;
122
- *"[bucket:new-issue]"*) [ "$c" = "post-deploy" ] && c="engineering"; [ "$c" = "engineering" ] && c="backlog" ;; # #5188: one per-batch issue
123
- *"[bucket:verify-now]"*) [ "$c" = "post-deploy" ] && c="verify-now" ;;
113
+ *"[bucket:owner]"*) [ "$c" = "ops" ] || c=$(owner_route "$w") || exit 2 ;;
114
+ *"[bucket:host]"*) c=$(host_route "$w") || exit 2 ;;
115
+ *"[bucket:new-issue]"*) c="engineering" ;; # #5207: in-lane work, rejected below
116
+ *"[bucket:verify-now]"*) case "$c" in engineering|verify-now) c="post-deploy" ;; esac ;;
124
117
  esac
118
+ [ "$c" = "verify-now" ] && c="post-deploy" # #5207: verify-now joins the rollup (no per-parent issue)
119
+ # #5207: engineering work is built in-lane, never deferred into an issue.
120
+ case "$c" in engineering|backlog) bad_row "engineering deferral: build it in-lane (#5207) (\`$id\`)"; continue ;; esac
125
121
  if cut -d "$SEP" -f1 "$TMP/items" | grep -qxF -- "$id"; then continue; fi
126
122
  case "${k:-}" in known-flaw|1|yes|true) k="known-flaw" ;; *) k="" ;; esac
127
123
  printf '%s%s%s%s%s%s%s%s%s\n' "$id" "$SEP" "$w" "$SEP" "$k" "$SEP" "${p:--}" "$SEP" "$c" >> "$TMP/items"
128
124
  done < "$TMP/items.raw"
129
125
  if [ "$BAD" -gt 0 ]; then echo "DEFERRED_TSV=INVALID"; exit 2; fi
130
- # #5078: host items join the parent's engineering follow-up of this run (dependent items together; it gets `host-task`).
131
- HOST_JOIN=""
132
- if awk -F"$SEP" '$5 == "engineering" { e = 1 } $5 == "host" { h = 1 } END { exit !(e && h) }' "$TMP/items"; then
133
- HOST_JOIN=1
134
- awk -F"$SEP" -v OFS="$SEP" '$5 == "host" { $5 = "engineering" } { print }' "$TMP/items" > "$TMP/items.j" && mv "$TMP/items.j" "$TMP/items"
135
- fi
136
126
  TOTAL=$(wc -l < "$TMP/items" | tr -d ' ')
137
127
 
138
- MARKER="<!-- FORGE:DEFERRED_FROM: #${PARENT} -->"
139
128
  TRUSTED_ASSOC="${FORGE_TRAIL_TRUSTED_ASSOCIATIONS-OWNER,MEMBER,COLLABORATOR}"
140
129
  TRUSTED_LOGINS="${FORGE_TRAIL_TRUSTED_LOGINS-}"
141
130
 
@@ -155,64 +144,11 @@ finish() { # $1 = batched_into numbers (space separated) or empty, $2 = filed co
155
144
  fi
156
145
  }
157
146
 
158
- # --- Trusted lookup (author predicate applied before path match), one retry ---------------------------------
159
- # Sources, in order: (1) claim markers `<!-- FORGE:DEFERRED_ISSUE: #M -->` on the parent's REST comments (read-after-write
160
- # consistent), (2) a search over ALL issue states (eventually consistent, so only a fallback). Every candidate is then
161
- # verified by number over REST (trusted author, DEFERRED_FROM marker, not a PR); the lowest number is canonical.
147
+ # --- Trusted author predicate (applied before any marker match) -------------------------------------------------------
162
148
  JQ_PRE='def lst: split(",") | map(gsub("^\\s+|\\s+$"; "")) | map(select(length > 0));
163
149
  def trusted: ((.author_association // "") as $x | ($assoc | lst) | index($x) != null)
164
150
  or ((.user.type // "") == "Bot")
165
151
  or ((.user.login // "") as $x | ($logins | lst) | index($x) != null);'
166
- CLAIM_RE='^\s*<!-- FORGE:DEFERRED_ISSUE: #(?<n>[0-9]+)(?: class=[a-z-]+)? -->'
167
- claim_nums() {
168
- gh api --paginate "repos/${REPO}/issues/${PARENT}/comments" 2>/dev/null \
169
- | jq -s -r --arg assoc "$TRUSTED_ASSOC" --arg logins "$TRUSTED_LOGINS" --arg re "$CLAIM_RE" "$JQ_PRE"'
170
- [.[][] | select(trusted) | (.body // "") | capture($re) | .n | tonumber] | unique | .[]' 2>/dev/null
171
- }
172
- search_nums() {
173
- gh api -X GET search/issues -f per_page=50 \
174
- -f q="\"FORGE:DEFERRED_FROM: #${PARENT}\" in:body repo:${REPO} is:issue" 2>/dev/null \
175
- | jq -r --arg assoc "$TRUSTED_ASSOC" --arg logins "$TRUSTED_LOGINS" --arg m "$MARKER" "$JQ_PRE"'
176
- [.items[] | select(trusted) | select((.body // "") | contains($m)) | .number] | sort | .[]' 2>/dev/null
177
- }
178
- verify_num() { # number -> `number<TAB>state` when a trusted, non-PR issue of class $CLS carries the marker (a closed one only if completed and not resolved by a person); empty when not (a 404 is "not it")
179
- local out rc
180
- out=$(gh api "repos/${REPO}/issues/$1" 2>"$TMP/verr"); rc=$?
181
- if [ "$rc" -ne 0 ]; then grep -qE '404|Not Found|410' "$TMP/verr" 2>/dev/null && return 0; return 1; fi
182
- out=$(printf '%s' "$out" | jq -r --arg assoc "$TRUSTED_ASSOC" --arg logins "$TRUSTED_LOGINS" --arg m "$MARKER" --arg cls "$CLS" "$JQ_PRE"'
183
- select(.pull_request == null) | select(trusted) | select((.body // "") | contains($m))
184
- | select((((.body // "") | capture("FORGE:DEFERRED_CLASS: (?<c>[a-z-]+)") | .c) // "engineering") == $cls)
185
- | select(.state != "closed" or .state_reason == "completed")
186
- | "\(.number)\t\(.state)"' 2>/dev/null) || return 1
187
- # #4924: a closed tracker was resolved on purpose when a person had the last word (fold, supersede, invalid): not reusable.
188
- case "$out" in *$'\t'closed)
189
- local last
190
- last=$(gh api "repos/${REPO}/issues/$1/comments?per_page=100" 2>/dev/null | jq -r 'if type == "array" and length > 0 then (last | .user.type // "") else "" end' 2>/dev/null) || return 1
191
- [ -z "$last" ] || [ "$last" = "Bot" ] || out="" ;;
192
- esac
193
- printf '%s' "$out"
194
- }
195
- CANON=""; CSTATE=""
196
- pick_verified() { # numbers... ; sets CANON/CSTATE from the first verified one; non-zero only when a fetch failed
197
- local n r
198
- for n in "$@"; do
199
- r=$(verify_num "$n") || return 1
200
- if [ -n "$r" ]; then CANON="${r%%$'\t'*}"; CSTATE="${r#*$'\t'}"; return 0; fi
201
- done
202
- return 0
203
- }
204
- find_canonical() {
205
- local cands
206
- CANON=""; CSTATE=""
207
- cands=$(claim_nums) || return 1
208
- # shellcheck disable=SC2086
209
- pick_verified $cands || return 1
210
- [ -n "$CANON" ] && return 0
211
- cands=$(search_nums) || return 1
212
- # shellcheck disable=SC2086
213
- pick_verified $cands || return 1
214
- return 0
215
- }
216
152
  # --- #4724: the post-deploy rollup: ONE open issue per release lane, found by marker (not by parent) ------------------
217
153
  # #5078: the same shape holds every external item of one batch (`FORGE:EXTERNAL_BATCH: <batch>`), and the rollup may also
218
154
  # be a repo's own open issue carrying forge.yaml `followups.rollup_issue_label` (FORGE_ROLLUP_LABEL) when no marked one is open.
@@ -221,8 +157,8 @@ ROLLUP_MARKER="<!-- FORGE:POSTDEPLOY_ROLLUP: ${RELEASE_LANE} -->"
221
157
  BATCH="${FORGE_BATCH_ID:-adhoc}"
222
158
  EXTERNAL_MARKER="<!-- FORGE:EXTERNAL_BATCH: ${BATCH} -->"
223
159
  ROLLUP_LABEL="${FORGE_ROLLUP_LABEL:-}"
224
- BACKLOG_MARKER="<!-- FORGE:BACKLOG_BATCH: ${BATCH} -->"
225
- agg_marker() { case "$1" in post-deploy) printf '%s' "$ROLLUP_MARKER" ;; backlog) printf '%s' "$BACKLOG_MARKER" ;; *) printf '%s' "$EXTERNAL_MARKER" ;; esac; }
160
+ HOST_MARKER="<!-- FORGE:HOST_BATCH: ${BATCH} -->"
161
+ agg_marker() { case "$1" in post-deploy) printf '%s' "$ROLLUP_MARKER" ;; host) printf '%s' "$HOST_MARKER" ;; *) printf '%s' "$EXTERNAL_MARKER" ;; esac; }
226
162
  verify_rollup() { # number [marker] -> `number<TAB>open` when a trusted, open, non-PR issue carries the marker
227
163
  local out rc m="${2:-$ROLLUP_MARKER}"
228
164
  out=$(gh api "repos/${REPO}/issues/$1" 2>"$TMP/verr"); rc=$?
@@ -239,7 +175,7 @@ verify_labelled() { # number -> `number<TAB>open` when a trusted, open, non-PR i
239
175
  select(.pull_request == null) | select(trusted) | select(.state == "open") | select(any(.labels[]?; (.name // .) == $l))
240
176
  | "\(.number)\t\(.state)"' 2>/dev/null
241
177
  }
242
- find_aggregate() { # kind (post-deploy|external|backlog) ; sets CANON/CSTATE to the lowest open one; non-zero only when a lookup failed
178
+ find_aggregate() { # kind (post-deploy|external|host) ; sets CANON/CSTATE to the lowest open one; non-zero only when a lookup failed
243
179
  local kind="$1" m q cands n r
244
180
  CANON=""; CSTATE=""
245
181
  m=$(agg_marker "$kind"); q="${m#<!-- }"; q="${q% -->}"
@@ -295,7 +231,7 @@ rollup_append() { # number ; non-zero = failure
295
231
  else gh issue edit "$num" -R "$REPO" --body-file "$TMP/newbody" >/dev/null 2>&1 || return 1; fi
296
232
  return 0
297
233
  }
298
- file_rollup() { # items in $ITEMS_F, class $CLS (post-deploy: the release-lane rollup; external: the batch aggregate, #5078); sets FILED_N, FILED_NEW
234
+ file_rollup() { # items in $ITEMS_F, aggregate $CLS (post-deploy: the release-lane rollup; external: the batch aggregate, #5078; host: the batch host aggregate, #5207); sets FILED_N, FILED_NEW
299
235
  local n_items; n_items=$(wc -l < "$ITEMS_F" | tr -d ' ')
300
236
  local m title what lbls
301
237
  FILED_N=""; FILED_NEW=0
@@ -308,8 +244,8 @@ file_rollup() { # items in $ITEMS_F, class $CLS (post-deploy: the release-lane r
308
244
  m=$(agg_marker "$CLS")
309
245
  if [ "$CLS" = "post-deploy" ]; then
310
246
  title="post-deploy: release checklist (${RELEASE_LANE})"; what="post-deploy rollup ${RELEASE_LANE}"; lbls="followup:post-deploy"
311
- elif [ "$CLS" = "backlog" ]; then
312
- title="follow-up: deferred work of batch ${BATCH}"; what="backlog aggregate of batch ${BATCH}"; lbls="followup:engineering followup:backlog"
247
+ elif [ "$CLS" = "host" ]; then
248
+ title="host: tasks of batch ${BATCH}"; what="host aggregate of batch ${BATCH}"; lbls="followup:host host-task"
313
249
  else
314
250
  title="external: prerequisites of batch ${BATCH}"; what="external aggregate of batch ${BATCH}"; lbls="followup:external external-prerequisite needs-human"
315
251
  fi
@@ -317,8 +253,8 @@ file_rollup() { # items in $ITEMS_F, class $CLS (post-deploy: the release-lane r
317
253
  {
318
254
  if [ "$CLS" = "post-deploy" ]; then
319
255
  printf '## Problem\n\nPost-deploy checklist of release lane `%s`%s. Every merged lane appends its post-deploy items under a `### #<parent>` heading (deduplicated), so one read-only verification works through this one issue per release.\n\n' "$RELEASE_LANE" "${FORGE_RELEASE_SHA:+ (deploy target at $FORGE_RELEASE_SHA)}"
320
- elif [ "$CLS" = "backlog" ]; then
321
- printf '## Problem\n\nDeferred engineering work of batch `%s`: items declared out of scope (`new-issue`) by the lanes of this batch. Every lane appends its items under a `### #<parent>` heading (deduplicated), so the batch has ONE backlog issue.\n\n' "$BATCH"
256
+ elif [ "$CLS" = "host" ]; then
257
+ printf '## Problem\n\nHost tasks of batch `%s`: every item below is work the host can run (read-only production data or capture) before promotion. Every lane of the batch appends its items under a `### #<parent>` heading (deduplicated), so the batch has ONE host issue.\n\n' "$BATCH"
322
258
  else
323
259
  printf '## Problem\n\nExternal prerequisites of batch `%s`: every item below waits on something outside the repo (credentials, spend, an account, a third party or a customer). Every lane of the batch appends its items under a `### #<parent>` heading (deduplicated), so the batch has ONE external issue.' "$BATCH"
324
260
  [ -n "${FORGE_EXTERNAL_PREREQ:-}" ] && printf ' Linked prerequisite: #%s.' "${FORGE_EXTERNAL_PREREQ#\#}"
@@ -339,6 +275,7 @@ file_rollup() { # items in $ITEMS_F, class $CLS (post-deploy: the release-lane r
339
275
  case "$l" in
340
276
  needs-human) gh label create "$l" -R "$REPO" --color D93F0B --description "Needs a human decision or action." >/dev/null 2>&1 || true ;; # never --force: the repo's own label wins
341
277
  external-prerequisite) gh label create "$l" -R "$REPO" --force --color E99695 --description "External prerequisite. Managed by ForgeDock." >/dev/null 2>&1 || true ;;
278
+ host-task) gh label create "$l" -R "$REPO" --color 0E8A16 --description "Work the host can run (read-only production access)." >/dev/null 2>&1 || true ;;
342
279
  *) gh label create "$l" -R "$REPO" --force --color BFD4F2 --description "Deferred follow-up (${CLS}). Managed by ForgeDock." >/dev/null 2>&1 || true ;;
343
280
  esac
344
281
  args+=(--label "$l")
@@ -369,37 +306,23 @@ file_rollup() { # items in $ITEMS_F, class $CLS (post-deploy: the release-lane r
369
306
  FILED_N="$NUM"; FILED_NEW=1
370
307
  }
371
308
 
372
- CLS_LIST=$(cut -d "$SEP" -f5 "$TMP/items" | sort -u)
373
- CLS=""; CKIND=""
374
- # #5078: post-deploy -> the release-lane rollup; external -> the batch aggregate, else (older runs) the parent's own external
375
- # follow-up; every other class -> the parent's follow-up of that class. Sets CANON/CSTATE/CKIND (agg|legacy|class).
376
- lookup_class() {
377
- CKIND="agg"
378
- case "$CLS" in
379
- post-deploy) find_aggregate post-deploy ;;
380
- backlog) find_aggregate backlog ;;
381
- external)
382
- find_aggregate external || return 1
383
- [ -n "$CANON" ] && return 0
384
- find_canonical || return 1
385
- [ -n "$CANON" ] && CKIND="legacy"
386
- return 0 ;;
387
- *) CKIND="class"; find_canonical ;;
388
- esac
389
- }
390
- # Phase 1: look up the canonical follow-up of every class before filing anything (a failed lookup files nothing).
309
+ # #5207: the aggregate of each class: ops shares the external batch aggregate.
310
+ agg_of() { case "$1" in ops) echo external ;; *) echo "$1" ;; esac; }
311
+ CLS_LIST=$(cut -d "$SEP" -f5 "$TMP/items" | while IFS= read -r c; do agg_of "$c"; done | sort -u)
312
+ CLS=""
313
+ # Phase 1: look up the canonical aggregate of every kind before filing anything (a failed lookup files nothing).
391
314
  for CLS in $CLS_LIST; do
392
315
  LOOKUP_OK=""
393
316
  for attempt in 1 2; do
394
- if lookup_class; then LOOKUP_OK=1; break; fi
317
+ if find_aggregate "$CLS"; then LOOKUP_OK=1; break; fi
395
318
  [ "$attempt" = 1 ] && sleep "${FORGE_DEFERRED_RETRY_SLEEP:-2}"
396
319
  done
397
320
  if [ -z "$LOOKUP_OK" ]; then
398
321
  echo "DEFERRED_LOOKUP=FAILED"
399
322
  exit 3
400
323
  fi
401
- printf '%s\t%s\t%s\n' "$CANON" "$CSTATE" "$CKIND" > "$TMP/canon.$CLS"
402
- awk -F"$SEP" -v c="$CLS" '$5 == c' "$TMP/items" > "$TMP/items.$CLS"
324
+ printf '%s\t%s\n' "$CANON" "$CSTATE" > "$TMP/canon.$CLS"
325
+ awk -F"$SEP" -v c="$CLS" '$5 == c || (c == "external" && $5 == "ops")' "$TMP/items" > "$TMP/items.$CLS"
403
326
  done
404
327
 
405
328
  # Checklist line for one item. Path always backticked so review-pr 6B.5 `contains` verification holds.
@@ -409,41 +332,6 @@ entry() { # path why flag
409
332
  [ -n "$2" ] && l="$l — $2"
410
333
  printf '%s\n' "$l"
411
334
  }
412
- has_entry() { # body-file path : exact checklist-line match, not substring
413
- grep -qE '^- \[[ xX]\] `' "$1" 2>/dev/null || return 1
414
- grep -F -- "\`$2\`" "$1" | grep -qE "^- \[[ xX]\] \`$(printf '%s' "$2" | sed 's/[][\.*^$+?(){}|]/\\&/g')\`( |\$)"
415
- }
416
-
417
- # Append the missing items to follow-up $1 (state $2), then reopen it when closed (review-finalize needs it open).
418
- append_items() { # number state ; non-zero = failure
419
- local num="$1" state="$2" note=""
420
- # Re-read the body immediately before editing (parallel builds of the same parent), then append what is missing.
421
- gh api "repos/${REPO}/issues/${num}" --jq '.body // ""' > "$TMP/body" 2>/dev/null || return 1
422
- : > "$TMP/add"
423
- while IFS="$SEP" read -r p w k fp cl; do
424
- has_entry "$TMP/body" "$p" || entry "$p" "$w" "$k" >> "$TMP/add"
425
- done < "$ITEMS_F"
426
- [ "$state" = "closed" ] && note=" (follow-up was closed; reopened)"
427
- if [ -s "$TMP/add" ]; then
428
- { cat "$TMP/body"; printf '\n### Added by a later build of #%s%s\n\n' "$PARENT" "$note"; cat "$TMP/add"; } > "$TMP/newbody"
429
- if [ -n "${DRY_RUN:-}" ]; then
430
- echo "DRY_RUN: gh issue edit $num (append $(wc -l < "$TMP/add" | tr -d ' ') item(s))" >&2
431
- else
432
- gh issue edit "$num" -R "$REPO" --body-file "$TMP/newbody" >/dev/null 2>&1 || return 1
433
- fi
434
- # #4924: reopen only for new items, and say why.
435
- if [ "$state" = "closed" ]; then
436
- if [ -n "${DRY_RUN:-}" ]; then echo "DRY_RUN: gh issue reopen $num" >&2
437
- else
438
- gh issue reopen "$num" -R "$REPO" >/dev/null 2>&1 || return 1
439
- gh issue comment "$num" -R "$REPO" --body "$(printf '<!-- FORGE:FOLLOWUP_REOPENED -->\nReopened by the run of #%s%s: it deferred new items not yet tracked here:\n\n%s' "$PARENT" "${FORGE_RUN_ID:+ (run \`$FORGE_RUN_ID\`)}" "$(cat "$TMP/add")")" >/dev/null 2>&1 \
440
- || echo "file-deferred-followups: warning: could not post reopen comment on #${num}" >&2
441
- fi
442
- fi
443
- fi
444
- return 0
445
- }
446
-
447
335
  MS_DONE=""; MS_TITLE=""
448
336
  resolve_milestone() { # sets MS_TITLE (empty = none): the parent's milestone, or for a shipped one the next open milestone, else the configured default
449
337
  [ -n "$MS_DONE" ] && return 0
@@ -459,93 +347,13 @@ resolve_milestone() { # sets MS_TITLE (empty = none): the parent's milestone, or
459
347
  | if $next != "" then $next elif ($d != "" and ($all | map(select(.title == $d and .state == "open")) | length) > 0) then $d else "" end) end' 2>/dev/null) || MS_TITLE="$t"
460
348
  }
461
349
 
462
- # File one class ($CLS, items in $ITEMS_F): append to its canonical follow-up, or create one. Sets FILED_N, FILED_NEW.
463
- file_class() {
464
- local n_items; n_items=$(wc -l < "$ITEMS_F" | tr -d ' ')
465
- FILED_N=""; FILED_NEW=0
466
- CANON=$(cut -f1 "$TMP/canon.$CLS"); CSTATE=$(cut -f2 "$TMP/canon.$CLS")
467
- if [ -n "$CANON" ]; then
468
- append_items "$CANON" "$CSTATE" || { echo "DEFERRED_FILE=FAILED"; exit 4; }
469
- if [ "$CLS" = "engineering" ] && [ -n "$HOST_JOIN" ]; then
470
- if [ -n "${DRY_RUN:-}" ]; then echo "DRY_RUN: gh issue edit $CANON (add label host-task)" >&2
471
- else gh issue edit "$CANON" -R "$REPO" --add-label host-task >/dev/null 2>&1 || echo "file-deferred-followups: warning: could not label #${CANON} host-task" >&2; fi
472
- fi
473
- FILED_N="$CANON"; return 0
474
- fi
475
- local claim="<!-- FORGE:DEFERRED_ISSUE: #%s -->" title="follow-up: ${n_items} deferred item(s) (deferred from #${PARENT})"
476
- if [ "$CLS" != "engineering" ]; then claim="<!-- FORGE:DEFERRED_ISSUE: #%s class=${CLS} -->"; title="follow-up (${CLS}): ${n_items} deferred item(s) (deferred from #${PARENT})"; fi
477
- local paths; paths=$(awk -F"$SEP" '$4 != "-" { print $4 }' "$ITEMS_F" | awk '!seen[$0]++')
478
- {
479
- printf '## Problem\n\n'
480
- printf 'Deferred from #%s: the items below were declared out of scope in its contract and are tracked here, in one issue per class (%s), instead of surfacing later as review findings.\n\n' "$PARENT" "$CLS"
481
- printf '**Parent**: #%s\n\n' "$PARENT"
482
- if [ "$CLS" = "external" ]; then
483
- printf 'External prerequisite of #%s: these items wait on something outside the repo (credentials, an account, a third party).' "$PARENT"
484
- [ -n "${FORGE_EXTERNAL_PREREQ:-}" ] && printf ' Linked prerequisite: #%s.' "${FORGE_EXTERNAL_PREREQ#\#}"
485
- printf '\n\n'
486
- fi
487
- printf '## Affected Files\n\n'
488
- if [ -n "$paths" ]; then printf '%s\n' "$paths" | while IFS= read -r fp; do printf -- '- `%s`\n' "$fp"; done
489
- else printf -- '- None (requirement-level items, see the checklist)\n'; fi
490
- printf '\n## Acceptance Criteria\n\n'
491
- while IFS="$SEP" read -r p w k fp cl; do entry "$p" "$w" "$k"; done < "$ITEMS_F"
492
- printf '\n%s\n<!-- FORGE:DEFERRED_CLASS: %s -->\n' "$MARKER" "$CLS"
493
- } > "$TMP/newissue"
494
- local NUM
495
- if [ -n "${DRY_RUN:-}" ]; then
496
- echo "DRY_RUN: gh issue create (follow-up ${CLS}: ${n_items} deferred item(s) from #${PARENT})" >&2
497
- NUM=0
498
- else
499
- resolve_milestone
500
- local lbl="followup:${CLS}" args=() URL
501
- gh label create "$lbl" -R "$REPO" --force --color BFD4F2 --description "Deferred follow-up (${CLS}). Managed by ForgeDock." >/dev/null 2>&1 || true
502
- args=(--label "$lbl")
503
- if [ "$CLS" = "external" ]; then
504
- gh label create external-prerequisite -R "$REPO" --force --color E99695 --description "External prerequisite. Managed by ForgeDock." >/dev/null 2>&1 || true
505
- args+=(--label external-prerequisite)
506
- fi
507
- if [ "$CLS" = "host" ] || { [ "$CLS" = "engineering" ] && [ -n "$HOST_JOIN" ]; }; then # #5078: never needs-human
508
- gh label create host-task -R "$REPO" --color 0E8A16 --description "Work the host can run (read-only production access)." >/dev/null 2>&1 || true
509
- args+=(--label host-task)
510
- fi
511
- [ -n "$MS_TITLE" ] && args+=(--milestone "$MS_TITLE")
512
- URL=$(gh issue create -R "$REPO" --title "$title" --body-file "$TMP/newissue" "${args[@]}" 2>/dev/null) || URL=""
513
- NUM=$(printf '%s' "$URL" | grep -oE '[0-9]+$' | tail -n 1)
514
- [ -n "$NUM" ] || { echo "DEFERRED_FILE=FAILED"; exit 4; }
515
- fi
516
- if [ -z "${DRY_RUN:-}" ]; then
517
- # Claim the follow-up on the parent (REST comments are read-after-write consistent; best effort, the search still finds it).
518
- # shellcheck disable=SC2059
519
- gh issue comment "$PARENT" -R "$REPO" --body "$(printf "$claim" "$NUM")" >/dev/null 2>&1 \
520
- || echo "file-deferred-followups: warning: could not post claim marker for #${NUM} on #${PARENT}" >&2
521
- # Post-create re-check: a concurrent build may have filed first. The lowest trusted number is canonical; the newer one is closed.
522
- if find_canonical; then
523
- if [ -n "$CANON" ] && [ "$CANON" -lt "$NUM" ]; then
524
- if append_items "$CANON" "$CSTATE"; then
525
- gh issue close "$NUM" -R "$REPO" --reason "not planned" --comment "Duplicate of #${CANON}: deferred items of #${PARENT} are tracked there." >/dev/null 2>&1 \
526
- || echo "file-deferred-followups: warning: could not close duplicate #${NUM}" >&2
527
- NUM="$CANON"
528
- else
529
- echo "file-deferred-followups: warning: could not move items to #${CANON}; keeping #${NUM}" >&2
530
- fi
531
- fi
532
- else
533
- echo "file-deferred-followups: warning: post-create re-check failed; keeping #${NUM}" >&2
534
- fi
535
- fi
536
- FILED_N="$NUM"; FILED_NEW=1
537
- }
538
-
539
350
  [ "$TOTAL" -gt 0 ] || { finish "" 0; exit 0; }
540
351
 
541
- # Phase 2: one issue per class.
352
+ # Phase 2: one aggregate per kind.
542
353
  INTO=""; FILED=0
543
354
  for CLS in $CLS_LIST; do
544
355
  ITEMS_F="$TMP/items.$CLS"
545
- case "$CLS:$(cut -f3 "$TMP/canon.$CLS")" in
546
- post-deploy:*|external:agg|backlog:agg) file_rollup ;;
547
- *) file_class ;;
548
- esac
356
+ file_rollup
549
357
  case " $INTO " in *" $FILED_N "*) ;; *) INTO="${INTO:+$INTO }$FILED_N" ;; esac
550
358
  FILED=$((FILED + FILED_NEW))
551
359
  while IFS="$SEP" read -r p w k fp cl; do printf '%s\t%s\n' "$p" "$FILED_N"; done < "$ITEMS_F"