fix(interpreter): restore working directory after pipeline stages - #430
josephbajor wants to merge 1 commit into
Conversation
|
@josephbajor is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
🤖 auto-maintain reviewAutomated, advisory triage for
Review panel: 🟡 medium highest severity just-bash maintainer code review: 🟡 medium
General code review: 🟡 medium
Adversarial security: 🟡 medium
Adversarial security (second opinion): 🟡 medium
Standard Bash and host portability: 🟡 medium
Posted by auto-maintain. This automated code review is advisory; a human maintainer makes the call. |
cdin a pipeline currently restores$PWDbut leaves the interpreter's actual working directory changed. Later pipeline stages and subsequent relative reads/writes therefore use the wrong directory, even though$PWDstill reports the parent.Reproduced against upstream
mainat062ce005c0a7676163852fb6f0c8590cbdaa1d45(just-bash 3.4.2).Reproduce
From the repository root, after
pnpm install --frozen-lockfile, run this on the base branch and then this branch.dev:execruns the commands in the virtual filesystem; it does not create/workon the host.Current upstream reports:
With this fix (and in real Bash), stdout is:
cd child | cat marker.txtalso currently reads the child's file in the second stage; it should read the parent's file. A relative write after the pipeline is similarly redirected to the child directory.Change
Save
ctx.state.cwdbefore each pipeline stage and restore it with the existing environment/array snapshots infinally. This also restores cwd when a stage throws, and removes the duplicated error-path restoration. The existing subshell decision remains unchanged: a single command or brace group can still change cwd, and the final pipeline stage can still do so withshopt -s lastpipe.Only TypeScript source, tests, recorded Bash fixtures, and a changeset are changed. No compiled bundles are edited or committed.
Verify
pnpm --filter just-bash test:unit src/interpreter/pipeline-cwd.test.ts pnpm --filter just-bash test:comparison src/comparison-tests/pipeline-cwd.comparison.test.ts # Optional: record the comparison cases against the machine's real Bash RECORD_FIXTURES=1 pnpm --filter just-bash test:comparison src/comparison-tests/pipeline-cwd.comparison.test.tsThe 12 unit cases cover first/middle/final stages, relative reads/writes, nested pipelines, explicit exit, unhandled errors, single commands, and lastpipe. Nine fail on the unmodified source. Seven recorded comparisons establish real Bash behavior.
Validation on Node 24.10.0 / macOS:
test:run: 15,629 passed, 98 skipped, 6 failed. The same six filesystem symlink/special-mode tests fail on unmodified062ce005in this environment (four existing files undersrc/fs/); they are unrelated to pipeline execution.