Conformance: pin walk page 0 and redirect behaviour; 3xx pages raise in Python and Ruby
Follow-up to #1139. This PR adds conformance runner, schema and SPEC §19 work that pins two things #1139 changed in every walk. It also fixes a bug in two SDKs that the second case exposed.
Assertions and token
requestQueryAbsentchecks that the query parameter named bypathis not on the recorded request atindex. The index defaults to 0, counts from the end when negative, and fails when out of range. Apage=with an empty value counts as present.foreignRequestCountcounts how many requests reached the runner's second mock origin, either exactly (expected) or at most (max).- The header token
{{foreignOrigin}}is allowed anywhere in a header value, such as aLinkor aLocation. Each runner's second origin answers from the samemockResponsesqueue, in the same order, and only adds a count. So a request that a broken SDK or a redirect-following transport sends there is answered and counted, never a dial error that would pass. - Any other
{{left in a header value, closed or not, is an error. That covers a whole value, an embedded token and an unclosed one. A typo such as<{{foreignOrign}}/…>would otherwise resolve as a same-origin path, and a case counting foreign requests would pass without ever naming the foreign origin. The fixture schema rejects such a value too. - Every runner checks its mock headers before it dispatches the case, and fails the case as a fixture error. If the check ran while serving, the resolver's error would reach the SDK as a transport error, which an
errorRaisedcase accepts. TypeScript, Python, Ruby, Kotlin and Swift have tests for this. Go and Rust have none.
All seven runners implement both assertions and the token, with unit tests beside their existing assertion tests. The SPEC §19 table, its prose lists and the fixture catalog are updated.
Cases (conformance/tests/pagination.json)
- A walk given page 0 / page -1 leaves page out of its first request. Every runner's ListProjects dispatch now passes 0 and negatives to the SDK.
- Go's runner held the page as an
intand passed it only when non-zero, so the page 0 case passed without reaching the SDK. It is a*intnow. - Proof: with the Go SDK mutated to send page 0, the old runner passes every case, and the new one fails the page 0 case with
Expected query parameter "page" absent on request index 0, got ["0"]. - Rust's fixture field
pagewas au64, so-1made all ofpagination.jsonfail to load there. It is ani64now. - The schema's
configOverrides.pagedescription now holds only the ListProjects walk to passing every value through. The page reads (ListProjectsPage, GetPersonProgressPage, SearchPage) pass only a positive one.
- Go's runner held the page as an
- A walk refuses a foreign next link served after a same-origin redirect. Page 2 answers a same-origin 302, and the page it redirects to links to
{{foreignOrigin}}.- The case asserts
foreignRequestCount: 0,errorRaised, and the path of request 1. - The 302 carries no Link. With one, a walk that decoded the 302 as a page would follow it on to the foreign Link and refuse that, passing the case for the wrong reason. Python with its 3xx guard reverted passed the case with the Link and fails it without.
errorRaisedstops the count from passing without testing anything: a walk that stopped quietly would reach no foreign origin either.- The request-1 path shows that the walk got past page 1.
- A following transport (Go, TypeScript, Kotlin) refuses the Link. A non-following one (Python, Ruby, Rust, Swift's scripted transport) fails on the 302.
- The case asserts
- A walk refuses a next link on the origin a redirect landed on. Page 2 answers a 302 to
{{foreignOrigin}}, which answers with a relative Link that resolves there.- The case asserts
foreignRequestCountat most 1,errorRaised, and the path of request 1. - Checking the Link against the URL that answered would follow it, a second foreign hit.
- Resolving it against the URL requested would land home and finish without an error.
- Its 302 carries a JSON body and a Link, so an SDK that decoded the redirect as a page would continue and finish without an error.
- The case asserts
No case is skipped in any runner.
Swift and redirects
Swift's conformance runner uses a scripted transport that hands a 3xx back rather than following it. Production's URLSessionTransport follows. So in Swift both redirect cases pin only the 3xx-fails path. The origin check after a followed redirect is pinned by a unit test instead, swift/Tests/BasecampTests/PageReadTests.swift testAWalkRefusesAForeignNextAfterASameOriginRedirect, beside the existing cross-origin one.
I chose a unit test over making ScriptedTransport follow redirects for two reasons. It is the smaller change. And a follow would change what data(for:) hands back on download fixtures whose second hop is a 302 that the SDK must see.
Proof: with isSameOrigin(nextURL, requestURL) mutated to compare nextURL with itself, the new test fails. With the mutation reverted, PageReadTests passes 33 of 33. ScriptedTransport now documents that it doesn't follow redirects.
SDK behaviour change: a 3xx on a page now raises (Python, Ruby)
Python's httpx client and Ruby's Faraday follow no redirect, and they raise only from 400 up, so a 302 reached the page parser. An empty body failed as a parse error by luck. A JSON body with a Link was read as a page, and the walk carried on.
The shared page fetch (Python _get_page, sync and async; Ruby parse_page) now raises the status error (ApiError, http_status 302) for any non-2xx page. That holds for the first page and later ones, in walks and in page reads. Rust already raised, and Go, TypeScript and Kotlin follow redirects.
Proof: before the fix, the second redirect case fails in Python and Ruby with "Expected the call to fail, but it succeeded". The new unit tests fail with the fix reverted.
The cases bite (Go)
Each mutation below was applied to the Go SDK and the conformance run observed. Then the mutation was reverted.
- Check the next link against the URL that answered. Only the cross-origin redirect case fails, with
Expected at most 1 requests to the foreign origin, got 2. - Drop the origin check. Both redirect cases fail.
- Resolve the next link against the URL requested. The cross-origin redirect case fails.
- Send a non-positive page. The page 0 case fails, and so does the page -1 case.
Control-sibling gate
check_kill_case_controls.py normally wants an errorRaised case's first body to differ from a decoded control's in exactly one field. It now also accepts one other shape: a decoded first body equal to a decoded control's. It accepts that shape only from a case that serves more than one response, and that pins a later request with requestPath at index 1 or more. Every runner fails such an assertion when no such request was made.
A second queued response alone no longer qualifies, for two reasons. A decoy response is never consumed. And an error raised on the first response would satisfy errorRaised with nothing under test.
The two redirect cases are the only ones the shape admits. The self-test now pins all of the following, and the new negatives fail under the gate as it was before:
- Identity passes, for an object body and for an array body.
- An identical body fails when there is no pin, when the pin is on request 0 or -1, when the pin's index is a boolean, or when the pin is another assertion type.
- An identical body fails on a kill that serves a single response.
- An identical body fails when the control's response is not decoded, or when the kill's own is not.
- An array body fails with a changed value, an added or dropped element, an added field, or reordered elements.
Declined from review
These are from the outside review of this branch:
- Redirect cases can fail on page 2 for another reason. A following SDK that errors on the landing page some other way, such as a decode failure, still satisfies
errorRaised. Pinning the landing request would take request index 2, which non-following transports never send, so the same case could not run in all seven runners.errorRaisedis deliberately mechanism-agnostic. Each SDK's own unit tests pin the post-redirect origin check, and the landing page's body has the same shape as the controls' decoded pages, so a model drift fails there first. - Authorization on the cross-origin redirect. Asserting it absent on the foreign request has the same index problem: in a non-following runner, the last request is the 302 to the API origin, which rightly carries it. That belongs in each transport's own redirect tests, not in this case.
- Python and Ruby request hooks see the 302 without an error.
on_request_endreports the exchange that happened, a 302 response. The page reader's refusal is an operation-level decision, like the Link origin refusal, which no SDK reports as a request error. The caller andon_operation_endboth get theApiError. - Rust's fixed foreign origin
http://127.0.0.1:9could equal abaseUrloverride. No fixture sets that base URL, and the port is the discard port, which nothing here serves. - Parity in how
foreignRequestCounthandles a missing or non-integermax. The schema requiresexpectedormaxto be a non-negative integer, and CI validates every fixture against it. - A live foreign-origin wiring test is missing in some runners. Python, TypeScript and Rust have one. The others count through the same queue code that every case runs.
- Later decoded pages in the redirect cases aren't controlled by the gate.
errorRaisedswitches off stop-on-mismatch for the whole case, so a typo in a landing page's body would pass it. The gate compares first bodies only, and adding a rule for each later response would be one more selector on an instrument that can't see which error fired. The landing pages share the controls' shape, and the cases' descriptions say what each response is for. - The runners accept
{{{foreignOrigin}}, and Python's whole-value match allows a trailing newline. The schema rejects both, and CI validates every fixture against it. The runner check is a backstop, and I've stopped extending it. - A 3xx with a body over the size limit raises the size error rather than the status error (Python, Ruby). The read still fails, and no case serves such a body.
foreignRequestCountwithexpected: 0.0. The schema reads that as an integer, and runners disagree on it. No fixture writes a count that way.
Open for a decision
- Python and Ruby treat a 3xx as success outside page reads. Their transports follow no redirect and raise only from 400 up. So a non-paginated read decodes, or fails to parse, a redirect's body, and a void mutation answered with a 302 returns as if it succeeded. Go, TypeScript, Swift, Kotlin and Rust raise. This PR fixes only the page fetch. Rejecting non-2xx in
_single_request/single_request(outside downloads) would cover every operation and also giveon_request_endthe error. That changes behaviour for every operation, so it is a scope call for a separate PR.
Release
There is no spec or openapi.json change, so this doesn't open a release window. MIGRATING's Unreleased section notes the Python and Ruby change. I've left the release label for the person landing this to choose: the change is a bug fix, but it does change behaviour.
CI
CI on this PR runs against page-reads as merged in at its current head. The only remaining failures are dependency advisory checks that page-reads fails too: the Actions audit, Bundler Audit, npm audit and Trivy. None of them comes from this change.
Base is page-reads (#1139). Retarget to main once that merges.
Summary by cubic
Follow-up to #1139 that pins two walk behaviors across all seven conformance runners, and pins that Python and Ruby page fetches refuse a 3xx.
Conformance pins
- Adds
requestQueryAbsentandforeignRequestCountassertions and a{{foreignOrigin}}header token in every runner; the second mock origin answers from the same response queue. - Runners forward page 0 and negative pages to the SDK instead of filtering them, so the page-0 case can't pass vacuously. Go's page override is now a pointer and Rust's is signed to carry those values.
- Adds two redirect cases: a same-origin 302 whose redirected page links to the foreign origin (0 foreign requests), and a 302 to the foreign origin whose relative Link stays there (an error, at most 1 foreign request).
- The control-sibling gate accepts an
errorRaisedcase whose first body is identical to a decoded control's, only when the case pins a later request's path; comparison is on JSON values, not text. - Swift's scripted transport hands 3xx back, so there the redirect cases pin only the status path; a unit test pins the walk's origin check after a followed redirect.
- Unrecognised header tokens, closed or not, are rejected before dispatch rather than served, so a typo'd
{{foreignOrigin}}can't resolve as a same-origin path.
SDK pins
- Python and Ruby tests pin that a non-2xx page raises the status error, keeping request id and Retry-After, instead of parsing a 302's body and Link as a page; main's executor already delivers that raising.
- Python reads an error body cut mid-character by the size cap as not JSON, so the
ApiErrorwith its status and request id still builds.
No openapi.json change, so no release window; MIGRATING notes the Python and Ruby behaviour change. The branch now tracks main, with #1139 already merged in.