Skip to content

fix(moarstats): catch clustered -o in --stats-options output guard#3882

Merged
jqnatividad merged 1 commit into
masterfrom
fix-moarstats-stats-options-output-guard
May 21, 2026
Merged

fix(moarstats): catch clustered -o in --stats-options output guard#3882
jqnatividad merged 1 commit into
masterfrom
fix-moarstats-stats-options-output-guard

Conversation

@jqnatividad
Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #3881 (joined-inputs subprocess race fix). The joined-inputs guard rejects a caller-supplied -o/--output in --stats-options because moarstats captures the qsv stats subprocess stdout itself. The guard used a naive token.starts_with("-o") check, which missed docopt-style clustered short options: -Eo joined.csv expands to -E -o joined.csv, so the joined stats CSV could still be silently redirected away from the captured stdout — reintroducing the empty-capture "missing 'field' column" parse failure.

Changes

  • Add stats_options_redirect_output(), which expands clustered short-option tokens. It treats the no-argument short flags from qsv stats USAGE (-E/-h/-n) as cluster-continuable and stops scanning at the first argument-taking option — so -so (select a column literally named o) is correctly not misread as -s -o.
  • Replace the naive starts_with("-o") guard in the --join-inputs path with the new helper.
  • Add a unit test covering plain (-o, --output, --output=), clustered (-Eo, -Eno), and false-positive (-so, --select output) cases.

Testing

  • cargo t moarstats -F all_features — 88 passed
  • cargo clippy -F all_features — clean

Addresses a roborev review finding (job 2332).

🤖 Generated with Claude Code

The joined-inputs guard rejected a caller-supplied -o/--output in
--stats-options with a naive `token.starts_with("-o")` check. That
missed docopt-style clustered short options: `-Eo joined.csv` expands
to `-E -o joined.csv`, so the joined `qsv stats` CSV could still be
redirected away from the captured stdout, reintroducing the empty-
capture "missing 'field' column" failure.

Add `stats_options_redirect_output()`, which expands clustered short
options using the no-argument short flags from `qsv stats` USAGE
(-E/-h/-n) and stops scanning at the first argument-taking option (so
`-so` — select a column named `o` — is not misread as `-s -o`). Add a
unit test covering plain, clustered, and false-positive cases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Copy link
Copy Markdown
Contributor

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 hardens moarstats --join-inputs against caller-supplied output redirection in --stats-options by correctly detecting docopt-style clustered short options (e.g. -Eo file) that previously bypassed the -o/--output guard and could cause the joined qsv stats subprocess stdout capture to be empty.

Changes:

  • Add stats_options_redirect_output() to detect -o/--output in --stats-options, including clustered short options while avoiding -so false-positives.
  • Replace the prior naive starts_with("-o") guard with the new helper in the --join-inputs path.
  • Add unit tests covering plain, clustered, and false-positive cases.

@jqnatividad jqnatividad merged commit 0243dec into master May 21, 2026
19 checks passed
@jqnatividad jqnatividad deleted the fix-moarstats-stats-options-output-guard branch May 21, 2026 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants