test(diffguard-lsp): cover server.rs edge cases#1613
Conversation
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.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
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.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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:
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_changesempty list, single full replacement, last-wins full replacement;mark_savedwith 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 caseServerState::from_initialize: defaultmax_findings, zero-clamping to 1,force_languagetrimming, load-failure warning fallbackis_config_uri: no config_path, unparseable URI, normalized matchreload_config: success and failure (resetsgit_supportand built-in fallback)handle_request): unsupported method (METHOD_NOT_FOUND), invalidCodeActionParams, invalidExecuteCommandParams,explainRulewithout arg,showRuleUrlwithout URL, unknown command, successful explain + show flowshandle_notification): invalid params fordidOpen/didChange/didSave/didClose/didChangeConfiguration;Exit; unknown method no-op;didOpenwith non-file URI skip;didChangefor unknown doc;didCloseclearing diagnostics;didSavewith baseline reset;didChangeConfigurationtriggering reloadrefresh_document_diagnostics: missing-document no-op, empty-relative-path early returnsend_ok_response,send_error_response,show_message(verified viaConnection::memory()drain)Branches deliberately skipped:
git_diff_for_path/run_git_diff/ git-timeout branches (require a real git repo, environment-flaky), and therefresh_document_diagnosticshappy path (already covered by integration tests intests/).The new tests use
.expect()/.unwrap()consistent with the file's pre-existing test style. Inline// diffguard: ignore rust.no_unwrapsuppressions 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 passcargo test -p diffguard-lsp— 9 integration tests still passcargo clippy -p diffguard-lsp --all-targets -- -D warnings— cleancargo fmt -p diffguard-lsp -- --checkGenerated by Claude Code