Files
rose-ash/lib/gitea/tests/wire-http-client.sx
giles 8ed44f7770 lib/gitea: fix the fetch-pack-over-HTTP hang — native parse fast path
The sx-forge native-loop blocker: clone! of the live giles/rose-ash
never returned over gitea/http-app. Root cause was NOT the transport —
pack-line-parse ran every pack line through the interpreted spec parser
(~6.6KB/s on the CEK machine; a full-repo pack = hours), and a non-hex
byte in a pkt length header parsed negative (index-of -1), walking the
scan index backwards forever.

- gitea/parse-obj: use the host reader (open-input-string + read,
  ~3700x faster, value-identical) when the host provides it; hosts
  without string ports keep sx-parse. Feature-detected at load.
- pkt-sections-loop: (< n 4) guard — malformed lengths error instead
  of hanging.
- push-cmd!: haves = every advertised remote ref held locally, so a
  NEW branch pushes only its delta, not the whole repo closure.
- tests/wire.sx: malformed-len errors, truncated-pkt clamps, parse-obj
  = sx-parse equivalence (blob/commit + cid). 83/83.
- tests/wire-http.sh + wire-http-client.sx: end-to-end over REAL
  http-listen/http-request on :8943 — ls-remote/clone/push-new-branch/
  fresh-clone-verify/delete. The coverage gap that hid all this.

Proven vs the live forge (in sx-gitea-1): full 4468-file clone in 77s
(was: hang), commit, push heads/sx-smoke-test ok, branch advertised on
sx.sx-web.org. Conformance 620/620.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-04 00:30:59 +00:00

84 lines
3.0 KiB
Plaintext

; lib/gitea/tests/wire-http-client.sx — client half of wire-http.sh.
;
; Drives the wire client against a REAL http-listen server through
; gitea/http-app (the kernel http-request primitive) — the transport
; the in-process wire tests can't cover. Asserts land in
; /tmp/sx-wire-http-test/results.txt as "ok <name>" / "ng <name> ..."
; lines; wire-http.sh greps for "ng ".
;
; Requires: the wire client stack (see wire-http.sh) + lib/gitea/import.sx
; (gitea/http-app), served forge on 127.0.0.1:8943 (giles/welcome seeded).
(define whc-out "/tmp/sx-wire-http-test/results.txt")
(define whc-results (list))
(define
whc-check
(fn
(name ok detail)
(begin
(set!
whc-results
(append
whc-results
(list
(if ok (str "ok " name) (str "ng " name " " (inspect detail))))))
(file-write whc-out (join "\n" whc-results)))))
(define whc-base "http://127.0.0.1:8943")
(define whc-token "wire-test-token")
(define whc-app (gitea/http-app whc-base))
; 1. ls-remote over real HTTP
(define whc-remote (gitea/remote whc-app "giles" "welcome" whc-token))
(define whc-ls (gitea/ls-remote whc-remote))
(whc-check "ls-remote head" (= (get whc-ls :head) "heads/main") whc-ls)
; 2. clone over real HTTP
(define whc-forge (gitea/forge (persist/mem-backend)))
(gitea/user-create! whc-forge "giles")
(define
whc-clone
(gitea/clone! whc-forge "giles" "welcome" whc-remote {}))
(whc-check
"clone returns repo"
(= (get whc-clone :name) "welcome")
whc-clone)
(define whc-g (gitea/repo-git whc-forge "giles" "welcome"))
(define whc-files (git/commit-files whc-g (git/head whc-g)))
(whc-check
"clone materializes README"
(not (nil? (get whc-files "README.md")))
(keys whc-files))
; 3. commit + push a NEW branch over real HTTP — push-cmd! with the
; commit cid (no local branch ref needed; delta-sized thanks to the
; remote-refs haves)
(git/add! whc-g "wire-http-test.txt" "pushed over real HTTP")
(define whc-cid (git/commit! whc-g {:message "wire-http round trip" :author "giles" :time 1}))
(define
whc-push
(gitea/push-cmd! whc-remote whc-g "heads/wire-http-test" whc-cid))
(whc-check "push new branch" (= (get whc-push :ok) true) whc-push)
; 4. fresh clone sees the pushed branch + file
(define whc-forge2 (gitea/forge (persist/mem-backend)))
(gitea/user-create! whc-forge2 "giles")
(gitea/clone! whc-forge2 "giles" "welcome" whc-remote {})
(define whc-g2 (gitea/repo-git whc-forge2 "giles" "welcome"))
(define whc-branch (git/branch-get whc-g2 "wire-http-test"))
(whc-check
"fresh clone sees pushed branch"
(not (nil? whc-branch))
(git/branches whc-g2))
(define whc-files2 (git/commit-files whc-g2 whc-branch))
(whc-check
"pushed file round-trips"
(= (get whc-files2 "wire-http-test.txt") "pushed over real HTTP")
(keys whc-files2))
; 5. delete the test branch again (leave the served forge clean)
(define whc-del (gitea/push-delete! whc-remote whc-g "heads/wire-http-test"))
(whc-check "delete test branch" (= (get whc-del :ok) true) whc-del)
"WIRE-HTTP-CLIENT-DONE"