diff --git a/scripts/test/v2-quota-preflight.test.sh b/scripts/test/v2-quota-preflight.test.sh index 114bee10..9a792cee 100755 --- a/scripts/test/v2-quota-preflight.test.sh +++ b/scripts/test/v2-quota-preflight.test.sh @@ -21,9 +21,11 @@ fi # Sanity call: `gh run list --limit 1 --json databaseId` # Count call: `gh run list --workflow ... --jq length` wf="" +all=0 prev="" for a in "$@"; do if [ "$prev" = "--workflow" ]; then wf="$a"; fi + if [ "$a" = "--all" ]; then all=1; fi prev="$a" done if [ -z "$wf" ]; then @@ -36,6 +38,14 @@ case ",${GH_STUB_FORBID:-}," in exit 9 ;; esac +case ",${GH_STUB_DISABLED:-}," in + *",${wf},"*) + if [ "$all" -ne 1 ]; then + echo "could not find any workflows named ${wf}" >&2 + exit 1 + fi + ;; +esac # Look up "=" in GH_STUB_RUNS. Unknown workflows fail with real # gh's missing-workflow message; a value of ERR simulates a transient outage. entry="$(printf '%s\n' "${GH_STUB_RUNS:-}" | tr ',' '\n' | grep "^${wf}=" || true)" @@ -81,6 +91,24 @@ set -e [ "$code" -eq 0 ] || fail "missing workflows must not fail the brake (got $code)" printf '%s\n' "$out" | grep -qx "runs=1" || fail "missing workflows count as 0 (got: $out)" +# Disabled selected workflows still contribute runs inside the window. +set +e +out="$(GH_STUB_RUNS="enabled.yml=3,disabled.yml=16" GH_STUB_DISABLED="disabled.yml" \ + YSTACK_LANE_WORKFLOWS="enabled.yml,disabled.yml" "$qp")" +code=$? +set -e +[ "$code" -eq 0 ] || fail "19 runs including a disabled workflow must exit 0 (got $code)" +printf '%s\n' "$out" | grep -qx "runs=19" || fail "disabled workflow runs must be counted (got: $out)" + +set +e +out="$(GH_STUB_RUNS="enabled.yml=3,disabled.yml=17" GH_STUB_DISABLED="disabled.yml" \ + YSTACK_LANE_WORKFLOWS="enabled.yml,disabled.yml" "$qp" 2>"$tmp/err")" +code=$? +set -e +[ "$code" -eq 1 ] || fail "20 runs including a disabled workflow must exit 1 (got $code)" +printf '%s\n' "$out" | grep -qx "runs=20" || fail "threshold count must include disabled runs (got: $out)" +grep -q "means a bug" "$tmp/err" || fail "disabled-workflow threshold failure must be loud" + # At the backstop: exit 1, loudly. set +e out="$(GH_STUB_RUNS="spec-on-intent.yml=20" "$qp" 2>"$tmp/err")" diff --git a/scripts/v2/quota-preflight.sh b/scripts/v2/quota-preflight.sh index 806f23e6..129f3c13 100755 --- a/scripts/v2/quota-preflight.sh +++ b/scripts/v2/quota-preflight.sh @@ -63,7 +63,7 @@ for wf in $lane; do # A workflow that doesn't exist yet (pre-Stack-B) counts as zero. Any OTHER # failure — outage, rate limit — must fail loudly: converting errors to zero # would make the brake fail open during a cascade (Codex review of #131). - if n="$(gh run list --workflow "$wf" --created ">=${cutoff}" --limit "$fetch_limit" \ + if n="$(gh run list --workflow "$wf" --all --created ">=${cutoff}" --limit "$fetch_limit" \ --json databaseId --jq 'length' 2>"$errf")"; then case "$n" in ''|*[!0-9]*)