fix: stop demo.py's menu dispatch from needing a hardcoded key whitelist - #430
Merged
Merged
Conversation
Selecting a category option checked the pressed key against a literal "0123456789abc...xyzA" string before ever looking at the category's own options dict. Every time a new uppercase option key got added to menu_categories (most recently [B] for get_next_scheduled_workout) that string had to be remembered and updated too, or the option is unreachable — pressing B printed "Invalid selection" even though it's a real, listed menu entry. Drop the whitelist. The options dict membership check right below it already does the real validation correctly by construction, and its "Invalid option selection" message already lists the real valid keys for the current category, so nothing is lost — the whole bug class becomes impossible instead of one whitelist edit behind every new key.
Contributor
|
Warning Review limit reachedNext included review available in 10 minutes. View limit detailsLimit details: You’ve used all 8 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (1)
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. Comment |
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
Pressing
[B]for the new "Get the earliest upcoming scheduled workout" menu option (added in #429) printed "❌ Invalid selection" instead of running it —demo.py's category-menu dispatch checked the pressed key against a literal"0123456789abc...xyzA"string before ever consulting the category's own options dict, and that string was never updated for the newBkey.Removed the whitelist entirely. The
if option in category_optionscheck right below it already validates correctly against the real menu (by construction, since it's the same dict driving what's printed on screen), and its error message already lists the real valid keys for that category — nothing is lost, and no future option key can go stale again.Test plan
python -m pytest -q(381 passed)ruff check/ruff format --check/mypyall cleanB→get_next_scheduled_workout,A→get_activities_filtered, an existing lowercase key still works, and a genuinely invalid key now prints the accurate list of valid options instead of a generic message