Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lisp/cider-endpoint.el
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ of remote SSH hosts."
(mapcar (lambda (pair)
(when-let* ((published (nrepl--container-published-port
container-method container
(string-to-number (cadr pair)))))
(list (car pair) (number-to-string published))))
(cadr pair))))
(list (car pair) published)))
(cider-locate-running-nrepl-ports default-directory)))))
;; change dir: current file might be remote
(change-dir-p (file-remote-p default-directory))
Expand Down
6 changes: 3 additions & 3 deletions lisp/nrepl-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ opened."
(car (member method '("docker" "podman")))))

(defun nrepl--container-published-port (method container port)
"Return the host port CONTAINER publishes PORT on, or nil.
"Return the host port CONTAINER publishes PORT on, as a string, or nil.
METHOD is the container CLI to use (\"docker\" or \"podman\"), run on
the local machine. Ports that the container doesn't publish yield nil."
(with-temp-buffer
Expand All @@ -313,7 +313,7 @@ the local machine. Ports that the container doesn't publish yield nil."
;; output looks like "0.0.0.0:12345\n[::]:12345"
(goto-char (point-min))
(when (re-search-forward ":\\([0-9]+\\)$" nil t)
(string-to-number (match-string 1))))))
(match-string 1)))))

(defun nrepl--ssh-file-name-matches-host-p (file-name host)
"Return t, if FILE-NAME is a tramp-file-name on HOST via ssh."
Expand Down Expand Up @@ -1334,7 +1334,7 @@ up."
(let* ((printed-host (match-string 2 output))
(tramp-host (file-remote-p default-directory 'host))
(container-method (nrepl--tramp-container-method))
(port (string-to-number (match-string 1 output)))
(port (match-string 1 output))
(published (and container-method tramp-host
(nrepl--container-published-port
container-method tramp-host port)))
Expand Down
2 changes: 1 addition & 1 deletion test/cider-endpoint-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
(if dir '(("app" "7888")) nil)))
(spy-on 'nrepl--container-published-port :and-call-fake
(lambda (_method _container port)
(when (= port 7888) 12345)))
(when (equal port "7888") "12345")))
(let ((default-directory "/docker:zz-app:/app/"))
(expect (cider--infer-ports "localhost" nil)
:to-equal '(("app" "12345")))))
Expand Down
26 changes: 19 additions & 7 deletions test/nrepl-client-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -757,19 +757,31 @@
(it "parses the published host port"
(spy-on 'call-process :and-call-fake
(lambda (&rest _) (insert "0.0.0.0:12345\n[::]:12345\n") 0))
(expect (nrepl--container-published-port "docker" "app" 7888) :to-equal 12345))
(expect (nrepl--container-published-port "docker" "app" "7888") :to-equal "12345"))

(it "returns nil when the port is not published"
(spy-on 'call-process :and-return-value 1)
(expect (nrepl--container-published-port "docker" "app" 7888) :to-be nil))
(expect (nrepl--container-published-port "docker" "app" "7888") :to-be nil))

(it "returns nil when the CLI is missing"
(spy-on 'call-process :and-throw-error 'file-missing)
(expect (nrepl--container-published-port "docker" "app" 7888) :to-be nil)))
(expect (nrepl--container-published-port "docker" "app" "7888") :to-be nil)))

(describe "nrepl-server-filter"
(it "stores the port as a string, as nrepl-connect does (#4180)"
(with-temp-buffer
(let ((proc (make-pipe-process :name "nrepl-test-server"
:buffer (current-buffer)
:noquery t)))
(unwind-protect
(progn
(nrepl-server-filter proc "nREPL server started on port 51139 on host localhost - nrepl://localhost:51139\n")
(expect (plist-get nrepl-endpoint :port) :to-equal "51139"))
(delete-process proc))))))

(describe "nrepl-server-filter in a container context"
(it "resolves the endpoint to the published localhost port"
(spy-on 'nrepl--container-published-port :and-return-value 12345)
(spy-on 'nrepl--container-published-port :and-return-value "12345")
(with-temp-buffer
(setq-local default-directory "/docker:zz-app:/app/")
(let ((proc (make-pipe-process :name "nrepl-test-server"
Expand All @@ -779,9 +791,9 @@
(progn
(nrepl-server-filter proc "nREPL server started on port 7888 on host 0.0.0.0 - nrepl://0.0.0.0:7888\n")
(expect (plist-get nrepl-endpoint :host) :to-equal "localhost")
(expect (plist-get nrepl-endpoint :port) :to-equal 12345)
(expect (plist-get nrepl-endpoint :port) :to-equal "12345")
(expect 'nrepl--container-published-port
:to-have-been-called-with "docker" "zz-app" 7888))
:to-have-been-called-with "docker" "zz-app" "7888"))
(delete-process proc)))))

(it "keeps the container host when nothing is published (with a warning)"
Expand All @@ -795,7 +807,7 @@
(unwind-protect
(progn
(nrepl-server-filter proc "nREPL server started on port 7888 on host 0.0.0.0 - nrepl://0.0.0.0:7888\n")
(expect (plist-get nrepl-endpoint :port) :to-equal 7888)
(expect (plist-get nrepl-endpoint :port) :to-equal "7888")
(expect 'message :to-have-been-called))
(delete-process proc))))))

Expand Down
Loading