Repository navigation
fix(cli): refuse a mistyped --root in five report commands (#14548) - #14616
Conversation
policy readiness, policy waiver-aging, pr-comments plan, reports index and reports ci-summary accepted a missing or file --root and wrote CWD-relative target/ripr output. Call the shared ensure_command_root after option parsing and before any write, and extend the cli_smoke regression to cover all five with a missing nested root and a file root, asserting exit 2, the shared message, and no write under the CWD.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
EffortlessSteven
left a comment
There was a problem hiding this comment.
SOURCE_REVIEW_READY, head 517511f
Round 1 source pass. Source stage only: this marker releases the labelled run; the merge marker follows the hosted result on this exact head.
Acceptance is met, measured with the head binary and the base binary (3e67e70), each run from a fresh CWD with both root shapes:
| command | base exit | base wrote CWD target | head exit | head CWD after |
|---|---|---|---|---|
| policy readiness | 0 | target/ripr/reports/policy-readiness.json |
2 | empty |
| policy waiver-aging | 0 | target/ripr/reports/waiver-aging.json |
2 | empty |
| pr-comments plan | 0 | target/ripr/review/comment-publish-plan.json |
2 | empty |
| reports index | 0 | target/ripr/reports/index.json |
2 | empty |
| reports ci-summary | 0 | nothing (stdout only) | 2 | empty |
Placement, per command: all five call ensure_command_root immediately after parse_*_options, and the parsers do no I/O for writes — reconcile_root only formats the path, and the loops only parse. ci_summary is the one command with a call before parse, CiSettings::from_env, and it only reads env plus GITHUB_EVENT_PATH. Nothing writes before the call in any of the five, and the end-to-end CWD is empty after each of the 16 head runs, so this is observed rather than inferred from placement.
Discrimination: exit 2 plus the per-command message "<name> root <path> is not a directory" holds for all five and both shapes. The write assertion is a single post-loop check on scratch/target, so it covers the eight commands collectively and cannot attribute a write to one of them. It is vacuous for reports ci-summary, which has no file write at all (render_ci_summary builds a String and the body writes stdout); its only discriminator is the exit/message assertion. The four commands with a write path are covered.
File root: the probe reads a-file after every run and the content is unchanged for all five and both command sets; the message names each command exactly, including policy waiver-aging and reports ci-summary.
The current_dir change strengthens the three pre-existing commands. run_ripr inherited the test process CWD, so a CWD-relative write landed in crates/ripr and was never asserted — the old test only checked that the mistyped root was absent and the file untouched. With current_dir = scratch, any write under the CWD is now caught. No loss: the roots are absolute, so the refusal does not depend on the CWD; the only other environment change is that run_command does not set RIPR_PROGRESS=1, and none of these assertions reads progress output.
Base control, measured: all five exit 0. Four write under the CWD; reports ci-summary exits 0 and writes nothing. Because the write assertion is evaluated before the failures vector, the base run surfaces the write message the Coder reported, and the exit-code assertion would additionally have tripped for all five — so the base red is both assertions for four commands and the exit-code assertion alone for reports ci-summary.
Non-blocking observation outside this claim's acceptance: with a valid --root that differs from the CWD, policy readiness still writes target/ripr/reports/policy-readiness.json under the CWD, while ensure_command_root's containment check (ensure_default_output_contained) inspects <root>/target/ripr. Measured at head: the CWD target is created and <root>/target is absent. Pre-existing at base, and irrelevant to a refused root, but the #7781 symlink gate is checking a different directory than the one written whenever root differs from the CWD; worth an issue.
Not verified: nothing is compiled or run on the hosted lane and no run exists on this head; I ran the built binary on the same inputs rather than the extended cli_smoke test binary.
EffortlessSteven
left a comment
There was a problem hiding this comment.
SOURCE_REVIEW_READY
VERDICT: APPROVE 517511f — no blocking findings on this head.
Independent source pass at the exact head; it does not replace review 5897935555, which is a separate pass at the same head.
What I verified in the tree
- Every one of the five call sites places
ensure_command_rootafter itsparse_*_optionscall and before any write:crates/ripr/src/cli/commands.rs:637(pr-comments plan),crates/ripr/src/cli/commands/ci_summary.rs:30,crates/ripr/src/cli/commands/policy/reports.rs:31(policy readiness) and:323(policy waiver-aging),crates/ripr/src/cli/commands/reports.rs:53(reports index). The parsers only format paths, and the one pre-parse call,CiSettings::from_env, reads env andGITHUB_EVENT_PATHonly. - The refusal text comes from the shared gate:
crates/ripr/src/cli/commands_context.rsformats"{command_name} root {path} is not a directory; pass the directory that contains the workspace (for a Cargo.toml path, its parent directory)", so the test's substring assertion on"{name} root {path} is not a directory"matches and exit 2 is the existing Err path. crates/ripr/tests/cli_smoke.rs:36489now runs each command withrun_command(..., Some(&scratch), ...), so a CWD-relative write lands in the asserted scratch tree;:36504adds thescratch/targetassertion and:36512keeps the file-root content check. Both roots per command, eight commands total.run_commandsetscurrent_diron the child (spawn_commandapplies it beforeargs), so the strengthened assertion observes the real behaviour rather than the harness CWD.
Non-blocking notes
- Two sibling report commands still write a CWD-relative default output and do not call the gate:
policy operationsandpolicy history(crates/ripr/src/output/policy_operations.rs:8andpolicy_history.rs:7default totarget/ripr/reports/...; neitherpolicy_operationsnorpolicy_historyincommands/policy/reports.rscallsensure_command_root). A mistyped--rooton either still writes into the CWD with exit 0 — the same failure mode, outside the five-command scope of #14548 and worth a follow-up issue.policy promoteandpolicy preview-promoterequire--out, so they do not have the default-write variant. - A valid
--rootthat differs from the CWD still writes the default output under the CWD, whileensure_command_root's containment check inspects<root>/target/ripr. That is pre-existing and unchanged by this PR, but it means the #7781 symlink containment gate and the actual write directory can differ.
Not checked
No hosted Rust gate exists at this head (CodeRabbit, Graphite, GitGuardian, Graphite mergeability only), so qualification is unestablished. I did not build or run the test binary; everything above is a read of the committed source. No checkout, no label, no branch change.
EffortlessSteven
left a comment
There was a problem hiding this comment.
REVIEW_READY, head 517511f
Round 1 merge marker. Hosted evidence on this exact head: run 43507179077, check-run 132190789951 success 21:48:22Z, 11 jobs success and 5 skipped with no failing job, mergeStateStatus CLEAN. The source judgement is review 5897935555 at 20:55:29Z; this adds the mutation check that pass left open.
Mutation binding, one call site at a time, each moved to after that command's first write and rebuilt from this head:
| call site | mutated command | exit | wrote CWD target | regression outcome |
|---|---|---|---|---|
| policy/reports.rs readiness | policy readiness | 2 | yes | red at the write assertion |
| policy/reports.rs waiver-aging | policy waiver-aging | 2 | yes | red at the write assertion |
| reports.rs index | reports index | 2 | yes | red at the write assertion |
| commands.rs pr-comments plan | pr-comments plan | 2 | yes | red at the write assertion |
| ci_summary.rs | reports ci-summary | 2 | no | passes |
No command's mutation is masked by another command's refusal: the shared write assertion fires for each of the four that write, and the exit/message assertion stays green in every mutation because the refusal still happens, just after the write. The one call site the regression cannot see is reports ci-summary: it has no file write, so moving the call after its stdout write still exits 2 with the message and leaves the CWD clean; the mutated binary printed 5915 bytes of summary before refusing and the test would pass. That is a limit of the test, not of the acceptance, because stdout is not a CWD write.
Scope of the write assertion: it inspects only <scratch>/target (let wrote_target = scratch.join("target").exists();), not the whole scratch tree, and the root assertion inspects only <scratch>/nope. A command writing any other CWD-relative path would escape both. What the test proves is "no target/ under the CWD", not "no write under the CWD"; the stronger statement in my round-1 note came from my own probe, which listed the whole CWD empty after each of the 16 runs on this head, and that still holds on this head.
reports ci-summary on this head: exit 2 with reports ci-summary root <path> is not a directory for both root shapes, no target/, and no other entry in the CWD. Its write assertion is vacuous by construction, and exit 2 plus the message is its only discriminator.
Non-blocking: the write assertion is one post-loop check, so a red names no command; a per-command scratch or a message naming the command would make the failure attributable. Worth an issue, not a change to this head.
Not verified: I did not build or run the cli_smoke test binary; the mutation results come from the built binary with the same argv, CWD and assertion conditions the test uses.
EffortlessSteven
left a comment
There was a problem hiding this comment.
REVIEW_READY, head 517511f
VERDICT: APPROVE 517511f
Round 1 merge marker. Hosted evidence on this exact head: run 43507179077, check-run 132190789951 success 21:48:22Z, 11 jobs success and 5 skipped with no failing job, mergeStateStatus CLEAN. The source judgement is review 5897935555 at 20:55:29Z; this adds the mutation check that pass left open.
Mutation binding, one call site at a time, each moved to after that command's first write and rebuilt from this head:
| call site | mutated command | exit | wrote CWD target | regression outcome |
|---|---|---|---|---|
| policy/reports.rs readiness | policy readiness | 2 | yes | red at the write assertion |
| policy/reports.rs waiver-aging | policy waiver-aging | 2 | yes | red at the write assertion |
| reports.rs index | reports index | 2 | yes | red at the write assertion |
| commands.rs pr-comments plan | pr-comments plan | 2 | yes | red at the write assertion |
| ci_summary.rs | reports ci-summary | 2 | no | passes |
No command's mutation is masked by another command's refusal: the shared write assertion fires for each of the four that write, and the exit/message assertion stays green in every mutation because the refusal still happens, just after the write. The one call site the regression cannot see is reports ci-summary: it has no file write, so moving the call after its stdout write still exits 2 with the message and leaves the CWD clean; the mutated binary printed 5915 bytes of summary before refusing and the test would pass. That is a limit of the test, not of the acceptance, because stdout is not a CWD write.
Scope of the write assertion: it inspects only <scratch>/target (let wrote_target = scratch.join("target").exists();), not the whole scratch tree, and the root assertion inspects only <scratch>/nope. A command writing any other CWD-relative path would escape both. What the test proves is "no target/ under the CWD", not "no write under the CWD"; the stronger statement in my round-1 note came from my own probe, which listed the whole CWD empty after each of the 16 runs on this head, and that still holds on this head.
reports ci-summary on this head: exit 2 with reports ci-summary root <path> is not a directory for both root shapes, no target/, and no other entry in the CWD. Its write assertion is vacuous by construction, and exit 2 plus the message is its only discriminator.
Non-blocking: the write assertion is one post-loop check, so a red names no command; a per-command scratch or a message naming the command would make the failure attributable. Worth an issue, not a change to this head.
Not verified: I did not build or run the cli_smoke test binary; the mutation results come from the built binary with the same argv, CWD and assertion conditions the test uses.
Summary
--rootand exited 0instead of the shared
<command> root <path> is not a directoryrefusal fromensure_command_root:policy readiness,policy waiver-aging,pr-comments plan,reports index,reports ci-summary.ignored and the command writes to the CWD-relative
target/ripr/..., so amistyped
--rootproduces reports in the wrong tree with a success exit.ensure_command_rootright after option parsing andbefore any write, matching the three commands fixed in fix(cli): refuse a mistyped --root in reports ci-packet and feedback (#14222) #14322.
mistyped_root_is_refused_and_not_createdregression is extendedto all eight commands and now runs each one with
current_dirset to a scratchdirectory, so it can assert that a refused command wrote nothing under the
CWD. A test that only checked the bad root was not created would pass on the
buggy code.
Source-of-truth Links
Proposal:
Spec:
ADR:
Plan item:
Governing issue or accepted claim: #14548
Acceptance delta (one sentence): Each of the five commands refuses a missing or file
--rootwith exit 2 and the shared message before any write, and the regression proves it by asserting notarget/appears under the CWD.Proof
3e67e70ea2: the extended test fails ata refused command wrote under the CWD (target/ripr), and the failure listshows all five commands exiting 0 for both the missing nested root and the
file root.
517511fa8f: the same test passes.an existing file, asserting exit 2, the exact
<command> root <path> is not a directorymessage, notarget/under the scratch CWD, and the file rootbyte-identical afterwards.
cargo fmt --all -- --checkexit 0;cargo xtask check-policy-allpass.Scope
Five call sites plus the shared regression. No behaviour change for a valid root:
the check only rejects a root that is not an existing directory, which is the
same gate the three #14322 commands already use.