; 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 " / "ng ..." ; 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"