HS E36: socket URL parsing + hs-socket-register! runtime (+3 tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 15s

- parser.sx: parse-socket-feat handles /path and scheme:// URLs; collect-url
  greedily joins URL continuation tokens (ident/number/op/colon/dot)
- tokenizer.sx: fix :// not treated as line comment (lookback check)
- compiler.sx: emit-socket compiles socket AST to hs-socket-register! call
- runtime.sx: hs-socket-register! normalises URL (relative→ws:/wss:),
  constructs WebSocket, builds wrapper dict, binds on window name-path
- hs-run-filtered.js: WebSocket mock uses plain object (not JS array) so
  host-global returns a foreign value rather than SX list; host-get idx works

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 09:55:48 +00:00
parent c2dcc94ce2
commit a20c9c4625
15 changed files with 291 additions and 65 deletions

View File

@@ -11508,9 +11508,19 @@
;; ── socket (16 tests) ──
(defsuite "hs-upstream-socket"
(deftest "converts relative URL to ws:// on http pages"
(error "SKIP (untranslated): converts relative URL to ws:// on http pages"))
(hs-cleanup!)
(host-set! (host-global "window") "__hs_ws_created" (list))
(eval-hs "socket RelSocket /my-ws end")
(let ((sock (host-get (host-global "__hs_ws_created") 0)))
(assert= (host-get sock "url") "ws://localhost/my-ws")))
(deftest "converts relative URL to wss:// on https pages"
(error "SKIP (untranslated): converts relative URL to wss:// on https pages"))
(hs-cleanup!)
(host-set! (host-global "window") "__hs_ws_created" (list))
(host-set! (host-global "location") "protocol" "https:")
(eval-hs "socket RelSocket /my-ws end")
(host-set! (host-global "location") "protocol" "http:")
(let ((sock (host-get (host-global "__hs_ws_created") 0)))
(assert= (host-get sock "url") "wss://localhost/my-ws")))
(deftest "dispatchEvent sends JSON-encoded event over the socket"
(error "SKIP (untranslated): dispatchEvent sends JSON-encoded event over the socket"))
(deftest "namespaced sockets work"
@@ -11522,7 +11532,11 @@
(deftest "on message handler fires on incoming text message"
(error "SKIP (untranslated): on message handler fires on incoming text message"))
(deftest "parses socket with absolute ws:// URL"
(error "SKIP (untranslated): parses socket with absolute ws:// URL"))
(hs-cleanup!)
(host-set! (host-global "window") "__hs_ws_created" (list))
(eval-hs "socket MySocket ws://localhost:1234/ws end")
(let ((sock (host-get (host-global "__hs_ws_created") 0)))
(assert= (host-get sock "url") "ws://localhost:1234/ws")))
(deftest "rpc proxy blacklists then/catch/length/toJSON"
(error "SKIP (untranslated): rpc proxy blacklists then/catch/length/toJSON"))
(deftest "rpc proxy default timeout rejects the promise"