Repository navigation
runtime: preserve $0 while sourcing files - #771
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fa9b3dc157
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0268ca29c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Summary
Fix sourced-file
$0handling so gbash preserves the shell invocation name whileBASH_SOURCE[0]tracks the sourced file.Root cause
While a sourced file was running, gbash resolved
$0from the current parse filename instead of a stable shell argv0. That made guards like[[ "${BASH_SOURCE[0]}" == "${0}" ]]flip the wrong way undersource, which caused the vendored Harness bootstrap to think it was being executed directly.What changed
Arg0field and seed it from execution context$0from the stable arg0 instead of the current source filenameValidation
go test ./internal/runtime -run 'TestExecInlineSourcePreservesArg0WhileUpdatingBashSource|TestExecScriptPathSourcePreservesTopLevelArg0|TestExecInlineSourceGuardReportsSourced|TestExecInlineSourceTracksCallLinesWithoutPseudoFrames|TestExecScriptPathSetsBashIntrospection|TestExecNameOnlyLeavesBashSourceUnset'go test ./internal/shell/interp -run 'TestPositionalZeroDefaultsToGBash'timeout 8s go run ./contrib/extras/cmd/gbash-extras --root /Users/ewhauser/.codex/worktrees/bb68/gbash/examples/harness-overlay/workspace --cwd /home/agent/project -c 'set -x; source ./bin/harness; echo after-source'Notes
examples/harness-overlayis not present onmain, so the example-side bug note update was intentionally not included in this PR.gbash-extras -s < <(...)stdin/process-substitution timeout is still reproducible for trivial stdin scripts and is not part of this fix.