fix(serve): validate --device via clap possible values (exit 2) - #304
Open
r0x0r wants to merge 1 commit into
Open
fix(serve): validate --device via clap possible values (exit 2)#304r0x0r wants to merge 1 commit into
r0x0r wants to merge 1 commit into
Conversation
Model `rocm serve --device` as a clap `ValueEnum` (`DevicePolicyArg`) so an invalid value is rejected by clap's usage validation (exit code 2) with the valid choices listed, instead of parsing as a free-form string and failing later in application logic with a generic "unsupported device policy" error (exit code 1). This makes `--device` consistent with every other enum-style argument in the CLI (`--engine`, config set-*, engines install, etc.), all of which use clap possible values. The historical aliases (`auto`/`gpu` for gpu_required, `cpu` for cpu_only) stay accepted for backward compatibility but are hidden from the advertised list, and the intentional cpu_only app-level rejection (exit 1 with a GPU-required message) is preserved. Adds regression tests asserting invalid `--device` is a clap InvalidValue usage error and that every value and alias still parses, and reworks the device possible-values sync test to read clap's structural possible values rather than a hand-written doc string. Signed-off-by: Roman Sirokov <roman.sirokov@amd.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rocm serve --device boguspreviously rejected the invalid value via applicationlogic (exit code 1, message "unsupported device policy") instead of clap's
possible valuesvalidation (exit code 2). Every other enum-style argument inthe CLI —
--engine,config set-*,engines install, etc. — uses clappossible values, which produces exit code 2 and lists the valid choices.This models
--deviceas a clapValueEnum(DevicePolicyArg) so invalid inputis rejected consistently and the valid choices are listed in the error.
Changes
DevicePolicyArg(gpu_required,gpu_preferred,cpu_only) and changeserve --devicefromOption<String>toOption<DevicePolicyArg>.auto/gpu→gpu_required,cpu→cpu_only) stayaccepted for backward compatibility but are hidden from the advertised list.
cpu_onlyapp-level rejection (exit 1 with a GPU-requiredmessage) is preserved — only the generic "unsupported device policy" exit-1
path is replaced by clap's exit-2 usage error.
possible values instead of a hand-written doc string, mirroring the existing
--enginetest.Behavior
Before:
After:
Tests
serve_rejects_unknown_device_policy_as_usage_error— asserts invalid--deviceis a clapInvalidValueusage error (fails before the fix, passesafter).
serve_accepts_device_policy_values_and_aliases— asserts every value andlegacy alias still parses to the expected variant.
serve_device_help_lists_match_device_policy_names— reworked to verify clap'sstructural possible values stay in sync with
DevicePolicy.cargo test -p rocm --bin rocm,cargo clippy -p rocm --all-targets -- -D warnings, andcargo fmtall pass. No new e2e scenario is added: the change isa CLI usage-validation/exit-code correction with no new runtime engine behavior,
and it is fully covered by the argument-parsing unit tests above.