Repository navigation
test(api-v1): hold each request schema to its parser with bodies the schema generates (request-parser step 0) - #228
Merged
Conversation
…ceField does
A project's `timezone` was read as a text (`char_field`), which trims, and then looked up. So " UTC" and "UTC " were taken and
saved, a blank answered "This field may not be blank.", and a bool or a list answered "Not a valid string.". The pin's field is a
model field with `choices`, which ModelSerializer builds as a `ChoiceField`: it does not trim, and it quotes Python's `str()` of
whatever it was given ("\" UTC\" is not a valid choice.", "\"\" is ...", "\"True\" is ...", "\"['UTC']\" is ...", and
"This field may not be null." for null).
Measured on DRF 3.15.2 over Django 4.2.30 (the pin's versions) for the same model field; not through the pin's HTTP.
`choice_by` is `choice_field` over a set that is not a slice (the timezones are a sorted table asked by name), and `choice_field`
now goes through it, so the rule is written once. Four regression cases pin the drift; two more (wrong case, null) were already
right and are plain cases.
Found by the request-conformance test of the next commit, from the document's own enum: it sent each listed zone and a padded
variant of three of them.
Refs: #58
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
… and send them to the router The document describes a request body in eight hand-written types, and the routes read it with hand parsers. Nothing compared the two: oasdiff compares the document with the pin, not with the parser, so a parser could change a bound and the document keep the old one. This is step 0 of the request-parser series. `tests/request_conformance.rs` reads each request schema of the document and generates the bodies its keywords speak of, then sends each to the router in a world of its own: - allowed, so accepted: each enum value, a string at minLength and maxLength in four alphabets (a length counts characters, not bytes), an integer at minimum and maximum, a `null` where the type has one, a row that is there for a key that names one; - forbidden, so refused under that key and no other: one past each bound, the case and spacing variants of an enum value, a `null` where the type has none, a string that is no uuid or date, a type DRF does not coerce, a key a creation requires left out. It cannot be written to agree with the parser, because the document is its only input. What it cannot say is stated and held: three refusals the schema cannot express (the triage group, an empty `description_html`, PQ-404's `deleted_at`) are entries of `KNOWN`, each with the answer it must still give, and an entry no probe meets is stale; seven keys that name a row the world lacks are `UNSAMPLED`, and a key that is in neither fails the test. It does not see a route that takes a value the schema leaves out of an enum: those lists are the pin's, and check-openapi.sh compares them. Its first run found a drift (the previous commit): a padded timezone was taken. Controls (AGENTS.md rule 8): the document broken in memory 17 ways, one keyword at a time, each reported while the unbroken key is quiet; and four bounds of the parsers changed with the document left alone (the state name's 255 to 256, the months' 12 to 13, the point's minimum 0 to 1, `none` dropped from the priorities), each failing the schema it belongs to under its own key, in all four alphabets, and reverted. The new test is a step of the `hermetic` job with the `openapi` feature, beside the existing one. Refs: #58 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Merged
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.
Step 0 of the request-parser series for
/api/v1: a test that holds each request schema of the OpenAPI document to the parser that reads the request, and the one drift it found, fixed. Part of #58, which is closed; this PR does not reopen it.Why
The document describes a request body in eight hand-written types (
openapi.rs), and the routes read the body with hand parsers (fields.rs). Nothing compared the two.oasdiffcompares the document with the pin, not with the parser, so a parser could change a bound and the document go on saying the old one. The series' later steps replace the hand copies with types the parsers fill; this step is the safety net they will be built under, and it works today with no refactor.What the test does
crates/api/v1/tests/request_conformance.rsreads each request schema of the document, generates the bodies its own keywords speak of, and sends each to the real router in a world of its own (a few thousand probes in all, about half a second per schema):minLengthand atmaxLengthin four alphabets (a length counts characters, not bytes: 1, 2, 3 and 4 bytes in UTF-8); an integer atminimumandmaximum; anullwhere the type has one; a row that is there, for a key that names one.nullwhere the type has none; a string that is no uuid or date; a type DRF does not coerce; a key a creation requires, left out.The document is the only input, so the probes cannot be written to agree with a parser.
What it found
Four kinds of disagreement on its first run.
timezonewas read as a text and trimmed, so" UTC"and"UTC "were taken and saved, a blank answered "may not be blank", and a bool or a list answered "Not a valid string". The pin's field is a model field withchoices, whichModelSerializerbuilds as aChoiceField: it does not trim and quotes Python'sstr()of the value. Measured on DRF 3.15.2 over Django 4.2.30, the pin's versions, for the same model field. Not measured through the pin's HTTP; a corpus recording of a padded timezone would settle that if you want one.choice_byischoice_fieldover a set that is not a slice, andchoice_fieldnow goes through it, so the rule is written once.KNOWNwith the answer each must still give (an entry no probe meets is stale): thetriagegroup of a state (StateSerializer.validate), an emptydescription_html(the pin'shtml.fromstring("")), and adeleted_aton a creation (PQ-404, a reproduced 500).UNSAMPLED: onlynulland what the schema forbids can be shown for them. A key in neither list fails the test.What it does not see
scripts/check-openapi.shcompares them.validate(), the order of the checks.Controls (AGENTS.md rule 8)
nulladded or removed, a choice more, a key made required or not, a format dropped, a type changed): each is reported, while the unbroken key is quiet.nonedropped from the priorities): each failed the schema it belongs to, under its own key, in all four alphabets. Reverted;git diffshowed only the intended files.null) were already right and are plain cases, notregression_.KNOWNabsorbs only the disagreement it names: another schema, key, value or answer, or a value the schema forbids, is not explained by an entry.Wiring and docs
OpenAPI tests (nextest, openapi feature)inhermeticnow selectsbinary(openapi) | binary(request_conformance); nextest lists both./api/v1row ofby-change.mdsay what the test ties and what it cannot.Checked
On the rebased tree (
mainat 9804f68):cargo nextest run -p thrust-api-v1 --features openapi --locked605 of 605;cargo fmt --all --check;clippy -p thrust-api-v1 --all-targets -- -D warningswith and without the feature;cargo metadata --locked; all 17 steps of thedepsjob, run locally (includingcheck-openapi.shwith Docker).Not checked here: the book build of the
docsjob (mdbook-mermaidis not installed on this machine; the edits add no page or link), and the whole CI run.Next
The States PR: a typed request struct that the parser fills and the document derives from, as the go/no-go for bounded newtypes. It goes under this test.
Refs: #58
🤖 Generated with Claude Code