Skip to content

Pass dir to dev when activating from subdir (fix #51)#61

Open
gaggle wants to merge 4 commits intopkgxdev:mainfrom
gaggle:pass-dir-to-dev-when-activating-from-subdir
Open

Pass dir to dev when activating from subdir (fix #51)#61
gaggle wants to merge 4 commits intopkgxdev:mainfrom
gaggle:pass-dir-to-dev-when-activating-from-subdir

Conversation

@gaggle
Copy link
Copy Markdown
Contributor

@gaggle gaggle commented May 7, 2026

Summary

  • What changed: Fixed pkgxdev/dev#51: cd-ing directly into a subdirectory of an already-activated devenv failed to activate it and emitted (eval):1: permission denied: <dir>. Also refactored shellcode() / datadir() to take an explicit env parameter (defaulted to Deno.env.toObject()) to support an integration test that drives the chpwd hook through a real zsh subprocess.
  • Why: The chpwd hook walked up $PWD to find an activation marker, then invoked dev with no arguments, causing dev to sniff $PWD (the subdirectory, with no keyfiles) instead of the activated parent dir. dev exited 1 with empty stdout, and the dir intended for dev was passed to eval as a positional arg, which the shell tried to execute as a command.

AI Intent

  • Prompt or task statement: Reproduce issue Error output when cd'ing into dev'd folder where path contains & #51 from a fresh terminal log, localize the bug in src/shellcode().ts, write a failing test first (TDD), then ship the fix as atomic commits following the repo's existing commit-message style.
  • Scope of AI-assisted changes: Commits are AI-assisted. Author reviewed each change before commit and requested the refactor to take an explicit env parameter to simplify testing.

Risk Assessment

  • Risk level: low
  • Primary risks: shellcode() output is eval'd in user shells, so a regression here would break shell init for anyone running dev integrate. Mitigated by the new end-to-end zsh integration test.
  • Compatibility impact: None. shellcode() and datadir() keep their old zero-arg call signatures via default parameters; app.ts callers are unchanged. The shell-side change is one token ("$dir" moved inside the command substitution); dev <path> was already supported by app.ts's default branch.

Rollback Plan

  • Revert path: git revert the commits. The shellcode is regenerated each shell session via eval "$(dev --shellcode)", so reverting + reinstalling will restore prior behavior for users.

Validation

  • Local checks run:
    • deno fmt --check .
    • deno lint .
    • deno check
    • deno test --allow-read --allow-write --allow-env --allow-run=bash
    • Manual reproducer (described in the issue) confirmed fixed.
  • CI checks expected: existing Deno/format/lint/test workflow passing

Internal/Public Boundary Check

  • No internal-only data, private URLs, secrets, or private runbooks were added.

gaggle added 4 commits May 7, 2026 02:41
The `chpwd` hook walks up from `$PWD` looking for an activation marker,
but when it found one in a parent dir it invoked `dev` with no arguments,
making `dev` sniff `$PWD` (the subdir, with no keyfiles) instead of the
activated dir. `dev` exited with "no devenv detected" and empty stdout,
and the dir intended for `dev` got passed to eval as a positional arg
instead, which the shell tried to execute, producing "permission
denied: <dir>" on `cd`.

This change moves "$dir" inside the command substitution, so `dev`
sniffs the activated directory.

This also adds an integration test that drives `zsh` end-to-end with a
fake `dev` on PATH to verify the hook invokes `dev` with the activated
dir as argv[1] and produces no permission-denied error.
shellcode() and datadir() read PATH and XDG_DATA_HOME from Deno.env
implicitly at codegen time, which made the integration test for issue
pkgxdev#51 noisy: it had to mutate process env, save originals, and restore
them so the generated shellcode would point at the test's temp dirs.

This change makes env an explicit parameter (defaulting to
Deno.env.toObject()) so production callers in app.ts stay unchanged,
but tests can pass a clean env per-invocation. Test drops from 130
to 68 lines, without all the save/restore ceremony.
CI Ubuntu runners ship without zsh, so the integration test failed
with `NotFound: Failed to spawn 'zsh'`. This changes the new test
to rely on bash.
The new chpwd-hook integration test spawns a bash subprocess to drive
the generated shellcode end-to-end, so --allow-run` is required.
This change also updates AGENTS.md's documented test command to match
the change in ci.yml.

Scoped to bash so the test suite cannot spawn arbitrary executables.
@gaggle gaggle force-pushed the pass-dir-to-dev-when-activating-from-subdir branch from a3a1bb7 to 0b959fd Compare May 7, 2026 01:25
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.

Error output when cd'ing into dev'd folder where path contains &

1 participant