Skip to content

test(editor): cover LSP server preset resolution - #1063

Open
mydd7 wants to merge 1 commit into
crynta:mainfrom
mydd7:test/coverage-8
Open

test(editor): cover LSP server preset resolution#1063
mydd7 wants to merge 1 commit into
crynta:mainfrom
mydd7:test/coverage-8

Conversation

@mydd7

@mydd7 mydd7 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What

Adds unit tests for the LSP preset resolvers in lsp/lib/presets.ts. Test-only:
no production files touched.

Why

serversForLanguage, serverForLanguage, serverById and allServers decide
which language server handles a file, and the activation precedence in
serverForLanguage is non-obvious. None had tests.

How

Pure functions, tested directly against the built-in LSP_PRESETS.

Locked behavior:

  • serversForLanguage: the built-in servers that claim a language (py -> pyright,
    ruff), custom servers appended after presets, and nothing for a null or unknown
    language.
  • serverForLanguage precedence: first candidate by default, an enabled server
    wins over preset order, and a dismissed server is skipped for the next fresh
    candidate.
  • serverById: preset and custom lookup, null for an unknown id.
  • allServers: presets plus custom servers.

Testing

Ran the full suite plus type-check and lint locally on Windows.

  • pnpm lint clean (unchanged: 103 pre-existing warnings, none introduced)
  • pnpm check-types clean
  • pnpm test clean (the new suite passes; see reviewer note on one
    pre-existing suite)
  • Manual smoke-test of the affected feature - N/A, test-only, no runtime change
  • (If you touched src-tauri/) cargo clippy - N/A, no Rust changes
  • (If you touched src-tauri/) cargo nextest - N/A, no Rust changes
  • (If you changed a #[tauri::command] signature) - N/A
  • (If UI) tested in pnpm tauri dev - N/A, no UI change
  • Platforms tested: Windows
  • Shells tested (if relevant): N/A

Screenshots / GIFs

N/A - no UI change.

Notes for reviewer

  • Test-only. No public API, behavior, dependency, or config change.
  • Branched a couple of commits behind current main on purpose (my token lacks
    the workflow scope). Only adds a new file; should merge cleanly. Happy to
    rebase.
  • Same unrelated pre-existing failure noted before: src/app/eager-budget.test.ts
    fails locally under Windows with git core.autocrlf=true; the committed blob is
    LF and it passes on CI.

Summary by CodeRabbit

  • Tests
    • Added coverage for language server preset selection, including built-in and custom servers.
    • Verified handling of enabled, dismissed, unknown, and unsupported language server configurations.
    • Added checks for server lookup by ID and combined preset listings.

serversForLanguage, serverForLanguage, serverById and allServers resolve which language server handles a file, but had no tests. Lock the built-in matches for a language, custom servers appended after presets, null/unknown language returning nothing, and the activation precedence in serverForLanguage: an enabled server wins over preset order, a dismissed one is skipped for the next fresh candidate, and the first candidate is the default.
@mydd7
mydd7 requested a review from crynta as a code owner July 28, 2026 21:49
@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Vitest coverage for LSP preset selection utilities, including language matching, enabled and dismissed server handling, ID lookup, custom-server inclusion, and aggregate server listing.

Changes

LSP preset selection tests

Layer / File(s) Summary
Language-based server selection
src/modules/lsp/lib/presets.test.ts
Adds reusable custom-server fixtures and tests preset/custom language matching, selection precedence, dismissal handling, and empty results.
Server lookup and aggregation
src/modules/lsp/lib/presets.test.ts
Tests lookup by server ID and verifies custom servers are appended to the complete server list.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title follows Conventional Commits and accurately summarizes the added LSP preset resolution tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/modules/lsp/lib/presets.test.ts`:
- Around line 77-79: Strengthen the allServers test for custom-server ordering
by asserting the resulting server IDs, with customPy.id as the final entry after
all preset IDs. Update the test around allServers and retain the existing length
check only if it remains useful.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 87a92ecb-31d4-4739-9d57-c8aa931ce469

📥 Commits

Reviewing files that changed from the base of the PR and between 2141d16 and 55eebff.

📒 Files selected for processing (1)
  • src/modules/lsp/lib/presets.test.ts

Comment on lines +77 to +79
it("appends custom servers to the presets", () => {
expect(allServers([customPy])).toHaveLength(LSP_PRESETS.length + 1);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert custom-server identity and append order.

Line [78] checks only the count, so allServers could return the wrong custom server or place it before the presets while this test still passes. Assert the resulting IDs, including customPy.id as the final entry.

Proposed test assertion
-    expect(allServers([customPy])).toHaveLength(LSP_PRESETS.length + 1);
+    expect(allServers([customPy]).map((p) => p.id)).toEqual([
+      ...LSP_PRESETS.map((p) => p.id),
+      customPy.id,
+    ]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it("appends custom servers to the presets", () => {
expect(allServers([customPy])).toHaveLength(LSP_PRESETS.length + 1);
});
it("appends custom servers to the presets", () => {
expect(allServers([customPy]).map((p) => p.id)).toEqual([
...LSP_PRESETS.map((p) => p.id),
customPy.id,
]);
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modules/lsp/lib/presets.test.ts` around lines 77 - 79, Strengthen the
allServers test for custom-server ordering by asserting the resulting server
IDs, with customPy.id as the final entry after all preset IDs. Update the test
around allServers and retain the existing length check only if it remains
useful.

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