Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions scripts/test/v2-quota-preflight.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ fi
# Sanity call: `gh run list --limit 1 --json databaseId`
# Count call: `gh run list --workflow <file> ... --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
Expand All @@ -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 "<wf>=<count>" 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)"
Expand Down Expand Up @@ -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")"
Expand Down
2 changes: 1 addition & 1 deletion scripts/v2/quota-preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]*)
Expand Down
Loading