Skip to content

test(api-v1): hold each request schema to its parser with bodies the schema generates (request-parser step 0) - #228

Merged
aRustyDev merged 2 commits into
mainfrom
test/api-v1-request-conformance
Nov 16, 2026
Merged

aRustyDev merged 2 commits into
mainfrom
test/api-v1-request-conformance

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

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. oasdiff compares 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.rs reads 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):

  • Allowed, so accepted: each enum value; a string at minLength and at maxLength in four alphabets (a length counts characters, not bytes: 1, 2, 3 and 4 bytes in UTF-8); 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.

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.

  1. A real drift, fixed here (first commit). A project's timezone was 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 with choices, which ModelSerializer builds as a ChoiceField: it does not trim and quotes Python's str() 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_by is choice_field over a set that is not a slice, and choice_field now goes through it, so the rule is written once.
  2. Three refusals the schema cannot say, each already pinned elsewhere, listed in KNOWN with the answer each must still give (an entry no probe meets is stale): the triage group of a state (StateSerializer.validate), an empty description_html (the pin's html.fromstring("")), and a deleted_at on a creation (PQ-404, a reproduced 500).
  3. Seven keys that name a row the world does not have (estimates, estimate points, work item types), in UNSAMPLED: only null and what the schema forbids can be shown for them. A key in neither list fails the test.

What it does not see

  • A route that takes a value the schema leaves out of an enum. Those lists are the pin's, and scripts/check-openapi.sh compares them.
  • Anything the schema cannot express: a row that must exist, validate(), the order of the checks.

Controls (AGENTS.md rule 8)

  • The document broken in memory 17 ways, one keyword at a time (a bound one more or less, a minimum, a null added 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.
  • 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 failed the schema it belongs to, under its own key, in all four alphabets. Reverted; git diff showed only the intended files.
  • The fix: with the old trimming read put back, the two project schemas' tests and four of the six new regression cases fail. The other two cases (wrong case, null) were already right and are plain cases, not regression_.
  • KNOWN absorbs 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

  • The CI step OpenAPI tests (nextest, openapi feature) in hermetic now selects binary(openapi) | binary(request_conformance); nextest lists both.
  • G-25 item (6), X14 and the /api/v1 row of by-change.md say what the test ties and what it cannot.

Checked

On the rebased tree (main at 9804f68): cargo nextest run -p thrust-api-v1 --features openapi --locked 605 of 605; cargo fmt --all --check; clippy -p thrust-api-v1 --all-targets -- -D warnings with and without the feature; cargo metadata --locked; all 17 steps of the deps job, run locally (including check-openapi.sh with Docker).

Not checked here: the book build of the docs job (mdbook-mermaid is 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

aRustyDev and others added 2 commits November 16, 2026 15:39
…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]>
@aRustyDev
aRustyDev merged commit 5ab7701 into main Nov 16, 2026
72 of 74 checks passed
@aRustyDev
aRustyDev deleted the test/api-v1-request-conformance branch November 16, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant