portal

seancorfield 2023-10-02T19:30:57.515619Z

Following on from a thread in #calva I'd be interested in having more nREPL ops processed via the Portal middleware -- more than just eval -- and I've messed with the portal.nrepl code (re-eval'ing changes into a running setup) but don't seem to be picking up a number of ops that I believe Calva is sending... this is really my first foray into nREPL middleware exploration so I'm not sure what to do to debug this... I updated wrap-portal* to tap> every (:op msg) and I'm seeing eval and clojuredocs-lookup but not others...

djblue 2023-10-04T01:44:28.957189Z

@seancorfield Okay, I think the solution I'm preferring currently is https://github.com/djblue/portal/pull/197 and https://github.com/djblue/cider-nrepl/commit/fcf5cce08123aab382a05aa17018ae14c6958edf. It's a minimal change on both ends and provides exactly the same info as the current test reporting.

djblue 2023-10-04T01:45:12.062169Z

It's still a POC as there are more ops to intercept and test I think, but the main pieces are there 👌

seancorfield 2023-10-04T01:53:30.889509Z

(requiring-resolve `cider.nrepl.middleware.test/report)
will throw an exception if the CIDER middleware is not on the classpath.

👍 1
djblue 2023-10-04T01:54:13.653959Z

Yeah, definitely need to change some bits

seancorfield 2023-10-04T01:54:55.367929Z

I've never seen :dynamic true on a defmulti -- and I don't see binding in your code... what am I missing?

djblue 2023-10-04T01:57:09.530219Z

Yeah, me neither but that's how https://github.com/clojure/clojure/blob/master/src/clj/clojure/test.clj#L324-L333 does it. The "binding" is the https://github.com/djblue/portal/pull/197/files#diff-f1a2573c99264defd9491ef2d622ab48536e2bf6f9ccbc17a88838f174e25d6cR118. Nrepl middleware always feels a little awkward/ different from normal clojure code

seancorfield 2023-10-04T02:00:29.547969Z

Weird. Hopefully vemv will be more amenable to that tiny change 🙂

🙏 1
seancorfield 2023-10-04T02:00:50.387249Z

(I assume it doesn't work without that dynamic tweak)

djblue 2023-10-04T02:01:50.950459Z

Yeah, I tried using with-redefs, but no dice. Not sure what the control flow is for the middleware 🤔

djblue 2023-10-04T02:13:12.557399Z

https://github.com/djblue/portal/commit/522b6c6b62f32379831248d25dfb23715614d70a is my with-redefs attempt.

djblue 2023-10-02T19:35:46.468669Z

index 503149e..fc1381f 100644
--- a/src/portal/nrepl.clj
+++ b/src/portal/nrepl.clj
@@ -60,6 +60,7 @@
     (transport/recv transport timeout))
   (send [_this  msg]
     (transport/send transport msg)
+    (tap> [(:op handler-msg) msg])
     (when (and (seq (p/sessions)) (:file handler-msg))
       (when-let [out (:out msg)]
         (swap! (:stdio handler-msg) conj {:tag :out :val out}))
@@ -97,7 +98,7 @@
                          (test-report value))]
     (handler
      (cond-> msg
-       (= (:op msg) "eval")
+       (#{"test-var-query" "eval"} (:op msg))
        (-> (update :transport
                    ->PortalTransport
                    (assoc msg
This worked for me locally

djblue 2023-10-02T19:37:50.004279Z

I think capturing the test output might involve looking through https://github.com/clojure-emacs/cider-nrepl/blob/master/src/cider/nrepl/middleware/test.clj and figuring out how it's capturing the test output

djblue 2023-10-02T19:38:17.070119Z

["test-var-query"
 {"elapsed-time" {"ms" 3, "humanized" "Completed in 3 ms"},
  "gen-input" nil,
  "results"
  {"portal.runtime.npm-test"
   {"invalid-modules"
    ({"type" "pass",
      "message" "",
      "ns" "portal.runtime.npm-test",
      "var" "invalid-modules",
      "index" 0,
      "context" nil,
      "elapsed-time" {"ms" 1, "humanized" "Completed in 1 ms"}}),
    "valid-modules"
    ({"type" "pass",
      "message" "",
      "ns" "portal.runtime.npm-test",
      "var" "valid-modules",
      "index" 0,
      "context" nil}
     {"type" "pass",
      "message" "",
      "ns" "portal.runtime.npm-test",
      "var" "valid-modules",
      "index" 1,
      "context" nil}
     {"type" "pass",
      "message" "",
      "ns" "portal.runtime.npm-test",
      "var" "valid-modules",
      "index" 2,
      "context" nil})}},
  "summary" {"ns" 1, "var" 2, "test" 4, "pass" 4, "fail" 0, "error" 0},
  "ns-elapsed-time"
  {"portal.runtime.npm-test"
   {"ms" 3, "humanized" "Completed in 3 ms"}},
  :id "794",
  "var-elapsed-time"
  {"portal.runtime.npm-test"
   {"invalid-modules"
    {"elapsed-time" {"ms" 1, "humanized" "Completed in 1 ms"}},
    "valid-modules"
    {"elapsed-time" {"ms" 1, "humanized" "Completed in 1 ms"}}}},
  "testing-ns" "portal.runtime.npm-test",
  :session "74cf2aee-9375-4b48-a084-59184e2b76c2"}]
The test output from the nrepl op looks something like ☝️

djblue 2023-10-02T19:39:47.245219Z

Which isn't quite what portal is expecting, so we can't use it directly. Portal expects raw clojure.test/report data.

djblue 2023-10-02T19:41:21.681949Z

Ideally, the cider.nrepl.middleware.test middleware would re-proxy the test report messages so the portal.nrepl middleware could capture it directly without even knowing about it 🤔

seancorfield 2023-10-02T20:01:57.410259Z

Weirdly, I'm not even seeing the test-var-query op flowing through...

djblue 2023-10-02T20:03:19.689619Z

That's odd 🤔 Might be an ordering issues as well

djblue 2023-10-02T20:03:53.540569Z

I tested the proxy stuff and it works, gonna put up a PR in a bit

seancorfield 2023-10-02T20:07:15.374769Z

I tried to prep Portal and got this failure:

=> npm ci
npm ERR! Cannot read property '@fortawesome/fontawesome-svg-core' of undefined

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/sean/.npm/_logs/2023-10-02T20_06_39_635Z-debug.log
-> 0.290 seconds (exit: 1)
Execution error (ExceptionInfo) at tasks.tools/sh* (tools.clj:58).
Non-zero exit code: npm ci

seancorfield 2023-10-02T20:09:02.188389Z

Ah, looks like I needed to run npm install in the Portal project first -- you need to make that part of the prep-lib step I think?

seancorfield 2023-10-02T20:12:24.381889Z

Okay, my dynamic attempts at eval'ing nrepl.clj into a running setup didn't work, but having a properly-prepped local dep does work...

seancorfield 2023-10-02T20:21:09.875239Z

LMK if/how I can help/test this stuff...

seancorfield 2023-10-02T20:27:06.971089Z

For the workflow I have with my custom snippets, having the Portal m/w use "summary" as the "result" would be "sufficient" but I leave it up to you want would be "ideal" from your p.o.v. for test integration.

djblue 2023-10-02T20:34:31.700449Z

https://github.com/clojure-emacs/cider-nrepl/pull/822 is the change we need on the nrepl side

djblue 2023-10-02T20:36:15.163689Z

Will get the portal.nrepl side done later 👌

seancorfield 2023-10-02T21:14:29.610389Z

I suspect you might get pushback on that...?

seancorfield 2023-10-02T21:15:24.457499Z

(but it does seem reasonable -- a lot of test reporters seem to assume they're the only one in the game which makes them non-composable)

djblue 2023-10-02T21:17:37.603379Z

I think vemv is open to it

seancorfield 2023-10-02T21:18:54.182929Z

His response to the PR suggests otherwise but I've added an explanatory note to it 🙂

🙏 1
djblue 2023-10-02T21:19:57.477729Z

I think I took reasonable as meaning open to it 😂

seancorfield 2023-10-02T21:21:34.468919Z

It'll take a while for it to filter through into a usable version for Calva... I'll see what could be done on the Portal side to improve integration in the short term, if that's okay with you?

djblue 2023-10-02T21:23:17.598939Z

Since cider-nrepl is part of your repl classpath, I think you could pull it in via git deps 🤔

seancorfield 2023-10-02T21:24:12.701619Z

Calva adds the CIDER dep as part of jack-in.

djblue 2023-10-02T21:24:48.490529Z

Ohh, and jack-in is part of your workflow 👌 Does calva allow customizing middleware?

seancorfield 2023-10-02T21:25:42.615249Z

Actually, now I think about it... maybe I already have this customized locally...

seancorfield 2023-10-02T21:26:33.491589Z

...hmm I use an alias to bring in additional stuff but Calva supplies cider/nrepl...

djblue 2023-10-02T21:28:08.794499Z

Time to hit them with :override-deps 🔥

seancorfield 2023-10-02T21:38:11.879729Z

cider-nrepl relies on a bunch of Leiningen plugin weirdness for adding/inlining a whole bunch of deps so that just doesn't work: https://github.com/clojure-emacs/cider-nrepl/blob/master/project.clj#L10-L26

😭 1
seancorfield 2023-10-02T21:39:12.376299Z

(it uses mranderson to rename all those deps inline so you don't have conflicts -- and that's a lot of deps)

seancorfield 2023-10-02T22:11:10.110329Z

I added this to PortalTransport send:

(when-let [summary (when (= "test-var-query" (:op handler-msg))
                         (get msg "summary"))]
      (when-let [ns (first (keys (get msg "results")))]
        (tap> (assoc summary "ns" ns))))
which at least displays the test summary via tap> which is sufficient for my workflow for now... but it's ugly and doesn't match how the regular nREPL results get handled. But the benefit of Calva's integration with the test explorer are enough to make this subpar experience useful for now.