Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions infra/github-backup/tests/test_deploy_rollback_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]}}'
Expand All @@ -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")
Expand All @@ -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
Expand Down Expand Up @@ -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)
15 changes: 14 additions & 1 deletion infra/github-backup/worker/deploy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading