forgedock 1.50.0 → 1.52.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 (50) hide show
  1. package/bin/engine/outcome-codes.mjs +2 -0
  2. package/bin/engine-cli.mjs +98 -10
  3. package/bin/forgedock.mjs +40 -2
  4. package/bin/lean/batch-health.mjs +219 -0
  5. package/bin/lean/batch-health.test.mjs +156 -0
  6. package/bin/lean/batch.mjs +3 -3
  7. package/bin/lean/batch.test.mjs +236 -8
  8. package/bin/lean/conformance.mjs +66 -12
  9. package/bin/lean/conformance.test.mjs +55 -3
  10. package/bin/lean/context.mjs +35 -19
  11. package/bin/lean/context.test.mjs +26 -1
  12. package/bin/lean/credentials.mjs +18 -0
  13. package/bin/lean/effects.mjs +3 -3
  14. package/bin/lean/execution.mjs +11 -6
  15. package/bin/lean/execution.test.mjs +28 -0
  16. package/bin/lean/fixclosereasons.mjs +52 -0
  17. package/bin/lean/fixclosereasons.test.mjs +64 -0
  18. package/bin/lean/heavy.mjs +6 -3
  19. package/bin/lean/hostload.mjs +78 -0
  20. package/bin/lean/hostload.test.mjs +117 -0
  21. package/bin/lean/hotspots-remote.e2e.test.mjs +71 -0
  22. package/bin/lean/lean.mjs +34 -19
  23. package/bin/lean/lean.test.mjs +87 -14
  24. package/bin/lean/orchestrate-blocked.test.mjs +47 -0
  25. package/bin/lean/orchestrate.mjs +138 -12
  26. package/bin/lean/prefilter.mjs +4 -3
  27. package/bin/lean/prefilter.test.mjs +5 -4
  28. package/bin/lean/prompts.mjs +4 -2
  29. package/bin/lean/recovery.test.mjs +5 -5
  30. package/bin/lean/sandbox-provider.contract.test.mjs +15 -1
  31. package/bin/lean/schedd.mjs +8 -3
  32. package/bin/lean/schedd.test.mjs +21 -0
  33. package/bin/pool/agent.mjs +3 -1
  34. package/bin/pool/router.mjs +74 -8
  35. package/bin/review-staging.mjs +2 -0
  36. package/bin/runner.mjs +24 -0
  37. package/commands/review-pr-staging.md +2 -2
  38. package/docs/CONFIG.md +41 -2
  39. package/docs/OUTCOME-CODES.md +2 -1
  40. package/package.json +1 -1
  41. package/pool/README.md +2 -0
  42. package/pool/image/cs-cred +8 -1
  43. package/pool/install/install-agent.ps1 +6 -2
  44. package/scripts/file-deferred-followups.sh +23 -9
  45. package/scripts/file-deferred-followups.test.sh +34 -1
  46. package/scripts/hotspots.sh +12 -8
  47. package/scripts/hotspots.test.sh +22 -0
  48. package/scripts/prior-attempts.test.mjs +1 -1
  49. package/scripts/review-staging-post.sh +70 -25
  50. package/scripts/review-staging-post.test.sh +40 -8
@@ -17,6 +17,7 @@ param(
17
17
  [int] $AllowCpus = 0, # 0 = logical CPUs minus 4 (min 2)
18
18
  [int] $AllowMemGb = 0, # 0 = half of physical RAM (min 4)
19
19
  [string] $Distro = 'computeshare',
20
+ [ValidateSet('auto', 'mirrored', 'nat')] [string] $Networking = 'auto', # nat: for PCs where mirrored mode fails (e.g. WSL error 0x8007054f)
20
21
  [switch] $Force # kept for compatibility; the install never prompts
21
22
  )
22
23
  $ErrorActionPreference = 'Stop'
@@ -106,7 +107,7 @@ if ($needReboot) {
106
107
  }
107
108
 
108
109
  $build = [int](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').CurrentBuildNumber
109
- $mirrored = $build -ge 22621
110
+ $mirrored = switch ($Networking) { 'nat' { $false } 'mirrored' { $true } default { $build -ge 22621 } }
110
111
  Say ("Networking: " + ($(if ($mirrored) { 'mirrored (agent listens on the Tailscale IP directly)' } else { 'NAT + portproxy (Windows 10 / older 11)' })))
111
112
 
112
113
  # .wslconfig is per Windows user and applies to every distro: merge our keys, keep everything else.
@@ -116,6 +117,7 @@ $want = [ordered]@{ processors = "$AllowCpus"; memory = "${vmMemGb}GB"; vmIdleTi
116
117
  if ($mirrored) { $want['networkingMode'] = 'mirrored' }
117
118
  $out = New-Object System.Collections.Generic.List[string]; $inWsl2 = $false; $seen = @{}
118
119
  foreach ($l in $lines) {
120
+ if (-not $mirrored -and $l -match '^\s*networkingMode\s*=\s*mirrored\s*$') { $out.Add("# $l # disabled by computeshare: -Networking nat"); continue }
119
121
  if ($l -match '^\s*\[(.+)\]\s*$') {
120
122
  if ($inWsl2) { foreach ($k in $want.Keys) { if (-not $seen[$k]) { $out.Add("$k=$($want[$k])"); $seen[$k] = $true } } }
121
123
  $inWsl2 = ($Matches[1].Trim().ToLower() -eq 'wsl2')
@@ -211,7 +213,9 @@ $taskArgs = "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$kee
211
213
  $action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $taskArgs
212
214
  $trigger = New-ScheduledTaskTrigger -AtLogOn -User "$env:USERDOMAIN\$env:USERNAME"
213
215
  $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero) -RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1)
214
- Register-ScheduledTask -TaskName 'computeshare-keepalive' -Action $action -Trigger $trigger -Settings $settings -Description 'computeshare agent keep-alive' -Force | Out-Null
216
+ # Highest: on NAT networking the task maintains a netsh portproxy, which needs an elevated token.
217
+ $principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -LogonType Interactive -RunLevel Highest
218
+ Register-ScheduledTask -TaskName 'computeshare-keepalive' -Action $action -Trigger $trigger -Settings $settings -Principal $principal -Description 'computeshare agent keep-alive' -Force | Out-Null
215
219
  Start-ScheduledTask -TaskName 'computeshare-keepalive'
216
220
 
217
221
  Start-Sleep -Seconds 5
@@ -23,7 +23,8 @@
23
23
  # the parent's engineering follow-up when the run has one. External items go to ONE aggregate per batch, found by
24
24
  # `<!-- FORGE:EXTERNAL_BATCH: <FORGE_BATCH_ID or adhoc> -->` (an older per-parent external follow-up is still appended to).
25
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, `verify-now` (the parent is already on the default branch) its own per-parent follow-up class
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
27
28
  # `verify-now` that the gate releases at once, and `post-deploy`/`date` go to the ONE open rollup of the release lane.
28
29
  # The rollup (class post-deploy) is found by `<!-- FORGE:POSTDEPLOY_ROLLUP: <lane> -->`, not by parent: every lane appends
29
30
  # its items under a `### #<root parent>` heading (a follow-up of a follow-up is filed under the root parent), deduplicated
@@ -62,20 +63,27 @@ if [ "$ITEMS" = "-" ]; then cat > "$TMP/items.raw"; else cat "$ITEMS" > "$TMP/it
62
63
  # Internal file uses a non-whitespace separator (US, \x1f): a tab IFS collapses an empty `why` and drops the known-flaw flag.
63
64
  # Fields: identity, why, flag, path (`-` when none), class.
64
65
  SEP=$(printf '\037')
65
- CLASSES="engineering post-deploy external ops verify-now host"
66
+ CLASSES="engineering post-deploy external ops verify-now host backlog"
66
67
  # #5078: an owner item is external only when it needs credentials, spend, an account, a third party or a customer. A
67
68
  # post-promotion action (owner:orchestrator, owner:promote:*, after promotion/release, rollout, purge) joins the rollup and
68
69
  # read-only production data or capture (obs-psql, *-monitor, a read-only prod query) is a host task. Mirrors
69
70
  # bin/lean/conformance.mjs ownerRoute; word boundaries spelled (^|[^[:alnum:]_]) / ([^[:alnum:]_]|$), no \b, for BSD grep (bash 3.2 hosts).
70
71
  POSTPROM_ERE='(after|post)[- ]?(promotion|release|deploy)|in production after|production[- ]verif|promot(e|ion)|rollout|purge|deploy[- ]time'
71
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:]_]|$)'
72
- EXTNEED_ERE='credential|secret|api[- ]?key|token|password|passphrase|ssh[- ]?keys?([^[:alnum:]_]|$)|private[- ]key|(^|[^[:alnum:]_])login([^[:alnum:]_]|$)|(^|[^[:alnum:]_])sudo([^[:alnum:]_]|$)|spend|budget|billing|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:]_]|$)'
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:]_]|$)'
73
74
  owner_route() { # why -> post-deploy | host | external
74
75
  case "$1" in "owner: orchestrator"*|"owner: promote"*) echo "post-deploy"; return 0 ;; esac
75
76
  if printf '%s' "$1" | grep -qiE "$POSTPROM_ERE" && ! printf '%s' "$1" | grep -qiE "$EXTNEED_ERE"; then echo "post-deploy"
76
77
  elif printf '%s' "$1" | grep -qiE "$ROPROD_ERE" && ! printf '%s' "$1" | grep -qiE "$EXTNEED_ERE"; then echo "host"
77
78
  else echo "external"; fi
78
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
86
+ }
79
87
  : > "$TMP/items"
80
88
  BAD=0; ROW=0
81
89
  bad_row() { BAD=$((BAD+1)); echo "file-deferred-followups: row $ROW: $1" >&2; }
@@ -106,12 +114,12 @@ while IFS= read -r line || [ -n "$line" ]; do
106
114
  if [ -z "$c" ]; then
107
115
  case "$w" in post-deploy:*) c="post-deploy" ;; external:*) c="external" ;; ops:*) c="ops" ;; host:*) c="host" ;; *) c="engineering" ;; esac
108
116
  fi
109
- case " $CLASSES " in *" $c "*) ;; *) bad_row "unknown class \`$c\` (engineering|post-deploy|external|ops|host)"; continue ;; esac
117
+ case " $CLASSES " in *" $c "*) ;; *) bad_row "unknown class \`$c\` (engineering|post-deploy|external|ops|host|backlog)"; continue ;; esac
110
118
  # #4724: the bucket token decides the class: owner actions never join the post-deploy rollup, verify-now needs no release.
111
119
  case "$w" in
112
120
  *"[bucket:owner]"*) [ "$c" = "ops" ] || c=$(owner_route "$w") ;;
113
- *"[bucket:host]"*) c="host" ;;
114
- *"[bucket:new-issue]"*) [ "$c" = "post-deploy" ] && c="engineering" ;;
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
115
123
  *"[bucket:verify-now]"*) [ "$c" = "post-deploy" ] && c="verify-now" ;;
116
124
  esac
117
125
  if cut -d "$SEP" -f1 "$TMP/items" | grep -qxF -- "$id"; then continue; fi
@@ -213,7 +221,8 @@ ROLLUP_MARKER="<!-- FORGE:POSTDEPLOY_ROLLUP: ${RELEASE_LANE} -->"
213
221
  BATCH="${FORGE_BATCH_ID:-adhoc}"
214
222
  EXTERNAL_MARKER="<!-- FORGE:EXTERNAL_BATCH: ${BATCH} -->"
215
223
  ROLLUP_LABEL="${FORGE_ROLLUP_LABEL:-}"
216
- agg_marker() { if [ "$1" = "post-deploy" ]; then printf '%s' "$ROLLUP_MARKER"; else printf '%s' "$EXTERNAL_MARKER"; fi; }
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; }
217
226
  verify_rollup() { # number [marker] -> `number<TAB>open` when a trusted, open, non-PR issue carries the marker
218
227
  local out rc m="${2:-$ROLLUP_MARKER}"
219
228
  out=$(gh api "repos/${REPO}/issues/$1" 2>"$TMP/verr"); rc=$?
@@ -230,7 +239,7 @@ verify_labelled() { # number -> `number<TAB>open` when a trusted, open, non-PR i
230
239
  select(.pull_request == null) | select(trusted) | select(.state == "open") | select(any(.labels[]?; (.name // .) == $l))
231
240
  | "\(.number)\t\(.state)"' 2>/dev/null
232
241
  }
233
- find_aggregate() { # kind (post-deploy|external) ; sets CANON/CSTATE to the lowest open one; non-zero only when a lookup failed
242
+ find_aggregate() { # kind (post-deploy|external|backlog) ; sets CANON/CSTATE to the lowest open one; non-zero only when a lookup failed
234
243
  local kind="$1" m q cands n r
235
244
  CANON=""; CSTATE=""
236
245
  m=$(agg_marker "$kind"); q="${m#<!-- }"; q="${q% -->}"
@@ -299,6 +308,8 @@ file_rollup() { # items in $ITEMS_F, class $CLS (post-deploy: the release-lane r
299
308
  m=$(agg_marker "$CLS")
300
309
  if [ "$CLS" = "post-deploy" ]; then
301
310
  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"
302
313
  else
303
314
  title="external: prerequisites of batch ${BATCH}"; what="external aggregate of batch ${BATCH}"; lbls="followup:external external-prerequisite needs-human"
304
315
  fi
@@ -306,6 +317,8 @@ file_rollup() { # items in $ITEMS_F, class $CLS (post-deploy: the release-lane r
306
317
  {
307
318
  if [ "$CLS" = "post-deploy" ]; then
308
319
  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"
309
322
  else
310
323
  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"
311
324
  [ -n "${FORGE_EXTERNAL_PREREQ:-}" ] && printf ' Linked prerequisite: #%s.' "${FORGE_EXTERNAL_PREREQ#\#}"
@@ -364,6 +377,7 @@ lookup_class() {
364
377
  CKIND="agg"
365
378
  case "$CLS" in
366
379
  post-deploy) find_aggregate post-deploy ;;
380
+ backlog) find_aggregate backlog ;;
367
381
  external)
368
382
  find_aggregate external || return 1
369
383
  [ -n "$CANON" ] && return 0
@@ -529,7 +543,7 @@ INTO=""; FILED=0
529
543
  for CLS in $CLS_LIST; do
530
544
  ITEMS_F="$TMP/items.$CLS"
531
545
  case "$CLS:$(cut -f3 "$TMP/canon.$CLS")" in
532
- post-deploy:*|external:agg) file_rollup ;;
546
+ post-deploy:*|external:agg|backlog:agg) file_rollup ;;
533
547
  *) file_class ;;
534
548
  esac
535
549
  case " $INTO " in *" $FILED_N "*) ;; *) INTO="${INTO:+$INTO }$FILED_N" ;; esac
@@ -363,9 +363,23 @@ OUT=$(bash "$S" --parent 10 --repo o/r --items "$T/host.tsv"); RC=$?
363
363
  check "routing: read-only prod owner item -> one host follow-up labelled host-task" "[ $RC -eq 0 ] && [ \$(grep -c '^issue create' '$GH_LOG') -eq 1 ] && grep '^issue create' '$GH_LOG' | grep -q -- '--label followup:host' && grep '^issue create' '$GH_LOG' | grep -q -- '--label host-task' && grep -q 'FORGE:DEFERRED_CLASS: host' '$T/created.901.body'"
364
364
  check "routing: host follow-up carries no needs-human or external-prerequisite" "! grep '^issue create' '$GH_LOG' | grep -qE 'needs-human|external-prerequisite'"
365
365
  reset
366
- printf -- '-\t[bucket:host] host: run the obs-psql report\t\t\tR6: report rows\n-\tdefer: [bucket:new-issue] wire it\t\t\tR7: wire the report\n' > "$T/join.tsv"
366
+ printf -- '-\t[bucket:host] host: run the obs-psql report\t\t\tR6: report rows\n-\tdefer: wire it\t\t\tR7: wire the report\n' > "$T/join.tsv"
367
367
  OUT=$(bash "$S" --parent 10 --repo o/r --items "$T/join.tsv"); RC=$?
368
368
  check "routing: host items join the engineering follow-up of the same run" "[ $RC -eq 0 ] && [ \$(grep -c '^issue create' '$GH_LOG') -eq 1 ] && grep -q 'report rows' '$T/created.901.body' && grep -q 'wire the report' '$T/created.901.body' && grep '^issue create' '$GH_LOG' | grep -q -- '--label followup:engineering' && grep '^issue create' '$GH_LOG' | grep -q -- '--label host-task' && ! grep '^issue create' '$GH_LOG' | grep -q needs-human"
369
+ # #5186: host + post-promotion text joins the rollup; the same text from two parents is listed once; pre-promotion stays host
370
+ reset
371
+ printf '{"number":902,"state":"open","author_association":"OWNER","user":{"type":"User"},"body":"<!-- FORGE:POSTDEPLOY_ROLLUP: default -->"}\n' > "$T/issue.902.json"
372
+ echo '{"items":[{"number":902}]}' > "$SEARCH_JSON"; printf '<!-- FORGE:POSTDEPLOY_ROLLUP: default -->\n' > "$ISSUE_BODY"
373
+ printf -- '-\thost: [bucket:host] billed margin from billing rows in production after promotion\t\t\tR1: billed margin check\n' > "$T/hp.tsv"
374
+ OUT=$(bash "$S" --parent 10 --repo o/r --items "$T/hp.tsv"); RC=$?
375
+ check "routing: host post-promotion item appends to the rollup, no issue create" "[ $RC -eq 0 ] && ! grep -q '^issue create' '$GH_LOG' && grep -q '^issue edit 902' '$GH_LOG' && grep -q 'billed margin check' '$ISSUE_BODY.edited' && printf '%s' \"\$OUT\" | grep -q 'classes=post-deploy '"
376
+ cp "$ISSUE_BODY.edited" "$ISSUE_BODY"; : > "$GH_LOG"
377
+ OUT=$(bash "$S" --parent 11 --repo o/r --items "$T/hp.tsv"); RC=$?
378
+ check "routing: the same host item from a second parent is listed once" "[ $RC -eq 0 ] && ! grep -q '^issue create' '$GH_LOG' && [ \$(grep -c 'billed margin check' '$ISSUE_BODY') -eq 1 ] && { [ ! -f '$ISSUE_BODY.edited' ] || [ \$(grep -c 'billed margin check' '$ISSUE_BODY.edited') -eq 1 ]; }"
379
+ reset
380
+ printf -- '-\thost: [bucket:host] capture the page in a browser on the host before promotion\t\t\tR2: browser capture\n' > "$T/hb.tsv"
381
+ OUT=$(bash "$S" --parent 10 --repo o/r --items "$T/hb.tsv"); RC=$?
382
+ check "routing: pre-promotion host item still files follow-up (host)" "[ $RC -eq 0 ] && [ \$(grep -c '^issue create' '$GH_LOG') -eq 1 ] && grep '^issue create' '$GH_LOG' | grep -q -- '--label followup:host'"
369
383
  # N external deferrals in one batch -> ONE aggregated issue carrying needs-human
370
384
  reset
371
385
  export FORGE_BATCH_ID=b42
@@ -387,5 +401,24 @@ printf -- '-\tdefer: parser first\t\t\tR1: add the parser\n-\tdefer: needs the p
387
401
  OUT=$(bash "$S" --parent 10 --repo o/r --items "$T/eng.tsv"); RC=$?
388
402
  check "engineering: dependent items of one parent in one issue" "[ $RC -eq 0 ] && [ \$(grep -c '^issue create' '$GH_LOG') -eq 1 ] && grep -q 'add the parser' '$T/created.901.body' && grep -q 'use the parser' '$T/created.901.body'"
389
403
 
404
+
405
+ # 25. #5188: new-issue deferrals of one batch -> ONE backlog issue per batch; sections per parent; duplicates once
406
+ reset
407
+ printf -- '-\tdefer: [bucket:new-issue] wire the report\t\t\tR1: wire the report\n-\tdefer: [bucket:new-issue] add the cache\t\t\tR2: add the cache\n' > "$T/bl1.tsv"
408
+ OUT=$(FORGE_BATCH_ID=b1 bash "$S" --parent 10 --repo o/r --items "$T/bl1.tsv"); RC=$?
409
+ check "backlog: lane 1 creates ONE batch issue holding both items" "[ $RC -eq 0 ] && [ \$(grep -c '^issue create' '$GH_LOG') -eq 1 ] && grep -q 'FORGE:BACKLOG_BATCH: b1' '$T/created.901.body' && grep -q 'wire the report' '$T/created.901.body' && grep -q 'add the cache' '$T/created.901.body' && grep -q '^### #10\$' '$T/created.901.body'"
410
+ check "backlog: labelled followup:engineering and followup:backlog, never needs-human" "grep '^issue create' '$GH_LOG' | grep -q -- '--label followup:engineering' && grep '^issue create' '$GH_LOG' | grep -q -- '--label followup:backlog' && ! grep '^issue create' '$GH_LOG' | grep -q needs-human && printf '%s' \"\$OUT\" | grep -q 'classes=backlog '"
411
+ cp "$T/created.901.body" "$ISSUE_BODY"; : > "$GH_LOG"
412
+ echo '{"items":[{"number":901}]}' > "$SEARCH_JSON"
413
+ printf '{"number":901,"state":"open","author_association":"OWNER","user":{"type":"User"},"body":"<!-- FORGE:BACKLOG_BATCH: b1 -->"}\n' > "$T/issue.901.json"
414
+ printf -- '-\tdefer: [bucket:new-issue] wire the report\t\t\tR9: Wire the report!\n-\tdefer: [bucket:new-issue] other\t\t\tR3: another thing\n' > "$T/bl2.tsv"
415
+ OUT=$(FORGE_BATCH_ID=b1 bash "$S" --parent 11 --repo o/r --items "$T/bl2.tsv"); RC=$?
416
+ check "backlog: lane 2 of the batch appends to #901, creates nothing" "[ $RC -eq 0 ] && ! grep -q '^issue create' '$GH_LOG' && grep -q '^issue edit 901' '$GH_LOG' && grep -q '^### #11\$' '$ISSUE_BODY.edited' && grep -q 'another thing' '$ISSUE_BODY.edited'"
417
+ check "backlog: duplicate text from another parent stored once" "[ \$(grep -ci 'wire the report' '$ISSUE_BODY.edited') -eq 1 ] && printf '%s\n' \"\$OUT\" | grep -q '^R9: Wire the report!.901'"
418
+ # another batch does not join it
419
+ : > "$GH_LOG"; echo '{"items":[]}' > "$SEARCH_JSON"
420
+ OUT=$(FORGE_BATCH_ID=b2 bash "$S" --parent 12 --repo o/r --items "$T/bl2.tsv"); RC=$?
421
+ check "backlog: a different batch files its own issue" "[ $RC -eq 0 ] && [ \$(grep -c '^issue create' '$GH_LOG') -eq 1 ] && grep -q 'FORGE:BACKLOG_BATCH: b2' '$T/created.902.body'"
422
+
390
423
  echo "passed=$PASS failed=$FAIL"
391
424
  [ "$FAIL" -eq 0 ]
@@ -5,12 +5,14 @@
5
5
  # hotspots.sh — deterministic size and churn facts for named files (forge#4195). No LLM, no network: git + wc + jq,
6
6
  # yq (optional) only to read forge.yaml. Run from the repo root.
7
7
  #
8
- # Usage: hotspots.sh [--base <ref>] [--] <path>...
8
+ # Usage: hotspots.sh [--base <ref>] [--config <forge.yaml>] [--] <path>...
9
+ # Config file (#5163, forge.yaml is often gitignored so a lane worktree has none): --config, then $FORGE_CONFIG, then ./forge.yaml;
10
+ # output config_source is the file read, or null (defaults used).
9
11
  # Config: forge.yaml maintenance.hotspot {enabled, file_lines, growth_lines, exclude_globs}; defaults true/2000/150/[] (lockfiles are always excluded)
10
12
  # (also when forge.yaml or yq is missing); maintenance.generated_paths (forge#4519): shell globs of generated,
11
13
  # bot-owned files, default [].
12
14
  # Output (stdout, one JSON object):
13
- # {"enabled","file_lines","growth_lines","generated_paths",
15
+ # {"enabled","file_lines","growth_lines","generated_paths","config_source",
14
16
  # "files":[{path,lines,commits_90d,hotspot,over,generated,excluded,base_lines,growth}]}
15
17
  # lines = `wc -l` of the working-tree file (0 when missing); commits_90d = `git rev-list --count --since=90.days HEAD`;
16
18
  # hotspot = lines × commits_90d; over = lines > file_lines; generated = linguist-generated set by .gitattributes, a
@@ -23,10 +25,11 @@ set -uo pipefail
23
25
 
24
26
  die() { echo "hotspots: $*" >&2; exit 2; }
25
27
  command -v jq >/dev/null 2>&1 || die "jq is required"
26
- BASE=""
28
+ BASE=""; CONFIG_ARG=""
27
29
  while [ $# -gt 0 ]; do
28
30
  case "$1" in
29
31
  --base) [ $# -ge 2 ] && [ -n "$2" ] || die "usage: hotspots.sh [--base <ref>] [--] <path>..."; BASE="$2"; shift 2 ;;
32
+ --config) [ $# -ge 2 ] && [ -n "$2" ] || die "usage: hotspots.sh [--base <ref>] [--config <forge.yaml>] [--] <path>..."; CONFIG_ARG="$2"; shift 2 ;;
30
33
  --) shift; break ;;
31
34
  -*) die "unknown option: $1" ;;
32
35
  *) break ;;
@@ -34,11 +37,12 @@ while [ $# -gt 0 ]; do
34
37
  done
35
38
 
36
39
  # ---- config: maintenance.hotspot as JSON, {} when unreadable ----
37
- CFG='{}'; GEN_CFG='[]'
38
- if [ -f forge.yaml ] && command -v yq >/dev/null 2>&1; then
39
- c=$(yq -o=json '.maintenance.hotspot // {}' forge.yaml 2>/dev/null) || c=""
40
+ CFG='{}'; GEN_CFG='[]'; CONFIG_FILE="${CONFIG_ARG:-${FORGE_CONFIG:-forge.yaml}}"; CONFIG_SRC=""
41
+ if [ -f "$CONFIG_FILE" ] && command -v yq >/dev/null 2>&1; then
42
+ CONFIG_SRC="$CONFIG_FILE"
43
+ c=$(yq -o=json '.maintenance.hotspot // {}' "$CONFIG_FILE" 2>/dev/null) || c=""
40
44
  printf '%s' "$c" | jq -e 'type == "object"' >/dev/null 2>&1 && CFG="$c"
41
- g=$(yq -o=json '.maintenance.generated_paths // []' forge.yaml 2>/dev/null) || g=""
45
+ g=$(yq -o=json '.maintenance.generated_paths // []' "$CONFIG_FILE" 2>/dev/null) || g=""
42
46
  printf '%s' "$g" | jq -e 'type == "array"' >/dev/null 2>&1 && GEN_CFG="$g"
43
47
  fi
44
48
  GEN_CFG=$(printf '%s' "$GEN_CFG" | jq -c '[.[] | strings | select(length > 0)]')
@@ -48,7 +52,7 @@ CFG=$(printf '%s' "$CFG" | jq -c '
48
52
  exclude_globs: ([(.exclude_globs // [])[]? | strings]) }')
49
53
  ENABLED=$(printf '%s' "$CFG" | jq -r '.enabled')
50
54
  FILE_LINES=$(printf '%s' "$CFG" | jq -r '.file_lines')
51
- head_json() { printf '%s' "$CFG" | jq -c --argjson files "$1" --argjson gen "$GEN_CFG" '{enabled, file_lines, growth_lines, generated_paths: $gen, files: $files}'; }
55
+ head_json() { printf '%s' "$CFG" | jq -c --argjson files "$1" --argjson gen "$GEN_CFG" --arg src "$CONFIG_SRC" '{enabled, file_lines, growth_lines, generated_paths: $gen, config_source: (if $src == "" then null else $src end), files: $files}'; }
52
56
  [ "$ENABLED" = true ] || { head_json '[]'; exit 0; }
53
57
 
54
58
  MB=""
@@ -125,5 +125,27 @@ OUT="$(bash "$S" --base main -- web/package-lock.json app.py)"
125
125
  eq "lockfile excluded" "$(q '.files[0] | [.excluded,.growth]')" '[true,900]'
126
126
  eq "ordinary file not excluded" "$(q '.files[1].excluded')" 'false'
127
127
 
128
+ # ---- #5163: gitignored forge.yaml: the config comes from --config / FORGE_CONFIG, not the worktree ----
129
+ if [ "$HAVE_YQ" = 1 ]; then
130
+ new_repo
131
+ lines gen.json 10; lines app.py 10; commit base
132
+ git checkout -q -b feat3; lines more 300; cat more >> gen.json; cat more >> app.py; commit grow
133
+ HOSTCFG="$TMP/host.yaml"; printf 'maintenance:\n generated_paths: ["gen.json"]\n hotspot:\n exclude_globs: ["app.py"]\n' > "$HOSTCFG"
134
+ OUT="$(bash "$S" --base main --config "$HOSTCFG" -- gen.json app.py)"
135
+ eq "--config: generated_paths" "$(q '.files[0] | [.generated,.excluded]')" '[true,true]'
136
+ eq "--config: exclude_globs" "$(q '.files[1].excluded')" 'true'
137
+ eq "--config: source" "$(q '.config_source')" "\"$HOSTCFG\""
138
+ OUT="$(FORGE_CONFIG="$HOSTCFG" bash "$S" -- app.py)"; eq "FORGE_CONFIG honoured" "$(q '.files[0].excluded')" 'true'
139
+ printf 'maintenance:\n hotspot:\n enabled: false\n' > forge.yaml
140
+ OUT="$(bash "$S" --config "$HOSTCFG" -- app.py)"; eq "--config beats ./forge.yaml" "$(q '.enabled')" 'true'
141
+ OUT="$(FORGE_CONFIG="$HOSTCFG" bash "$S" --config "$TMP/none.yaml" -- app.py)"; eq "--config beats env" "$(q '.config_source')" 'null'
142
+ rm -f forge.yaml
143
+ fi
144
+ new_repo; lines a.py 5; commit base
145
+ OUT="$(bash "$S" -- a.py)"; eq "no config: config_source null" "$(q '.config_source')" 'null'
146
+ eq "no config: key present" "$(q 'has("config_source")')" 'true'
147
+ OUT="$(bash "$S" --config "$TMP/none.yaml" -- a.py)"; eq "bad --config: not exit 2, source null" "$(q '[has("config_source"),.config_source]')" '[true,null]'
148
+ eq "no config: defaults" "$(q '[.enabled,.file_lines]')" '[true,2000]'
149
+
128
150
  echo "hotspots.test.sh: $PASS passed, $FAILN failed"
129
151
  [ "$FAILN" -eq 0 ]
@@ -22,7 +22,7 @@ describe("#5085: prior-attempts.mjs", () => {
22
22
  assert.ok(t.includes("| #34935 won't fix (issue, not_planned) | ? | no | ? |"), t);
23
23
  assert.ok(t.includes("| #34683 TLS bypass counted as block (issue, completed) | ? | closed | ? |"), t);
24
24
  assert.ok(t.includes("| #34735 Classify tls.bypass_misclassified as success (PR, merged) | ? | yes | ? |"), t);
25
- assert.ok(t.includes("Search terms: tls.bypass_misclassified, bypass, misclassified"), t);
25
+ assert.ok(t.includes("Search terms: tls.bypass_misclassified, tls, bypass, misclassified"), t);
26
26
  assert.ok(queries.every((q) => q.startsWith("q=repo:o/r is:closed ")) && !queries.some((q) => q.includes("src/a.ts")));
27
27
  });
28
28
 
@@ -10,12 +10,15 @@
10
10
  # delivery counts trusted, current-head FORGE:REVIEW-AGENT comments (findings block required) for every domain listed in
11
11
  # DIR/<N>_launched_review_agents. A shortfall labels the PR review-degraded + needs-human and posts
12
12
  # FORGE:GATE_FAILURE:TYPE=review-panel-integrity; an empty/unreadable list or a missing domain is a delivery failure.
13
- # Exit 0 = every launched reviewer delivered, 1 = not.
13
+ # The comments are listed once per attempt; a missing domain or an API error re-lists after each
14
+ # FORGE_REVIEW_DELIVERY_RETRY_DELAYS wait (seconds, default "5 15 45"). An API error on the last attempt is
15
+ # REVIEW DELIVERY UNVERIFIED (exit 2, nothing labelled or posted), never "missing" (forge#5166).
16
+ # Exit 0 = every launched reviewer delivered, 1 = not, 2 = could not be verified.
14
17
  # test-gate reads the saved /test-gate output FILE (the last FORGE:TEST_GATE:RESULT= marker; an absent marker stays empty and
15
18
  # fails closed as BLOCK, never SKIP), applies the trusted override, the posture and the FORGE:GATE_PASS /
16
19
  # FORGE:GATE_FAILURE test-gate comments, and persists DIR/<N>_test_gate_verdict and _reason.
17
20
  # Exit 0 = continue, 1 = RESULT: BLOCK DEPLOY.
18
- # Exit: 2 on a usage error.
21
+ # Exit: 2 on a usage error (and delivery UNVERIFIED).
19
22
  #
20
23
  # The `# BEGIN <name>` ... `# END <name>` blocks below are the spec's former fences, copied without their forge_resolve locator
21
24
  # stubs (this script resolves helpers once, below). Helpers (trusted-comments.sh) resolve through forge_resolve from trusted
@@ -59,24 +62,77 @@ type forge_resolve >/dev/null 2>&1 || { setopt nonomatch 2>/dev/null || true; _S
59
62
 
60
63
  if [ "$CMD" = delivery ]; then
61
64
  echo "=== Incomplete-panel guard and Phase 6.75: verify agent delivery ==="
65
+ # BEGIN delivery-fetch
66
+ # The PR's comments are listed ONCE per attempt into a cache file; the panel guard and the per-domain check both read it (forge#5166).
67
+ # An attempt is an API error unless gh exits 0 and every page is a JSON array: an error is never evidence that a comment is absent.
68
+ DELIVERY_CACHE="$_SD/${PR_NUMBER}_delivery_comments.json"
69
+ delivery_fetch() {
70
+ rm -f "$DELIVERY_CACHE" "$DELIVERY_CACHE.tmp"
71
+ gh api --paginate "repos/${GH_REPO}/issues/${PR_NUMBER}/comments" > "$DELIVERY_CACHE.tmp" 2>/dev/null || { rm -f "$DELIVERY_CACHE.tmp"; return 1; }
72
+ jq -se 'length > 0 and all(.[]; type == "array")' "$DELIVERY_CACHE.tmp" >/dev/null 2>&1 || { rm -f "$DELIVERY_CACHE.tmp"; return 1; }
73
+ mv -f "$DELIVERY_CACHE.tmp" "$DELIVERY_CACHE"
74
+ }
75
+ # Unique trusted current-head reviewer domains in the cached listing (findings block not required), one per line.
76
+ delivery_domains() {
77
+ bash "$TRUSTED_SCRIPT" bodies "^<!-- FORGE:REVIEW-AGENT:[a-z0-9-]+ -->[\\s\\S]*(^|\\n)Reviewed-SHA:[ ]${REVIEW_SHA_FULL}(\\r?\\n|$)" < "$DELIVERY_CACHE" 2>/dev/null \
78
+ | jq -r 'scan("^<!-- FORGE:REVIEW-AGENT:([a-z0-9-]+) -->") | .[0]' 2>/dev/null | sort -u
79
+ }
80
+ # Trusted current-head comments for one domain that carry a findings block, in the cached listing.
81
+ delivery_count() {
82
+ local AGENT_DOMAIN="$1" n
83
+ n=$(bash "$TRUSTED_SCRIPT" count "^(?=[\\s\\S]*<!-- REVIEW-FINDINGS-START -->[\\s\\S]*<!-- REVIEW-FINDINGS-END -->)<!-- FORGE:REVIEW-AGENT:${AGENT_DOMAIN} -->[\\s\\S]*(^|\\n)Reviewed-SHA:[ ]${REVIEW_SHA_FULL}(\\r?\\n|$)" < "$DELIVERY_CACHE" 2>/dev/null)
84
+ case "$n" in ''|*[!0-9]*) n=0 ;; esac # fail closed: counts as missing
85
+ printf '%s\n' "$n"
86
+ }
87
+ # END delivery-fetch
62
88
  # BEGIN panel-guard
63
89
  # Each Bash call is a fresh shell: re-resolve the full head SHA if it is not set, and refuse when it is not a commit id
64
90
  # (an empty SHA would make the Reviewed-SHA match accept any head).
65
91
  [ -n "${REVIEW_SHA_FULL:-}" ] || REVIEW_SHA_FULL=$(gh pr view "$PR_NUMBER" -R "$GH_REPO" --json headRefOid --jq '.headRefOid' 2>/dev/null || echo "")
66
92
  case "$REVIEW_SHA_FULL" in *[!0-9a-f]*|"") REVIEW_SHA_FULL="" ;; *) [ "${#REVIEW_SHA_FULL}" -eq 40 ] || [ "${#REVIEW_SHA_FULL}" -eq 64 ] || REVIEW_SHA_FULL="" ;; esac
67
93
  TRUSTED_SCRIPT=$(forge_resolve trusted-comments.sh)
68
- ACTUAL_AGENT_COUNT=0
69
- if [ -n "$REVIEW_SHA_FULL" ] && [ -n "$TRUSTED_SCRIPT" ]; then
70
- # Only TRUSTED, current-head reviewer comments count, over every page of comments. Unique domains, so a duplicate does not inflate the count.
71
- ACTUAL_AGENT_COUNT=$(gh api --paginate "repos/${GH_REPO}/issues/${PR_NUMBER}/comments" 2>/dev/null \
72
- | bash "$TRUSTED_SCRIPT" bodies "^<!-- FORGE:REVIEW-AGENT:[a-z0-9-]+ -->[\\s\\S]*(^|\\n)Reviewed-SHA:[ ]${REVIEW_SHA_FULL}(\\r?\\n|$)" 2>/dev/null \
73
- | jq -r 'scan("^<!-- FORGE:REVIEW-AGENT:([a-z0-9-]+) -->") | .[0]' 2>/dev/null | sort -u | grep -c . || echo 0)
74
- fi
75
- case "$ACTUAL_AGENT_COUNT" in ''|*[!0-9]*) ACTUAL_AGENT_COUNT=0 ;; esac # fail closed: unreadable or untrusted counts as not posted
76
94
  # Fresh shell: SELECTED_AGENT_COUNT is not carried over. Reload it from the PR-keyed launched-agent file, then fail closed when it is empty, non-integer or zero (a staging review always selects at least one reviewer).
77
95
  [ -n "${SELECTED_AGENT_COUNT:-}" ] || { [ -n "${PR_NUMBER:-}" ] && [ -r "$_SD/${PR_NUMBER}_launched_review_agents" ] && SELECTED_AGENT_COUNT=$(grep -E '^[a-z0-9-]+$' "$_SD/${PR_NUMBER}_launched_review_agents" | sort -u | grep -c .); }
78
96
  SELECTED_COUNT_INVALID=false
79
97
  case "${SELECTED_AGENT_COUNT:-}" in ''|*[!0-9]*|0) SELECTED_COUNT_INVALID=true; SELECTED_AGENT_COUNT=0 ;; esac
98
+ # Reload the launched-agent list persisted at dispatch (validated: lowercase marker domains only).
99
+ [ -n "${LAUNCHED_REVIEW_AGENTS:-}" ] || { [ -r "$_SD/${PR_NUMBER}_launched_review_agents" ] && LAUNCHED_REVIEW_AGENTS=$(grep -E '^[a-z0-9-]+$' "$_SD/${PR_NUMBER}_launched_review_agents" | sort -u | tr '\n' ' '); }
100
+ ACTUAL_AGENT_COUNT=0
101
+ DELIVERY_LAST=skipped # ok = the last attempt was a successful listing, error = it was an API error
102
+ DELIVERY_FOUND=" " # launched domains with a findings block, found on any attempt (found stays found)
103
+ DELIVERY_SEEN="" # union of trusted current-head reviewer domains over the successful listings
104
+ if [ -n "$REVIEW_SHA_FULL" ] && [ -n "$TRUSTED_SCRIPT" ] && [ "${DISPATCH_FAILED:-}" != "true" ]; then
105
+ if [ "$SELECTED_COUNT_INVALID" = "true" ] || [ -z "${LAUNCHED_REVIEW_AGENTS:-}" ]; then
106
+ # Nothing to wait for: one listing for the report only, no retry.
107
+ if delivery_fetch; then DELIVERY_LAST=ok; DELIVERY_SEEN=$(delivery_domains); else DELIVERY_LAST=error; fi
108
+ else
109
+ # Retry on listing lag or an API error, after each FORGE_REVIEW_DELIVERY_RETRY_DELAYS wait (seconds; non-integers ignored).
110
+ _ATTEMPT=0
111
+ for _DELAY in 0 ${FORGE_REVIEW_DELIVERY_RETRY_DELAYS-5 15 45}; do
112
+ case "$_DELAY" in ''|*[!0-9]*) continue ;; esac
113
+ _ATTEMPT=$((_ATTEMPT + 1))
114
+ [ "$_ATTEMPT" -gt 1 ] && [ "$_DELAY" -gt 0 ] && sleep "$_DELAY"
115
+ if ! delivery_fetch; then DELIVERY_LAST=error; echo "DELIVERY: attempt ${_ATTEMPT}: API error listing PR comments"; continue; fi
116
+ DELIVERY_LAST=ok
117
+ DELIVERY_SEEN=$(printf '%s\n%s\n' "$DELIVERY_SEEN" "$(delivery_domains)" | grep -E '^[a-z0-9-]+$' | sort -u)
118
+ _PENDING=""
119
+ for _D in $LAUNCHED_REVIEW_AGENTS; do
120
+ case "$DELIVERY_FOUND" in *" $_D "*) continue ;; esac
121
+ if [ "$(delivery_count "$_D")" -ge 1 ]; then DELIVERY_FOUND="${DELIVERY_FOUND}${_D} "; echo "DELIVERY: ${_D} found on attempt ${_ATTEMPT}"; else _PENDING="${_PENDING} ${_D}"; fi
122
+ done
123
+ [ -z "$_PENDING" ] && break
124
+ echo "DELIVERY: attempt ${_ATTEMPT}: missing:${_PENDING}"
125
+ done
126
+ fi
127
+ ACTUAL_AGENT_COUNT=$(printf '%s\n' "$DELIVERY_SEEN" | grep -c . || true)
128
+ fi
129
+ case "$ACTUAL_AGENT_COUNT" in ''|*[!0-9]*) ACTUAL_AGENT_COUNT=0 ;; esac # fail closed: unreadable or untrusted counts as not posted
130
+ if [ "${DISPATCH_FAILED:-}" != "true" ] && [ "$SELECTED_COUNT_INVALID" != "true" ] && [ -n "${LAUNCHED_REVIEW_AGENTS:-}" ] && [ "$DELIVERY_LAST" = error ]; then
131
+ # Never "missing": the comments could not be listed, so nothing is labelled or posted (forge#5166).
132
+ echo "REVIEW DELIVERY UNVERIFIED: could not list PR comments after ${_ATTEMPT:-1} attempt(s) (GitHub API error); found so far:${DELIVERY_FOUND% }"
133
+ echo "Do not re-dispatch reviewers: rerun the finalize step once GitHub answers."
134
+ exit 2
135
+ fi
80
136
  if [ "${DISPATCH_FAILED:-}" = "true" ] || [ "$SELECTED_COUNT_INVALID" = "true" ] || [ "$ACTUAL_AGENT_COUNT" -lt "$SELECTED_AGENT_COUNT" ]; then
81
137
  gh label create "review-degraded" --color "E4E669" --description "PR review panel was incomplete; re-review required before deployment. Managed by ForgeDock." --force -R "$GH_REPO" 2>/dev/null || true
82
138
  gh pr edit "$PR_NUMBER" -R "$GH_REPO" --add-label "review-degraded" --add-label "needs-human" 2>/dev/null || true # allowlist:check-command-side-effects
@@ -91,7 +147,7 @@ Re-run the full staging review in a fresh session before deployment."
91
147
  fi
92
148
  # END panel-guard
93
149
  # BEGIN delivery-check
94
- # Reload the launched-agent list persisted at dispatch (validated: lowercase marker domains only).
150
+ # Reload the launched-agent list persisted at dispatch (validated: lowercase marker domains only); a no-op when the panel guard loaded it.
95
151
  [ -n "${LAUNCHED_REVIEW_AGENTS:-}" ] || { [ -r "$_SD/${PR_NUMBER}_launched_review_agents" ] && LAUNCHED_REVIEW_AGENTS=$(grep -E '^[a-z0-9-]+$' "$_SD/${PR_NUMBER}_launched_review_agents" | sort -u | tr '\n' ' '); }
96
152
  # Fail closed: a staging review always launches at least the Phase 2 material-change agent, so an empty list means lost state or skipped bookkeeping, never "nothing to verify".
97
153
  if [ -z "${PR_NUMBER:-}" ] || [ -z "${LAUNCHED_REVIEW_AGENTS:-}" ]; then
@@ -100,21 +156,9 @@ if [ -z "${PR_NUMBER:-}" ] || [ -z "${LAUNCHED_REVIEW_AGENTS:-}" ]; then
100
156
  exit 1
101
157
  fi
102
158
  MISSING_AGENT_COMMENTS=""
103
- # Each Bash call is a fresh shell: re-resolve the full head SHA if it is not set, and refuse when it is not a commit id
104
- # (an empty SHA would make the Reviewed-SHA match accept any head).
105
- [ -n "${REVIEW_SHA_FULL:-}" ] || REVIEW_SHA_FULL=$(gh pr view "$PR_NUMBER" -R "$GH_REPO" --json headRefOid --jq '.headRefOid' 2>/dev/null || echo "")
106
- case "$REVIEW_SHA_FULL" in *[!0-9a-f]*|"") REVIEW_SHA_FULL="" ;; *) [ "${#REVIEW_SHA_FULL}" -eq 40 ] || [ "${#REVIEW_SHA_FULL}" -eq 64 ] || REVIEW_SHA_FULL="" ;; esac
107
- TRUSTED_SCRIPT=$(forge_resolve trusted-comments.sh)
159
+ # Counted once per attempt from the cached listing above (delivery_count); a domain not found on any attempt is missing.
108
160
  for AGENT_DOMAIN in $LAUNCHED_REVIEW_AGENTS; do
109
- AGENT_COMMENT_COUNT=0
110
- if [ -n "$REVIEW_SHA_FULL" ] && [ -n "$TRUSTED_SCRIPT" ]; then
111
- AGENT_COMMENT_COUNT=$(gh api --paginate "repos/${GH_REPO}/issues/${PR_NUMBER}/comments" 2>/dev/null \
112
- | bash "$TRUSTED_SCRIPT" count "^(?=[\\s\\S]*<!-- REVIEW-FINDINGS-START -->[\\s\\S]*<!-- REVIEW-FINDINGS-END -->)<!-- FORGE:REVIEW-AGENT:${AGENT_DOMAIN} -->[\\s\\S]*(^|\\n)Reviewed-SHA:[ ]${REVIEW_SHA_FULL}(\\r?\\n|$)" 2>/dev/null || echo 0)
113
- fi
114
- case "$AGENT_COMMENT_COUNT" in ''|*[!0-9]*) AGENT_COMMENT_COUNT=0 ;; esac # fail closed: counts as missing
115
- if [ "${AGENT_COMMENT_COUNT:-0}" -lt 1 ]; then
116
- MISSING_AGENT_COMMENTS="${MISSING_AGENT_COMMENTS} ${AGENT_DOMAIN}"
117
- fi
161
+ case "$DELIVERY_FOUND" in *" ${AGENT_DOMAIN} "*) ;; *) MISSING_AGENT_COMMENTS="${MISSING_AGENT_COMMENTS} ${AGENT_DOMAIN}" ;; esac
118
162
  done
119
163
 
120
164
  if [ -n "$MISSING_AGENT_COMMENTS" ]; then
@@ -123,6 +167,7 @@ if [ -n "$MISSING_AGENT_COMMENTS" ]; then
123
167
  exit 1
124
168
  fi
125
169
  # END delivery-check
170
+ rm -f "$DELIVERY_CACHE"
126
171
  echo "DELIVERY: OK (${ACTUAL_AGENT_COUNT}/${SELECTED_AGENT_COUNT} launched reviewers posted a findings block for head ${REVIEW_SHA_FULL})"
127
172
  exit 0
128
173
  fi
@@ -19,12 +19,12 @@ OTHER=fedcba9876543210fedcba9876543210fedcba98
19
19
  blk() { awk -v n="$1" '$0 == "# BEGIN " n {f=1; next} $0 == "# END " n {f=0} f' "$POST"; }
20
20
 
21
21
  # (1) the fences now live only in the script: the blocks exist, the spec no longer carries them
22
- for b in panel-guard delivery-check test-gate-extract test-gate-verdict; do
22
+ for b in delivery-fetch panel-guard delivery-check test-gate-extract test-gate-verdict; do
23
23
  [ -n "$(blk "$b")" ] && ok || bad "block $b missing from review-staging-post.sh"
24
24
  done
25
25
  if grep -qE 'ACTUAL_AGENT_COUNT=\$\(gh api|MISSING_AGENT_COMMENTS=""|GATE_VERDICT_INVALID=0' "$SPEC"; then bad "the spec must not carry a copy of the panel-guard, delivery or verdict-handling fence"; else ok; fi
26
- # 6.75 carries the findings-block lookahead; the 6.75 empty-list guard precedes the per-domain loop
27
- blk delivery-check | grep -qF 'count "^(?=[\\s\\S]*<!-- REVIEW-FINDINGS-START -->[\\s\\S]*<!-- REVIEW-FINDINGS-END -->)<!-- FORGE:REVIEW-AGENT:${AGENT_DOMAIN} -->' && ok || bad "6.75 count must require the findings block"
26
+ # 6.75 carries the findings-block lookahead (in the shared cached-listing counter); the 6.75 empty-list guard precedes the per-domain loop
27
+ blk delivery-fetch | grep -qF 'count "^(?=[\\s\\S]*<!-- REVIEW-FINDINGS-START -->[\\s\\S]*<!-- REVIEW-FINDINGS-END -->)<!-- FORGE:REVIEW-AGENT:${AGENT_DOMAIN} -->' && ok || bad "6.75 count must require the findings block"
28
28
  G=$(blk delivery-check | grep -n 'launched-agent list is empty or unreadable' | head -1 | cut -d: -f1); L=$(blk delivery-check | grep -n '^for AGENT_DOMAIN in' | head -1 | cut -d: -f1)
29
29
  [ -n "$G" ] && [ -n "$L" ] && [ "$G" -lt "$L" ] && ok || bad "6.75 empty-list guard must precede the for AGENT_DOMAIN loop"
30
30
  # the producer never coerces an absent marker to SKIP; the catch-all arm never sets SKIP
@@ -38,7 +38,8 @@ bash "$POST" delivery --repo o/r --pr 1 >/dev/null 2>&1; [ $? -eq 2 ] && ok || b
38
38
  bash "$POST" test-gate --repo o/r --pr 1 --sd "$TMP/u" --output x --prs-file "$TMP/none" >/dev/null 2>&1; [ $? -eq 2 ] && ok || bad "unreadable --prs-file must exit 2"
39
39
  bash "$POST" test-gate --repo o/r --pr 1 --sd "$TMP/u" --output x --prs-file /dev/null --posture lax >/dev/null 2>&1; [ $? -eq 2 ] && ok || bad "unknown --posture must exit 2"
40
40
 
41
- # gh stub: $FIX/comments.json is the PR's comment list; posted bodies and edits go to $FIX/posted / $FIX/edits
41
+ # gh stub: $FIX/comments.json is the PR's comment list ($FIX/comments.<k>.json, when present, answers the k-th listing; no file = API error);
42
+ # each listing is logged to $FIX/api_calls; posted bodies and edits go to $FIX/posted / $FIX/edits
42
43
  mkdir -p "$TMP/bin"
43
44
  cat > "$TMP/bin/gh" <<'STUB'
44
45
  #!/usr/bin/env bash
@@ -49,17 +50,21 @@ case "$1 $2" in
49
50
  "label create") exit 0 ;;
50
51
  "pr view") [ -f "$F/head" ] && { cat "$F/head"; exit 0; }; exit 1 ;;
51
52
  esac
52
- if [ "$1" = api ]; then case "$a" in *"/comments"*) cat "$F/comments.json" 2>/dev/null || exit 1; exit 0 ;; esac; fi
53
+ if [ "$1" = api ]; then case "$a" in *"/comments"*)
54
+ echo x >> "$F/api_calls"; k=$(wc -l < "$F/api_calls" | tr -d ' ')
55
+ if [ -f "$F/comments.$k.json" ]; then cat "$F/comments.$k.json"; else cat "$F/comments.json" 2>/dev/null || exit 1; fi; exit 0 ;; esac; fi
53
56
  echo "gh stub: unhandled: $a" >&2; exit 1
54
57
  STUB
55
58
  printf '#!/bin/sh\nexit 1\n' > "$TMP/bin/yq" # no yq: defaults apply
56
59
  chmod +x "$TMP/bin/gh" "$TMP/bin/yq"
57
60
  export PATH="$TMP/bin:$PATH"
61
+ export FORGE_REVIEW_DELIVERY_RETRY_DELAYS="0 0 0" # retries without waiting (4 attempts)
58
62
  newfix() { FIX="$TMP/fix.$1"; rm -rf "$FIX"; mkdir -p "$FIX/sd"; export FIX; }
59
63
  FB=$'<!-- REVIEW-FINDINGS-START -->\n<!-- REVIEW-FINDINGS-END -->'
60
64
  cm() { jq -n --arg b "$1" --arg t "${2:-Bot}" '{body:$b, author_association:"NONE", user:{type:$t, login:"x"}}'; }
61
65
  agent() { printf '<!-- FORGE:REVIEW-AGENT:%s -->\nReviewed-SHA: %s\n\n%s' "$1" "${2:-$HEAD}" "${3-$FB}"; }
62
- comments() { jq -s '.' > "$FIX/comments.json"; }
66
+ comments() { jq -s '.' > "$FIX/comments${1:+.$1}.json"; }
67
+ calls() { [ -f "$FIX/api_calls" ] && wc -l < "$FIX/api_calls" | tr -d ' ' || echo 0; }
63
68
  deliver() { bash "$POST" delivery --repo o/r --pr 42 --sd "$FIX/sd" --head "${1:-$HEAD}" 2>&1; echo "rc=$?"; }
64
69
 
65
70
  # (3) delivery: a complete panel passes and posts nothing
@@ -67,6 +72,7 @@ newfix full; printf 'security\nmaterial-change\n' > "$FIX/sd/42_launched_review_
67
72
  { cm "$(agent security)"; cm "$(agent material-change)"; } | comments
68
73
  OUT=$(deliver); case "$OUT" in *"DELIVERY: OK (2/2"*"rc=0") ok ;; *) bad "complete panel must pass (got: $OUT)" ;; esac
69
74
  [ ! -s "$FIX/posted" ] && ok || bad "a complete panel must post nothing"
75
+ [ "$(calls)" = 1 ] && ok || bad "delivery: complete panel lists comments once (got $(calls) listings)"
70
76
  # a duplicate domain line does not inflate the selected count
71
77
  printf 'security\nsecurity\nmaterial-change\n' > "$FIX/sd/42_launched_review_agents"
72
78
  OUT=$(deliver); case "$OUT" in *"rc=0") ok ;; *) bad "duplicate launched lines must count once (got: $OUT)" ;; esac
@@ -94,9 +100,35 @@ newfix empty; : > "$FIX/sd/42_launched_review_agents"; cm "$(agent security)" |
94
100
  OUT=$(deliver); case "$OUT" in *"rc=1") ok ;; *) bad "empty launched list must fail (got: $OUT)" ;; esac
95
101
  newfix none; cm "$(agent security)" | comments
96
102
  OUT=$(deliver); case "$OUT" in *"rc=1") ok ;; *) bad "absent launched list must fail (got: $OUT)" ;; esac
97
- # unreadable comments count as 0 delivered
103
+ # unreadable comments (an API error on every attempt) fail closed as UNVERIFIED, never as missing (forge#5166)
98
104
  newfix unreadable; printf 'security\n' > "$FIX/sd/42_launched_review_agents"
99
- OUT=$(deliver); case "$OUT" in *"rc=1") ok ;; *) bad "unreadable comments must fail closed (got: $OUT)" ;; esac
105
+ OUT=$(deliver); case "$OUT" in *"REVIEW DELIVERY UNVERIFIED"*"rc=2") ok ;; *) bad "delivery: API error on every attempt is UNVERIFIED (got: $OUT)" ;; esac
106
+ case "$OUT" in *"REVIEW DELIVERY FAILURE"*) bad "an API error must not be reported as missing" ;; *) ok ;; esac
107
+ [ ! -s "$FIX/posted" ] && [ ! -s "$FIX/edits" ] && ok || bad "UNVERIFIED must post no GATE_FAILURE and add no label"
108
+ [ "$(calls)" = 4 ] && ok || bad "UNVERIFIED must come after every retry (got $(calls) listings)"
109
+ # delivery: lagging listing passes on retry -- the first listing lacks a comment, the second shows it
110
+ newfix lag; printf 'security\nmaterial-change\n' > "$FIX/sd/42_launched_review_agents"
111
+ cm "$(agent security)" | comments 1
112
+ { cm "$(agent security)"; cm "$(agent material-change)"; } | comments
113
+ OUT=$(deliver); case "$OUT" in *"DELIVERY: OK (2/2"*"rc=0") ok ;; *) bad "delivery: lagging listing passes on retry (got: $OUT)" ;; esac
114
+ case "$OUT" in *"material-change found on attempt 2"*) ok ;; *) bad "lag: must print the attempt a domain was found on (got: $OUT)" ;; esac
115
+ case "$OUT" in *"security found on attempt 1"*) ok ;; *) bad "lag: security must be found on attempt 1 (got: $OUT)" ;; esac
116
+ [ ! -s "$FIX/posted" ] && [ ! -s "$FIX/edits" ] && ok || bad "lag: a panel delivered on retry must post and label nothing"
117
+ [ "$(calls)" = 2 ] && ok || bad "lag: retries stop once every domain is found (got $(calls) listings)"
118
+ # a transient API error, then a full listing, passes
119
+ newfix transient; printf 'security\n' > "$FIX/sd/42_launched_review_agents"
120
+ echo 'not json' > "$FIX/comments.1.json"; cm "$(agent security)" | comments
121
+ OUT=$(deliver); case "$OUT" in *"attempt 1: API error"*"security found on attempt 2"*"rc=0") ok ;; *) bad "a transient API error must be retried (got: $OUT)" ;; esac
122
+ # a real absence after every retry is still missing (listed and absent), with the panel-integrity failure
123
+ newfix absent; printf 'security\nmaterial-change\n' > "$FIX/sd/42_launched_review_agents"; cm "$(agent security)" | comments
124
+ OUT=$(deliver); case "$OUT" in *"rc=1") ok ;; *) bad "absent after retries must fail as missing (got: $OUT)" ;; esac
125
+ case "$OUT" in *UNVERIFIED*) bad "a listed absence is not UNVERIFIED" ;; *) ok ;; esac
126
+ grep -qF 'review-panel-integrity' "$FIX/posted" 2>/dev/null && ok || bad "absent: must post GATE_FAILURE:TYPE=review-panel-integrity"
127
+ [ "$(calls)" = 4 ] && ok || bad "absent: must retry before declaring missing (got $(calls) listings)"
128
+ # an API error on the LAST attempt after a lacking listing is UNVERIFIED, not missing
129
+ newfix lasterr; printf 'security\nmaterial-change\n' > "$FIX/sd/42_launched_review_agents"
130
+ cm "$(agent security)" | comments 1; cm "$(agent security)" | comments 2; cm "$(agent security)" | comments 3; echo '{}' > "$FIX/comments.4.json"
131
+ OUT=$(deliver); case "$OUT" in *"REVIEW DELIVERY UNVERIFIED"*"rc=2") ok ;; *) bad "an error on the last attempt must be UNVERIFIED (got: $OUT)" ;; esac
100
132
  # a malformed --head with no resolvable head refuses
101
133
  newfix badhead; printf 'security\n' > "$FIX/sd/42_launched_review_agents"; cm "$(agent security)" | comments
102
134
  OUT=$(deliver "n/a"); case "$OUT" in *"rc=1") ok ;; *) bad "an unresolvable head must fail closed (got: $OUT)" ;; esac