fix: use fuzzyMatch for similar project suggestions and add tests (CLI-C0)#504
fix: use fuzzyMatch for similar project suggestions and add tests (CLI-C0)#504
Conversation
…I-C0) Improves the 'project not found' error from PR #493: 1. Replace ad-hoc prefix/substring scoring in findSimilarProjects with the shared fuzzyMatch utility from src/lib/fuzzy.ts. This adds Levenshtein distance matching so typos like 'senry' → 'sentry' are caught, while keeping the same prefix and substring matching. 2. Change the primary 'Try:' hint from a settings URL to the more actionable 'sentry project list <org>/' command that users can run directly in their terminal. 3. Add two new tests covering the 404 suggestion paths: - Similar projects found: verifies fuzzy-matched slugs appear in error - listProjects fails: verifies the project list command still appears Addresses review feedback on PR #493 (low patch coverage, missing fuzzy matching, should suggest project list command).
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 1057 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.68% 95.72% +0.04%
==========================================
Files 180 180 —
Lines 24704 24691 -13
Branches 0 0 —
==========================================
+ Hits 23637 23634 -3
- Misses 1067 1057 -10
- Partials 0 0 —Generated by Codecov Action |
Address Bugbot: the project list command appeared both as the primary hint (under 'Try:') and in the suggestions list (under 'Or:'). Keep it only as the primary hint.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
|
|
||
| return scored.slice(0, 3).map((s) => s.slug); | ||
| const slugs = projects.map((p) => p.slug); | ||
| return fuzzyMatch(slug, slugs, { maxResults: 3 }); |
There was a problem hiding this comment.
Lost bidirectional matching degrades similar project suggestions
Medium Severity
fuzzyMatch only checks if the candidate starts with or contains the input (unidirectional), but the old code also checked the reverse — whether the input starts with or contains the candidate (bidirectional). This matters when the user types a slug longer than the actual project (e.g., "my-project-staging" when the real slug is "my-project"). The old lower.startsWith(pLower) would match, but fuzzyMatch won't match via prefix/contains, and the Levenshtein fallback also misses it when the suffix exceeds the threshold (floor(len/3)).


Follow-up to PR #493
Addresses review feedback on PR #493:
sentry project list→ Changed primary hint from settings URL tosentry project list <org>/fuzzyMatchutilityChanges
src/lib/resolve-target.tsfindSimilarProjects: Replaced 15-line ad-hoc scoring with 3-line delegation tofuzzyMatch():This adds Levenshtein distance matching for typos (e.g.,
senry→sentry) while keeping the same prefix/substring matching from before.fetchProjectIdsuggestions: Reordered to lead with the actionable CLI command:test/lib/resolve-target.test.tsTwo new tests:
includes similar project suggestions on 404 when projects exist— Mocks getProject→404 + listProjects→project list, verifies fuzzy matches appear and unrelated projects are excludedincludes project list suggestion even when listProjects fails— Mocks all requests→404, verifies thesentry project listfallback still appears