Repository navigation
refactor(api-v1): read a work item's request into a typed struct that writes its own schema (request-parser, Work Items) - #250
Merged
Conversation
… writes its own schema
The last of the four, after the States', the Labels' and the Projects'. `PatchedIssueRequest` (work_items.rs) is the struct the parser
reads into and the document's schema is derived from it; `IssueRequest` is the creation's marker, filled by `Creations` with
`PatchedIssueRequest::REQUIRED`. The two hand-written structs in openapi.rs (about 100 lines) and `request_sequence_id` are gone, and
so is the local `PRIORITIES` list: `PriorityValue` takes its choices from `Priority::ALL`, and writes the pin's `allOf` of the enum by
reference, as before.
What the work items added to the pattern, in values.rs and fields.rs:
- Lists: `KeyList` (the people and the labels), whose items are refused by their place (`{"0": [message]}`). `fields::read` now takes a
reader that fails with a message or with a whole answer (`Refusal`), so one reader serves both.
- Dates: `NullableDate` (keeps the text as it was sent, which the activity quotes), `NullableDateTime` (only whether it was given:
`deleted_at` is read, checked and not stored), `NullableWhole<MIN, MAX>` (the point), `SentText<MIN, MAX>` (the name, as sent and as kept).
- A key that is not the field's name. `type` is a Rust keyword, so the field is `type_` and `read_into!` says `type_ as "type"`
beside the schema's `rename = "type"`; a mis-spelt key fails the wire tests and the `type` rows of the new test.
- Three stages, as the Projects': `read` (every key, no database), `check_rows` (the people, the labels, the parent and the state, and
the keys that name a type or an estimate that no project has), then one `refuse_if_any`, then `validate()` (the dates, the
description as HTML, the assignees' roles). The fields the route reads and does not keep (`sequence_id`, `sort_order`,
`archived_at`, `is_draft`) are typed fields with an `allow(dead_code)` and the reason, as `is_triage` was.
Two numbers that were written in more than one place are one now, as the months were:
- `MAX_WORK_ITEM_POINT` (thrust-contracts): the struct's `NullableWhole<0, { .. }>`, the memory adapter's two checks (`work_items_point_valid`)
and the document. The Postgres column's `CHECK` (migration 0015) says the same number in SQL, which no constant reaches; the
constant's doc comment says so.
- `MAX_NAME_CHARS` (thrust-core): `validate_name` and its refusal text ("name must be 1..=255 characters") and the struct's
`SentText<1, { .. }>`. Changing it once moved all three and no conformance test failed; only `a_long_name`, which hard-codes 255 as a
wire test should, did.
A property with no test is pinned: `a_key_that_names_no_row_is_reported_beside_the_other_fields_that_are_wrong` (48 cases: six kinds
of row refusal by four wrong fields, on a creation and on a change, a list refused by the place of its item). With the first stage
refusing before the rows are checked exactly these 48 fail and the 92 other work item tests pass.
Wire proof: tools/oracle-v1/schema/openapi.thrust.json regenerates BYTE-IDENTICAL; 679 tests with the feature and 653 without
(+48, none removed); contracts, core and the memory adapter 2174; oracle-v1 and contract.sh as in the PR.
Controls, each one edit made and reverted: `point` to `NullableWhole<0, 13>` (the struct alone) makes the conformance test fail with
"the schema allows 13, the route refused: 500" and the document go stale, and the same edit to the constant moves the struct, the adapter
and the document together; the priority parser narrowed so that `none` is refused, with the document unchanged, fails 5 tests (the
two conformance tests, `each_priority_the_document_lists_is_taken_and_answered_and_no_other_is`, `order_by_follows_the_pins_allowlist`
and the document-side control); `priority` without `nullable = false` writes a `oneOf` around the pin's `allOf` and is caught from both
sides (conformance and the stale document); the name's bound in the struct alone fails `a_long_name`, the conformance test and the
stale document.
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.
The Work Items' request is now read into a typed struct, and the document's schema is derived from that struct: the last of the four resources of the request-parser series, after the States (#235), the Labels (#242) and the Projects (#247). With this, no request body of
/api/v1is described by a hand-written copy. Part of #58, which is closed; this PR does not reopen it.What changed
The same pattern as #235, #242 and #247, for
IssueRequestandPatchedIssueRequest:PatchedIssueRequest(work_items.rs) is the struct the parser reads into, and the document's schema is derived from it.IssueRequestis the creation's marker, filled byCreationswithPatchedIssueRequest::REQUIRED. The two hand-written structs inopenapi.rs(about 100 lines),request_sequence_idand the localPRIORITIESlist are removed:PriorityValuetakes its choices fromPriority::ALLand writes the pin'sallOfof the enum by reference, as before.KeyList(the people and the labels; an item that is wrong is filed by its place,{"0": [message]}),NullableDate,NullableDateTime,NullableWhole<MIN, MAX>(the point) andSentText<MIN, MAX>(the name as sent and as kept: the activity quotes both).fields::readnow takes a reader that fails with a message or with a whole answer (Refusal), so one function serves both.typeis a Rust keyword, so the field istype_and the macro saystype_ as "type"beside the schema'srename = "type".read(every key, no database),check_rows(the people, the labels, the parent, the state, and the keys that name a type or an estimate that no project has), then onerefuse_if_any, thenvalidate()(the dates, the description as HTML, the assignees' roles). The fields the route reads and does not keep (sequence_id,sort_order,archived_at,is_draft) are typed fields with anallow(dead_code)and the reason, asis_triagewas in the States.Two numbers that were written in more than one place
As the months were in #247, both found by changing a bound in the struct alone:
MAX_WORK_ITEM_POINT(thrust-contracts): the struct, the memory adapter's two checks (work_items_point_valid) and the document. The Postgres column'sCHECK(migration 0015) says the same number in SQL, which no constant reaches; the constant's doc comment says so.MAX_NAME_CHARS(thrust-core):validate_name, its refusal text (name must be 1..=255 characters) and the struct.Changing either constant once moves all of its places, and no conformance test fails; only the wire test that hard-codes the old number does, as a wire test should. These are the only changes outside
thrust-api-v1: two constants and the lines that read them.A property that had no test, now pinned
a_key_that_names_no_row_is_reported_beside_the_other_fields_that_are_wrong(48 cases): six kinds of row refusal (parent, state,created_by,type, an assignee, a label) by four wrong fields, on a creation and on a change. With the first stage refusing before the rows are checked, exactly these 48 fail and the 92 other work item tests pass.The wire is unchanged
tools/oracle-v1/schema/openapi.thrust.jsonregenerates byte-identical, socheck-openapi.shis unchanged (103 findings, none unaccepted).openapifeature and 653 without (the 48 new cases; none removed);thrust-contracts,thrust-coreandthrust-adapters-memorywith them: 2174 passed.scripts/oracle-v1.sh native-memory controlsis PASS on the tree replayed ontomainat 57f06d4 (gate 162 cases, 12 failures all accepted, 0 unaccepted, 0 stale; corpus 112 exchanges, including the 36 for work items, 15 accepted, 0 unaccepted, 0 stale; the controls pass) andscripts/contract.sh native-memory mainis 71 of 71 (nextest exit=0 passed=71 expected=71).maingained only CI scripts and the mutants harness (ci(gate): teach the planner and the gate about called workflows, and run the mutants in ci-scripts (stage 0.3) #245, fix(mutants): tell a row that did not run from one that survived #248) since the commit was built, andgit range-diffshows it unchanged.depsjob, fmt, clippy for the four crates touched with and without the feature, and for the Worker's wasm32 target.Controls (AGENTS.md rule 8), each one edit made and reverted
point: NullableWhole<0, 13>in the struct alone: the conformance test fails ("the schema allows 13, the route refused: 500") and the committed document goes stale. The same edit made once toMAX_WORK_ITEM_POINTmoves the struct, the adapter and the document together.noneis refused, the document unchanged: 5 tests fail (both conformance tests,each_priority_the_document_lists_is_taken_and_answered_and_no_other_is,order_by_follows_the_pins_allowlist, and the document-side control).prioritywithoutnullable = false: the document wraps the pin'sallOfin aoneOf, and it is caught from both sides (the conformance tests and the stale document).typekey mis-spelt in the parser:a_type_by_its_model_nameand my new test'styperows fail.a_long_name, the conformance test and the stale document.Not checked
values.rsgrows by a few more small types).docsjob (mdbook-mermaidis not installed on this machine; I rewrote G-25 item 6, and the edits add no page or link).What is left of the series
Nothing is hand-written on the request side now. G-25 item 6 says what the conformance test cannot see: three refusals the schema cannot say (
KNOWN), seven keys that name a row the world has none of (UNSAMPLED), and a field whose schema is any value (icon_prop), where a forgottennullable = falseis seen only by the stale document andoasdiff. The attribute#[schema(inline, nullable = false)]is now written on 60 fields (9 States, 7 Labels, 23 Projects, 21 Work Items); arequest!macro that writes it would remove the chance to forget it, and would be its own PR.Refs: #58
🤖 Generated with Claude Code