Fix zsh alias quoting in sourced shell snapshots (#48187)

## Why

Sourced snapshots parse options and aliases as a group before restored options take effect. Aliases serialized with `RC_QUOTES` enabled can therefore be misinterpreted by the replay shell.

## What changed

Serialize zsh aliases for sourced snapshots with `NO_RC_QUOTES` in a subshell, preserving the captured shell options and avoiding a dependency on the optional `zsh/parameter` module.

## Testing

Extend regression coverage to execute restored aliases with `RC_QUOTES` enabled and disabled across source and eval replay. Expand macOS zsh concurrent replay tests to cover quoted aliases, preserved options, and blocked descriptor paths with and without a TTY.

GitOrigin-RevId: 48086f380c21318bece9226dfe6486c179c2a440
This commit is contained in:
jif
2026-09-25 19:43:06 +00:00
committed by copyberry
parent 1d804e91b7
commit 8f0b05910e
3 changed files with 63 additions and 15 deletions
@@ -88,6 +88,13 @@ fn capture_script(
script
.replace("SNAPSHOT_OPTIONS_BEGIN", match replay { Replay::Eval => "", Replay::Source => "printf '{\\n'" })
.replace("SNAPSHOT_ALIASES_END", match replay { Replay::Eval => "", Replay::Source => "printf \"case '' in '') ;; esac\\n}\\n\"" })
// The source group is parsed before its options take effect. Serialize
// aliases with the replay shell's initial quoting rules, not RC_QUOTES.
// setopt works without the optional zsh/parameter module.
.replace("SNAPSHOT_ZSH_ALIASES", match replay {
Replay::Eval => "\\alias -L",
Replay::Source => "(\\setopt NO_RC_QUOTES; \\alias -L)",
})
.replace("SNAPSHOT_EXPORTS", &declarations)
.replace(
"SNAPSHOT_DECLARATION_ENVIRONMENT",
@@ -133,7 +140,7 @@ print ''
printf '\0'
alias_count=$(\alias -L | __codex_snapshot_command wc -l | __codex_snapshot_command tr -d ' ')
print "# aliases $alias_count"
\alias -L
SNAPSHOT_ZSH_ALIASES
print ''
SNAPSHOT_ALIASES_END
printf '\0'