Skip to content

Business operating system for Claude Code — 57 skills, 21 agents, smart daemon. Unified inbox (WhatsApp/Email/Slack/Telegram), autonomous PR merge, full-AWS monitoring, revenue (Stripe+RevenueCat), e-commerce (Shopify), marketing (Klaviyo/Meta/GA4), voice (Bland/ElevenLabs), APM (Datadog/NewRelic/OTEL), YOLO mode.

fix(ops-ci): survive a partial GraphQL failure instead of half-parsing it (#930)

Aurora Capital261842a7542d
diff --git a/claude-ops/bin/ops-ci b/claude-ops/bin/ops-ci
index be808915..aa3e278f 100755
--- a/claude-ops/bin/ops-ci
+++ b/claude-ops/bin/ops-ci
@@ -91,14 +91,22 @@ scan_all_graphql() {
done < <(printf '%s' "$repos_json" | jq -c '.[]')
query+="}"
- # Fire the single GraphQL call
+ # Fire the single GraphQL call.
+ # NOTE: `gh api graphql` exits non-zero on a PARTIAL failure while still
+ # printing a complete, usable payload — one unreadable repo in a 30-repo
+ # aliased query returns {"data":{...},"errors":[NOT_FOUND]} AND exit 1. A
+ # `|| echo '{}'` fallback therefore appends a second JSON document to a good
+ # payload, and every downstream `jq` emits one value per document ("14\n0"),
+ # which blows up the numeric test below. Only fall back when there is no
+ # output at all.
local gql_result
- gql_result=$(gh api graphql -f query="$query" 2>/dev/null || echo '{}')
+ gql_result=$(gh api graphql -f query="$query" 2>/dev/null) || true
+ [ -z "$gql_result" ] && gql_result='{}'
# Extract data (errors from NOT_FOUND/private repos are tolerated — those keys
# will simply have null values which the jq below skips gracefully)
local gql_data
- gql_data=$(printf '%s' "$gql_result" | jq '.data // {}')
+ gql_data=$(printf '%s' "$gql_result" | jq -s '.[0].data // {}')
# For each repo alias, collect FAILURE suites → write per-repo JSON file
while IFS= read -r entry; do
@@ -140,7 +148,9 @@ scan_all_graphql() {
' 2>/dev/null || echo '[]')
local fcount
- fcount=$(printf '%s' "$failures" | jq 'length' 2>/dev/null || echo 0)
+ # jq -s so a multi-document input can never yield a multi-line count.
+ fcount=$(printf '%s' "$failures" | jq -s '.[0] // [] | length' 2>/dev/null || echo 0)
+ [[ "$fcount" =~ ^[0-9]+$ ]] || fcount=0
if [ "$fcount" -gt 0 ]; then
printf '{"repo":"%s","failures":%s}' "$repo_slug" "$failures" \
> "$TMPDIR_OPS/${safe_name}.json"
diff --git a/claude-ops/tests/run-all.sh b/claude-ops/tests/run-all.sh
index 45ebb0fa..f59ec325 100755
--- a/claude-ops/tests/run-all.sh
+++ b/claude-ops/tests/run-all.sh
@@ -38,6 +38,7 @@ run_suite "$TESTS_DIR/test-agents-lint.sh"
run_suite "$TESTS_DIR/test-compact-discovery.sh"
run_suite "$TESTS_DIR/test-bin-scripts.sh"
run_suite "$TESTS_DIR/test-gog-account.sh"
+run_suite "$TESTS_DIR/test-ops-ci.sh"
run_suite "$TESTS_DIR/test-ops-speedup.sh"
run_suite "$TESTS_DIR/test-ops-update-stale-clone.sh"
run_suite "$TESTS_DIR/test-ops-status.sh"
diff --git a/claude-ops/tests/test-ops-ci.sh b/claude-ops/tests/test-ops-ci.sh
new file mode 100755
index 00000000..22c83f72
--- /dev/null
+++ b/claude-ops/tests/test-ops-ci.sh
@@ -0,0 +1,76 @@
+#!/usr/bin/env bash
+# test-ops-ci.sh — ops-ci must survive a PARTIAL GraphQL failure.
+#
+# Regression: `gh api graphql` on an aliased multi-repo query exits NON-ZERO
+# when any single alias is unreadable (NOT_FOUND on a private/renamed repo),
+# while still printing a complete, usable payload:
+# {"data":{...},"errors":[{"type":"NOT_FOUND",...}]} + exit 1
+# ops-ci wrapped that in `|| echo '{}'`, which APPENDED a second JSON document.
+# Every downstream `jq` then emitted one value per document ("14\n0"), and the
+# numeric test blew up 30 times with:
+# ops-ci: line 144: [: 14\n0: integer expected
+# The scan still exited 0, so the dashboard printed a fire count derived from a
+# half-parsed payload — a checker that could not measure, reading as a result.
+set -uo pipefail
+
+ROOT="$(cd "$(dirname "$0")/.." && pwd)"
+pass=0
+fail=0
+ok() {
+ echo " PASS: $1"
+ pass=$((pass + 1))
+}
+no() {
+ echo " FAIL: $1"
+ fail=$((fail + 1))
+}
+
+echo "ops-ci partial-GraphQL handling"
+
+# 1. the fallback must not be able to append a second document
+if grep -q "gh api graphql -f query=\"\$query\" 2>/dev/null || echo '{}'" "$ROOT/bin/ops-ci"; then
+ no "gh graphql still falls back with '|| echo {}' (appends a 2nd JSON doc)"
+else
+ ok "gh graphql fallback cannot append a second JSON document"
+fi
+
+# 2. every count derived from gh output must be slurped, so a multi-document
+# input can never produce a multi-line integer
+if grep -nE "fcount=.*jq '" "$ROOT/bin/ops-ci" | grep -qv 'jq -s'; then
+ no "fcount is computed without jq -s"
+else
+ ok "fcount uses jq -s and cannot yield a multi-line integer"
+fi
+
+# 3. the numeric test is guarded against a non-integer
+if grep -q 'fcount" =~ \^\[0-9\]+\$' "$ROOT/bin/ops-ci"; then
+ ok "fcount is validated as an integer before the numeric test"
+else
+ no "fcount reaches [ -gt ] without an integer guard"
+fi
+
+# 4. behavioural: a real partial payload must parse to exactly one value
+partial='{"data":{"r0":{"main":{"target":{"oid":"abc"}}},"r1":null},"errors":[{"type":"NOT_FOUND"}]}'
+# old shape: payload + appended '{}' — this is what the bug produced
+doubled="${partial}{}"
+lines=$(printf '%s' "$doubled" | jq -s '.[0].data // {}' | jq -s 'length')
+if [ "$lines" = "1" ]; then
+ ok "jq -s collapses an accidentally doubled payload to one value"
+else
+ no "expected 1 value from a doubled payload, got $lines"
+fi
+
+# 5. and the good half of a partial payload must survive
+oid=$(printf '%s' "$partial" | jq -rs '.[0].data.r0.main.target.oid')
+[ "$oid" = "abc" ] &&
+ ok "readable repos still parse when a sibling alias is NOT_FOUND" ||
+ no "partial payload lost its readable data, got: $oid"
+
+# 6. ops-ci is syntactically valid
+bash -n "$ROOT/bin/ops-ci" 2>/dev/null &&
+ ok "ops-ci parses" ||
+ no "ops-ci has a syntax error"
+
+echo ""
+echo "Results: $pass passed, $fail failed"
+[ "$fail" -eq 0 ]