mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-06 08:18:56 +01:00
printcraft's storage-security fix merged green and then could not deploy. Its `verify` had run twice on the squashed commit — cancelled once when auto-merge pushed mid-run, then re-run to success. The gate counted every run, so the cancelled attempt outvoted the green re-run that replaced it, and the deploy was blocked no matter how many times CI passed. Judging the latest run per workflow fixes it, and subsumes the retry case the deploy-exclusion comment was already worrying about. The larger point is that this is the THIRD wrong verdict in this file — dependabot runs counting as CI, the deploy workflow counting itself, and now this — and the first one to arrive with a test. Each earlier bug was found the same way: a real deploy blocked, and someone reading Actions logs to discover the gate had misread them. All three said RED about code that was fine, which is the dangerous direction: the only way past a gate that will not open is to turn it off. So the verdict is now a pure function of the run list, and all three failures are pinned in scripts/hetzner/test-ci-gate.sh (15 cases, wired into test:ops and therefore verify and CI). Reverting the fix turns 3 of them red; the "must block" half is pinned too, so a later simplification cannot buy convenience by making the gate permissive. Co-authored-by: t <t@t.t> Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
115 lines
4.6 KiB
Bash
Executable File
115 lines
4.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Tests for the CI gate's verdict — the rule that decides whether a commit is
|
|
# allowed to reach production.
|
|
#
|
|
# This rule had been wrong three times before it had a single test, and each
|
|
# bug was found the same way: a real deploy blocked, a human digging through
|
|
# Actions logs to learn that the gate had misread them.
|
|
#
|
|
# 1. Dependabot's updater run counted as CI, so solon and reparaturbonus-zh
|
|
# could not deploy commits whose `verify` was green.
|
|
# 2. The deploy workflow counted itself, so a retry after a failed deploy
|
|
# read its own earlier failure as a red and could never succeed.
|
|
# 3. A cancelled run outvoted the green RE-RUN that replaced it on the same
|
|
# SHA, so printcraft's storage-security fix sat undeployed while `verify`
|
|
# passed.
|
|
#
|
|
# All three are cases where the gate said RED about code that was fine. That is
|
|
# the dangerous direction for a gate to be wrong in, because the only way past
|
|
# a gate that will not open is to disable it. So each is pinned here.
|
|
#
|
|
# The opposite direction is pinned too: every "must block" case below exists so
|
|
# a future simplification cannot make the gate permissive to buy convenience.
|
|
|
|
set -uo pipefail
|
|
|
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
GATE="$HERE/ci-gate.sh"
|
|
|
|
PASS=0; FAIL=0
|
|
ok() { printf ' ✓ %s\n' "$1"; PASS=$((PASS + 1)); }
|
|
no() { printf ' ✗ %s\n' "$1"; FAIL=$((FAIL + 1)); }
|
|
|
|
export CI_GATE_LIB_ONLY=1
|
|
# shellcheck source=/dev/null
|
|
source "$GATE" owner/repo deadbeef
|
|
unset CI_GATE_LIB_ONLY
|
|
|
|
# run <path> <run_number> <status> <conclusion>
|
|
run() {
|
|
printf '{"path":"%s","run_number":%s,"status":"%s","conclusion":%s}' \
|
|
"$1" "$2" "$3" "$([ "$4" = "null" ] && echo null || echo "\"$4\"")"
|
|
}
|
|
runs() { local IFS=,; echo "[$*]"; }
|
|
|
|
expect() {
|
|
local desc="$1" want="$2" exclude="$3" json="$4"
|
|
local got; got="$(printf '%s' "$json" | ci_verdict "$exclude" | cut -d' ' -f1)"
|
|
[ "$got" = "$want" ] && ok "$desc" || no "$desc (want $want, got $got)"
|
|
}
|
|
|
|
CI='.github/workflows/ci.yml'
|
|
DEPLOY='.github/workflows/deploy.yml'
|
|
SWEEP='.github/workflows/sweep.yml'
|
|
DEPENDABOT='dynamic/dependabot/dependabot-updates'
|
|
|
|
echo "the verdict rule:"
|
|
|
|
expect "one green workflow is green" GREEN "" \
|
|
"$(runs "$(run "$CI" 1 completed success)")"
|
|
|
|
expect "a genuine failure blocks" FAILED "" \
|
|
"$(runs "$(run "$CI" 1 completed failure)")"
|
|
|
|
expect "a timeout blocks — it is not a cancellation" FAILED "" \
|
|
"$(runs "$(run "$CI" 1 completed timed_out)")"
|
|
|
|
expect "an unfinished workflow is pending, not green" PENDING "" \
|
|
"$(runs "$(run "$CI" 1 in_progress null)")"
|
|
|
|
expect "no runs at all means no CI is defined" NONE "" "[]"
|
|
|
|
expect "green only when EVERY workflow is green" FAILED "" \
|
|
"$(runs "$(run "$CI" 1 completed success)" "$(run "$SWEEP" 1 completed failure)")"
|
|
|
|
echo
|
|
echo "regressions — each of these once blocked a real deploy:"
|
|
|
|
# Bug 3, the one that blocked printcraft's security fix today.
|
|
expect "a green re-run replaces the cancelled attempt it superseded" GREEN "" \
|
|
"$(runs "$(run "$CI" 1 completed cancelled)" "$(run "$CI" 2 completed success)")"
|
|
|
|
expect "...and the cancellation is judged by recency, not list order" GREEN "" \
|
|
"$(runs "$(run "$CI" 2 completed success)" "$(run "$CI" 1 completed cancelled)")"
|
|
|
|
# The inverse must still hold, or "latest wins" would be a way to launder a red.
|
|
expect "a cancellation AFTER a green run is not laundered by the earlier pass" CANCELLED "" \
|
|
"$(runs "$(run "$CI" 1 completed success)" "$(run "$CI" 2 completed cancelled)")"
|
|
|
|
expect "a failing re-run overrides an earlier pass" FAILED "" \
|
|
"$(runs "$(run "$CI" 1 completed success)" "$(run "$CI" 2 completed failure)")"
|
|
|
|
# Bug 2 — the deploy workflow reading its own earlier failure as red.
|
|
expect "the deploy workflow does not count itself as CI" GREEN "$DEPLOY" \
|
|
"$(runs "$(run "$CI" 1 completed success)" "$(run "$DEPLOY" 1 completed failure)")"
|
|
|
|
expect "excluding deploy does not excuse a real CI failure" FAILED "$DEPLOY" \
|
|
"$(runs "$(run "$CI" 1 completed failure)" "$(run "$DEPLOY" 1 completed failure)")"
|
|
|
|
# Bug 1 — dependabot's updater is not a statement about the code.
|
|
expect "a failed dependabot update is not a red CI" GREEN "" \
|
|
"$(runs "$(run "$CI" 1 completed success)" "$(run "$DEPENDABOT" 1 completed failure)")"
|
|
|
|
expect "excluding non-workflow runs cannot manufacture a pass from nothing" NONE "" \
|
|
"$(runs "$(run "$DEPENDABOT" 1 completed success)")"
|
|
|
|
# Cancellation still has to survive as a signal — it is how a superseded commit
|
|
# bows out with exit 3 instead of deploying stale code.
|
|
expect "an unreplaced cancellation is still reported as cancelled" CANCELLED "" \
|
|
"$(runs "$(run "$CI" 1 completed cancelled)")"
|
|
|
|
echo
|
|
echo " $PASS passed, $FAIL failed"
|
|
[ "$FAIL" -eq 0 ]
|