Skip to content

test: prevent duplicated aliases from idiots#365

Merged
KSXGitHub merged 6 commits into
masterfrom
claude/fix-visible-alias-conflict-o1le1
Mar 22, 2026
Merged

test: prevent duplicated aliases from idiots#365
KSXGitHub merged 6 commits into
masterfrom
claude/fix-visible-alias-conflict-o1le1

Conversation

@KSXGitHub

Copy link
Copy Markdown
Owner

Summary

This PR adds validation to detect and reject redundant visible aliases in CLI arguments that duplicate their own primary flag names. The render_usage_md() function now returns a Result type to communicate validation errors, and the CLI tool properly handles and reports these errors.

Key Changes

  • New error type: Added RenderUsageMdError enum with two variants:

    • RedundantVisibleLongAlias: Detects when a visible alias matches the argument's own long flag
    • RedundantVisibleShortAlias: Detects when a visible short alias matches the argument's own short flag
  • Validation function: Implemented reject_redundant_aliases() to iterate through all arguments and check for duplicate aliases before rendering

  • API change: Modified render_usage_md() to return Result<String, RenderUsageMdError> instead of String, allowing callers to handle validation errors

  • CLI error handling: Updated the usage_md binary to:

    • Handle the Result return type
    • Print errors to stderr with proper formatting
    • Return appropriate exit codes (SUCCESS or FAILURE)
  • Test updates: Updated the test to unwrap the Result from render_usage_md()

Implementation Details

  • Uses derive_more crate for automatic Display and Error trait implementations
  • Uses pipe_trait for functional-style error construction in the validation function
  • Validation runs early in the rendering process to fail fast on configuration errors
  • Error messages clearly indicate which flag has the problematic alias

https://claude.ai/code/session_01TSnvxN1HBwwzhxfFShWAQ5

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds fail-fast validation when generating USAGE.md so redundant visible aliases (aliases that repeat the argument’s own primary flag name) are detected and reported as a structured error, with the CLI binary returning an appropriate exit code.

Changes:

  • Changed render_usage_md() to return Result<String, RenderUsageMdError> and introduced RenderUsageMdError.
  • Added reject_redundant_aliases() validation before rendering usage markdown.
  • Updated pdu-usage-md and the sync test to handle the new Result API.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/sync_usage_md.rs Updates the sync test to unwrap the new Result from render_usage_md().
src/usage_md.rs Introduces a new error type, adds redundant-alias validation, and returns Ok(out) instead of a bare String.
cli/usage_md.rs Handles render_usage_md() errors, prints to stderr, and returns success/failure exit codes.

Comment thread src/usage_md.rs
@github-actions

github-actions Bot commented Mar 22, 2026

Copy link
Copy Markdown

Performance Regression Reports

commit: a108ad4

There are no regressions.

claude added 5 commits March 22, 2026 21:58
… own flag name

A visible_alias matching the argument's own --long name (or a
visible_short_alias matching its -short flag) is a coding mistake that
produces redundant output in USAGE.md. The new validation runs at the
start of render_usage_md() and exits with code 1 if any such
redundancy is found.

https://claude.ai/code/session_01TSnvxN1HBwwzhxfFShWAQ5
…ss::exit

Define a non-exhaustive `RenderUsageMdError` enum with
`derive_more::{Display, Error}` and make `render_usage_md` return
`Result<String, RenderUsageMdError>`. The callsites in cli/usage_md.rs
and tests/sync_usage_md.rs now handle the error appropriately.

https://claude.ai/code/session_01TSnvxN1HBwwzhxfFShWAQ5
- Split RedundantVisibleAlias into RedundantVisibleLongAlias(String)
  and RedundantVisibleShortAlias(char), moving message into #[display]
- Rename validate_no_redundant_visible_aliases to check_visible_aliases
- Use if-let-Err pattern in cli/usage_md.rs to match lib.rs style
- Simplify test to use .unwrap() instead of .expect()
- Fix doc comment to use plain English instead of backtick-wrapped flags

https://claude.ai/code/session_01TSnvxN1HBwwzhxfFShWAQ5
…t, revert to match

- Rename check_visible_aliases to reject_redundant_aliases
- Use pipe-trait to flatten nested constructor and Err calls
- Revert cli/usage_md.rs back to match pattern

https://claude.ai/code/session_01TSnvxN1HBwwzhxfFShWAQ5
@KSXGitHub KSXGitHub force-pushed the claude/fix-visible-alias-conflict-o1le1 branch from 3609c60 to 224c3ec Compare March 22, 2026 21:58
@KSXGitHub KSXGitHub requested a review from Copilot March 22, 2026 22:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread tests/sync_usage_md.rs Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@KSXGitHub KSXGitHub marked this pull request as ready for review March 22, 2026 22:18
@KSXGitHub KSXGitHub merged commit d27c20b into master Mar 22, 2026
13 checks passed
@KSXGitHub KSXGitHub deleted the claude/fix-visible-alias-conflict-o1le1 branch March 22, 2026 22:26
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.

3 participants