Pin the 401 → refresh → retry path in PPClient._request#4
Merged
Conversation
The retry only fires when a token expires mid-session, so it's exercised
by chance rather than by design. When it regresses, the failure mode is
a cascade: every PP request returns 401, no awards render, callers see
"no award found" for the entire session.
Three tests, all driven by httpx.MockTransport + a monkeypatched
refresh_tokens:
1. happy path — 401 → refresh fires once → retry uses the new
access token → 200 surfaces to caller
2. non-401 — refresh must NOT fire; response passes through
3. double-401 — retry-once semantics: refresh runs once, no third
request, second 401 surfaces (we don't loop forever)
Closes work-rdus.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds three tests against
PPClient._request's auth-retry path, driven byhttpx.MockTransport+ a monkeypatchedrefresh_tokens. The retry only fires when a token expires mid-session, so it's exercised by chance rather than by design — when it regresses, the failure mode is a cascade (every PP request returns 401, no awards render, callers see "no award found" for the whole session).Coverage:
Authorizationheader carries the refreshed token, not the stale one.refresh_tokensmust not fire.refresh_tokensruns once, only two requests go out (no third), the second 401 surfaces. Guards against an infinite-loop regression.Pure unit tests, no live API.
Closes
work-rdus.Test plan
make check(ruff lint + format + basedpyright strict + pytest) — all greenMockTransport+monkeypatchonly — no network