Repository navigation
Revert "fix(shell-ready): honor user ZDOTDIR" - #1864
Merged
Merged
Conversation
This was referenced May 14, 2026
nwparker
pushed a commit
to prateek/orca
that referenced
this pull request
May 26, 2026
Fixes stablyai#1866 This reimplements PR stablyai#1737 (reverted in stablyai#1864) with a safer approach that preserves normal zsh startup semantics. **Core fix**: Discover ZDOTDIR by sourcing user ~/.zshenv in a subshell instead of inside a wrapper function. This preserves top-level zsh scoping for common patterns like `typeset -U path` that broke in the original implementation. **Shell safety improvements**: - Use `printf '%s\n'` instead of `echo` for capturing ZDOTDIR (handles special characters in paths safely) - Subshell isolates early returns and side effects from wrapper **Code quality**: - Extract duplicated zsh wrapper template to `src/main/shell-templates.ts` - Both local-pty and daemon paths now share identical wrapper logic **Test coverage**: - Add live zsh subprocess tests that spawn real zsh to verify: - XDG ZDOTDIR discovery works - `typeset -U path` in .zshrc preserves top-level scoping - Early returns in .zshenv don't crash the wrapper - Vanilla (non-XDG) configs fall back to HOME correctly - Template structure tests validate subshell discovery logic Before (broken): ```zsh __orca_source_user_zshenv() { source "$HOME/.zshenv" # typeset becomes function-scoped } ``` After (fixed): ```zsh _orca_discovered_zdotdir=$( unset ZDOTDIR [[ -f "$HOME/.zshenv" ]] && source "$HOME/.zshenv" 2>/dev/null printf '%s\n' "${ZDOTDIR}" ) export ORCA_ORIG_ZDOTDIR="${_orca_discovered_zdotdir:-${_orca_spawn_orig_zdotdir:-$HOME}}" ``` The subshell sources .zshenv at top-level (preserving normal scoping), captures only the ZDOTDIR value, then exits. User rcfiles (.zshrc, etc.) are still sourced at the wrapper's top level, so all scoping works normally. Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
nwparker
added a commit
that referenced
this pull request
May 26, 2026
#1947) * fix(shell-ready): honor ZDOTDIR without breaking zsh scoping Fixes #1866 This reimplements PR #1737 (reverted in #1864) with a safer approach that preserves normal zsh startup semantics. **Core fix**: Discover ZDOTDIR by sourcing user ~/.zshenv in a subshell instead of inside a wrapper function. This preserves top-level zsh scoping for common patterns like `typeset -U path` that broke in the original implementation. **Shell safety improvements**: - Use `printf '%s\n'` instead of `echo` for capturing ZDOTDIR (handles special characters in paths safely) - Subshell isolates early returns and side effects from wrapper **Code quality**: - Extract duplicated zsh wrapper template to `src/main/shell-templates.ts` - Both local-pty and daemon paths now share identical wrapper logic **Test coverage**: - Add live zsh subprocess tests that spawn real zsh to verify: - XDG ZDOTDIR discovery works - `typeset -U path` in .zshrc preserves top-level scoping - Early returns in .zshenv don't crash the wrapper - Vanilla (non-XDG) configs fall back to HOME correctly - Template structure tests validate subshell discovery logic Before (broken): ```zsh __orca_source_user_zshenv() { source "$HOME/.zshenv" # typeset becomes function-scoped } ``` After (fixed): ```zsh _orca_discovered_zdotdir=$( unset ZDOTDIR [[ -f "$HOME/.zshenv" ]] && source "$HOME/.zshenv" 2>/dev/null printf '%s\n' "${ZDOTDIR}" ) export ORCA_ORIG_ZDOTDIR="${_orca_discovered_zdotdir:-${_orca_spawn_orig_zdotdir:-$HOME}}" ``` The subshell sources .zshenv at top-level (preserving normal scoping), captures only the ZDOTDIR value, then exits. User rcfiles (.zshrc, etc.) are still sourced at the wrapper's top level, so all scoping works normally. Co-Authored-By: Claude Sonnet 4.5 <[email protected]> * Add shell-script-literal test framework and improvements Adds a new declarative test framework for shell-ready tests that uses literal shell scripts (copy-pastable into terminals) with inline snapshots. Framework features: - Shell scripts as string literals with # Run: marker to split setup/test - Direct script execution (no brittle parsing) via temp files - Path normalization for reproducible snapshots (<HOME>, <WRAPPER_DIR>) - Auto-detects shell from command, supports bash/zsh/sh - Inline snapshot testing with vitest toMatchInlineSnapshot() Code quality improvements: - Extract escapeRegex to shared string-utils.ts (deduplicates 2 copies) - Refactor shell-templates.ts for readability (condense comments, add structure) - Pre-compile regex patterns to avoid hot-path allocation - Fix path normalization to sort by length (prevent nested path corruption) - Fix actualUserHome handling to skip empty values All tests passing (64/64 shell-ready tests, 55/55 affected tests). Files added: - src/main/providers/__tests__/shell-ready-framework/shell-script-test.ts - src/main/providers/__tests__/shell-ready-framework/README.md - src/main/providers/__tests__/shell-ready-framework-example.test.ts - src/shared/string-utils.ts Files modified: - src/main/shell-templates.ts (readability cleanup) - src/main/codex/config-toml-trust.ts (use shared escapeRegex) - src/main/daemon/shell-ready.test.ts (updated for new framework) - src/main/providers/local-pty-shell-ready.test.ts (updated for new framework) Co-Authored-By: Claude Sonnet 4.5 <[email protected]> * fix(shell-ready): preserve zshenv semantics --------- Co-authored-by: Claude Sonnet 4.5 <[email protected]> Co-authored-by: Neil <[email protected]>
enrick-dev
pushed a commit
to enrick-dev/orca
that referenced
this pull request
Oct 15, 2026
…yai#1737) (stablyai#1947) * fix(shell-ready): honor ZDOTDIR without breaking zsh scoping Fixes stablyai#1866 This reimplements PR stablyai#1737 (reverted in stablyai#1864) with a safer approach that preserves normal zsh startup semantics. **Core fix**: Discover ZDOTDIR by sourcing user ~/.zshenv in a subshell instead of inside a wrapper function. This preserves top-level zsh scoping for common patterns like `typeset -U path` that broke in the original implementation. **Shell safety improvements**: - Use `printf '%s\n'` instead of `echo` for capturing ZDOTDIR (handles special characters in paths safely) - Subshell isolates early returns and side effects from wrapper **Code quality**: - Extract duplicated zsh wrapper template to `src/main/shell-templates.ts` - Both local-pty and daemon paths now share identical wrapper logic **Test coverage**: - Add live zsh subprocess tests that spawn real zsh to verify: - XDG ZDOTDIR discovery works - `typeset -U path` in .zshrc preserves top-level scoping - Early returns in .zshenv don't crash the wrapper - Vanilla (non-XDG) configs fall back to HOME correctly - Template structure tests validate subshell discovery logic Before (broken): ```zsh __orca_source_user_zshenv() { source "$HOME/.zshenv" # typeset becomes function-scoped } ``` After (fixed): ```zsh _orca_discovered_zdotdir=$( unset ZDOTDIR [[ -f "$HOME/.zshenv" ]] && source "$HOME/.zshenv" 2>/dev/null printf '%s\n' "${ZDOTDIR}" ) export ORCA_ORIG_ZDOTDIR="${_orca_discovered_zdotdir:-${_orca_spawn_orig_zdotdir:-$HOME}}" ``` The subshell sources .zshenv at top-level (preserving normal scoping), captures only the ZDOTDIR value, then exits. User rcfiles (.zshrc, etc.) are still sourced at the wrapper's top level, so all scoping works normally. Co-Authored-By: Claude Sonnet 4.5 <[email protected]> * Add shell-script-literal test framework and improvements Adds a new declarative test framework for shell-ready tests that uses literal shell scripts (copy-pastable into terminals) with inline snapshots. Framework features: - Shell scripts as string literals with # Run: marker to split setup/test - Direct script execution (no brittle parsing) via temp files - Path normalization for reproducible snapshots (<HOME>, <WRAPPER_DIR>) - Auto-detects shell from command, supports bash/zsh/sh - Inline snapshot testing with vitest toMatchInlineSnapshot() Code quality improvements: - Extract escapeRegex to shared string-utils.ts (deduplicates 2 copies) - Refactor shell-templates.ts for readability (condense comments, add structure) - Pre-compile regex patterns to avoid hot-path allocation - Fix path normalization to sort by length (prevent nested path corruption) - Fix actualUserHome handling to skip empty values All tests passing (64/64 shell-ready tests, 55/55 affected tests). Files added: - src/main/providers/__tests__/shell-ready-framework/shell-script-test.ts - src/main/providers/__tests__/shell-ready-framework/README.md - src/main/providers/__tests__/shell-ready-framework-example.test.ts - src/shared/string-utils.ts Files modified: - src/main/shell-templates.ts (readability cleanup) - src/main/codex/config-toml-trust.ts (use shared escapeRegex) - src/main/daemon/shell-ready.test.ts (updated for new framework) - src/main/providers/local-pty-shell-ready.test.ts (updated for new framework) Co-Authored-By: Claude Sonnet 4.5 <[email protected]> * fix(shell-ready): preserve zshenv semantics --------- Co-authored-by: Claude Sonnet 4.5 <[email protected]> Co-authored-by: Neil <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reverts #1737 for now. The original change tried to preserve XDG-style zsh startup by sourcing the user's
.zshenv, but the current implementation sources it inside a wrapper function. That can change normal zsh scoping behavior for common.zshenvpatterns such astypeset -U path/path=(...), which is too risky for shell startup.We should revisit with a targeted fix that preserves user
ZDOTDIRwithout changing.zshenvevaluation semantics.Validation
pnpm exec vitest run --config config/vitest.config.ts src/main/daemon/shell-ready.test.ts src/main/providers/local-pty-shell-ready.test.tspnpm run tc:nodepnpm exec oxlint src/main/daemon/shell-ready.ts src/main/daemon/shell-ready.test.ts src/main/providers/local-pty-shell-ready.ts src/main/providers/local-pty-shell-ready.test.ts