Skip to content

fix(cli): accept --debug on the Rust binary and actually toggle it in Python#1464

Merged
mergify[bot] merged 1 commit into
mainfrom
devs/jd/worktree-rust-port/accept-debug-rust-binary-actually-toggle-python--62ac941d
May 27, 2026
Merged

fix(cli): accept --debug on the Rust binary and actually toggle it in Python#1464
mergify[bot] merged 1 commit into
mainfrom
devs/jd/worktree-rust-port/accept-debug-rust-binary-actually-toggle-python--62ac941d

Conversation

@jd
Copy link
Copy Markdown
Member

@jd jd commented May 27, 2026

Two coupled gaps the same user-visible bug was hiding:

  1. The Rust binary never declared the top-level --debug flag the
    Python CLI accepts. Invocations like mergify --debug ci git-refs
    were rejected with error: unexpected argument '--debug' found
    the moment a command was promoted from shim to native. Add
    debug: bool as a global = true argument on CliRoot; native
    commands accept it as a no-op (no native code path consults the
    flag yet) and shimmed dispatches re-inject --debug at the front
    of the forwarded argv so the Python cli group still receives it.

  2. The Python cli.py parsed --debug into ctx.obj["debug"] but
    never called utils.set_debug(...), so the module-level _DEBUG
    toggle stayed False and the 6+ if is_debug(): sites in
    utils.py / stack/* never fired regardless of the flag. Wire
    set_debug(debug=debug) from the root group so the flag has the
    effect users have always expected it to have.

Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com

Copilot AI review requested due to automatic review settings May 27, 2026 07:53
@mergify mergify Bot had a problem deploying to Mergify Merge Protections May 27, 2026 07:53 Failure
@jd jd temporarily deployed to func-tests-live May 27, 2026 07:53 — with GitHub Actions Inactive
@jd
Copy link
Copy Markdown
Member Author

jd commented May 27, 2026

This pull request is part of a Mergify stack:

# Pull Request Link
1 fix(cli): accept --debug on the Rust binary and actually toggle it in Python #1464 👈
2 refactor(rust): share test scaffolding via mergify-test-support crate #1439
3 refactor(core): introduce CommandContext for the queue+freeze prelude #1441
4 refactor(ci): consolidate the CI-env scrubber into a shared testing module #1442
5 refactor: drop stale Phase X.Y doc markers and one inline color branch #1443
6 refactor(tui): share StyledGlyph across queue show/status renderers #1444
7 refactor(queue): drop indexmap, group_by_scope returns a Vec<(K, V)> #1445
8 refactor(ci): swap uuid for getrandom in the GHA heredoc delimiter #1446
9 refactor(config): standardize the workspace on serde_yaml_ng for YAML parsing #1447
10 test(ci): add live smoke test for ci scopes select-all path #1460
11 feat(rust): port ci scopes to native Rust #1461
12 feat(ci): parse JUnit XML reports in native Rust #1465
13 feat(ci): encode JUnit cases as OTLP and upload to Mergify CI Insights #1466
14 feat(ci): promote ci junit-process from shim to native Rust #1467
15 feat(ci): promote ci junit-upload from shim to native as a deprecated alias #1468
16 fix(ci): prefer GitHub Actions PR-event head SHA over GITHUB_SHA #1469

@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 27, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 🤖 Continuous Integration

Wonderful, this rule succeeded.
  • all of:
    • check-success=ci-gate

🟢 👀 Review Requirements

Wonderful, this rule succeeded.
  • any of:
    • #approved-reviews-by>=2
    • author = dependabot[bot]
    • author = mergify-ci-bot
    • author = renovate[bot]

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|ui)(?:\(.+\))?:

🟢 🔎 Reviews

Wonderful, this rule succeeded.
  • #changes-requested-reviews-by = 0
  • #review-requested = 0
  • #review-threads-unresolved = 0

🟢 📕 PR description

Wonderful, this rule succeeded.
  • body ~= (?ms:.{48,})

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes --debug behavior across the split Rust/Python CLI by (1) teaching the Rust binary to accept the top-level --debug flag and forward it when dispatching to Python shims, and (2) actually enabling the Python-side debug toggle so existing is_debug() call sites start working.

Changes:

  • Python: call utils.set_debug(debug=debug) from the root Click group so --debug affects runtime behavior.
  • Rust: add a global --debug flag to CliRoot and re-inject it into forwarded argv for shimmed dispatches; add unit tests covering parsing and forwarding.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
mergify_cli/cli.py Propagates Click’s parsed --debug into the module-level debug toggle used by utils.is_debug().
crates/mergify-cli/src/main.rs Adds a global --debug clap flag and forwards it to Python shim argv (plus unit tests).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/mergify-cli/src/main.rs Outdated
Comment thread mergify_cli/cli.py
@jd jd marked this pull request as ready for review May 27, 2026 08:04
@mergify mergify Bot requested a review from a team May 27, 2026 08:09
… Python

Two coupled gaps the same user-visible bug was hiding:

1. The Rust binary never declared the top-level `--debug` flag the
   Python CLI accepts. Invocations like `mergify --debug ci git-refs`
   were rejected with `error: unexpected argument '--debug' found`
   the moment a command was promoted from shim to native. Add
   `debug: bool` as a `global = true` argument on `CliRoot`; native
   commands accept it as a no-op (no native code path consults the
   flag yet) and shimmed dispatches re-inject `--debug` at the front
   of the forwarded argv so the Python `cli` group still receives it.

2. The Python `cli.py` parsed `--debug` into `ctx.obj["debug"]` but
   never called `utils.set_debug(...)`, so the module-level `_DEBUG`
   toggle stayed `False` and the 6+ `if is_debug():` sites in
   `utils.py` / `stack/*` never fired regardless of the flag. Wire
   `set_debug(debug=debug)` from the root group so the flag has the
   effect users have always expected it to have.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Change-Id: I62ac941db12c55c988896086d7042c3dacf863af
@jd jd force-pushed the devs/jd/worktree-rust-port/accept-debug-rust-binary-actually-toggle-python--62ac941d branch from 83fc4d3 to fe3d611 Compare May 27, 2026 08:27
@jd jd temporarily deployed to func-tests-live May 27, 2026 08:27 — with GitHub Actions Inactive
@jd jd temporarily deployed to func-tests-live May 27, 2026 08:27 — with GitHub Actions Inactive
@jd
Copy link
Copy Markdown
Member Author

jd commented May 27, 2026

Revision history

# Type Changes Reason Date
1 initial 83fc4d3 2026-05-27 08:27 UTC
2 content 83fc4d3 → fe3d611 (raw) 2026-05-27 08:27 UTC

@mergify mergify Bot deployed to Mergify Merge Protections May 27, 2026 08:28 Active
@mergify mergify Bot requested a review from a team May 27, 2026 09:10
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented May 27, 2026

Merge Queue Status

  • Entered queue2026-05-27 11:55 UTC · Rule: default
  • Checks skipped · PR is already up-to-date
  • Merged2026-05-27 11:55 UTC · at fe3d61123a676bdabd6df9d21b166d176e2b5580 · squash

This pull request spent 11 seconds in the queue, including 2 seconds running CI.

Required conditions to merge

@mergify mergify Bot added the queued label May 27, 2026
@mergify mergify Bot merged commit 3a99878 into main May 27, 2026
36 checks passed
@mergify mergify Bot removed the queued label May 27, 2026
@mergify mergify Bot deleted the devs/jd/worktree-rust-port/accept-debug-rust-binary-actually-toggle-python--62ac941d branch May 27, 2026 12:29
mergify Bot pushed a commit that referenced this pull request May 27, 2026
…#1439)

Every command crate's test module re-rolled the same ~30 LOC of
`SharedBytes` / `SharedWriter` / `Captured` / `make_output` glue —
about 350 LOC of pure boilerplate across 15 files, drifting over
time (some `Captured` had `stderr`, some didn't; one file even
carried a `_stderr_accessor_lives` dead-code stub just to silence
the resulting warning).

Extract the canonical version into a new `mergify-test-support`
crate that other crates pull in as a `dev-dependencies`. The new
`Captured` API exposes `human()` / `new(mode)` constructors and
`stdout()` / `stderr()` accessors, so the common pattern shrinks
from a 12-line `String::from_utf8(cap.stdout.lock().unwrap().clone())`
to `let s = cap.stdout()`.

Net `-418 / +114` lines across the workspace. Behavior unchanged;
all 233 tests pass.

The crate is `publish = false` and only ever appears under
`[dev-dependencies]`, so the test-only types never leak into a
production build.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Depends-On: #1464
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants