fed-sx-m1: 8b-bridge cleanup — remove dead helpers + duplicate test
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 34s

Step 8b-bridge was actually completed in 0f85bd96 (Step 8b-start) using
er-request-dict-to-proplist / er-proplist-to-dict plus er-spawn-fun to
host the handler inside a real Erlang process. My previous commit
(31ff1e6a) shipped a parallel set of helpers (er-http-req-of-sx,
er-http-resp-to-sx and friends) plus a duplicate test under
next/tests/http_listen_bridge.sh — the BIF body never referenced them,
so they sat in runtime.sx as dead code while http_marshal.sh already
covered the live marshalers.

This commit:
  - deletes the 8 dead helpers from lib/erlang/runtime.sx
  - deletes the duplicate next/tests/http_listen_bridge.sh
  - rewrites next/README.md substrate gap #3 to name the helpers and
    tests that are actually live

No behaviour change. Erlang conformance still 761/761; http_listen_bif
5/5, http_route 11/11, http_publish_fold 10/10, http_marshal 10/10.
This commit is contained in:
2026-06-05 23:10:45 +00:00
parent 7267b83b08
commit 78eae9ef12
3 changed files with 12 additions and 331 deletions

View File

@@ -1,177 +0,0 @@
#!/usr/bin/env bash
# next/tests/http_listen_bridge.sh — Step 8b-bridge acceptance test.
#
# Exercises the SX↔Erlang marshaling layer that sits between the
# native http-listen primitive (which delivers an SX dict shaped
# {:method :path :query :headers :body}) and the Erlang handler
# (which expects a proplist of binaries / atoms and returns the
# same on the way out). The native TCP listener is NOT started
# here — http-listen blocks forever; this test verifies the bridge
# in isolation by calling er-http-req-of-sx / er-http-resp-to-sx
# directly, plus a round-trip through http_server:route/2 to prove
# the proplist shape is what the router consumes.
set -uo pipefail
cd "$(git rev-parse --show-toplevel)"
SX_SERVER="${SX_SERVER:-hosts/ocaml/_build/default/bin/sx_server.exe}"
if [ ! -x "$SX_SERVER" ]; then
SX_SERVER="/root/rose-ash/hosts/ocaml/_build/default/bin/sx_server.exe"
fi
if [ ! -x "$SX_SERVER" ]; then
echo "ERROR: sx_server.exe not found." >&2
exit 1
fi
VERBOSE="${1:-}"
PASS=0; FAIL=0; ERRORS=""
TMPFILE=$(mktemp); trap "rm -f $TMPFILE" EXIT
cat > "$TMPFILE" <<'EPOCHS'
(epoch 1)
(load "lib/erlang/tokenizer.sx")
(load "lib/erlang/parser.sx")
(load "lib/erlang/parser-core.sx")
(load "lib/erlang/parser-expr.sx")
(load "lib/erlang/parser-module.sx")
(load "lib/erlang/transpile.sx")
(load "lib/erlang/runtime.sx")
(load "lib/erlang/vm/dispatcher.sx")
(epoch 2)
(eval "(get (erlang-load-module (file-read \"next/kernel/http_server.erl\")) :name)")
;; Binary ↔ string round-trip.
(epoch 10)
(eval "(= (er-binary->string (string->er-binary \"hello\")) \"hello\")")
;; Empty string → empty binary → empty string.
(epoch 11)
(eval "(= (er-binary->string (string->er-binary \"\")) \"\")")
;; er-http-req-of-sx produces an Erlang cons-list (proplist).
(epoch 12)
(eval "(er-cons? (er-http-req-of-sx {\"method\" \"GET\" \"path\" \"/\" \"query\" \"\" \"headers\" {} \"body\" \"\"}))")
;; method key carries the original method as a binary.
(epoch 13)
(eval "(let ((pl (er-http-req-of-sx {\"method\" \"GET\" \"path\" \"/\" \"query\" \"\" \"headers\" {} \"body\" \"\"}))) (er-binary->string (er-proplist-get pl \"method\" nil)))")
;; path key carries the original path as a binary.
(epoch 14)
(eval "(let ((pl (er-http-req-of-sx {\"method\" \"POST\" \"path\" \"/activity\" \"query\" \"\" \"headers\" {} \"body\" \"\"}))) (er-binary->string (er-proplist-get pl \"path\" nil)))")
;; query key carries the original query string as a binary.
(epoch 15)
(eval "(let ((pl (er-http-req-of-sx {\"method\" \"GET\" \"path\" \"/\" \"query\" \"a=1&b=2\" \"headers\" {} \"body\" \"\"}))) (er-binary->string (er-proplist-get pl \"query\" nil)))")
;; body key carries the body bytes as a binary.
(epoch 16)
(eval "(let ((pl (er-http-req-of-sx {\"method\" \"POST\" \"path\" \"/\" \"query\" \"\" \"headers\" {} \"body\" \"payload\"}))) (er-binary->string (er-proplist-get pl \"body\" nil)))")
;; headers value is an Erlang cons-list (or er-nil for empty).
(epoch 17)
(eval "(er-nil? (er-proplist-get (er-http-req-of-sx {\"method\" \"GET\" \"path\" \"/\" \"query\" \"\" \"headers\" {} \"body\" \"\"}) \"headers\" nil))")
;; Non-empty headers dict → a cons of {bin, bin} tuples.
(epoch 18)
(eval "(let ((h (er-proplist-get (er-http-req-of-sx {\"method\" \"GET\" \"path\" \"/\" \"query\" \"\" \"headers\" {\"x-foo\" \"bar\"} \"body\" \"\"}) \"headers\" nil))) (er-cons? h))")
;; First header tuple element 0 is the name as a binary.
(epoch 19)
(eval "(let ((h (er-proplist-get (er-http-req-of-sx {\"method\" \"GET\" \"path\" \"/\" \"query\" \"\" \"headers\" {\"X-Echo\" \"GET\"} \"body\" \"\"}) \"headers\" nil))) (let ((tup (get h :head))) (er-binary->string (nth (get tup :elements) 0))))")
;; First header tuple element 1 is the value as a binary.
(epoch 20)
(eval "(let ((h (er-proplist-get (er-http-req-of-sx {\"method\" \"GET\" \"path\" \"/\" \"query\" \"\" \"headers\" {\"X-Echo\" \"GET\"} \"body\" \"\"}) \"headers\" nil))) (let ((tup (get h :head))) (er-binary->string (nth (get tup :elements) 1))))")
;; er-http-resp-to-sx pulls status as an SX number.
(epoch 21)
(eval "(get (er-http-resp-to-sx (er-mk-cons (er-mk-tuple (list (er-mk-atom \"status\") 201)) (er-mk-nil))) :status)")
;; Default status is 200 when no status key in proplist.
(epoch 22)
(eval "(get (er-http-resp-to-sx (er-mk-nil)) :status)")
;; Body binary → SX string.
(epoch 23)
(eval "(get (er-http-resp-to-sx (er-mk-cons (er-mk-tuple (list (er-mk-atom \"body\") (string->er-binary \"hi\"))) (er-mk-nil))) :body)")
;; Empty body default.
(epoch 24)
(eval "(get (er-http-resp-to-sx (er-mk-nil)) :body)")
;; Response headers cons-list → SX dict.
(epoch 25)
(eval "(get (get (er-http-resp-to-sx (er-mk-cons (er-mk-tuple (list (er-mk-atom \"headers\") (er-mk-cons (er-mk-tuple (list (string->er-binary \"X-A\") (string->er-binary \"1\"))) (er-mk-nil)))) (er-mk-nil))) :headers) \"X-A\")")
;; Empty response headers → empty SX dict.
(epoch 26)
(eval "(len (keys (get (er-http-resp-to-sx (er-mk-nil)) :headers)))")
;; End-to-end: marshal an SX dict → run through http_server:route/2 →
;; marshal Erlang response back to SX dict. Verify status=200 and
;; the body matches http_server:welcome_body() for GET /.
(epoch 30)
(eval "(let ((req (er-http-req-of-sx {\"method\" \"GET\" \"path\" \"/\" \"query\" \"\" \"headers\" {} \"body\" \"\"}))) (let ((resp-pl (erlang-eval-ast (str \"http_server:route(R).\")))) :skip))")
(epoch 31)
(eval "(let ((sx-req {\"method\" \"GET\" \"path\" \"/\" \"query\" \"\" \"headers\" {} \"body\" \"\"})) (let ((resp (er-http-resp-to-sx (er-apply-user-module \"http_server\" \"route\" (list (er-http-req-of-sx sx-req)))))) (get resp :status)))")
(epoch 32)
(eval "(let ((sx-req {\"method\" \"POST\" \"path\" \"/nowhere\" \"query\" \"\" \"headers\" {} \"body\" \"\"})) (let ((resp (er-http-resp-to-sx (er-apply-user-module \"http_server\" \"route\" (list (er-http-req-of-sx sx-req)))))) (get resp :status)))")
(epoch 33)
(eval "(let ((sx-req {\"method\" \"GET\" \"path\" \"/\" \"query\" \"\" \"headers\" {} \"body\" \"\"})) (let ((resp (er-http-resp-to-sx (er-apply-user-module \"http_server\" \"route\" (list (er-http-req-of-sx sx-req)))))) (> (string-length (get resp :body)) 0)))")
EPOCHS
OUTPUT=$(timeout 120 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
check() {
local epoch="$1" desc="$2" expected="$3"
local actual
actual=$(echo "$OUTPUT" | awk -v e="$epoch" '
$0 ~ "^\\(ok-len " e " " { getline; print; exit }
$0 ~ "^\\(ok " e " " { print; exit }
$0 ~ "^\\(error " e " " { print; exit }
')
[ -z "$actual" ] && actual="<no output for epoch $epoch>"
if echo "$actual" | grep -qF -- "$expected"; then
PASS=$((PASS+1))
[ "$VERBOSE" = "-v" ] && echo " ok $desc"
else
FAIL=$((FAIL+1))
ERRORS+=" FAIL [$desc] (epoch $epoch) expected: $expected | actual: $actual
"
fi
}
check 10 "binary↔string round-trip" "true"
check 11 "empty string round-trip" "true"
check 12 "req-of-sx returns cons-list" "true"
check 13 "method binary carries 'GET'" "\"GET\""
check 14 "path binary carries '/activity'" "\"/activity\""
check 15 "query binary carries 'a=1&b=2'" "\"a=1&b=2\""
check 16 "body binary carries 'payload'" "\"payload\""
check 17 "empty headers → er-nil" "true"
check 18 "non-empty headers → cons" "true"
check 19 "header name marshals to binary" "\"X-Echo\""
check 20 "header value marshals to binary" "\"GET\""
check 21 "resp-to-sx pulls status integer" "201"
check 22 "default status is 200" "200"
check 23 "body binary → SX string" "\"hi\""
check 24 "default body is empty string" "\"\""
check 25 "response headers → SX dict" "\"1\""
check 26 "empty response headers → {}" "0"
check 31 "end-to-end GET / → status 200" "200"
check 32 "end-to-end POST /nowhere → 404" "404"
check 33 "end-to-end GET / body non-empty" "true"
TOTAL=$((PASS+FAIL))
if [ $FAIL -eq 0 ]; then
echo "ok $PASS/$TOTAL next/tests/http_listen_bridge.sh passed"
else
echo "FAIL $PASS/$TOTAL passed, $FAIL failed:"
echo "$ERRORS"
fi
[ $FAIL -eq 0 ]