AtlatestRepositorycourier
1
;; End-to-end smoke test for the leader-dispatched media-upload flow.2
;;3
;; In-process: starts a leader-side relay listener with the4
;; media-upload handler installed, then opens a raw unix-socket5
;; connection (acting as a worker) and writes a `media-upload`6
;; envelope line. The leader's reader-loop dispatches via7
;; `tg-upload-*`. We bypass the full `relay-worker-connect!` flow8
;; (which blocks on MCP `channel-wait-initialized!`) because there's9
;; no real MCP client in this script.10
;;11
;; This makes a real Telegram API call. Run via:12
;; COURIER_TELEGRAM_TOKEN=... COURIER_TELEGRAM_CHAT_ID=... \13
;; sigil run --redirects worktree-redirects.sgl test/smoke-media.sgl <path>14
;;15
;; If <path> is omitted, defaults to /tmp/smoke-photo.png.17
(import (sigil core)18
(sigil io)19
(sigil fs)20
(sigil path)21
(sigil process)22
(sigil async)23
(sigil socket)24
(sigil mcp server)25
(sigil mcp channel)26
(courier config)27
(courier relay)28
(courier telegram))30
(define (smoke-main)31
;; The Sigil test runner consumes argv, so we read the path from the32
;; SMOKE_MEDIA_PATH env var instead. Defaults to the smoke photo.33
(let* ((path (or (getenv "SMOKE_MEDIA_PATH") "/tmp/smoke-photo.png"))34
(config (load-courier-config))35
(relay-dir (path-join (or (getenv "TMPDIR") "/tmp") "smoke-media-relay"))36
(relay-name "smoke-worker"))37
(unless (file-exists? path)38
(display (string-append "ERR: file not found: " path "\n"))39
(exit 2))40
(unless (courier-config-telegram-token config)41
(display "ERR: COURIER_TELEGRAM_TOKEN not set\n")42
(exit 2))43
(unless (courier-config-telegram-chat-id config)44
(display "ERR: COURIER_TELEGRAM_CHAT_ID not set\n")45
(exit 2))46
(setenv! "COURIER_RELAY_DIR" relay-dir)47
(ensure-directory relay-dir)49
(with-async50
(let* ((leader-state (make-relay-state))51
(leader-server (mcp-channel-server name: "smoke-leader"52
version: "0.0.0"53
instructions: "")))54
;; Leader: install media-upload handler, create the relay.55
(register-media-upload-handler! leader-state config)56
(create-relay! leader-state leader-server relay-name)57
(display (string-append "Leader listening on relay '"58
relay-name "'\n"))60
;; Give the accept-loop a tick to start awaiting.61
(sleep 0.2)63
;; Worker side: open a raw unix-socket connection and write64
;; the media-upload envelope line directly.65
(let* ((sock-path (path-join relay-dir66
(string-append relay-name ".sock")))67
(sock (unix-connect sock-path)))68
(unless sock69
(display (string-append "ERR: could not connect to "70
sock-path "\n"))71
(exit 3))72
(let ((envelope (make-media-upload-envelope path73
caption: "send-media smoke test (worker -> leader -> Telegram)")))74
(display (string-append "Sending envelope: " envelope "\n"))75
(socket-write-line sock envelope)76
;; Give the leader time to dispatch + upload.77
(sleep 8)78
(display "Smoke test complete. Check Telegram for delivery.\n")79
(socket-close sock)))81
(relay-cleanup! leader-state)82
(exit 0)))))84
(smoke-main)