fix(885): two dependencies with opposite failure directions, and a token leg that got zero retries

The header comment and the record's `rule:` said the registry reads and the
commit-status reads "both depend on `timothy/ersatztv` and its `ersatztv-ci`
package staying PUBLIC; making either private fails those jobs loudly at image
pull, never silently". Wrong in both clauses for the repo half, and this branch
has already been sent back twice for exactly this shape of mechanism claim.
Measured 2026-09-05: the `ersatztv-ci` package is linked to no repository (every
version reports `"repository": null`), so the repo's visibility does not gate the
anonymous pull token at all; and the only thing it does gate — the combined-status
GET — fails in the opposite direction, because `ci-detect-already-validated.sh`
answers a failed `curl -sf` with `emit false; exit 0`. That job stays GREEN and
the #420 cross-run skip silently stops firing. So the two dependencies are now
stated apart, each with its own failure direction, in `docker-build.yml`, in the
preflight's header, in the record and in the `ci-cd.md` outcome table; the
preflight's own 401/403 messages stop sending an operator to the repo's
visibility when it is the package's.

`token_leg_done` was set once per RUN, before the attempt, so a token endpoint
that could not be reached failed the preflight with no retry while an identical
blip on the manifest read got three. The stated reason — "a registry genuinely
refusing anonymous reads is asked once rather than once per pin" — is a per-pin
argument that never covered the per-attempt axis. It is now sorted by what the
endpoint SAID rather than by which leg it happened on: an answer (no token in the
body, a challenge naming no realm, no challenge at all) settles the question and
is asked once per run; an endpoint that could not be reached, or that answered
5xx, settled nothing and is retried on the same `ETV_CI_ATTEMPTS` budget as the
manifest read, because a red here denies a merge (the consent hook reads the
COMBINED status, #598) and the two legs of one read must not have opposite flake
tolerances. The token-leg message now reports the attempts it actually made.

Driven against the SHIPPED predecessor rather than a hand-written mutant: the
three new behavioural assertions are red on it (1 token call where 3 are
required, and a blip shorter than the budget failing the run), while the two that
pin the property the retry must not cost pass on both.

Refs #885

Decisions-Edit: yes
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015QqCpYFsKgnAnx6jVwrKiV
This commit is contained in:
2026-09-05 15:15:43 +02:00
co-authored by Claude Fable 5.1
parent 8885fdd9d2
commit 23cef5c9d1
6 changed files with 175 additions and 33 deletions
@@ -70,8 +70,18 @@ with (state / "calls").open("a") as fh:
# --- the token endpoint --------------------------------------------------------------------
if "/token" in url:
behaviour = codes.get("TOKEN", "issue")
if behaviour == "blip":
# Unreachable on the FIRST ask and healthy afterwards -- a token-endpoint outage shorter
# than the retry budget, which is the shape a retry exists to absorb.
marker = state / "token-blip"
behaviour = "issue" if marker.exists() else "unreachable"
marker.write_text("1")
if behaviour == "unreachable":
sys.exit(7)
if behaviour == "server-error":
# It ANSWERS, but with nothing a client can use -- the other half of "told us nothing".
print("<html>502 Bad Gateway</html>\n502", end="")
sys.exit(0)
if behaviour == "empty":
print('{"expires_in": 300}\n200', end="")
else:
@@ -380,6 +390,67 @@ def test_a_token_endpoint_that_yields_NO_TOKEN_refuses(preflight, behaviour):
assert preflight.authenticated_manifest_calls() == [], "no read can have carried a token"
@pytest.mark.parametrize("behaviour", ["unreachable", "server-error"])
def test_a_token_endpoint_that_SAID_NOTHING_is_retried_like_any_other_unknown(preflight, behaviour):
"""The two legs of one read must not have opposite flake tolerances.
A token endpoint that cannot be reached (or answers 5xx) has told the run nothing — it is the
same transport blip a flaky manifest read gets three tries to survive. Measured 2026-09-05 on
the predecessor of this commit, it got ZERO: `token_leg_done` was set once per RUN, the failed
leg left the first read's `401` standing, and `401` was in the retry loop's break list, so the
job reddened after one token call. A red here denies a merge (the consent hook reads the
COMBINED status, ersatztv#598), so that was a one-second outage blocking a merge until someone
re-ran the job.
"""
preflight.env["ETV_CI_ATTEMPTS"] = "3"
preflight.set_codes({"*": "200", "TOKEN": behaviour})
result = preflight.run()
assert result.returncode != 0, "a run that never obtained a token must not report success"
assert len(preflight.token_calls()) == 3, (
f"expected the token leg to be retried on the attempt budget, got {preflight.calls()}"
)
assert "could NOT OBTAIN an anonymous pull token" in result.stderr, result.stderr
assert "after 3 token-leg attempt(s)" in result.stderr, (
f"the message must report what the run actually did, not what it might have. stderr={result.stderr}"
)
@pytest.mark.parametrize("codes", [{"TOKEN": "empty"}, {"CHALLENGE": "none", "REFUSAL": "401"}])
def test_a_token_endpoint_that_ANSWERED_is_asked_ONCE(preflight, codes):
"""The other direction, and the property the retry above must not cost.
An endpoint that answered and named no token — or a `401` carrying no challenge to follow — has
said something, and asking again cannot change it. That is a registry genuinely refusing
anonymous reads, and it is asked once per RUN.
"""
preflight.env["ETV_CI_ATTEMPTS"] = "3"
preflight.set_codes({"*": "200", **codes})
result = preflight.run()
assert result.returncode != 0
assert len(preflight.token_calls()) <= 1, (
f"a settled token leg must not be re-asked, got {preflight.calls()}"
)
assert len(preflight.manifest_calls()) == 1, (
f"nor may the manifest read be retried behind it, got {preflight.calls()}"
)
assert "could NOT OBTAIN an anonymous pull token" in result.stderr, result.stderr
def test_a_token_endpoint_BLIP_shorter_than_the_budget_RECOVERS(preflight):
"""Retrying is only worth anything if the run can still succeed.
The endpoint is unreachable on the first ask and healthy on the second, so the whole point is
the exit code: the pin resolves, with a bearer that reached the registry.
"""
preflight.env["ETV_CI_ATTEMPTS"] = "3"
preflight.set_codes({"*": "200", "TOKEN": "blip"})
result = preflight.run()
assert result.returncode == 0, f"stdout={result.stdout}\nstderr={result.stderr}"
assert "32747a0 resolves" in result.stdout
assert len(preflight.token_calls()) == 2, f"expected one failed ask and one good one, got {preflight.calls()}"
assert preflight.authenticated_manifest_calls(), "the recovered token never reached the registry"
def test_the_TOKEN_LEG_is_performed_ONCE_across_every_pin(preflight):
"""The token is state that must survive the pin loop.