Skip to content

Fix auto-venv compatibility with nushell 0.108#1252

Open
hyiltiz wants to merge 5 commits into
nushell:mainfrom
hyiltiz:fix/auto-venv-0.108-compat
Open

Fix auto-venv compatibility with nushell 0.108#1252
hyiltiz wants to merge 5 commits into
nushell:mainfrom
hyiltiz:fix/auto-venv-0.108-compat

Conversation

@hyiltiz
Copy link
Copy Markdown
Contributor

@hyiltiz hyiltiz commented May 8, 2026

Summary

auto-venv is broken on nushell 0.108 due to several API changes in the
engine. This PR fixes all the issues needed to make it functional again.

Fixes:

  • default-hooks wrapped the existing PWD hooks list in another list,
    producing an invalid list<list<closure>> type that corrupted hook
    evaluation (and broke tab completion as a side effect)

  • on_enter used transient cd to resolve overlay use relative to
    PWD; nushell 0.108 resolves overlay use at parse time only, so
    this no longer works — removed in favor of NU_LIB_DIRS resolution

  • on_exit crashed when the overlay was not active (e.g. activation
    failed due to missing .venv)

  • venv-is-active checked all overlays including inactive ones;
    overlay list in 0.108 includes inactive entries

  • path find-sub returned [] instead of null on no match, causing
    type errors in downstream path join calls; also changed to return
    the deepest ancestor match rather than shallowest, which is the
    expected behavior for nested project directories

Test plan

  • cd into a directory with .__auto-venv.nu trigger + .venv/ → venv activates
  • cd out → venv deactivates without error
  • cd into a directory with trigger but no .venv/ → no crash
  • Tab completion (cd <TAB>) works after the hooks are registered
  • Existing PWD hooks (mise, zoxide, etc.) still fire correctly

- default-hooks: don't wrap existing hooks list in another list;
  this produced an invalid nested type that broke hook evaluation
  and downstream tab completion

- on_enter: remove transient cd operations that triggered spurious
  hook evaluations; overlay use now resolves via NU_LIB_DIRS instead
  of runtime PWD (which nushell 0.108 no longer supports for
  dynamically evaluated code)

- on_enter: guard against missing trigger file

- on_exit: guard overlay hide against inactive overlay

- venv_helpers: filter overlay list to active overlays only
  (overlay list now includes inactive entries in 0.108)

- path_extensions: return null instead of [] on no match to prevent
  type errors in downstream path join calls; return deepest ancestor
  match rather than shallowest
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 8, 2026

If we fix it for v0.108.0 it may not work with the latest version v0.112.2. So, I'd ask you to test your changes on the latest version to see if these changes work. I don't want to patch for a 7 month old version.

@hyiltiz
Copy link
Copy Markdown
Contributor Author

hyiltiz commented May 9, 2026

Hmm, valid. I just fixed for the version I was running. Let me build remote/main:HEAD and test it there. BTW, we could add a Github Actions so we'd know when this breaks next time... Any interest in that?

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 9, 2026

It already runs toolkit check pr in CI. If that's not good enough feel free to investigate further what would help.

hyiltiz added 4 commits May 10, 2026 18:10
Tests cover path resolution, hook registration, overlay
loading, and condition logic. CI runs on ubuntu and macos
using the latest nushell release via hustcer/setup-nu.
default-hooks now uses $env.config? with get -o to avoid
column-not-found errors when running under nu-check without
a config file. Updated setup-nu action to v3.23 and use
working-directory instead of shell:nu cd workaround.
- Export main in test file so toolkit uses `use` resolution
  (relative to file dir) instead of `source` (fails from repo root)
- Match setup-nu version to existing CI (v3.9)
macos-latest (arm64) fails in setup-nu; pin to macos-13
for now. Explicit shell:bash ensures nu is found on PATH.
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented May 11, 2026

I definitely don't want to have a CI yaml just to test auto-venv. If you want to make changes you should CI how to integrate the existing toolkit check pr so it runs your test.

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.

2 participants