Skip to content

jack-in: TRAMP fixes, runtime defaults, tests, docs#3885

Merged
bbatsov merged 7 commits into
masterfrom
jack-in-tramp-and-tests
Apr 28, 2026
Merged

jack-in: TRAMP fixes, runtime defaults, tests, docs#3885
bbatsov merged 7 commits into
masterfrom
jack-in-tramp-and-tests

Conversation

@bbatsov
Copy link
Copy Markdown
Member

@bbatsov bbatsov commented Apr 28, 2026

Final round of cleanup after #3883 (entry-point unification) and #3884 (registry refactor).

TRAMP / robustness

  • cider-locate-running-nrepl-ports now drives its ps/lsof probes through process-file, so endpoint completion for cider-connect queries the remote host when called from a TRAMP buffer instead of always scraping the local machine. Same change for the lsof health check on .nrepl-port files in nrepl-client.el.
  • cider-clojure-cli-command and cider-jack-in-default no longer freeze their auto-detection at package load. Both default to nil now, with the auto-detect logic running at jack-in time. Installing Clojure later, or putting it on PATH, doesn't require restarting Emacs. The clojure-cli tool spec gets the fallback via a new :default-command-fn registry key.
  • cider--update-project-dir stops reusing a single shared *cider-context-buffer*. Each invocation creates a unique hidden buffer, so concurrent or interrupted jack-ins don't corrupt each other's state.
  • nrepl-server-filter's host fallback now treats wildcard/loopback addresses (localhost, 127.0.0.1, 0.0.0.0, ::1, ::) printed by the server as "use the calling context", so a jack-in over TRAMP to e.g. babashka -- which announces localhost -- connects to the TRAMP host instead of the local machine. Explicit non-loopback hosts in the server's output are still honored as-is.

Tests

  • New Buttercup specs for the registry: built-in tools have the expected keys, cider-register-jack-in-tool add/replace semantics, the no-op injectors (babashka, nbb, basilisp), shadow-cljs -d injection, cider-jack-in-universal prefix-arg dispatch (clj, cljs, unknown arg, completing-read fallback), and cider--identify-buildtools-present iterating the registry.
  • Killed the FIXME at cider-tests.el:191: the existing jack-in describe blocks were using setq-local to override dynamic vars, which leaked into later specs. Replaced with plain setq and extended each block's :var list so Buttercup's per-spec rebinding actually scopes them.

Docs

  • Rewrote the Universal jack-in section to describe cider-jack-in-tools and cider-register-jack-in-tool (the variable from Introduce a jack-in tool registry #3884 replaced cider-jack-in-universal-options).
  • New "Overriding the jack-in command per buffer" subsection covering cider-jack-in-cmd -- the right escape hatch for containers/TRAMP/wrapper scripts.
  • New "Known TRAMP caveats" subsection: executable resolution, endpoint discovery, loopback bind addresses, cross-OS quoting.
  • Fixed a stale claim about cider-jack-in-default defaulting to clj.
  • cider-enable-nrepl-jvmti-agent docstring now spells out the Java 21 eval-interrupt context.

Verified

  • eldev compile clean.
  • eldev test: 519/522 specs pass, 0 failures, 3 skipped (platform/version-gated; same as master).

bbatsov added 7 commits April 28, 2026 08:25
`cider-locate-running-nrepl-ports' previously scraped the local machine
even when called from a TRAMP buffer, because its `ps' and `lsof' probes
went through `shell-command-to-string'. Switch them to `process-file' so
they honor `default-directory' and inspect the host the user is actually
on. Same fix for the `lsof' health check on `.nrepl-port' files in
`nrepl--port-from-file'.

Adds two small helpers, `cider--shell-command-to-string' and
`cider--process-file-to-string', plus `cider--lsof-fn-field' to dedupe
the per-PID lsof parsing.
When jacking in over TRAMP to a server that announces a wildcard or
loopback bind address (e.g. babashka prints `localhost'), CIDER's host
fallback was taking the printed host first, causing connections to land
on the local machine.

Detect wildcard/loopback addresses ("localhost", "127.0.0.1", "0.0.0.0",
"::1", "::") and prefer the TRAMP host when present.  Explicit non-
loopback hosts in the server's output are still honored as-is.
`cider-clojure-cli-command' and `cider-jack-in-default' both ran
`executable-find' at defcustom evaluation time, so the auto-detected
result was frozen at package load.  A user who installed Clojure later,
or whose PATH changed, had to restart Emacs to get the right default.

Make both default to nil and resolve lazily at jack-in time.  The
clojure-cli tool spec picks up the Windows fallback via a new
`:default-command-fn' registry key, evaluated by a small
`cider--jack-in-tool-command' helper that the dispatchers share.
`cider-project-type' now goes through `cider--effective-jack-in-default'
for the same lazy detection.

Updates the corresponding `cider-project-type' specs to assert both the
explicit-override and auto-detect paths.
`cider--update-project-dir' was reusing one fixed-name hidden buffer
(\" *cider-context-buffer*\") across all invocations, killing whatever
content was there at the start of each call.  Two interleaved or
interrupted jack-ins could corrupt each other's context (dir-local
variables, transferred buffer-locals).

Use `generate-new-buffer' for a unique name per invocation.  The
buffers are hidden and small; we let Emacs reclaim them once no longer
referenced.
Cover the registry-driven dispatch that landed in #3884:

- Each built-in tool has the expected :command-var, :params-var, and
  :project-files keys.
- `cider--jack-in-tool' signals user-error for an unknown project type.
- `cider-register-jack-in-tool' adds and replaces entries.
- `cider-inject-jack-in-dependencies' is a no-op for babashka, nbb,
  basilisp, and prepends -d flags for shadow-cljs.
- `cider-jack-in-universal' dispatches by :universal-prefix-arg to the
  right entry point (clj vs cljs), errors on unknown args, and falls
  back to `completing-read' when called with nil outside a project.
- `cider--identify-buildtools-present' iterates the registry's
  :project-files entries.
Several before-each blocks in cider-tests.el used `setq-local' on
dynamic vars that were not in their describe's `:var' list.  Buttercup's
per-spec rebinding only covers `:var', so the buffer-local writes
survived past the `it' boundary and silently weakened later assertions.
This is the FIXME at the former line 191.

Replace `setq-local' with plain `setq' inside those before-each blocks
and extend each describe's `:var' to cover every var being rebound.
The two remaining `setq-local' calls (in the shadow-cljs-init-form
spec) are inside `with-temp-buffer' and are scoped correctly.
- Rewrite the universal jack-in section in up_and_running.adoc to
  describe `cider-jack-in-tools' and `cider-register-jack-in-tool'
  (`cider-jack-in-universal-options' is gone since #3884).
- New "Overriding the jack-in command per buffer" subsection covering
  `cider-jack-in-cmd' as the right escape hatch for containers, TRAMP,
  and wrapper scripts.
- New "Known TRAMP caveats" subsection: executable resolution, endpoint
  discovery, loopback bind addresses, cross-OS quoting.
- Fix a stale claim that `cider-jack-in-default' defaults to `clj'.
- `cider-enable-nrepl-jvmti-agent' docstring now spells out the Java 21
  eval-interrupt context that motivates it.
- CHANGELOG entries for the TRAMP and runtime-default bug fixes from
  the preceding commits.
@bbatsov bbatsov force-pushed the jack-in-tramp-and-tests branch from 94e500c to 0ef9253 Compare April 28, 2026 08:32
@bbatsov bbatsov merged commit 1fffd94 into master Apr 28, 2026
13 checks passed
@bbatsov bbatsov deleted the jack-in-tramp-and-tests branch April 29, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant