host: Phase 1 — router + handler + GET /feed endpoint on Dream, 28/28
First migrated endpoint onto the SX host. lib/host is a thin wiring layer: a host handler is a Dream handler (request->response) that calls a subsystem public API and serialises via a shared JSON envelope. - handler.sx: host/ok, host/ok-status, host/error, host/json-status (Dream's dream-json is 200-only), host/query-int - router.sx: host/make-app assembles per-domain route groups + /health probe into one dream-router (reuses dr/flatten-routes) - feed.sx: GET /feed reads feed/all + stream combinators, recent-first, with ?actor= filter and ?limit= cap - 3 test suites incl. a golden test (body == subsystem recent stream + envelope) - conformance.sh mirrors lib/dream's runner Builds on dream-on-sx (merged, gate green 480/480) rather than a throwaway native request model; collapses most of plan Phase 4 into Phase 1. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
75
lib/host/tests/router.sx
Normal file
75
lib/host/tests/router.sx
Normal file
@@ -0,0 +1,75 @@
|
||||
;; lib/host/tests/router.sx — host app assembly: health endpoint, group mounting,
|
||||
;; 404 fallback.
|
||||
|
||||
(define host-rt-pass 0)
|
||||
(define host-rt-fail 0)
|
||||
(define host-rt-fails (list))
|
||||
|
||||
(define
|
||||
host-rt-test
|
||||
(fn
|
||||
(name actual expected)
|
||||
(if
|
||||
(= actual expected)
|
||||
(set! host-rt-pass (+ host-rt-pass 1))
|
||||
(begin
|
||||
(set! host-rt-fail (+ host-rt-fail 1))
|
||||
(append! host-rt-fails {:name name :actual actual :expected expected})))))
|
||||
|
||||
(define
|
||||
host-rt-req
|
||||
(fn (method target) (dream-request method target {} "")))
|
||||
|
||||
;; An app built from one domain group of two routes.
|
||||
(define
|
||||
host-rt-app
|
||||
(host/make-app
|
||||
(list
|
||||
(list
|
||||
(dream-get "/ping" (fn (req) (host/ok "pong")))
|
||||
(dream-get "/widgets/:id" (fn (req) (host/ok (dream-param req "id"))))))))
|
||||
|
||||
;; ── health ─────────────────────────────────────────────────────────
|
||||
(host-rt-test
|
||||
"health status 200"
|
||||
(dream-status (host-rt-app (host-rt-req "GET" "/health")))
|
||||
200)
|
||||
(host-rt-test
|
||||
"health body healthy"
|
||||
(contains?
|
||||
(dream-resp-body (host-rt-app (host-rt-req "GET" "/health")))
|
||||
"healthy")
|
||||
true)
|
||||
|
||||
;; ── group routes mounted ───────────────────────────────────────────
|
||||
(host-rt-test
|
||||
"group route ping"
|
||||
(contains?
|
||||
(dream-resp-body (host-rt-app (host-rt-req "GET" "/ping")))
|
||||
"pong")
|
||||
true)
|
||||
(host-rt-test
|
||||
"group path param"
|
||||
(contains?
|
||||
(dream-resp-body (host-rt-app (host-rt-req "GET" "/widgets/42")))
|
||||
"\"data\":\"42\"")
|
||||
true)
|
||||
|
||||
;; ── fallback ───────────────────────────────────────────────────────
|
||||
(host-rt-test
|
||||
"unknown path 404"
|
||||
(dream-status (host-rt-app (host-rt-req "GET" "/nope")))
|
||||
404)
|
||||
(host-rt-test
|
||||
"wrong method 405"
|
||||
(dream-status (host-rt-app (host-rt-req "POST" "/ping")))
|
||||
405)
|
||||
|
||||
(define
|
||||
host-rt-tests-run!
|
||||
(fn
|
||||
()
|
||||
{:total (+ host-rt-pass host-rt-fail)
|
||||
:passed host-rt-pass
|
||||
:failed host-rt-fail
|
||||
:fails host-rt-fails}))
|
||||
Reference in New Issue
Block a user