Skip to content

fix: use fuzzyMatch for similar project suggestions and add tests (CLI-C0)#504

Merged
BYK merged 2 commits intomainfrom
fix/cli-c0-improve-similar-projects
Mar 20, 2026
Merged

fix: use fuzzyMatch for similar project suggestions and add tests (CLI-C0)#504
BYK merged 2 commits intomainfrom
fix/cli-c0-improve-similar-projects

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 20, 2026

Follow-up to PR #493

Addresses review feedback on PR #493:

  1. Low patch coverage → Added 2 new tests covering the similar-project suggestion paths
  2. Should suggest sentry project list → Changed primary hint from settings URL to sentry project list <org>/
  3. Should use existing fuzzy matching → Replaced ad-hoc prefix/substring scoring with the shared fuzzyMatch utility

Changes

src/lib/resolve-target.ts

findSimilarProjects: Replaced 15-line ad-hoc scoring with 3-line delegation to fuzzyMatch():

const slugs = projects.map((p) => p.slug);
return fuzzyMatch(slug, slugs, { maxResults: 3 });

This adds Levenshtein distance matching for typos (e.g., senrysentry) while keeping the same prefix/substring matching from before.

fetchProjectId suggestions: Reordered to lead with the actionable CLI command:

Or:
  - Similar projects: 'test-project-api', 'test-project-web'
  - List available projects: sentry project list my-org/
  - Check the project slug at https://sentry.io/organizations/my-org/projects/

test/lib/resolve-target.test.ts

Two 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 excluded
  • includes project list suggestion even when listProjects fails — Mocks all requests→404, verifies the sentry project list fallback still appears

…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).
@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (telemetry) Track TTY vs non-TTY invocations via metric by betegon in #482
  • Dynamic cache-backed shell completions with fuzzy matching by BYK in #465

Bug Fixes 🐛

  • (help) Hide ASCII banner when stdout is not a TTY by betegon in #501
  • (project) Fallback to org listing when bare slug matches an organization by betegon in #475
  • Use fuzzyMatch for similar project suggestions and add tests (CLI-C0) by BYK in #504
  • Use resolved org in numeric issue ID 404 hint (CLI-BT) by BYK in #502
  • Include API endpoint in error messages for better diagnostics (CLI-BS) by BYK in #500
  • Enrich 403 on org listing with token scope guidance (CLI-89) by BYK in #498
  • Add 400 suggestions to org-all issue list path (CLI-BY) by BYK in #497
  • Lowercase project slug in issue arg parsing (CLI-C8) by BYK in #496
  • Enrich short ID 404 with org context and suggestions (CLI-A1) by BYK in #494
  • Suggest similar projects when project not found in org (CLI-C0) by BYK in #493
  • Event 404 hint should suggest different project, not repeat failing command by BYK in #492
  • Enrich event 404 errors with retention and format suggestions (CLI-6F) by BYK in #491
  • Add actionable suggestions for 400 Bad Request on issue list (CLI-BM, CLI-7B) by BYK in #489
  • Detect issue short IDs passed to issue list (CLI-C3) by BYK in #488
  • Add Glob.match() polyfill + improve auto-detect diagnostics (CLI-7T) by BYK in #487
  • Add org-slug pre-check to dispatchOrgScopedList (CLI-9A) by BYK in #485

Internal Changes 🔧

  • (issue) Skip getProject round-trip in project-search resolution by betegon in #473
  • (resolve) Carry project data through resolution to eliminate redundant getProject calls by BYK in #486
  • (telemetry) Convert is_tty metric to span tag by betegon in #499
  • HTTP latency optimizations — diagnostics, cache warming, concurrency limits by BYK in #490
  • Switch from @sentry/bun to @sentry/node-core/light (~170ms startup savings) by BYK in #474
  • Regenerate skill files by github-actions[bot] in b7b240ec

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Codecov Results 📊

126 passed | Total: 126 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1057 uncovered lines.
✅ Project coverage is 95.72%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
resolve-target.ts 83.64% ⚠️ 117 Missing
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.
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

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 });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)).

Fix in Cursor Fix in Web

@BYK BYK merged commit da74739 into main Mar 20, 2026
22 checks passed
@BYK BYK deleted the fix/cli-c0-improve-similar-projects branch March 20, 2026 10:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant