Repository navigation
fix(sudo): keep line endings when replaying captured command output - #49
Merged
Merged
Conversation
_gos_sudo_for_target captures a command's stdout and stderr with command substitution, which strips trailing newlines, then replayed them with printf '%s'. The next progress or error line was glued onto the command's last line, e.g. "mv: ...: Permission deniedError: ..." or "sudo mv ... go.gos-backup.1234Activating go from ..." (which is also why tests/install-transaction.bash failed when run as root). Replay each non-empty stream with its line ending through one helper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ExmnfUngrDYjAheGvYwMnn
This was referenced Oct 6, 2026
…endings # Conflicts: # CHANGELOG.md
- add a first-try success case with stdout and stderr to the replay regression - describe the fix as covering every replay path, not only retries Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ExmnfUngrDYjAheGvYwMnn
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
_gos_sudo_for_target(gos.sh) runs a privileged command by capturing its stdout and stderr with command substitution, which strips trailing newlines. It then replays them withprintf '%s', so the command's last line lost its line ending and the next progress or error line was glued onto it. For example:This affected all four replay paths: success, permission-retry success, permission-retry failure (the original error and the sudo error were also concatenated), and plain failure.
What changed: one small helper,
_gos_sudo_replay, prints each non-empty stream followed by a newline. All four paths use it.Why it matters beyond cosmetics: this is also why
tests/install-transaction.bashfailed when the suite ran as root. As root, the protected-parent side-by-side case goes through the permission-retry path, and the gluedsudo mv … go.gos-backup.NActivating go from <versions dir>line made the "no sudo inside the versions dir" grep match a line that never existed. With this fix, the full suite passes as root as well.Behavior note: a command whose output lacked a trailing newline now gets one when replayed. That matches what a terminal shows for a directly executed command. Callers that capture
_gos_sudooutput with$(…)are unaffected, since command substitution strips it again.Type of Change
Validation
bash -n gos.sh install.shshfmt -d -i 2 -ci -bn .(shfmt 3.13.1, as pinned in CI)shellcheck gos.sh install.sh completions/gos.bash scripts/*.bash scripts/*.sh tests/*.bash(ShellCheck 0.11.0, as pinned in CI)scripts/sync-command-surfaces.bash --checkbash tests/install-transaction.bash: passes as root (it failed onmainas root) and as non-rootscripts/run-tests.bash --jobs 4: 31/31 passed as a non-root user and as root (Linux, Bash 5.2)tests/unit-versions.bashdrives the sourced_gos_sudo_for_targetthrough the retry-success, retry-failure and plain-failure paths. It asserts the exact stdout/stderr line sequence, and it fails without the fix (movedafter-retry).824fb14: all 10 jobs and all 11 checks green, including native macOS Bash 3.2, Linux Fish and Windows Bash/PowerShell.Notes
main). It touches the### Fixedlist inCHANGELOG.md, which fix(project): resolve Go pins past unrelated tool manifests #44 also edits, so whichever merges later may need a trivial changelog merge.🤖 Generated with Claude Code
https://claude.ai/code/session_01ExmnfUngrDYjAheGvYwMnn