Skip to content

test: Add test case for exact match prioritization in fzf#110685

Merged
JonasBa merged 5 commits intomasterfrom
cursor/fzf-exact-match-tests-faca
Mar 13, 2026
Merged

test: Add test case for exact match prioritization in fzf#110685
JonasBa merged 5 commits intomasterfrom
cursor/fzf-exact-match-tests-faca

Conversation

@JonasBa
Copy link
Member

@JonasBa JonasBa commented Mar 13, 2026

Summary

Adds test cases to demonstrate and document the expected behavior for exact match prioritization in the fzf fuzzy search algorithm, both at the algorithm level and at the CompactSelect component level.

Test Cases

1. Unit Test (fzf.spec.tsx)

Tests the fzf algorithm directly with the pattern "path" against:

  • binary_path
  • code.file.path
  • path

Verifies that the exact match scores higher than partial matches.

2. Integration Test (compactSelect.spec.tsx)

Tests CompactSelect with search enabled using the same real-world examples from the Slack discussion. Verifies that when searching for "path", the exact match option appears first in the sorted results.

Current Behavior

Both tests are currently skipped to avoid blocking CI. When unskipped locally, they fail because all three options receive the same score (104), confirming the issue described in the Slack thread about exact matches not being boosted properly.

Next Steps

Once the fix from #110680 is applied, these tests should be unskipped and will serve as regression tests to ensure exact matches are properly prioritized at both the algorithm and component levels.

Related

Slack Thread

Open in Web Open in Cursor 

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Mar 13, 2026
This test documents the expected behavior that exact matches should score
higher than partial matches. Currently fails, demonstrating the bug where
'path' scores the same as 'binary_path' and 'code.file.path'.

Related to GH-110680

Co-authored-by: Jonas <JonasBa@users.noreply.github.com>
Adds integration test verifying that exact matches are prioritized over
partial matches when using CompactSelect with search enabled. Test uses
the same real-world examples (binary_path, code.file.path, path) to
verify the behavior at the component level.

Currently skipped until fix from GH-110680 is implemented.

Co-authored-by: Jonas <JonasBa@users.noreply.github.com>
Boost fzf score by scoreMatch when text exactly equals the pattern,
so exact matches rank above partial matches with the same characters.

Unskips and tightens the two related tests to assert each result by
index rather than via find/filter loops.

Fixes GH-110680
Co-Authored-By: Claude <noreply@anthropic.com>
@JonasBa JonasBa requested a review from mrduncan March 13, 2026 21:38
@JonasBa JonasBa marked this pull request as ready for review March 13, 2026 21:38
@JonasBa JonasBa requested a review from a team as a code owner March 13, 2026 21:38
Copy link
Contributor

@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 prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Exact match detection condition is too broad
    • Replaced the condition with 'textLength === patternLength' which correctly identifies exact matches when combined with the subsequence match.

Create PR

Or push these changes by commenting:

@cursor push b39408e01b
Preview (b39408e01b)
diff --git a/static/app/utils/search/fzf.tsx b/static/app/utils/search/fzf.tsx
--- a/static/app/utils/search/fzf.tsx
+++ b/static/app/utils/search/fzf.tsx
@@ -137,7 +137,7 @@
   let [score, matches] = calculateScore(text, pattern, sidx, eidx, caseSensitive);
 
   // Boost exact matches (text === pattern) so they rank above partial matches
-  if (sidx === 0 && eidx === textLength) {
+  if (textLength === patternLength) {
     score += scoreMatch;
   }

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

The previous condition `sidx === 0 && eidx === textLength` also
boosted subsequence matches that happen to span the full text (e.g.
pattern `az` in `abcz`). Adding `textLength === patternLength`
ensures the boost only applies when text and pattern are identical.

Co-Authored-By: Claude <noreply@anthropic.com>
@JonasBa
Copy link
Member Author

JonasBa commented Mar 13, 2026

@cursoragent fix the following lint error

/home/runner/work/sentry/sentry/static/app/utils/search/fzf.tsx
Error:   137:15  error  'matches' is never reassigned. Use 'const' instead  prefer-const

@cursor
Copy link
Contributor

cursor bot commented Mar 13, 2026

Fixed! I've resolved the lint error by separating the destructuring:

• Changed let [score, matches] = calculateScore(...) to use const for the destructuring
• Introduced a scoreBase variable that holds the initial score
• Declared score separately as let since it needs to be reassigned for the exact match boost

The matches variable is now properly declared as const since it's never reassigned, while score remains as let for the exact match boosting logic. Tests pass and pre-commit checks pass.

Open in Web Open in Cursor 

@JonasBa JonasBa enabled auto-merge (squash) March 13, 2026 21:49
@JonasBa JonasBa disabled auto-merge March 13, 2026 21:50
Fixes eslint prefer-const warning. The matches variable from
calculateScore is never reassigned, so it should be const.

Co-authored-by: Jonas <JonasBa@users.noreply.github.com>
@JonasBa JonasBa merged commit c154d84 into master Mar 13, 2026
63 checks passed
@JonasBa JonasBa deleted the cursor/fzf-exact-match-tests-faca branch March 13, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants