Skip to content

test(diffguard-lsp): cover server.rs edge cases#1613

Merged
EffortlessSteven merged 3 commits into
mainfrom
claude/improve-code-coverage-dZYp6-lsp-server
May 16, 2026
Merged

test(diffguard-lsp): cover server.rs edge cases#1613
EffortlessSteven merged 3 commits into
mainfrom
claude/improve-code-coverage-dZYp6-lsp-server

Conversation

@EffortlessSteven
Copy link
Copy Markdown
Member

Summary

Closes a large coverage gap in crates/diffguard-lsp/src/server.rs (region coverage 75.84% → 91.62%, 267 → 53 uncovered regions in production code). Pure test-only additions — no behavior change.

Closes #1609 (tracked alongside sibling PRs).

53 new unit tests cover:

  • Helper functions: normalize_option_string (whitespace, empty, trimmed), parse_init_options (None / invalid / valid camelCase), nth_string_arg (missing / wrong-type / out-of-bounds), uri_to_file_path (malformed and valid file URIs), explain_rule_message (found / not-found / not-found with similar suggestions)
  • DocumentState: apply_changes empty list, single full replacement, last-wins full replacement; mark_saved with and without override text (baseline reset, changed_lines clear)
  • extract_workspace_root: all three precedence branches (workspace_folders, root_uri, root_path) plus the None case
  • ServerState::from_initialize: default max_findings, zero-clamping to 1, force_language trimming, load-failure warning fallback
  • is_config_uri: no config_path, unparseable URI, normalized match
  • reload_config: success and failure (resets git_support and built-in fallback)
  • Request dispatch (handle_request): unsupported method (METHOD_NOT_FOUND), invalid CodeActionParams, invalid ExecuteCommandParams, explainRule without arg, showRuleUrl without URL, unknown command, successful explain + show flows
  • Notification dispatch (handle_notification): invalid params for didOpen/didChange/didSave/didClose/didChangeConfiguration; Exit; unknown method no-op; didOpen with non-file URI skip; didChange for unknown doc; didClose clearing diagnostics; didSave with baseline reset; didChangeConfiguration triggering reload
  • refresh_document_diagnostics: missing-document no-op, empty-relative-path early return
  • Send helpers: send_ok_response, send_error_response, show_message (verified via Connection::memory() drain)

Branches deliberately skipped: git_diff_for_path / run_git_diff / git-timeout branches (require a real git repo, environment-flaky), and the refresh_document_diagnostics happy path (already covered by integration tests in tests/).

The new tests use .expect() / .unwrap() consistent with the file's pre-existing test style. Inline // diffguard: ignore rust.no_unwrap suppressions are applied to each such line so the diffguard self-lint does not fire.

Test plan

  • cargo test -p diffguard-lsp --lib — 56 server tests + others pass
  • cargo test -p diffguard-lsp — 9 integration tests still pass
  • cargo clippy -p diffguard-lsp --all-targets -- -D warnings — clean
  • cargo fmt -p diffguard-lsp -- --check

Generated by Claude Code

claude added 2 commits May 16, 2026 08:14
Add 53 focused unit tests covering helper functions (normalize_option_string,
parse_init_options, nth_string_arg, uri_to_file_path, explain_rule_message,
findings_to_diagnostics), DocumentState behaviours (apply_changes / mark_saved
variants), ServerState::from_initialize branches, is_config_uri / reload_config,
and the request and notification dispatch paths (invalid params, unknown command,
unsupported method, did-open with non-file URI, did-change for unknown document,
did-close clears diagnostics, exit signal, did-save baseline reset) via
Connection::memory(). Server.rs region coverage moves from 75.84% to 91.62%.

Closes #1609.
…p() calls

Add inline 'diffguard: ignore rust.no_unwrap' suppressions to the new
test module additions so the diffguard self-lint does not fire on
.expect()/.unwrap() inside #[cfg(test)] code (the rule's exclude_paths
already covers **/tests/** but not src/ files containing inline test
modules).

Refs #1609.
@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 16, 2026

Warning

Rate limit exceeded

@EffortlessSteven has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 11 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c2e5ac8f-9f9e-4273-8584-e0d898e7647c

📥 Commits

Reviewing files that changed from the base of the PR and between 29bd0ad and 97c1c7f.

📒 Files selected for processing (1)
  • crates/diffguard-lsp/src/server.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/improve-code-coverage-dZYp6-lsp-server

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.

Comment thread crates/diffguard-lsp/src/server.rs Fixed
Comment thread crates/diffguard-lsp/src/server.rs Fixed
Comment thread crates/diffguard-lsp/src/server.rs Fixed
Switch http://example.com/... to https://example.com/... in the three
non-file URI test fixtures to avoid tripping the diffguard self-lint
security.http_url. Tests still exercise the non-file URI branches
(uri_to_file_path / is_config_uri / didOpen-skip).

Refs #1609.
@EffortlessSteven EffortlessSteven marked this pull request as ready for review May 16, 2026 18:48
@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@EffortlessSteven EffortlessSteven merged commit 6f562eb into main May 16, 2026
11 checks passed
@EffortlessSteven EffortlessSteven deleted the claude/improve-code-coverage-dZYp6-lsp-server branch May 16, 2026 18:48
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.

Close code coverage gaps in lsp + analytics + main

3 participants