fed-prims: Phase J — http-request + 6 tests
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 2m48s

NATIVE-ONLY http-request primitive (bin/sx_server.ml). HTTP/1.1 over
Unix sockets + gethostbyname; inline http:// URL parsing (full
url-parse deferred to Phase K); Connection: close + Host +
Content-Length headers auto-supplied; reads response via
Content-Length or read-to-EOF; chunked transfer-encoding rejected.
Test bin/test_http_client.sh spins a Phase-H echo server and drives
a second sx_server: GET+query, POST+body, 404, custom request
header reflected, non-http scheme rejected, integer status — 6/6.
WASM boot green (prim not in lib); Erlang conformance 530/530.
This commit is contained in:
2026-05-26 19:53:58 +00:00
parent 4548461bfc
commit 46e0653911
3 changed files with 290 additions and 0 deletions

View File

@@ -145,6 +145,44 @@ check** → tests → commit → tick box → Progress-log line → push.
- **Acceptance:** curl test script green; WASM build untouched (prim not in lib).
Satisfies fed-sx Step 8 transport.
### Phase J — HTTP/1.1 client, **native-only** (`bin/sx_server.ml`) ✅ DONE
- Mirror of Phase H, inverse direction. TCP connect via `Unix.gethostbyname` +
`Unix.socket`/`Unix.connect`. Write request line + headers + body, read
response status line + headers + body (Content-Length first; chunked
encoding optional v2 — flag as Blockers if a fed-sx need hits it).
- Primitive `(http-request method url headers body) -> response-dict`
registered ONLY in `bin/sx_server.ml`. Response dict shape:
`{:status :headers :body}` (mirror of server's request dict). URL must be
`http://...` for v1; HTTPS is a separate later phase (needs TLS lib).
- Tests: `bin/test_http_client.sh` — start a tiny python HTTP server in a
subprocess (or reuse Phase H's SX server), drive GET / POST / 404 /
custom-header roundtrip via `(http-request ...)` from the epoch protocol,
assert response dict shape + body, kill server.
- **Acceptance:** test script green; WASM build untouched (prim not in lib);
Erlang conformance unchanged. Unblocks Erlang Phase 8 `httpc:request/4` BIF
wiring and fed-sx Milestone 2 federation `POST /inbox` outbound.
### Phase K — URL parser, pure OCaml, WASM-safe (`lib/sx_url.ml`)
- `(url-parse "http://host:port/path?q=1") -> {:scheme :host :port :path :query}`
— small recursive-descent parser. No external deps. Port is integer when
present, absent key otherwise (or default per scheme: 80/443).
- `(url-encode-component string) -> string` /
`(url-decode-component string) -> string` — percent-encoding per RFC 3986
(reserved/unreserved sets).
- Tests: `bin/test_url.ml` — full URL, port-less, path-only, query string with
multiple pairs, empty path, percent-encoding round-trips, malformed inputs
(return error-shaped result, not exception).
- **Acceptance:** WASM boot green (pure lib); supports fed-sx kernel actor URL
parsing and Phase J HTTP-client url handling.
### Phase L — (open) further client prims as fed-sx kernel needs surface
- Add new phases here as the kernel loop or design conversations identify
needs: chunked HTTP transfer encoding, HTTPS / TLS verify (likely opam-dep
Blockers), webfinger HTTP shape, DNS (probably folded into `http-request`).
- Each new phase: define test vectors / contract → implement → WASM-check
(skip for native-only) → commit → Progress log. Same iteration discipline as
AI.
### Phase I — handoff ✅ DONE
- Flip the `plans/erlang-on-sx.md` Blockers entry "SX runtime lacks platform
primitives …" to **RESOLVED**, listing the exact SX primitive names so the
@@ -226,6 +264,20 @@ should leave `httpc`/`sqlite` BIFs blocked with that note.
_Newest first._
- 2026-05-26 — Phase J: `http-request` primitive in `bin/sx_server.ml`
(NATIVE ONLY — `Unix.gethostbyname` + `Unix.connect`; HTTP/1.1 with
inline `http://` URL parser; sends Connection: close + Host +
Content-Length unless caller supplies them; reads status line +
headers + body via Content-Length, falling back to read-to-EOF;
Transfer-Encoding: chunked rejected with explicit error per plan).
Test `bin/test_http_client.sh` spins up a Phase-H echo server in a
background sx_server and drives a second sx_server with epoch
`(eval …)` calls: GET+query, POST+body, 404, custom request
header reflected back, non-http scheme rejected (error path),
integer status — 6/6 pass. NOT in lib/ so WASM boot untouched
(green); Erlang conformance 530/530 unchanged; run_tests
unchanged. Unblocks Erlang Phase 8 `httpc:request/4` BIF wiring
and fed-sx Milestone 2 federation `POST /inbox` outbound.
- 2026-05-18 — Phase I: handoff. `erlang-on-sx.md` Blockers gained one
RESOLVED entry (no "SX runtime lacks…" entry pre-existed; it read
"_(none yet)_") mapping every delivered primitive → its Phase 8 BIF,