fix(cli): suggest no longer aborts with empty output under strict set -e#70
Merged
Merged
Conversation
The threshold-parse loop in both `local_suggest` and `cmd_suggest` used
`(( i++ ))`. A standalone `(( i++ ))` returns exit status 1 when `i` is 0
(post-increment yields the old value 0, which `((…))` reports as false).
Under `set -euo pipefail` on bashes that abort on arithmetic-evaluating-to-
zero (common on Linux; Apple's bash 3.2 does not), this killed `suggest` on
the first loop iteration before any output:
opensop suggest "qualify sales lead by email" --local --json
# exit 1, empty stdout
`search` was unaffected because it has no such loop — which is exactly why a
no-match `search` passed while `suggest` failed in the same test run.
Replace both occurrences with the assignment form `i=$((i + 1))`, which
always returns 0. Add a source-level guard to test/test.sh forbidding
standalone `(( var++ ))` / `(( var-- ))` so the footgun cannot reappear on a
bash where it doesn't bite locally.
Co-Authored-By: Claude Opus 4.8 (1M context) <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.
What & why
A user reported that on their (Linux) box the CLI test suite exits non-zero at the local suggest section, and reproduced it directly:
Root cause. The threshold-parse loop in both
local_suggestandcmd_suggestused(( i++ )). A standalone(( i++ ))returns exit status 1 wheniis0— the post-increment evaluates to the old value0, and((…))reports a zero result as "false". Underset -euo pipefail, on bashes that abort on arithmetic-evaluating-to-zero (common on Linux; Apple's bash 3.2 happens not to), this killedsuggeston the very first loop iteration, before any output — hence "exit 1, empty stdout".searchwas unaffected becauselocal_searchhas no such loop. That asymmetry is exactly what the reporter saw: a no-matchsearchpassed, thensuggestfailed in the same run.The fix replaces both
(( i++ ))with the assignment formi=$((i + 1)), which always returns exit status 0.Changes
cli/bin/opensop—(( i++ ))→i=$((i + 1))inlocal_suggest(the reported--localpath) andcmd_suggest(the remote path; identical latent bug from the mirrored implementation).cli/test/test.sh— source-level guard forbidding standalone(( var++ ))/(( var-- )). A behavioral test passes on a non-aborting bash and gives false confidence; this guard is portable and catches the whole footgun class.cli/CHANGELOG.md—[Unreleased] → Fixedentry.Test plan
bash -n cli/bin/opensop— clean.bash cli/test/test.sh—ALL PASS(exit 0), including the new guard and allsuggest --localcases.set -ebash (treating the arithmetic command's rc=1 as fatal) and confirmed the assignment form survives where(( i++ ))aborted.Self-rating
🤖 Generated with Claude Code