Repository navigation
fix: reject an option to sh instead of reading it as a script path - #270
Conversation
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve once two small things are fixed. The fix is right, and so is its scope: lash --help now fails with a clear status-2 error instead of a "no such file <cwd>/--help" error. Scripts and -c behave the same as before.
- 🟡 A stray file
f(contentsx) was committed at the repo root. - 🟡
sh -- s,sh -e s,sh -x s,sh -sandsh -all printinvalid option, but bash accepts every one of these. Telling a model the flag doesn't exist is the wrong signal. Below is a verified 1-hunk fix: it strips--, as the-cbranch already does, and uses the house style<thing> not supported; use <alt>.
Neither is a regression. On main, all of these already failed with a 126 no such file error.
What I verified, passes run, scope, test coverage
✅ Verified at head 36826f5:
cargo test --test shell_integration: 1965 passed, 0 failed.- Probes through
strands-shell -c:sh s a→hi a,sh ./-s b→hi b,lash --help→lash: --help: invalid optionwith status 2.sh -- s c,sh -x s,sh -e s,sh -sandecho x | sh -all printsh: <opt>: invalid optionwith status 2.- Under bash 5.2,
bash -- s cprintshi c,bash -x straces, andecho … | bash -runs stdin. set -xandset -ework in this shell, so the suggested message points at a real alternative.
- I applied the inline suggestion locally and rebuilt.
sh -- s c→hi c(status 0),sh -x s→ the new message (status 2), andsh s ais unchanged. - Logs:
s3://…/strands-agents/shell/pr/270/{shell_integration-pytest.log,probes.txt}.
Passes:
- Correctness reviewer (default tier, fresh context): run. Its two findings are the two above, and I re-checked both myself.
- API bar-raiser: skipped. No Rust or bindings API changed, and the one model-facing string is covered in the inline comment.
- Adversarial: skipped. The change is a 5-line branch with a single caller (
src/exec.rs:3842, onlysh/lash). Shebang dispatch (src/exec.rs:3467-3477) passes the resolved path, never a dash option.
Tests: tests/shell_integration.rs:9178-9191 ("lash --help" → "lash: --help: invalid option\n", 2, and "sh -x a" → "sh: -x: invalid option\n", 2) do prove the fix. On main, both inputs reach os.open and fail with strands-shell: …: no such file … and status 126. If you take the suggestion, update the two expected strings and consider adding sh -- FILE.
Scope vs #207: this matches the P2 item "Running a missing binary like lash --help gives no such file or directory: <cwd>/--help", and the tool-level ask to "return a clear error for unsupported … flags". Saying "Part of #207" rather than closing it is right. Deferring real -e/-x/-s and stdin support is reasonable.
Appendix, non-blocking: the sh FILE open-failure exit code (126 vs bash's 127) is already called out in the PR body as follow-up work, so I didn't file it.
|
@strandly-the-agent Please review this PR |
There was a problem hiding this comment.
Approve. Both earlier findings are fixed in ea38228 and 6a5378c. Treating the word after -- as a path even when it starts with a dash (sh -- -s b) is better than what I suggested, and it matches bash. I found nothing new.
What I checked at 6a5378c
cargo test --test shell_integration: 1967 passed, 0 failed. That includes the two new--tests.cargo fmt --checkis clean. Clippy shows only warnings that were already there before this PR (e.g.src/exec.rs:3459,src/builtins/find.rs:656); none are in changed lines.- Probes through
strands-shell -c:sh -- s a→hi a,sh -- -s b→hi b,sh s c→hi c,sh -c 'echo ok'→ok.sh -x sand a baresh --both give the new "option not supported" message with status 2.sh -- -c xopens-cas a file, as bash does (bash -- -c x→No such file or directory). - A bare
sh --reads stdin in bash. That falls under the stdin support the PR body already defers, so it isn't a finding here. - CI is green at
6a5378c. It was still pending when I first posted this review.
Passes: this is a fixes-only follow-up, so I didn't re-run the reviewer subagent. The delta applies my earlier suggestion plus the ---then-path change, which I probed by hand above. I skipped the API pass because no Rust or bindings API changed, and the one model-facing message is the string I proposed. I skipped the adversarial pass because the change is a ~10-line branch with a single caller (src/exec.rs:3842), and I tried its edge cases by hand (--, -- -s, -- -c, bare --).
Description
Running
lash --helporsh -xinside the shell took the option for a script file name, so you got a confusing "no such file" error about a file called--helpin the home directory.lashandshare the shell's own commands, and they only understood-c; anything else in that spot was opened as a script. An agent poking at the shell to see what it does ends up chasing a file that was never there.Now an option other than
-cis reported as an invalid option, the way bash reports one it doesn't know, with status 2. Scripts and-cwork as before.I ran the examples from the issue before and after. Unknown commands with or without arguments, missing paths, directories, and non-executable files all give the same errors as before. I added tests for a long and a short option, and the full Rust suite passes. I didn't run the Python or Node suites since the bindings aren't touched.
I left out a few related things for separate changes: real support for options like
-e,-xand-s, reading a script from stdin, and a missing script exiting 126 where bash exits 127.Related Issues
Part of #207
Documentation PR
N/A
Type of Change
Bug fix
Testing
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.