Skip to content

chore(ci): run the activation scripts in sh, dash, bash, zsh and fish - #397

Merged
ekalinin merged 17 commits into
masterfrom
chore/ci-activate-shells
Sep 17, 2026
Merged

ekalinin merged 17 commits into
masterfrom
chore/ci-activate-shells

Conversation

@ekalinin

Copy link
Copy Markdown
Owner

Problem

The generated activation scripts are never executed by any test or CI job.
tests/test_install_activate.py compares the generated text against the
templates in nodeenv.py; the only exception is
test_isolate_npm_sh_sets_and_restores, which runs sh -c '. activate && ...'.
zsh and fish are never run at all.

b042056 ("fix(nodeenv): guard fish npm config restore") is what that costs:
a logic error in activate.fish that text assertions cannot catch.

What this adds

tests/test_activate_shells.py actually runs the generated scripts in sh,
dash, bash, zsh and fish, and asserts on the environment they produce:
activation sets PATH / NODE_PATH / NPM_CONFIG_PREFIX, deactivation
restores it, repeated cycles do not grow PATH, --isolate-npm round-trips,
and the prompt override applies and is undone.

A table of Shell objects is the only place that knows per-shell syntax.
Rather than echoing variables inside each shell, the harness sources the
script and then execs a small Python dumper as a child process, so exported
values come back normalised - fish stores PATH as a list but exports it
colon-joined. The environment is a stub built in tmpdir with a fake
bin/node: no network, no Node.js download. The whole job runs in under four
seconds.

A new activate-shells job on ubuntu-latest installs zsh and fish and runs
the module with NODEENV_REQUIRE_SHELLS=1, which turns a missing shell into a
hard failure instead of a silent skip. Without it the job would go green if
apt-get quietly failed, and the check would be theatre. Locally, a shell you
do not have installed is simply skipped.

Three bugs this found

Each is marked xfail(strict=True), so the marker must be removed when the
bug is fixed or the suite fails. Fixes go on their own branches, one concern
per branch.

  1. zsh cannot source bin/activate. 68abdc3 (FEAT: Check if activate is called as script. #384) added
    case $0 in */bin/activate ) ... exit 1. zsh sets $0 to the sourced
    file's path (FUNCTION_ARGZERO), so the guard fires on
    source env/bin/activate and activation aborts with rc=1. Confirmed by
    disarming the guard: all ten marked zsh parameters flip to XPASS(strict).

  2. activate.fish erases a pre-existing NODE_PATH. The
    deactivate_node nondestructive pass near the top runs before the
    activation code saves _OLD_NODE_PATH, and the NODE_PATH branch of
    deactivate_node has no if set -q NODE_VIRTUAL_ENV guard, so its else
    arm does set -e NODE_PATH. b042056 added that guard for the npm
    variables only; NPM_CONFIG_PREFIX and npm_config_prefix have the same
    problem, currently masked by assertion order.

  3. activate.fish leaves a literal ^/dev/null in PATH. fish 3.0
    turned on stderr-nocaret, so the trailing ^/dev/null on the PATH line
    is no longer a redirect and lands in PATH as an entry. The same line's
    comment is also defeated: the warning it meant to suppress now reaches
    stderr.

Scope

Tests and CI only. nodeenv.py is not modified. Windows scripts
(activate.bat, Activate.ps1) and macOS runners are out of scope and can
follow separately.

Verification

activate-shells on CI: 46 passed, 14 xfailed, zero skipped - all five
shells really ran. Full matrix green on ubuntu, macOS and Windows.

pytest turns any failure raised inside an xfail-marked test into an
expected failure, so pytest.fail() from _binary() was indistinguishable
from the known zsh and fish bugs and NODEENV_REQUIRE_SHELLS=1 could not
keep the job red.  Check the shells once at import instead.
run() and _fish_prompt_output() built the same subprocess call, and
neither set cwd, so the shells ran in the git work tree: fish's stock
prompt appends the vcs ref, and relative paths resolved against the
checkout.  Both now go through _launch(), which runs in env.home.

The dumper also prints a sentinel first, so stray output from an
activation script gives a readable assertion instead of a bare
ValueError from the key=value parser.
Only the first two entries were checked, and the deactivation test
compares against the wholesale-restored _OLD_NODE_VIRTUAL_PATH, so
nothing an activation script appended to PATH was observable.  Compare
the activated PATH against the unactivated one with the two environment
entries prepended.
NODE_VIRTUAL_ENV_DISABLE_PROMPT disables exactly what
test_prompt_override asserts, so a developer who exports it saw the
prompt tests fail; BASH_ENV lets `bash -c` source arbitrary setup.
The FISH_NODE_PATH_CLOBBER reason named NODE_PATH only, although the
same nondestructive pass leaves NPM_CONFIG_PREFIX and npm_config_prefix
unrestored as well.  The NODE_PATH comment described the post-fix
behaviour, not today's.
Match the "Added ..." wording the other unreleased entries use.
CI proved the whole-PATH assertion right: fish 3.0 turned on
stderr-nocaret, so the `^/dev/null` at the end of the PATH line in
activate.fish is no longer a redirect and ends up in PATH as a literal
entry.  Marked like the other two known nodeenv bugs; the fix goes on
its own branch.
pytestmark is applied after the module is imported, so the
NODEENV_REQUIRE_SHELLS guard would abort collection on Windows before
the POSIX-only skip could take effect.

Also reworded the _launch docstring: every path handed to the shells is
absolute, so pinning cwd buys determinism and keeps fish's vcs prompt
out, not relative path resolution.
@ekalinin

Copy link
Copy Markdown
Owner Author

Filed the three bugs this branch found, so the xfail(strict=True) markers
have something to point at:

Each gets its own fix/ branch. The markers are strict, so whichever fix
lands first will fail the suite until its marker is removed.

@ekalinin
ekalinin merged commit 6cc63ab into master Sep 17, 2026
40 checks passed
ekalinin added a commit that referenced this pull request Sep 18, 2026
#397 added activate-shells and this branch added integration; git saw
overlapping adds in the same gap of tests.yml and interleaved them into
one job. Both are kept, each with its own steps and command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant