-
-
Notifications
You must be signed in to change notification settings - Fork 41
refactor(error): improve command suggestion logic to return better matches using aliases #999
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…tches using aliases
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Reviewer's GuideRefactors command suggestion logic to return the closest-matching alias when it better matches user input, rather than always returning the command’s qualified name. Class diagram for updated command suggestion logicclassDiagram
class ErrorHandler {
_suggest_command(ctx: Context) List~str~ | None
}
class Command {
qualified_name: str
aliases: List~str~
}
ErrorHandler --> Command : iterates over
%% Highlighted logic change
ErrorHandler : +Suggests best match (alias or qualified_name)
Command : +aliases considered for suggestion
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @electron271 - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `tux/handlers/error.py:1231` </location>
<code_context>
# than previously stored, update the distance.
- current_min = command_distances.get(qualified_name, max_distance + 1)
+ current_min = command_distances.get(best_match_name, max_distance + 1)
if min_dist_for_cmd < current_min:
- command_distances[qualified_name] = min_dist_for_cmd
+ command_distances[best_match_name] = min_dist_for_cmd
# If no commands were within the distance threshold.
</code_context>
<issue_to_address>
Storing suggestions by best_match_name may lead to duplicate suggestions for commands with multiple close aliases.
To prevent redundant suggestions, deduplicate or select a single alias per command when multiple aliases meet the threshold.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
if distance < min_dist_for_cmd:
min_dist_for_cmd = distance
best_match_name = name
# If the command is close enough, store its distance.
if min_dist_for_cmd <= max_distance:
# If we found a closer match for this command (e.g., via an alias)
# than previously stored, update the distance.
current_min = command_distances.get(best_match_name, max_distance + 1)
if min_dist_for_cmd < current_min:
command_distances[best_match_name] = min_dist_for_cmd
=======
if distance < min_dist_for_cmd:
min_dist_for_cmd = distance
best_match_name = name
canonical_name = qualified_name # Track the canonical command name
# If the command is close enough, store its distance.
if min_dist_for_cmd <= max_distance:
# Deduplicate by canonical command name, only keep the closest alias
current_min = command_distances.get(canonical_name, max_distance + 1)
if min_dist_for_cmd < current_min:
command_distances[canonical_name] = min_dist_for_cmd
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if distance < min_dist_for_cmd: | ||
| min_dist_for_cmd = distance | ||
| best_match_name = name | ||
|
|
||
| # If the command is close enough, store its distance. | ||
| if min_dist_for_cmd <= max_distance: | ||
| # If we found a closer match for this command (e.g., via an alias) | ||
| # than previously stored, update the distance. | ||
| current_min = command_distances.get(qualified_name, max_distance + 1) | ||
| current_min = command_distances.get(best_match_name, max_distance + 1) | ||
| if min_dist_for_cmd < current_min: | ||
| command_distances[qualified_name] = min_dist_for_cmd | ||
| command_distances[best_match_name] = min_dist_for_cmd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Storing suggestions by best_match_name may lead to duplicate suggestions for commands with multiple close aliases.
To prevent redundant suggestions, deduplicate or select a single alias per command when multiple aliases meet the threshold.
| if distance < min_dist_for_cmd: | |
| min_dist_for_cmd = distance | |
| best_match_name = name | |
| # If the command is close enough, store its distance. | |
| if min_dist_for_cmd <= max_distance: | |
| # If we found a closer match for this command (e.g., via an alias) | |
| # than previously stored, update the distance. | |
| current_min = command_distances.get(qualified_name, max_distance + 1) | |
| current_min = command_distances.get(best_match_name, max_distance + 1) | |
| if min_dist_for_cmd < current_min: | |
| command_distances[qualified_name] = min_dist_for_cmd | |
| command_distances[best_match_name] = min_dist_for_cmd | |
| if distance < min_dist_for_cmd: | |
| min_dist_for_cmd = distance | |
| best_match_name = name | |
| canonical_name = qualified_name # Track the canonical command name | |
| # If the command is close enough, store its distance. | |
| if min_dist_for_cmd <= max_distance: | |
| # Deduplicate by canonical command name, only keep the closest alias | |
| current_min = command_distances.get(canonical_name, max_distance + 1) | |
| if min_dist_for_cmd < current_min: | |
| command_distances[canonical_name] = min_dist_for_cmd |
meatharvester
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everything looks good from what we tested so i think this is good to merge
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #999 +/- ##
========================================
- Coverage 9.57% 9.57% -0.01%
========================================
Files 123 123
Lines 10412 10415 +3
Branches 1278 1279 +1
========================================
Hits 997 997
- Misses 9313 9316 +3
Partials 102 102
*This pull request uses carry forward flags. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Description
tux will now suggest aliases if they are a closer match to ensure the user gets a more accurate recommendation
Guidelines
My code follows the style guidelines of this project (formatted with Ruff)
I have performed a self-review of my own code
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation if needed
My changes generate no new warnings
I have tested this change
Any dependent changes have been merged and published in downstream modules
I have added all appropriate labels to this PR
I have followed all of these guidelines.
How Has This Been Tested? (if applicable)
ran a bunch of wrong commands that are similar to aliases
Screenshots (if applicable)
Please add screenshots to help explain your changes.
Additional Information
Please add any other information that is important to this PR.
Summary by Sourcery
Enhance the command suggestion logic to evaluate aliases when determining the closest match and return the alias if it provides a better match than the original command name.
Enhancements:
Documentation: