Repository navigation
Harden the CLI Usage Gate Against False Greens - #2944
Conversation
The unknown-flag case now requires a refusal naming the flag as an unknown option, and a script needing a subcommand or positionals gets arguments that satisfy its parser first, so the refusal seen is of the flag. Help must print the same text for both spellings, opening on a usage line naming the script. Each run is checked on its own for a changed path, ignored paths included, and for a process left running, found by a token in its inherited environment. Every home and config-home variable points into the scratch directory. Discovery also finds an extensionless file opening on a shebang, and on Windows the PowerShell entry points now run behind .cmd stubs instead of the whole case skipping. configure.sh passes -- before resolve_description.py's positionals, so a repo name starting with a dash is read as a name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
BEFORE_FLAG now uses arguments that alone exit 0 or reach a stub, and a control case holds that, so a script that warns on the flag and carries on fails. Output goes to files rather than pipes, so a survivor holding an inherited stream is named at once instead of timing the run out, and the survivor scan repeats until it finds none. The tree check also records every directory's time, which catches an empty directory git never lists. Controls pin the refusal pattern, the usage-line check, the ignored-path check, and the survivor check. The env shebang reader skips env's own flags and assignments, wsl and fsutil are stubbed, and the configure.sh case reuses the lift and run_bash helpers of the archived-repository tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A file a run leaves in a scratch home is now an effect, PowerShell's own startup cache aside, so redirecting a home no longer hides a write into it. A control runs a bare git through pwsh and requires the stub to record it, which on Windows proves the .cmd stub is found ahead of the real command. The docstring now names HOMES rather than claiming every home variable. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 15 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
home_writes now reports every entry a run leaves in a scratch home, an empty directory or a symlink included, rather than only regular files. The exclusion is now only the powershell directory under XDG_CACHE_HOME, and only for a pwsh run, so a Python or bash script writing under a powershell directory is reported. The control covers all three shapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #2944 +/- ##
========================================
Coverage 59.96% 59.96%
========================================
Files 17 17
Lines 8777 8778 +1
========================================
+ Hits 5263 5264 +1
Misses 3514 3514
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved findings remain in output validation, shebang parsing, filesystem-effect detection, and Git config tracking.
3 open findings
What changed in this PR
Hardens the CLI usage gate against false positives and fixes handling of repository names beginning with -.
Changes:
- Strengthens help, option, sandbox, process, and discovery checks.
- Adds Windows and extensionless shebang coverage.
- Passes
--before description resolver positional arguments.
| File | Description |
|---|---|
tests/test_cli_usage.py |
Adds hardened CLI sandbox and discovery checks. |
spec/resolve_description.py |
Documents end-of-options handling. |
repo-config/configure.sh |
Passes -- before positional arguments. |
🧠 Review effort: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
A recorded local strict-review pass covers head |
…Reads On Windows pwsh writes its startup cache under the scratch USERPROFILE, so a pwsh run now sets that path aside, with the directories leading to it, beside the XDG_CACHE_HOME one used elsewhere. The usage check reads the very first line and needs the script's stem as a whole word, so usage for another script whose name contains it no longer passes. An env shebang skips the operand of -u and -C before naming the command. Controls cover each. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A control now calls home_writes for a pwsh run directly, with a sibling under AppData/Local and a powershell directory under XDG_CONFIG_HOME, and requires both still to be reported, so a widened set-aside fails. The env operand walk is dropped again: an env shebang whose -u or -C operand the reader takes for the command already fails the case loudly as naming no runtime. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
…thheld The set-aside control now plants a sibling of each cache leaf as well as of its parents, so widening the set-aside to either cache's parent fails it. The module docstring names the WITHHELD variables instead of claiming no credential reaches a run. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The control accepts any effect from a BEFORE_FLAG set run alone, so the docstrings now say an effect rather than a stub call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
…l Config in HOME The run that must name the unknown flag now also fails where its output reports a missing or required argument, so a script outside BEFORE_FLAG that warns on the flag and then stops on a missing argument no longer passes. GIT_CONFIG_GLOBAL now points at .gitconfig in the scratch HOME, so a global git config write lands where the home check reports it. Controls cover both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A word list cannot show whether the flag or a missing argument stopped a run, and this repository's own missing-argument refusals use wording it would not match. The check and its control are removed, and the docstring now says an unlisted script that needs an argument is held only to a non-zero exit with no effect. #2948 tracks closing that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
An unlisted script is still held to naming the flag as an unknown option. What it is not held to is a run without the flag, so the docstring now says that one warning on the flag and then stopping on a missing argument passes until it is listed in BEFORE_FLAG. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e Rule Strictly A shell script parsing with getopt refuses an unknown long option as "unrecognized option", which the refusal pattern now accepts, with a control. The module docstring says the checks read CODESTYLE.md's rule strictly, so meeting the rule's words is not always enough here. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
|
@coderabbitai review |
|
|
Answering the Copilot round on 8726c1b (#2944 (review)), whose headline names four areas against 3 open findings. The fourth headline area, "Git config tracking", has no thread of its own. Read against that head: The three threaded findings were answered and resolved in their threads (one declined with evidence, two fixed). |
…nd Attest Sleep Alias to Main (#2950) - #2945 makes `gh-write-guard` fail closed on the push shapes it could not read: a push inside an `eval`/`source` argument, a quoted command handed to `bisect run` or `submodule foreach`, a here-string or attached `-c` wrapper body, a `-c`/`--config-env` override on a push, a bare push inside a wrapper body or after a head-moving command, `HEAD`/`@`/`:` destinations, and `--admin` inside a wrapper. It also denies a mutating git command whose `-C`, `--work-tree`, `--git-dir`, `GIT_DIR=`, or leading `cd` holds a `..` component. A differential over 1043 commands found no command the new guard allows that the previous one denied. The over-denials it introduces are listed in that pull request with their workarounds, and the shared gaps outside both issues are tracked on #2943 - #2944 hardens `tests/test_cli_usage.py`: the unknown-flag case must see the flag itself refused, the help case must open on a usage line naming the script, the tree check sees ignored paths and empty directories, every config home is redirected, detached grandchildren are found through `/proc`, extensionless shebang CLIs are discovered, and PowerShell entry points run natively on Windows. `repo-config/configure.sh` passes `--` before a name - #2942 sleeps through an alias in `pr_review.py`'s attest head wait, so the `TestAttest` timing tests no longer record subprocess polling sleeps, and states in `scripts/README.md` when a genuine review outranks a refusal on the same head - #2952 answers this promotion's first review round: the guard reads every `-c`/`--config-env` spelling and `--attr-source`, judges a head move per push (scanning the whole command where a pipe, background job, loop, or fused redirection can reorder it), stops reading a lone `:` as a deletion, and the CLI usage gate sets aside only the host's own PowerShell startup cache. Three precision findings from the second round, each a broader deny rather than a new allow, are deferred to #2953 Closes #2824 Closes #2831 Closes #2932 Closes #2934 Closes #2936 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Hardens
tests/test_cli_usage.py, the CLI usage gate, against the false greens #2831 lists, and fixes the one usage defect it names.Closes on promotion: #2831
What changed
--bogus-flagas an unknown option (REFUSED_AS_OPTION, which accepts argparse's, getopt's, PowerShell's and this repository's shell wordings). A script needing a subcommand or positionals is first given arguments that satisfy its parser (BEFORE_FLAG), so the refusal observed is of the flag rather than of a missing argument. A control requires eachBEFORE_FLAGset alone to exit 0 or leave an effect, so a listed script that warns on the flag and carries on still fails. An unlisted script that needs an argument is held only to a non-zero exit with no effect, since its output cannot show whether the flag or the missing argument stopped it. Hold an Unlisted CLI That Needs an Argument to Refusing the Unknown Flag Itself #2948 tracks closing that. The run with no prefix still runs too, so an unrecognized first argument is still held to a non-zero exit with no effect.--helpand-hmust print the same text, so a default-mode report that merely mentions "usage" fails.git status --ignored, with size and time per listed path) and every directory's time, which catches an empty directory git never lists..gitconfigin the scratch HOME. Any entry a run leaves in a scratch home is an effect, apart from a pwsh run's own startup cache (under XDG_CACHE_HOME off Windows, under USERPROFILE on Windows) and the directories leading to it.setsidone included, is found through/proc, named as an effect and killed, with the scan repeating until it finds none. Output goes to files rather than pipes, so a survivor holding the inherited stream no longer stalls the run. This check runs only where/procexists, so not on Windows or macOS.envflags such as-Sand assignments skipped.catalog/snippets/husky/pre-commitjoinsNOT_COMMAND_LINEas a Git hook..cmdstubs that PowerShell's lookup finds ahead of the real command, and a control runs a baregitthrough pwsh and requires the stub to record it. Python and bash entry points still skip on Windows, since a process Python starts is found by its.exename and a stub cannot shadow it. A call naming its.exeexplicitly is not shadowed either.wslandfsutilare now stubbed.repo-config/configure.shpasses--beforespec/resolve_description.py's positionals, so a repo name starting with-is read as a name. A test runs configure.sh's own lifted lines with such a name, reusingliftandrun_bashfromtests/test_configure_archived.py.Each new check has a control in
ControlCasethat fails when the check is removed. Mutation runs against a real script confirmed each hardened assertion catches its case: a default-mode "usage" report, a "cannot read --bogus-flag" refusal, a write into an ignored directory, a detached grandchild, and a-hthat differs from--help.No real script failed the hardened gate, so no script needed an expected-failure marker.
Local review findings
Every local finding has an outcome. Fixed in later commits on this branch: the three listed here earlier (non-file home entries, the over-wide PowerShell exclusion, and the first commit's "every home variable" wording, which the squash message written from this body replaces), the pwsh cache on Windows, a sibling control for the cache set-aside, the WITHHELD wording, and the global git config path.
Declined or deferred, with reasons:
tests/test_configure_*.pyfile, and consolidating the shebang reader withscripts/docker_lint.py's. This change may edit only the three files it touches, and docker_lint's helper names only bash and sh.tree_state's porcelain parsing withscripts/carry.py'sgit_status_paths: deferred to Share One Porcelain Status Parser Between carry.py and the CLI Usage Gate #2947, for the same file-scope reason.--fix as over-hardening. Harden the CLI Usage Gate Against False Greens #2831 lists it as a defect to fix.env -u/-Coperands in the shebang reader: that shape already fails the case loudly as naming no runtime, and the shebangs are trusted tracked input.Verification
python3 -m unittest discover -s tests: 2713 tests, OK (7 skipped) on Linux with pwsh present.prose_lint.py --diffwith and without--check sentence-length,repo_gate.py --check eolandeol-coverage,spec/validate.py: clean.windows-test) is the native check for the PowerShell path, and it passes. Its first run on this branch showed pwsh writing its startup cache under the scratch USERPROFILE, which the set-aside now covers. Its skipped count is consistent with the PowerShell cases running rather than skipping, and the control requiring the.cmdstub to record a baregitpasses there.🤖 Generated with Claude Code