Skip to content

fix(lib): validate every variadic fallback - #1049

Merged
jdx merged 2 commits into
mainfrom
codex/validate-variadic-fallbacks
Aug 19, 2026
Merged

fix(lib): validate every variadic fallback#1049
jdx merged 2 commits into
mainfrom
codex/validate-variadic-fallbacks

Conversation

@jdx

@jdx jdx commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • normalize variadic environment, default, and conditional-default values to MultiString
  • split fallback values with the declared delimiter before choices and expression validation
  • validate later fallback values instead of only the first or a combined string

Context

Follow-up to #1037 for the final incremental CodeRabbit finding that arrived as the original PR merged.

Test plan

  • cargo test --workspace --all-features
  • cargo clippy --workspace --all-features -- -D warnings
  • regression coverage includes positional env values plus flag env, default, and default_if values

This PR description was AI-generated.


Note

Medium Risk
Changes core CLI fallback parsing and validation semantics; incorrect edge cases could affect apps using delimited env/defaults, though behavior is intentionally stricter with added tests.

Overview
Fixes variadic fallbacks (env, defaults, default_if) so delimited strings are split and each piece is validated—not only the first value or one combined string.

Fallback binding now uses split_fallback_values with the arg’s delimiter, runs validate_choice_values on the full list, enforces var_min/var_max via new validate_*_fallback_count helpers, and stores MultiString when var applies (including flag env paths where flag.var or arg.var is set). bind_flag_fallback is aligned so option flags with variadic args split and validate the same way; boolean-only variadic flags still map to MultiBool.

Regression tests cover delimiter-split env/defaults, per-value expression errors, and var_max overflow messages for positionals and flags.

Reviewed by Cursor Bugbot for commit 44d5cd5. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Environment-variable and default fallback values are now correctly split using configured delimiters before validation.
    • Variadic arguments and flags now preserve their expected multi-value output when fallbacks contain delimited values.
    • Every split fallback value is validated, providing clearer error reporting for invalid entries.

@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 5aec7f36-f0cb-4b6e-95fb-b8fb8293564f

📥 Commits

Reviewing files that changed from the base of the PR and between cc60dcb and 8f02fed.

📒 Files selected for processing (2)
  • lib/src/parse.rs
  • lib/src/spec/arg.rs

Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

Fallback values now split by configured delimiters before validation. Argument and flag fallbacks preserve scalar or variadic output types. Tests cover environment, default, and conditional fallback values.

Changes

Fallback validation

Layer / File(s) Summary
Argument fallback splitting
lib/src/parse.rs
A shared helper splits fallback values by delimiter. Argument fallbacks validate each split value and preserve scalar or variadic output.
Flag fallback splitting and coverage
lib/src/parse.rs, lib/src/spec/arg.rs
Flag fallbacks account for nested variadic arguments and validate each split value. The parser specification covers environment, default, and conditional fallbacks.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 8f02f

This localized validation change is merge-ready after normal checks and review; no actionable merge-blocking risk remains.

Possibly related PRs

  • jdx/usage#902: Both changes handle splitting and validation for variadic fallback values.
  • jdx/usage#1037: Both changes modify fallback handling and validation in the parser and specification tests.

Suggested reviewers: jambalaya56562

Poem

I split each fallback, neat and bright,
Then check each value left and right.
Scalar stays single, lists expand,
Flags and arguments follow command.
The rabbit hops through passing tests. 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: validating every variadic fallback value.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8f02fed. Configure here.

Comment thread lib/src/parse.rs
@github-actions

Copy link
Copy Markdown
Contributor

Instruction counts

benchmark trend instructions Δ wall (min) Δ
markdown ▁▁▃▃▃▃▃▃▃▃▂█▇ 198,978,780 → 198,711,937 -0.13% 18.27 → 18.71ms +2.38%
startup ▁▁▁▁▁▁▁▁▁▁▁██ 1,212,677 → 1,214,934 +0.19% 1.34 → 1.40ms +4.59%

No instruction-count regression above 1%.

Only instruction counts gate. Wall clock is shown for context — on identical hardware it moves 4-20% run to run.

Measured by tak — instruction-counted CLI benchmarks, stored in this repository's git notes.

Shadow comparison

Parsing mise use -g node@20 against a shadow of mise's committed spec.
Reported, not gated: the shadow grows as the derive learns to express more, so
what to watch is the ratio rather than either column.

framework instructions, cold parse vs usage
usage 4253
argh 6292 1.5x
clap 5893640 1385x
bpaf 21917948 5153x
                                              min       p01       p10    median
usage-rs: argv -> struct                      192       196       199       204  ns
argh: argv -> struct                          287       291       296       303  ns
clap: build tree + parse -> struct         486297    488854    493445    502767  ns
bpaf: build parser + parse -> struct      1634698   1634698   1651604   1682172  ns

usage: argv -> struct                             204 ns      0.20 µs
clap: build tree + parse -> struct             501054 ns    501.05 µs
clap: parse -> struct, tree reused              23472 ns     23.47 µs
clap: build tree only                          306634 ns    306.63 µs

44d5cd52d768 vs cc60dcb7fd01 · measured on the runner, not pushed to the history.

@jdx
jdx merged commit 3f9bdd7 into main Aug 19, 2026
10 checks passed
@jdx
jdx deleted the codex/validate-variadic-fallbacks branch August 19, 2026 02:41
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.

1 participant