Skip to content

Fix unified search lexical tiebreaks for values and connectors - #141

Merged
kentcdodds merged 2 commits into
mainfrom
cursor/fix-unified-search-lexical-tiebreak-6e25
Apr 9, 2026
Merged

kentcdodds merged 2 commits into
mainfrom
cursor/fix-unified-search-lexical-tiebreak-6e25

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Apr 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • reuse shared phrase-match bonus helpers for value and connector lexical scoring
  • apply those helpers in unified cross-entity lexical tiebreaking
  • add regression tests covering exact value-name and connector-name matches against capabilities

Testing

  • red/green targeted workers-unit regression tests for unified search ordering
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Refactor

    • Improved search scoring algorithm organization for enhanced maintainability and code clarity.
  • Tests

    • Added integration tests validating search result ranking behavior across entity types.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@coderabbitai

coderabbitai Bot commented Apr 9, 2026 •

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Refactored phrase-level bonus scoring logic for value and connector entities by extracting inline calculations into dedicated functions (scoreValuePhraseBonus() and scoreConnectorPhraseBonus()), and updated unified cross-entity lexical scoring to use these new functions. Added integration tests validating cross-entity ranking tie-breaking behavior.

Changes

Cohort / File(s) Summary
Search scoring refactoring
packages/worker/src/mcp/capabilities/unified-search.ts
Extracted phrase-level bonus scoring into scoreValuePhraseBonus() and scoreConnectorPhraseBonus() functions; updated scoreValueLexicalMatch() and scoreConnectorLexicalMatch() to compose lexical score with respective bonus functions; refactored searchUnified() to use these functions for n: (connector) and v: (value) entity scoring; reformatted import statement to multi-line format.
Cross-entity ranking tests
packages/worker/src/mcp/capabilities/unified-search.workers.test.ts
Added two integration tests: one validating exact value match by ValueMetadata.name ranking precedence when querying preferred org; another validating exact connector match derived from stored ValueMetadata ranking first when querying github.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through scoring fields so bright,
Extracting bonuses into functions tight,
With ValueLexical and ConnectorBonus care,
The search now ranks with precision fair! 🎯

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: fixing unified search lexical tiebreaks for values and connectors. It directly relates to the core refactoring and improvements made in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cursor/fix-unified-search-lexical-tiebreak-6e25

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds
kentcdodds marked this pull request as ready for review April 9, 2026 20:26
@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

🔎 Preview deployed: https://kody-pr-141.kentcdodds.workers.dev

Worker: kody-pr-141
D1: kody-pr-141-db
KV: kody-pr-141-oauth-kv

Mocks:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/worker/src/mcp/capabilities/unified-search.workers.test.ts (1)

390-407: Strengthen tie-break tests by asserting the competing capability is present.

These assertions prove rank-1 output, but they don’t verify the cross-entity tie path was actually contested. Add a guard that the capability candidate also exists in result.matches in both tests.

Proposed test hardening
 	expect(result.matches[0]).toMatchObject({
 		type: 'value',
 		name: 'preferred_org',
 	})
+	expect(
+		result.matches.some(
+			(match) =>
+				match.type === 'capability' && match.name === 'preferred_org_lookup',
+		),
+	).toBe(true)
@@
 	expect(result.matches[0]).toMatchObject({
 		type: 'connector',
 		connectorName: 'github',
 	})
+	expect(
+		result.matches.some(
+			(match) =>
+				match.type === 'capability' && match.name === 'github_connector_lookup',
+		),
+	).toBe(true)

Also applies to: 442-459

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/worker/src/mcp/capabilities/unified-search.workers.test.ts` around
lines 390 - 407, The test currently only asserts the top-ranked match from
searchUnified is the value 'preferred_org' but doesn't verify the competing
capability was present to contest the tie; update the test that calls
searchUnified (function searchUnified) to also assert that result.matches
contains the competing capability candidate (e.g., the other capability's
identifier/name/type that should have been in the candidate set) before checking
rank-1, and apply the same additional assertion in the sibling test (the similar
block around the other test that currently spans lines ~442-459). Ensure you
reference result.matches and the competing capability's unique identifier used
in the spec so the tie-break path is validated.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/worker/src/mcp/capabilities/unified-search.workers.test.ts`:
- Around line 390-407: The test currently only asserts the top-ranked match from
searchUnified is the value 'preferred_org' but doesn't verify the competing
capability was present to contest the tie; update the test that calls
searchUnified (function searchUnified) to also assert that result.matches
contains the competing capability candidate (e.g., the other capability's
identifier/name/type that should have been in the candidate set) before checking
rank-1, and apply the same additional assertion in the sibling test (the similar
block around the other test that currently spans lines ~442-459). Ensure you
reference result.matches and the competing capability's unique identifier used
in the spec so the tie-break path is validated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 869fdfaf-e72f-4725-bd35-889a7a19066a

📥 Commits

Reviewing files that changed from the base of the PR and between f8fcf89 and 1e37590.

📒 Files selected for processing (2)
  • packages/worker/src/mcp/capabilities/unified-search.ts
  • packages/worker/src/mcp/capabilities/unified-search.workers.test.ts

@kentcdodds
kentcdodds merged commit 92fb461 into main Apr 9, 2026
16 checks passed
@kentcdodds
kentcdodds deleted the cursor/fix-unified-search-lexical-tiebreak-6e25 branch April 17, 2026 00:59
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.

2 participants