From 68d7f5660cca686d8da456234fff768c984b1052 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 09:50:31 -0600 Subject: [PATCH] fix(github-backup): deploy.mjs fails loudly when the post-provisioning live re-read is indeterminate (#6507) --- .../tests/test_deploy_rollback_version.py | 47 +++++++++++++++++-- infra/github-backup/worker/deploy.mjs | 15 +++++- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/infra/github-backup/tests/test_deploy_rollback_version.py b/infra/github-backup/tests/test_deploy_rollback_version.py index 972b4b1d76..6edd32b609 100644 --- a/infra/github-backup/tests/test_deploy_rollback_version.py +++ b/infra/github-backup/tests/test_deploy_rollback_version.py @@ -61,14 +61,29 @@ def check(name, ok): echo uploaded;; "deployments list") live=$(cat "$STUB_STATE/live" 2>/dev/null) - if [ -n "$live" ]; then + case " $* " in *" --json "*) json=1;; *) json=;; esac + if [ "$live" = "READFAIL" ] && [ -n "$json" ]; then + echo "stub: deployments list --json failed" >&2 + exit 1 + elif [ "$live" = "READFAIL" ]; then + echo "(human-readable deployments)" + elif [ "$live" = "SPLIT" ] && [ -z "$json" ]; then + echo "(human-readable deployments)" + elif [ "$live" = "SPLIT" ]; then + echo '[{"created_on":"2026-01-02T00:00:00Z","versions":[{"version_id":"a","percentage":50},{"version_id":"b","percentage":50}]}]' + elif [ "$live" = "GARBAGE" ] && [ -z "$json" ]; then + echo "(human-readable deployments)" + elif [ "$live" = "GARBAGE" ]; then + echo 'not json' + elif [ -n "$live" ]; then echo "[{\\"created_on\\":\\"2026-01-02T00:00:00Z\\",\\"versions\\":[{\\"version_id\\":\\"$live\\",\\"percentage\\":100}]}]" else echo '[]' fi;; "secret put") cat > /dev/null - echo "configured-final" > "$STUB_STATE/live";; + # STUB_AFTER_SECRET models what the post-provisioning re-read sees. + echo "${STUB_AFTER_SECRET-configured-final}" > "$STUB_STATE/live";; "versions view") if [ "$3" = "old-v9" ]; then echo '{"resources":{"bindings":[{"name":"DRAIN_BEARER","type":"secret_text"},{"name":"GITHUB_WEBHOOK_SECRET","type":"secret_text"}]}}' @@ -86,7 +101,7 @@ def check(name, ok): """ -def run_deploy(args): +def run_deploy(args, extra_env=None): root = tempfile.mkdtemp(prefix="ghb-deploy-rollback-test-") stub_bin = os.path.join(root, "bin") state = os.path.join(root, "state") @@ -108,6 +123,7 @@ def run_deploy(args): "CLOUDFLARE_ACCOUNT_ID": "stub-account", "STUB_LOG": log, "STUB_STATE": state, + **(extra_env or {}), } proc = subprocess.run( ["node", DEPLOY, *args], env=env, capture_output=True, text=True, timeout=60 @@ -183,5 +199,30 @@ def run_deploy(args): check("unconfigured: no versions deploy happened", "versions deploy" not in calls) check("unconfigured: no secret put attempted", "wrangler secret put" not in calls) +# 4. #6507: when the post-provisioning re-read cannot name a live +# version, the pre-secrets upload must NOT be advertised as live or as +# the rollback target; the run fails non-zero naming the problem. +for label, mode in ( + ("empty deployments list", ""), + ("deployments list read failure", "READFAIL"), + ("no version at 100% (split rollout)", "SPLIT"), + ("unparseable deployments output", "GARBAGE"), +): + proc, calls = run_deploy([], {"STUB_AFTER_SECRET": mode}) + out = proc.stdout + proc.stderr + check("indeterminate (%s): non-zero exit" % label, proc.returncode != 0) + check( + "indeterminate (%s): rollback target reported UNKNOWN" % label, + "UNKNOWN" in proc.stderr, + ) + check( + "indeterminate (%s): no live: line advertising the upload" % label, + not any(ln.startswith("live:") for ln in proc.stdout.splitlines()), + ) + check( + "indeterminate (%s): no mock secret value in output" % label, + "stub-bearer-value" not in out and "stub-webhook-value" not in out, + ) + print(f"\n{sum(1 for _, ok in PASS if ok)}/{len(PASS)} checks passed") sys.exit(0 if all(ok for _, ok in PASS) else 1) diff --git a/infra/github-backup/worker/deploy.mjs b/infra/github-backup/worker/deploy.mjs index bb06a2cf37..ca47f4687e 100644 --- a/infra/github-backup/worker/deploy.mjs +++ b/infra/github-backup/worker/deploy.mjs @@ -178,8 +178,21 @@ reportLive(); // it and has no secret bindings. The version to advertise — and the // only sound rollback target — is the final configured live version, // re-read after provisioning, not the pre-secrets upload. +// If the re-read cannot name a live version (read/parse failure, empty +// deployments list, no version at 100%), the uploaded version must NOT +// be advertised in its place (#6507): fail loudly instead. const configuredLive = liveVersionIds(); -const liveId = configuredLive.join(", ") || version.id; +if (configuredLive.length === 0) { + console.error( + `error: could not determine the configured live version after provisioning secrets ` + + `(deployments list was empty, unreadable, or had no version at 100%). ` + + `Rollback target UNKNOWN: do NOT use the uploaded version ${version.id} (${tag}); it predates ` + + `the secret bindings (#3475). Check \`wrangler deployments list --name ${WORKER}\` and ` + + `use the configured version it shows.` + ); + process.exit(1); +} +const liveId = configuredLive.join(", "); console.log(`live: ${WORKER_URL} at version ${liveId} (${tag})`); if (liveId !== version.id) { console.log(