carlos / platform Public

scripts: region gate counts version headers apart from their values; a duplicate fails (review fix 2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev d6b1b839f1b76f754456f1689f28b8c31ed86478 parent 5f20390
2 files changed, +21 −3
  • region_service_gate_test.go +15 −0
  • scripts/region-service-gate.sh +6 −3
diff --git a/region_service_gate_test.go b/region_service_gate_test.go
index 1a33241b8..0e23b6473 100644
--- a/region_service_gate_test.go
+++ b/region_service_gate_test.go
@@ -81,6 +81,21 @@ func TestRegionServiceGateJudgesTheFinalResponse(t *testing.T) {
}); err == nil || !strings.Contains(out, "FAIL") {
t.Errorf("a version only on the 103 passed: %s", out)
}
+ // Two version headers in the final response: an empty one and the right
+ // one. A duplicate fails whatever either value is.
+ if out, err := gate(func(w http.ResponseWriter, r *http.Request) {
+ w.Header()["X-Carlos-Version"] = []string{"", version}
+ w.WriteHeader(http.StatusOK)
+ }); err == nil || !strings.Contains(out, "FAIL") {
+ t.Errorf("an empty and a correct version header on the final 200 passed: %s", out)
+ }
+ // The same duplicate with identical values is still a duplicate.
+ if out, err := gate(func(w http.ResponseWriter, r *http.Request) {
+ w.Header()["X-Carlos-Version"] = []string{version, version}
+ w.WriteHeader(http.StatusOK)
+ }); err == nil || !strings.Contains(out, "FAIL") {
+ t.Errorf("two identical version headers on the final 200 passed: %s", out)
+ }
// Both blocks carry the version: the final one is right, so it passes.
if out, err := gate(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Carlos-Version", version)
diff --git a/scripts/region-service-gate.sh b/scripts/region-service-gate.sh
index a339f723f..5385b0729 100755
--- a/scripts/region-service-gate.sh
+++ b/scripts/region-service-gate.sh
@@ -22,7 +22,7 @@ trap 'rm -f "$hdr"' EXIT
fail=0
check() { # <label> <expected-ip or ""> [curl args...]
local label="$1" eip="$2"; shift 2
- local out ip status version
+ local out res count ip status version
# -q must be first: it stops curl reading ~/.curlrc. $insecure is
# unquoted on purpose so that empty expands to nothing (bash 3.2 safe).
# The status is curl's own final %{http_code}, never a header that happens
@@ -35,9 +35,12 @@ check() { # <label> <expected-ip or ""> [curl args...]
if [ -n "$eip" ] && [ "$ip" != "$eip" ]; then
echo "FAIL $label: connected to $ip, not $eip"; fail=1; return
fi
- version="$(awk -F': *' '/^HTTP\/[0-9.]+ [0-9][0-9][0-9]/ {v=""; next} tolower($1)=="x-carlos-version" {gsub(/\r/,"",$2); v = (v=="" ? $2 : v "," $2)} END {print v}' "$hdr")"
+ # n counts the version headers in the final block, apart from their values,
+ # so an empty value still counts. More than one is a failure.
+ res="$(awk -F': *' '/^HTTP\/[0-9.]+ [0-9][0-9][0-9]/ {n=0; v=""; next} tolower($1)=="x-carlos-version" {gsub(/\r/,"",$2); v = (n ? v "," $2 : $2); n++} END {print n+0, v}' "$hdr")"
+ count="${res%% *}"; version="${res#* }"
if [[ "$status" != 2* ]]; then echo "FAIL $label: status $status"; fail=1; return; fi
- if [ "$version" != "$want" ]; then echo "FAIL $label: X-Carlos-Version '$version', want '$want'"; fail=1; return; fi
+ if [ "$count" != 1 ] || [ "$version" != "$want" ]; then echo "FAIL $label: X-Carlos-Version '$version', want '$want'"; fail=1; return; fi
echo "ok $label: $status $version"
}
[ "${GATE_SKIP_PUBLIC:-}" = 1 ] || check "public DNS" ""