Skip to content

feat(plane-types): one plane_500() for the pin's three 500 texts - #126

Merged
aRustyDev merged 1 commit into
mainfrom
feat/plane-500-helper
Nov 11, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
feat/plane-500-helper

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

What

First of three changes for #51. It adds the one helper and moves /api/v1 onto it. The internal API (thrust-compat-plane) and the acceptance-list work are the next two and are not in here. No wire change.

  • New crate thrust-plane-types: Plane500 { SomethingWentWrong, UnexpectedError, InternalServerError } and plane_500(kind, cause) -> Response<Body>. It sets 500, writes the pin's exact body for the kind and attaches the cause as InternalErrorDetail, so the root logs it and the body never carries it.
  • /api/v1 answers every 500 through it. V1Error::Plane500 now holds a kind and a required cause (V1Error::internal, V1Error::unexpected). The array body to project create was the one hand-written 500; it is now UnexpectedError. Each of the nine deliberate 500s names its rule as the cause (per_page <= 0 ... (PQ-402) and so on), which the log gains.
  • scripts/check-plane-500.sh (CI job deps, with --self-test) refuses INTERNAL_SERVER_ERROR, from_u16(500), try_from(500) and .status(500) in the src of thrust-api-v1 and thrust-compat-plane, and refuses to pass on a directory with no .rs file.
  • The crate is in CLEAN_CRATES; crates.md and standards.md name it and the guard. The crate counts in crates.md were already stale and are corrected.

Evidence

Check Result
cargo nextest run -p thrust-api-v1 -p thrust-plane-types 554 passed (9 new). The v1 suites assert the same statuses and bodies as before.
cargo clippy --workspace --all-targets --locked -- -D warnings, cargo fmt --all --check clean
scripts/check-deps.sh exit 0, no FORBIDDEN
scripts/check-plane-500.sh clean on the two crates. --self-test: 12 cases, each pattern refused, an empty or missing directory is exit 2. Run on the previous v1 error.rs and projects.rs it reports error.rs:102 and projects.rs:377 and exits 1.
Planted bugs, one at a time, in lib.rs 8 of 8 killed, baseline green, source restored byte-for-byte: a word dropped from the base text, one byte changed in each of the other two texts, two kinds' texts swapped, the cause not attached, status 502, cause written into the body, cause put in a header. A kill needed nextest exit 100 and a FAIL line, so a compile error cannot pass for one.
cargo mutants -f crates/thrust-plane-types/src/lib.rs 6 mutants: 4 caught, 2 unviable, 0 missed. It only produces return-value mutants, so it does not cover the text, mapping, extension or body cases above; the planted bugs do.

Tests in the new crate: parity_plane_500_bodies (status and body bytes per kind against a fixture), a check that the base text's fixture is the oracle's own corpus/assets.json#workspace-asset-upload, a scan that every 500 recorded in the corpus (4 today) is one of the three texts, controls (a changed byte, a changed status, a kind against another kind's fixture), and prop_plane_500_never_leaks_the_cause (status, headers and body equal those for an empty cause, whatever the cause is).

Read before merging

  • One v1 test is edited on purpose. a_500_keeps_its_cause_out_of_the_body asserted that a deliberate 500 carries no cause. The helper now always attaches one, so the test now asserts that. The contract changed; the test was not wrong.
  • Deviations from the issue's wording. The free function thrust_api_v1::plane_500() is removed, not kept beside the new one, so there is one plane_500. The crate is named thrust-plane-types, not thrust-compat-types as chore(contracts): keep compat DTOs out of thrust-contracts; add the check-deps.sh rule #52 writes it, because /api/v1 uses it too; chore(contracts): keep compat DTOs out of thrust-contracts; add the check-deps.sh rule #52's PR should change that line.
  • "Body bytes" is by DRF's default. The corpus keeps a body as parsed JSON, not as sent. The test compares our raw bytes with the compact serialisation of the recorded value, which is what DRF's renderer writes by default; that the pin leaves the default alone is read from the shape of its output, not recorded.
  • Two fixtures are the pinned source, not recordings. An unexpected error occurred and Internal server error were never reached by the harness (testing rule 9b). Each fixture says so. InternalServerError has no caller yet (v1 has no asset routes).

Not run here

The contract suite and the oracle gate, which this change does not touch (no route, status or body moves). CI runs them.

Next for #51

The internal API's 500 (it answers a Thrust-shaped body today, and 400 where the pin answers 500 for per_page <= 0), then the acceptance list with the comm -3 check. Not a closing PR: it says "Refs #51" on purpose.

🤖 Generated with Claude Code

Round 27 decided to reproduce every Plane 500 as a handled response, and the
text of a 500 is part of the contract (research/0007 PQ-409). They are now
answered by one function in a new crate, thrust-plane-types:
plane_500(kind, cause) sets status 500, writes the pin's exact body for that
kind and attaches the cause as InternalErrorDetail, so the root logs it and the
body never carries it. Plane500 names the three texts: the base handlers'
catch-all, project create's, and the generic asset GET's.

/api/v1 answers its 500s through it. V1Error::Plane500 now carries a kind and a
required cause, built by V1Error::internal and V1Error::unexpected; the free
thrust_api_v1::plane_500() is removed, so a deliberate 500 now says why in the
log. The array body to project create was the one 500 written by hand; it is
Plane500::UnexpectedError.

The wire does not move: the v1 suites assert the same statuses and bodies and
pass as before. One test is edited on purpose,
a_500_keeps_its_cause_out_of_the_body, which asserted that a deliberate 500
carries no cause; the helper now always attaches one (the test is not wrong,
the contract changed).

Tests, in the new crate: parity_plane_500_bodies compares each kind's status
and body bytes with a fixture. The base text is tied to the oracle's recording
(corpus/assets.json#workspace-asset-upload), every 500 recorded in the corpus
must be one of the three texts, and the other two cite the pinned source (rule
9b). Controls: one changed byte, a changed status, and one kind against
another's fixture each make the comparison fail.
prop_plane_500_never_leaks_the_cause generates the cause.

scripts/check-plane-500.sh (CI job deps, with --self-test as its control)
refuses INTERNAL_SERVER_ERROR, from_u16(500), try_from(500) and .status(500) in
the src of thrust-api-v1 and thrust-compat-plane, and refuses to pass on a
directory with no .rs file. Run against the previous v1 sources it reports
error.rs:102 and projects.rs:377.

The crate is added to CLEAN_CRATES in check-deps.sh, and docs/src/contributing
crates.md is brought up to date with it (its crate counts were already stale).

The internal API (thrust-compat-plane) does not call it yet; that is the next
change for #51.

Refs: plane-byd.5
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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