Skip to content

Promote try_parse_localized to a generic blanket trait (11.1.2)#350

Merged
leynos merged 11 commits into
mainfrom
11-1-2-promote-try-parse-localized-to-a-generic-blanket-trait
Jun 22, 2026
Merged

Promote try_parse_localized to a generic blanket trait (11.1.2)#350
leynos merged 11 commits into
mainfrom
11-1-2-promote-try-parse-localized-to-a-generic-blanket-trait

Conversation

@lodyai

@lodyai lodyai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements roadmap item 11.1.2 — promote try_parse_localized* from the hello_world example into crate-level localized parsing APIs in ortho_config.

This adds:

  • LocalizedParse: clap::Parser, a blanket extension trait for default-base localized parsing.
  • parse_localized_command, the base-agnostic primitive for callers that already localized a clap::Command with LocalizeCmd::with_base.
  • hello_world migration to the public parsing primitive while preserving its hello_world.cli catalogue base.

Plan document: docs/execplans/11-1-2-promote-try-parse-localized-to-a-generic-blanket-trait.md. Design source: docs/cli-localization-design.md §4.2.

Review Feedback Addressed

  • Added CHANGELOG.md entries for LocalizedParse and parse_localized_command.
  • Added README signposts for localized CLI parsing.
  • Added trybuild pass/fail coverage for the LocalizedParse: clap::Parser compile-time contract.
  • Documented why Fluent-unsafe command identifiers remain runtime panic coverage until derive-time identifier validation lands.
  • Added warn-level tracing when clap-error localization falls back to the stock message, with stable identifier, error_kind, and locale fields.

Key Design Decisions

  • Ship parse_localized_command as the load-bearing primitive and keep LocalizedParse as thin default-base convenience.
  • Keep the hello_world example on its existing with_base("hello_world.cli") catalogue.
  • Preserve .with_cmd(&command) enrichment on the from_arg_matches error path.
  • Treat Fluent-unsafe identifiers as a documented panic contract for this task; compile-time validation remains planned derive work.

Validation

  • make fmt
  • make check-fmt
  • make lint
  • make test
  • make markdownlint
  • make nixie

References

@sourcery-ai sourcery-ai Bot 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.

Sorry @LodyAI[bot], you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4ddb350e-bb23-4d18-9aa1-008d919f0a72

📥 Commits

Reviewing files that changed from the base of the PR and between dde16c8 and 5e6704a.

📒 Files selected for processing (6)
  • docs/users-guide.md
  • ortho_config/src/localizer/clap_command/parse.rs
  • ortho_config/src/localizer/clap_error.rs
  • ortho_config/tests/trybuild/localized_parse_parser.rs
  • ortho_config/tests/trybuild/localized_parse_requires_parser.rs
  • ortho_config/tests/trybuild/localized_parse_requires_parser.stderr
⚠️ Files not reviewed because the changes were too large to process (6)
  • docs/users-guide.md
  • ortho_config/src/localizer/clap_command/parse.rs
  • ortho_config/src/localizer/clap_error.rs
  • ortho_config/tests/trybuild/localized_parse_parser.rs
  • ortho_config/tests/trybuild/localized_parse_requires_parser.rs
  • ortho_config/tests/trybuild/localized_parse_requires_parser.stderr

Localised CLI parsing promotion to public APIs (roadmap 11.1.2)

This PR implements roadmap item 11.1.2 by promoting try_parse_localized* functionality from the hello_world example into crate-level, reusable localised parsing APIs for ortho_config, following the plan in docs/execplans/11-1-2-promote-try-parse-localized-to-a-generic-blanket-trait.md and aligning with docs/cli-localization-design.md’s clarified CLI localisation/error-metadata and identifier semantics.

Core API additions

  • LocalizedParse: clap::Parser (blanket extension trait)

    • try_parse_localized(localizer) parses from std::env::args_os()
    • try_parse_localized_from(iter, localizer) parses from a supplied iterator (typed output)
    • try_parse_localized_with_matches(iter, localizer) parses from a supplied iterator (typed output + raw clap::ArgMatches)
    • Implemented via a blanket impl<P: Parser> LocalizedParse for P {} delegating to parse_localized_command(Self::command().localize(localizer), ...), enabling “default-base” behaviour when catalogue keys are rooted compatibly with the command bin_name.
  • parse_localized_command (base-agnostic primitive)

    • Accepts an already-localised clap::Command, an argument iterator, and a Localizer.
    • Runs try_get_matches_from_mut, localises clap parse errors, converts ArgMatches into P: FromArgMatches, and localises conversion errors while preserving the from_arg_matches error enrichment via .with_cmd(&command).

Exports are wired through ortho_config::localizer::{..., LocalizedParse, parse_localized_command}.

Observability for localisation fallback

  • When clap error localisation falls back to stock clap messaging (i.e., no Fluent translation is found), the implementation emits warn-level tracing with stable fields:
    • identifier, error_kind, locale
  • To support stable locale reporting, Localizer now exposes locale() -> Option<&LanguageIdentifier> (with FluentLocalizer reporting the consumer bundle locale when available).

Documentation + changelog updates

  • CHANGELOG.md documents the new public APIs: LocalizedParse and parse_localized_command.
  • README.md adds/points to the “Localized CLI parsing” core feature.
  • docs/users-guide.md is updated with concrete examples:
    • Cli::try_parse_localized(&localizer)
    • Cli::try_parse_localized_from([...], localizer)
    • Cli::try_parse_localized_with_matches([...], localizer)
    • plus guidance distinguishing when to use LocalizedParse vs LocalizeCmd::with_base(...) + parse_localized_command based on catalogue-key root.
  • docs/developers-guide.md clarifies the two integration approaches and the requirement to keep the error-enrichment paths distinct (including preserving valid_subcommands on the from_arg_matches path).
  • docs/adr-006-identifier-derivation-panics.md and docs/cli-localization-design.md document the expanded runtime panic surface when opting into LocalizedParse (until the planned derive-time guard in a later roadmap item).

Example migration: hello_world

  • The hello_world example migrates off its example-specific localised parsing glue:
    • it constructs a localised clap command (with with_base("hello_world.cli") and localisation before parsing)
    • then calls ortho_config::parse_localized_command(...) to produce (typed value, clap::ArgMatches)
  • The example’s localisation tests are refactored accordingly, and help/version locale tests remain snapshot-based where applicable.

Test and contract coverage

  • Trybuild (compile-time) coverage

    • Verifies LocalizedParse: clap::Parser usage is available for parser types.
    • Adds compile-fail coverage ensuring non-clap::Parser receivers cannot call try_parse_localized_*.
  • Integration tests

    • Adds ortho_config/tests/localized_parse.rs covering:
      • successful localised nested-subcommand parsing
      • ArgMatches/subcommand_name() correctness via try_parse_localized_with_matches
      • expected Fluent identifier lookup behaviour (matching message_id_for(...))
      • warn-level fallback tracing fields (identifier, error_kind, locale)
      • documented panic behaviour for Fluent-unsafe identifiers.

Summary

parse_localized_command is the primary load-bearing primitive, with LocalizedParse as a thin convenience layer for default-base scenarios. The example and documentation were updated to consistently reflect both integration patterns, while adding fallback observability and comprehensive compile-time/runtime test coverage.

Walkthrough

Introduces parse_localized_command (free function) and LocalizedParse (blanket trait) to the public API, enabling any #[derive(clap::Parser)] type to parse with localised help and error messages via Fluent. Extends Localizer with optional locale() method. Removes example-specific helpers. Adds comprehensive integration and compile-time tests. Emits warn-level tracing on translation fallback. Updates ADR-006, CLI design document, user/developer guidance, and execution plans.

Changes

Localised Parsing API Promotion and Rollout

Layer / File(s) Summary
Core parsing API, Localizer extension, and module exports
ortho_config/src/localizer/clap_command/parse.rs, ortho_config/src/localizer/clap_command/mod.rs, ortho_config/src/localizer/mod.rs, ortho_config/src/localizer/clap_error.rs, ortho_config/src/lib.rs
Introduces parse_localized_command free function and LocalizedParse blanket trait in a new parse submodule; adds Localizer::locale() method with FluentLocalizer implementation; emits tracing::warn! on translation fallback with identifier/error_kind/locale fields; re-exports all new items through the module hierarchy.
Integration tests, test doubles, and compile-time validation
ortho_config/tests/localized_parse.rs, ortho_config/tests/localized_parse_trybuild.rs, ortho_config/tests/trybuild/localized_parse_*.rs, ortho_config/tests/trybuild/localized_parse_requires_parser.stderr, ortho_config/Cargo.toml
Defines fixture CLI structures with nested subcommands and invalid Fluent identifier variant; creates test Localizer doubles (RecordingLocalizer, MissingSubcommandLocalizer, TranslatedLocalizer) and tracing event capture harness; validates successful parse with ArgMatches retention, NoOpLocalizer parity, error-context preservation, Fluent identifier coverage against message_id_for, panic on invalid identifier, and trait-bound enforcement via trybuild pass/fail fixtures.
hello_world example parsing migration
examples/hello_world/src/cli/localization.rs, examples/hello_world/src/cli/mod.rs, examples/hello_world/src/main.rs, examples/hello_world/src/cli/tests/localisation.rs, examples/hello_world/tests/localised_help.rs
Removes ParsedCommandLine struct and three inherent parsing helpers; simplifies localization.rs to a single re-export; refactors parse_command_line() to construct pre-localised command and call parse_localized_command; migrates unit tests to the new function; adds assert_display_request_succeeds helper for --help/--version coverage across en-US and ja-JP locales.
ADR-006 and CLI localisation design contract updates
docs/adr-006-identifier-derivation-panics.md, docs/cli-localization-design.md
Extends ADR-006 with LocalizedParse panic-surface observation. Substantially revises the CLI localisation design document covering promoted parsing surfaces, identifier normalisation and collision contracts, locale-resolution lifecycle and typestate observability, clap error coverage gates with build-time drift detection, eager error-context localisation, i18n-embed bridge semantics, derive behaviour and artefact emission, and updated failure modes.
User and developer guidance, README, and CHANGELOG
docs/users-guide.md, docs/developers-guide.md, docs/design.md, examples/hello_world/README.md, README.md, ortho_config/README.md, ortho_config_macros/README.md, CHANGELOG.md
Documents LocalizedParse and parse_localized_command usage patterns with worked examples; adds parse-error enrichment rules; updates design references; refreshes the hello_world README; adds feature bullets and CHANGELOG entries for the new public items; clarifies JSON5 feature semantics.
11.1.2 execution plan, roadmap completion, and living document updates
docs/execplans/11-1-2-promote-try-parse-localized-to-a-generic-blanket-trait.md, docs/roadmap.md, docs/execplans/*.md
Introduces the 11.1.2 living execution plan with constraints, tolerances, risks, decision log D-1–D-5, validation criteria, and interface sketches; marks roadmap item 11.1.2 complete with implementation evidence and findings; reflows and updates all other execution plans for accuracy and consistency.
Documentation-only line-reflow
docs/adr-*.md, docs/*.md, docs/execplans/*.md, ortho_config_macros/README.md
Markdown prose reflow across ADRs, guides, and reference documents without substantive content changes.

Possibly Related Issues

Possibly Related PRs

  • leynos/ortho-config#238: This PR builds directly on PR #238's Fluent Localizer/DemoLocalizer clap integration by refactoring example-specific parsing glue into the new parse_localized_command + LocalizedParse API and extending the Localizer trait (adding locale()).
  • leynos/ortho-config#243: This PR builds on the Fluent localisation integration from #243 by extending ortho_config's Localizer trait and adding clap-localised parsing APIs on top of that same localisation layer.
  • leynos/ortho-config#245: This PR extends the clap error Fluent-localisation infrastructure from PR #245 by adding warn-level tracing on translation fallback and strengthening error-context localisation semantics.

Suggested Reviewers

  • codescene-delta-analysis

Poem

🦀 The parse glue is gone, no more bespoke mess,
A blanket trait covers each Parser no less,
parse_localized_command stands proud and alone,
Fluent identifiers looked up, warnings are shown.
The roadmap ticks forward — 11.1.2 complete! 🎉

🚥 Pre-merge checks | ✅ 20
✅ Passed checks (20 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and directly summarises the primary changeset: promoting try_parse_localized to a blanket trait with roadmap reference (11.1.2).
Description check ✅ Passed The description comprehensively relates the changeset scope, implementation details, design decisions, validation steps, and references to roadmap item 11.1.2.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Testing (Overall) ✅ Passed New functionality is guarded by substantive, rigorous tests that directly exercise behaviour. Tests use explicit assertions on localiser interaction recording, tracing event capture, and parsed out...
User-Facing Documentation ✅ Passed User-facing documentation is comprehensive and properly addresses all new functionality introduced in roadmap item 11.1.2: LocalizedParse trait and parse_localized_command function are clearly...
Developer Documentation ✅ Passed All documentation requirements met: developers guide updated with LocalizedParse/parse_localized_command guidance; design documents (cli-localization-design.md §4.2, design.md) reflect changes; roa...
Module-Level Documentation ✅ Passed All Rust modules in this PR carry docstrings explaining purpose, utility, function, and component relationships. Primary module parse.rs documents its role connecting parser implementations, comm...
Testing (Unit And Behavioural) ✅ Passed Tests comprehensively cover unit-level behaviour, edge cases and error paths: 8 unit tests exercise trait methods, error localisation, panic contracts, and identifier coverage; 2 trybuild tests ver...
Testing (Property / Proof) ✅ Passed The PR introduces documented hard constraints (identifier semantics, output preservation, circular dependency avoidance) but does not establish algorithmic invariants over input ranges, state order...
Testing (Compile-Time / Ui) ✅ Passed Trybuild tests comprehensively verify compile-time contracts (blanket trait availability and Parser bound enforcement) with meaningful expected diagnostics. Snapshot tests encode help-text/error-ou...
Unit Architecture ✅ Passed PR maintains clear separation of concerns: parse-localized functions are queries with explicit error handling and warn-level tracing side-effects; LocalizeCmd trait is a documented command with #[m...
Domain Architecture ✅ Passed LocalizedParse and parse_localized_command properly segregate clap framework concerns within a dedicated adapter module (clap_command/). Domain logic remains framework-agnostic; these utilities are...
Observability ✅ Passed Observability properly implemented: warn-level tracing at translation fallback boundary with stable fields (identifier, error_kind, locale), comprehensive test coverage validating event emission, a...
Security And Privacy ✅ Passed No secrets, injection risks, unsafe code, or privacy concerns detected. Logging emits only metadata (identifier, error_kind, locale), test credentials are fake, argument handling is type-safe throu...
Performance And Resource Use ✅ Passed Changes avoid performance regressions. parse_localized_command and LocalizedParse are thin wrappers around clap parsing with error-path-only allocations. All string/HashMap allocations are bounded...
Concurrency And State ✅ Passed No shared mutable state, async code, locks held across operations, or concurrency hazards introduced. All state is owned locally by test-local localizer instances; Localizer trait enforces Send+Syn...
Architectural Complexity And Maintainability ✅ Passed LocalizedParse trait and parse_localized_command function justify their introduction: they remove 81 lines of example-specific boilerplate, establish a crate-level contract with clear reuse paths (...
Rust Compiler Lint Integrity ✅ Passed No lint suppressions hiding unused code, all imports used, dead code properly removed, no excessive cloning; module structure appropriately scoped.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 11-1-2-promote-try-parse-localized-to-a-generic-blanket-trait

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

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@lodyai lodyai Bot force-pushed the 11-1-2-promote-try-parse-localized-to-a-generic-blanket-trait branch from ab73ff3 to 660267f Compare June 14, 2026 23:27
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos leynos marked this pull request as ready for review June 15, 2026 22:59

@sourcery-ai sourcery-ai Bot 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.

Sorry @leynos, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos

leynos commented Jun 20, 2026

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot added the Roadmap label Jun 20, 2026
@leynos

leynos commented Jun 21, 2026

Copy link
Copy Markdown
Owner

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@lodyai lodyai Bot force-pushed the 11-1-2-promote-try-parse-localized-to-a-generic-blanket-trait branch from 90bbb5e to 2c6b597 Compare June 21, 2026 14:30
codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos

leynos commented Jun 21, 2026

Copy link
Copy Markdown
Owner

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos leynos changed the title Draft execplan: promote try_parse_localized to a generic blanket trait (11.1.2) Promote try_parse_localized to a generic blanket trait (11.1.2) Jun 21, 2026
@leynos

leynos commented Jun 21, 2026

Copy link
Copy Markdown
Owner

@coderabbitai Have the following now been resolved?

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
User-Facing Documentation ⚠️ Warning New LocalizedParse trait methods lack documentation with code examples in users-guide; only parse_localized_command function is shown, missing the zero-configuration trait approach. Add users-guide example showing trait method usage (e.g. Cli::try_parse_localized(&localizer) and try_parse_localized_from), clearly distinguishing the two approaches by catalogue key root.

@leynos

leynos commented Jun 21, 2026

Copy link
Copy Markdown
Owner

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n "try_parse_localized|parse_localized_command|LocalizedParse" docs/users-guide.md

Length of output: 823



@leynos Yes, that warning is resolved. docs/users-guide.md now includes:

  • Cli::try_parse_localized(&localizer) (line 292) — zero-configuration trait usage for environment args.
  • Cli::try_parse_localized_from(["demo", "--verbose"], localizer) (line 296) — supplied-iterator variant.
  • Cli::try_parse_localized_with_matches(...) (line 311) — returns both typed output and raw ArgMatches.

The document explicitly distinguishes the two approaches by catalogue-key root: use LocalizedParse when catalogue keys are rooted at the command bin_name, and reach for LocalizeCmd::with_base + parse_localized_command when the key root differs.

leynos and others added 2 commits June 22, 2026 00:11
…1.2)

Add the ExecPlan for roadmap 11.1.2: promote the example's inherent
`try_parse_localized*` methods into a crate-level `LocalizedParse:
clap::Parser` blanket trait, backed by a base-agnostic public
`parse_localized_command` free function so custom-base (`with_base`)
applications also drop the copy-pasted error-localization glue.

The plan captures the community-of-experts review outcomes: the free-fn
primitive (forward-compatible with 11.1.3's derived identifiers), the
panic-as-contract decision (ADR-006 amendment), preservation of the
`with_cmd` enrichment on the from_arg_matches error path, NoOp
transparency, and the identifier-coverage test interpretation.

Status: DRAFT — awaiting approval before implementation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Expose `parse_localized_command` as the base-agnostic parsing primitive
and add the `LocalizedParse` blanket trait for default-base consumers.
Both paths preserve localized clap errors and return raw `ArgMatches`
where callers need them for downstream merge logic.

Add integration coverage for successful parsing, match preservation,
no-op transparency, `from_arg_matches` command enrichment, identifier
coverage through `message_id_for`, and the documented panic contract for
invalid Fluent roots.
leynos added 6 commits June 22, 2026 00:11
Replace the example's copied parsing glue with the crate-level
`parse_localized_command` primitive while preserving the custom
`hello_world.cli` identifier base.

Remove `ParsedCommandLine` and the inherent `try_parse_localized*` methods
so the example no longer shadows the promoted blanket trait API.
Update user, developer, design, ADR, roadmap, and example documentation for
`LocalizedParse` and `parse_localized_command`. Mark roadmap item 11.1.2 as
complete and record final validation in the execplan.

Strengthen the hello world localized help tests so display requests assert
successful exit status, stdout output, and empty stderr for help and version
requests.
Add the completed 11.1.2 decisions, findings, progress, validation, and
CodeRabbit observation to the roadmap so it reflects the implemented
localized parsing surface.
Set the 11.1.2 execplan status to complete and record that the roadmap now
carries the same decisions, findings, progress, validation, and CodeRabbit
observations.
Add observable warnings when clap-error localization falls back to the
stock message, including the missing identifier, error kind, and locale
context when the localizer exposes one.

Add trybuild coverage for the `LocalizedParse: clap::Parser` contract and
document why Fluent-unsafe identifiers remain runtime panic coverage until
derive-time identifier validation lands.

Update the changelog, README signposts, and localization design notes for
the promoted parsing APIs. Apply the repository Markdown formatter output
required for the documentation changes.
Add user-guide examples for the zero-configuration `LocalizedParse`
methods, including environment parsing, supplied-argument parsing, and the
matches-returning variant.

Clarify that the trait uses the command `bin_name` as its catalogue root,
while `parse_localized_command` remains the custom-base path for callers that
need a different message-id namespace.
@lodyai lodyai Bot force-pushed the 11-1-2-promote-try-parse-localized-to-a-generic-blanket-trait branch from 4383c9c to 12b9064 Compare June 21, 2026 22:14
codescene-delta-analysis[bot]

This comment was marked as outdated.

@leynos

leynos commented Jun 21, 2026

Copy link
Copy Markdown
Owner

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

Add runtime coverage for the warn-level clap error fallback event so the
stable `identifier`, `error_kind`, and `locale` fields are asserted. Also
strengthen the parse success path by proving translated command metadata
lookups are used with a caller-provided catalogue base.

Expand the localized parsing module documentation to explain how the parse
helpers relate to `LocalizeCmd` and `Localizer`, and when to use the free
function versus the blanket trait.
codescene-delta-analysis[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as resolved.

@leynos

leynos commented Jun 22, 2026

Copy link
Copy Markdown
Owner

@coderabbitai resume

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Reviews resumed.

Use Oxford spelling in the localized parse module documentation.

Extract the non-trivial localized parse test localizers into `rstest`
fixtures while keeping the tests as separate scenarios. The reviewed tests
exercise different behaviours, so avoid merging them into a single table that
would obscure the assertions.
codescene-delta-analysis[bot]

This comment was marked as outdated.

Document the warn-level tracing emitted when clap error localization falls
back to stock output. Add module docs to the localized parse trybuild
fixtures so their compile-time contract purpose is explicit.

Add user-guide migration guidance for callers moving from direct
`LocalizeCmd` command parsing to `LocalizedParse` or
`parse_localized_command`.
@leynos

leynos commented Jun 22, 2026

Copy link
Copy Markdown
Owner

@coderabbitai Have the following now been resolved?

ortho_config/tests/localized_parse.rs (1)

213-345: 🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Extract shared setup into rstest fixtures and parameterized cases.
Refactor the repeated setup and invocation flow on Line 213-345 into rstest fixtures and #[rstest] cases. Remove duplication around localizer construction, parse invocation, and warning-field assertions.

Refactor sketch
+use rstest::{fixture, rstest};
+
+#[fixture]
+fn fallback_localizer() -> TranslatedLocalizer {
+    TranslatedLocalizer::fallback(langid!("fr-FR"))
+}
+
+#[rstest]
+fn missing_subcommand_reports_expected_warning_fields(
+    fallback_localizer: TranslatedLocalizer,
+) {
+    // shared capture + parse + assert flow
+}

As per coding guidelines, Rust tests must use rstest fixtures for shared setup and replace duplicated tests with parameterized cases; based on learnings, reuse the established fixture pattern rather than parallel helpers.

🤖 Detailed instructions

Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @ortho_config/tests/localized_parse.rs around lines 213 - 345, The test
functions parse_localized_command_uses_translated_metadata_on_success,
noop_localizer_matches_stock_clap,
from_arg_matches_error_retains_valid_subcommands, and
missing_clap_error_translation_emits_warning_fields contain duplicated setup and
invocation patterns around localizer construction and command parsing. Refactor
this by creating rstest fixtures for common localizer creation (such as
TranslatedLocalizer setup, NoOpLocalizer instantiation, and fallback
localizers), then convert these individual test functions into parameterized
rstest cases that accept these fixtures as parameters. This consolidation will
eliminate the repeated parsing and assertion patterns while maintaining the
existing test coverage.

Sources: Coding guidelines, Learnings

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n "rstest|fixture|#\[rstest\]|TranslatedLocalizer|NoOpLocalizer|fallback_localizer" ortho_config/tests/localized_parse.rs | head -60
echo "---"
sed -n '200,360p' ortho_config/tests/localized_parse.rs

Length of output: 8555



@leynos Yes, that suggestion has been resolved. The evidence:

  • use rstest::{fixture, rstest}; is imported at line 8.
  • #[fixture] functions fallback_localizer and translated_localizer are defined at lines 193–206.
  • All three functions cited as having duplicated setup now carry #[rstest] and receive fixtures as parameters:
    • parse_localized_command_uses_translated_metadata_on_success#[rstest] with translated_localizer: TranslatedLocalizer
    • from_arg_matches_error_retains_valid_subcommands#[rstest] with missing_subcommand_localizer
    • missing_clap_error_translation_emits_warning_fields#[rstest] with fallback_localizer: TranslatedLocalizer

noop_localizer_matches_stock_clap remains #[test] — it constructs NoOpLocalizer::new() inline with no shared state to extract, so no fixture is warranted there.

@pandalump

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@leynos leynos merged commit 2b286db into main Jun 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants