fix: zsh portability, store integrity, and test coverage (3.1.1) - #13
Open
Jintin wants to merge 2 commits into
Open
fix: zsh portability, store integrity, and test coverage (3.1.1)#13Jintin wants to merge 2 commits into
Jintin wants to merge 2 commits into
Conversation
Storage was written with echo, which expands backslash escapes under zsh. Adding `printf "[%s]\n"` wrote a real newline into ~/.aliasme/cmd, breaking the two-lines-per-record format and orphaning every entry after it. All writes and all rendering of stored text now use printf. Also fixes two zsh-only execution bugs and one variable leak: - A stored command containing an unmatched glob character aborted under zsh with "no matches found" (any URL with a query string). _excute now sets no_nomatch locally; intentional globs still expand. - _excute's locals were visible to the eval'd command, so an alias referencing $name or $value saw aliasme's internals. They are now _al_* prefixed. The command also runs after the storage fd is closed. Tests: run against a mktemp store instead of the real ~/.aliasme, exit non-zero on failure (the suite previously printed failures and exited 0, so CI was green regardless), and cover the name/command collision, exit code propagation, escape handling, and variable isolation cases. CI now runs them on bash and zsh across ubuntu and macos, with ShellCheck split into its own job. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
assert.sh declares expected/actual as arrays, so reusing those names for scalars in check() triggered SC2178/SC2128. The empty-name case calls _add with no arguments, which prompts interactively; without stdin redirected the suite blocked forever when run from a terminal. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Three zsh-only bugs, one of which corrupts the alias store, plus the test coverage that would have caught them. All findings were reproduced against
master(post-#12) before fixing, and every fix is verified in both bash and zsh.1.
_addcorrupted the store under zsh (data loss)Records were written with
echo, and zsh'sechoexpands backslash escapes. Storing a command containing\nwrote a real newline into~/.aliasme/cmd, breaking the two-lines-per-record format and orphaning every entry after it.Reproduced on master under zsh:
All writes and all rendering of stored text now use
printf._listhad the same defect on the display side, soal lsmangled any command containing a backslash.2. A literal
?in a command failed under zshzsh aborts on a glob that matches nothing, so any stored command with a query-string URL died:
_excutenow setsno_nomatchwithlocal_optionsso it auto-restores. Intentional globs still expand — there's a test for that.3.
_excute's locals leaked into the eval'd commandIntroduced by #12, which named them
name/value— common enough that a user's own alias would collide:Renamed to
_al_*, and the command now runs after the storage file descriptor is closed rather than inheriting fd 9.Tests
The suite previously printed failures and exited 0, so CI was green no matter what — verified by fault injection. It also wrote to the developer's real
~/.aliasme.Now it uses a
mktempstore with anEXITtrap, exits non-zero on failure, and covers what was untested: the name/command collision and exit-code propagation fixed in #12, plus escape handling, literal?, glob expansion, and variable isolation from this PR. 19 assertions, passing in bash and zsh.CI runs the suite on
{bash, zsh} x {ubuntu, macos}— the zsh legs are the point, since every bug here is zsh-only and the primary install channel is Homebrew on macOS. ShellCheck moved to its own job.Test plan
bash test/aliastest.shandzsh test/aliastest.shboth exit 0 (19/19)_listmakes the suite exit 1🤖 Generated with Claude Code