Skip to content

feat(format): http-api-v1 4-gate PARTIAL discharge#1375

Closed
noahgift wants to merge 2 commits into
mainfrom
feat/http-001-004-partial-discharge
Closed

feat(format): http-api-v1 4-gate PARTIAL discharge#1375
noahgift wants to merge 2 commits into
mainfrom
feat/http-001-004-partial-discharge

Conversation

@noahgift
Copy link
Copy Markdown
Contributor

@noahgift noahgift commented May 2, 2026

Summary

  • Binds FALSIFY-HTTP-001..004 from http-api-v1 at PARTIAL_ALGORITHM_LEVEL via 4 verdict functions over a fixture HTTP-response struct.
  • 27 unit tests including 17-case mutation surveys over status codes around 200/400/404.
  • Algorithm-level coverage advances by 4 gates; runtime ship % unchanged.

Gates bound

Gate ID Rule
HTTP-001 200 has Content-Type: application/json AND parseable body
HTTP-002 400 carries {error: {message, type}} envelope
HTTP-003 --no-cors response has zero access-control-allow-origin headers
HTTP-004 404 unknown endpoint uses the JSON error envelope

Three-way body classification

BodyParseStatus::{ValidJson, JsonMissingFields, NotJson} forces the call site to distinguish "empty JSON" from "JSON with required envelope fields" — collapsing them would let {} silently pass HTTP-002.

Five Whys

See commit message — captures why we use a 3-state enum vs is_json: bool and why CORS header check is case-insensitive.

Test plan

  • cargo test -p aprender-core --lib http_001_004 — 27 passed
  • PMAT pre-commit gates green
  • CI green

🤖 Generated with Claude Code

Binds FALSIFY-HTTP-001..004 from http-api-v1 at PARTIAL_ALGORITHM_LEVEL
via 4 pure-Rust verdict functions over a fixture HTTP-response struct.

- HTTP-001: 200 has Content-Type=application/json AND parseable body
- HTTP-002: 400 carries `{error: {message, type}}` envelope
- HTTP-003: --no-cors response has zero `access-control-allow-origin`
- HTTP-004: 404 unknown endpoint also uses the JSON error envelope

## Five Whys

1. Why does http-api-v1 list 4 falsification IDs without algorithm-level
   discharge? PMAT lints flagged FALSIFY-HTTP-001..004 as unbound at
   PARTIAL_ALGORITHM_LEVEL.
2. Why does that block ship? Coverage % cannot move while peripheral
   serve-surface contracts have no algorithm-level verdict module.
3. Why bind here vs in aprender-serve crate? Algorithm-level captures
   the decision rule (status / content-type / envelope-shape / CORS
   header set-membership) independent of any specific serve impl —
   the live integration test in the YAML still asserts the
   behavioural contract.
4. Why these specific decision predicates? Pinned per contract:
   AC_HTTP_JSON_CONTENT_TYPE, AC_HTTP_BAD_REQUEST=400,
   AC_HTTP_NOT_FOUND=404, AC_HTTP_CORS_HEADER (lowercased per RFC 7230
   header-name case-insensitivity).
5. Why a `BodyParseStatus` enum vs a boolean is_json? The contract
   distinguishes "valid JSON without envelope fields" from "valid
   JSON with required fields" — collapsing them would let an empty
   `{}` body silently pass HTTP-002. The enum forces three-way
   classification at the call site.

Adds 27 unit tests including 17-case mutation surveys over status
codes around 200 / 400 / 404. Realistic-healthy walks an `apr serve
--no-cors` healthy run; pre-fix walks a regression where text/plain
500s, missing envelopes, and CORS leakage all coexist.

No runtime % shift; algorithm-level coverage advances by 4 gates.
@noahgift noahgift force-pushed the feat/http-001-004-partial-discharge branch from 8a9056b to 7be6c26 Compare May 11, 2026 15:42
@noahgift noahgift enabled auto-merge (squash) May 11, 2026 15:42
@noahgift
Copy link
Copy Markdown
Contributor Author

Superseded by #1637 (135-PR squash). The commit content is included verbatim in that PR's diff. Closing now to release runner slots; this PR would have auto-closed when #1637 merges.

@noahgift noahgift closed this May 12, 2026
auto-merge was automatically disabled May 12, 2026 09:21

Pull request was closed

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