Skip to content

fix(cli): refuse a mistyped --root in five report commands (#14548) - #14616

Merged
EffortlessSteven merged 1 commit into
mainfrom
codex/14548-root-refusal
Nov 14, 2026
Merged

EffortlessSteven merged 1 commit into
mainfrom
codex/14548-root-refusal

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

  • Five report commands still accepted a missing or file --root and exited 0
    instead of the shared <command> root <path> is not a directory refusal from
    ensure_command_root: policy readiness, policy waiver-aging,
    pr-comments plan, reports index, reports ci-summary.
  • The failure mode is not "creates the bad root". The bad root is silently
    ignored and the command writes to the CWD-relative target/ripr/..., so a
    mistyped --root produces reports in the wrong tree with a success exit.
  • Each command now calls ensure_command_root right after option parsing and
    before any write, matching the three commands fixed in fix(cli): refuse a mistyped --root in reports ci-packet and feedback (#14222) #14322.
  • The existing mistyped_root_is_refused_and_not_created regression is extended
    to all eight commands and now runs each one with current_dir set to a scratch
    directory, 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 --root with exit 2 and the shared message before any write, and the regression proves it by asserting no target/ appears under the CWD.

Proof

  1. Negative control on the base 3e67e70ea2: the extended test fails at
    a refused command wrote under the CWD (target/ripr), and the failure list
    shows all five commands exiting 0 for both the missing nested root and the
    file root.
  2. Fixed head 517511fa8f: the same test passes.
  3. The test covers both root shapes per command: a missing nested directory and
    an existing file, asserting exit 2, the exact <command> root <path> is not a directory message, no target/ under the scratch CWD, and the file root
    byte-identical afterwards.
  4. cargo fmt --all -- --check exit 0; cargo xtask check-policy-all pass.

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.

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.
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary by CodeRabbit

  • Bug Fixes
    • Commands that generate reports or summaries now validate the selected root first and stop with a clear error if it is not a directory.
    • Invalid roots no longer lead to report generation or creation of output directories.

Walkthrough

Five CLI commands now validate their configured root before building inputs or reports. The invalid-root smoke test covers eight commands and checks exit codes, diagnostics, and filesystem effects.

Changes

CLI Root Validation

Layer / File(s) Summary
Validate roots before processing
crates/ripr/src/cli/commands.rs, crates/ripr/src/cli/commands/ci_summary.rs, crates/ripr/src/cli/commands/policy/reports.rs, crates/ripr/src/cli/commands/reports.rs
PR comment planning, CI summary, policy readiness, policy waiver aging, and report indexing call ensure_command_root before processing. Each command returns a root-validation error if the check fails.
Exercise invalid roots
crates/ripr/tests/cli_smoke.rs
The smoke test covers eight commands from a scratch working directory. It checks for exit code 2, a root-specific diagnostic, and no creation or change of the tested paths.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to 51751

The change makes five report commands refuse a missing or file root instead of writing output under the current directory. Valid-root behavior is unchanged. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (refusing a mistyped --root) and the scope (five report commands) and the CLI area. The raw summary, the objectives and the description all describe this same change. The title…
Description check Passed The description follows the repository template's main sections: Summary, Source-of-truth Links (with governing issue #14548 and an acceptance delta), Scope, Proof, and a sentence on behavior for vali…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix (refusing a mistyped --root) and the scope (five report commands) and the CLI area. The raw summary, the objectives and the description all describe this same change. The title is short and specific. The issue number is an extra detail, not a problem. The title does not name the five commands, but it covers the main change.

Full details: Description check

Explanation

The description follows the repository template's main sections: Summary, Source-of-truth Links (with governing issue #14548 and an acceptance delta), Scope, Proof, and a sentence on behavior for valid roots. Many template sections are absent or blank, including Swarm/Source Boundary, Candidate Relationships, Scope Classification checkboxes, Support-tier Impact, Policy Impact, Claim Boundary, Rollback, Spec-Test-Code Traceability, Static Language Check, CI Economics, Engineering Check, and the Gates checklist. The Proof section lists results but not the exact commands run in the template code block. Because the core content is present and the change is clear, the description is mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the root before the run,
Then guards each report beneath the sun.
Eight commands meet a missing place,
And leave no new path in their trace.
The burrow rests; the checks are done.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: a7450bfb-5562-480c-a822-2dd4c120754e
Commits

Reviewing files that changed from the base of the PR and between e9f76b7 and 517511f.

Files selected for processing: 5

  • crates/ripr/src/cli/commands.rs
  • crates/ripr/src/cli/commands/ci_summary.rs
  • crates/ripr/src/cli/commands/policy/reports.rs
  • crates/ripr/src/cli/commands/reports.rs
  • crates/ripr/tests/cli_smoke.rs

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

@EffortlessSteven EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_root after its parse_*_options call 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 and GITHUB_EVENT_PATH only.
  • The refusal text comes from the shared gate: crates/ripr/src/cli/commands_context.rs formats "{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:36489 now runs each command with run_command(..., Some(&scratch), ...), so a CWD-relative write lands in the asserted scratch tree; :36504 adds the scratch/target assertion and :36512 keeps the file-root content check. Both roots per command, eight commands total.
  • run_command sets current_dir on the child (spawn_command applies it before args), so the strengthened assertion observes the real behaviour rather than the harness CWD.

Non-blocking notes

  1. Two sibling report commands still write a CWD-relative default output and do not call the gate: policy operations and policy history (crates/ripr/src/output/policy_operations.rs:8 and policy_history.rs:7 default to target/ripr/reports/...; neither policy_operations nor policy_history in commands/policy/reports.rs calls ensure_command_root). A mistyped --root on 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 promote and policy preview-promote require --out, so they do not have the default-write variant.
  2. A valid --root that differs from the CWD still writes the default output under the CWD, while ensure_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 EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EffortlessSteven left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant