Compare commits

...
Author SHA1 Message Date
james.maesandCodex 8c0530ee74 fix: reject empty ref responses across jq versions
Co-Authored-By: Codex <noreply@openai.com>
2026-10-21 02:13:02 -05:00
james.maesandCodex 225186356a fix: distinguish missing rc refs from github error bodies
Co-Authored-By: Codex <noreply@openai.com>
2026-10-21 02:09:46 -05:00
3 changed files with 63 additions and 2 deletions

No files matched your search

+1
View File
@@ -62,6 +62,7 @@ jobs:
python3 tests/test_rc_finalize_sweep.py
python3 tests/test_rc_guard.py
python3 -m unittest discover -s tests -p test_rc_timeout_recovery.py
python3 -m unittest discover -s tests -p test_rc_ref_lookup.py
python3 -m unittest discover -s tests -p test_generate_rc_workflow.py
python3 -m unittest discover -s tests -p test_audit_estate.py
python3 tests/test_all_profiles.py
+18 -2
View File
@@ -174,6 +174,22 @@ jobs:
fi
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
# BEGIN RC REF LOOKUP
read_ref() {
local body sha
if body=$(gh api "repos/$REPO/git/ref/$1" 2>"$workdir/ref-error"); then
sha=$(jq -er '.object.sha' <<< "$body") || return 1
[[ "$sha" =~ ^[0-9a-f]{40}$ ]] || return 1
printf '%s\n' "$sha"
elif jq -se 'length == 1 and .[0].status == "404"' >/dev/null 2>&1 <<< "$body"; then
# gh prints HTTP error JSON on stdout even when --jq was requested.
return 0
else
cat "$workdir/ref-error" >&2
return 1
fi
}
# END RC REF LOOKUP
# The evaluator is inline so a pinned reusable workflow cannot fetch mutable code.
cat > "$workdir/rc_guard.py" <<'PY'
# BEGIN RC GUARD
@@ -442,7 +458,7 @@ jobs:
PY
MERGED_AT=$(jq -er .merged_at "$workdir/intent.json")
lock=automation/qbit-rc-pending
current_lock=$(gh api "repos/$REPO/git/ref/heads/$lock" -q .object.sha 2>/dev/null || true)
current_lock=$(read_ref "heads/$lock")
# A duplicate after completed finalization is safe only after tag/source checks below.
[[ -z "$current_lock" || "$current_lock" == "$MERGE_SHA" ]] || { echo "::error::Different release owns pending lock"; exit 1; }
gh api "repos/$REPO/commits/$MERGE_SHA/check-runs?filter=latest&per_page=100" \
@@ -520,7 +536,7 @@ jobs:
python3 "$workdir/rc_guard.py" central "$version" "$artifact" "$workdir/central.pom" "$last_modified" "$MERGED_AT"
# 3. Signed annotated tag on the exact bump; duplicate runs must not accept a different tag.
existing=$(gh api "repos/$REPO/git/ref/tags/v$version" --jq '.object.sha' 2>/dev/null || true)
existing=$(read_ref "tags/v$version")
target=""; release_exists=false
if [[ -n "$existing" ]]; then
target=$(gh api "repos/$REPO/git/tags/$existing" --jq '.object.sha')
+44
View File
@@ -0,0 +1,44 @@
"""Exercise actual shell handling of gh error JSON, including the observed 404."""
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import textwrap
import unittest
SOURCE = Path(__file__).parents[1].joinpath('.github/workflows/qbit-release-rc.yml').read_text()
FUNCTION = textwrap.dedent(SOURCE.split(' # BEGIN RC REF LOOKUP\n')[1].split(' # END RC REF LOOKUP')[0])
@unittest.skipUnless(shutil.which('bash') and shutil.which('jq'), 'Bash and jq required')
class RefLookupTests(unittest.TestCase):
def lookup(self, body, code):
with tempfile.TemporaryDirectory() as directory:
env = dict(os.environ, BODY=body, CODE=str(code), REPO='QRun-IO/qbit-alerts', workdir=directory)
script = 'set -euo pipefail\ngh() { printf "%s" "$BODY"; return "$CODE"; }\n' + FUNCTION + '\nresult=$(read_ref tags/v0.1.0-RC.17)\nprintf "%s" "$result"\n'
return subprocess.run(['bash', '-c', script], env=env, text=True, capture_output=True)
def test_absent_tag_returns_empty_not_error_json(self):
result = self.lookup('{"message":"Not Found","documentation_url":"https://docs.github.com/rest/git/refs#get-a-reference","status":"404"}', 1)
self.assertEqual(0, result.returncode, result.stderr)
self.assertEqual('', result.stdout)
def test_existing_tag_returns_only_valid_object_sha(self):
result = self.lookup('{"object":{"sha":"' + 'a' * 40 + '"}}', 0)
self.assertEqual(0, result.returncode, result.stderr)
self.assertEqual('a' * 40, result.stdout)
def test_permission_network_and_server_errors_are_not_missing_refs(self):
for body in ('{"status":"403"}', '{"status":"500"}', '', ' ', '\n', 'not json'):
with self.subTest(body=body):
self.assertNotEqual(0, self.lookup(body, 1).returncode)
def test_malformed_success_response_is_rejected(self):
for body in ('{}', '{"object":{"sha":null}}', '{"object":{"sha":"not-a-sha"}}'):
with self.subTest(body=body):
self.assertNotEqual(0, self.lookup(body, 0).returncode)
if __name__ == '__main__':
unittest.main()