ReviewOS

home-lang/home

Port Express JSON parser and encoded-body contracts

#220
Closed chris opened this 10 days ago ·
10 days ago

Context

The sequential Bun corpus frontier is js/third_party/express/express.json.test.ts at position 3962/4708, following the completed router/Supertest work in #219. This contributes to #66.

Current gap

The copied 745-line suite now reaches the in-memory request adapter but requires full request mutation and JSON body-parser semantics: header removal and streamed writes, length/limit enforcement, strict JSON, content-type selection, verification callbacks, charset decoding, compression, and structured middleware errors.

Acceptance criteria

  • Supertest supports case-insensitive set/unset, streamed write, byte-preserving bodies, and once-only completion.
  • express.json() handles absent/zero/duplicate bodies and strict JSON parsing without re-reading consumed input.
  • Numeric/string limits and content-length mismatches produce the correct 413/400 middleware errors.
  • Type functions/arrays, verify callbacks, custom status/type, original body, and useful stack context are preserved.
  • UTF-8/UTF-16 decoding and identity/gzip/deflate content encodings work, with structured 400/415 errors for malformed or unsupported input.
  • The copied suite passes with its existing todos and is pinned in the permanent third-party gate.
10 days ago

Completed on main in 6873fb3.

The shared Supertest request model now supports case-insensitive set/unset, streamed byte-preserving writes, object JSON defaults, and once-only completion. express.json() now snapshots its options, avoids duplicate reads, enforces content length and numeric/string limits, supports strict parsing and type functions/arrays, preserves verify errors and raw bodies, decodes UTF-8/UTF-16, and handles identity/gzip/deflate plus structured 400/403/413/415 errors.

Error forwarding now repairs runtimes that expose frame-only Error.stack values by prepending the original error name/message, while retaining the original error object/cause and frames. This makes both default and custom middleware diagnostics actionable.

Verification: focused position 3962 reports files=1, passed=47, todo=7, failed=0, unsupported=0, allowed-empty=0; all permanent copied-corpus, SQL, and third-party gates pass.

Sign in to comment on this issue.