Skip to content

test(diffguard-lsp): cover config.rs edge cases#1612

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

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

Conversation

@EffortlessSteven
Copy link
Copy Markdown
Member

Summary

Closes a large coverage gap in crates/diffguard-lsp/src/config.rs (region coverage 73.98% → 95.70%, line coverage 78.00% → 96.63%, function coverage 64.29% → 93.27%). Pure test-only additions — no behavior change.

Closes #1609 (tracked alongside sibling PRs).

54 new unit tests cover:

  • resolve_config_path — all branches (absolute override, relative+workspace, relative-no-workspace, default-in-workspace exists/missing, fallback when neither workspace nor file exists)
  • paths_match — canonicalized-equal, canonicalize-fails-strings-equal, canonicalize-fails-strings-differ
  • normalize_path backslash handling and to_workspace_relative_path (no-root, not-under-root, strip-prefix)
  • extract_rule_id — no code/data, numeric code, data without ruleId
  • find_rule — present/absent
  • format_rule_explanationMatchMode::Absent, explicit/default multiline_window, context_window default (3) + explicit, escalate_to/escalate_window defaults + explicit, depends_on, paths/excludes/languages, help-with-newlines, missing URL, no-ignore flags
  • find_similar_rules — contains branch, prefix-over-distance ordering, truncate-to-5, empty rule id, distance-only branch
  • load_directory_overrides_for_file — empty (no files), root override, nested aggregation, malformed TOML error, missing-env-var-without-default error
  • load_config_recursive — missing include, circular include, depth-exceeded (chain of 12), unparseable TOML, nonexistent path, non-default Defaults preserved through merge
  • merge_with_built_in — user rule overrides built-in by ID
  • expand_env_vars${VAR:-default} fallback path, ${VAR} substituted from a set env var
  • collect_override_candidates_for_path — empty input (no parent), nested ancestor walk, bare filename
  • normalize_override_directory — root/dot empty result and nested directory preservation (exercised through the loader)
  • simple_edit_distance — zero-on-empty short-circuits

Tests use let-else / match rather than .expect() / .unwrap() to avoid tripping the diffguard self-lint rust.no_unwrap. The two helper functions that needed .expect() carry inline // diffguard: ignore suppressions.

Test plan

  • cargo test -p diffguard-lsp — 62 lib tests + 39 integration tests pass
  • cargo clippy -p diffguard-lsp --all-targets -- -D warnings — clean
  • cargo fmt -p diffguard-lsp -- --check

Generated by Claude Code

Adds focused unit tests covering resolve_config_path branches, paths_match
canonicalization fallback, format_rule_explanation defaults for context/
escalate windows and MatchMode::Absent, find_similar_rules contains/distance
paths, load_directory_overrides aggregation and error handling, and the
include-depth / circular-include / missing-include error paths in
load_config_recursive. Also exercises expand_env_vars set/default branches
via the override loader.

Closes #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 16 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: bd9fd27d-1b04-4fa8-860b-89fc051784ba

📥 Commits

Reviewing files that changed from the base of the PR and between 29bd0ad and 157d529.

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

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.

The expand_env_vars_substitutes_set_variable test mutates the
process-wide environment via std::env::set_var/remove_var, which in
Rust 2024 is unsafe specifically because it races with parallel
threads doing std::env::var() reads — under cargo test's default
parallelism this can segfault other crates' tests.

Drops only the substitution-path test; the fallback (\${VAR:-default})
and no-default-error branches remain covered.

Refs #1609.
@EffortlessSteven EffortlessSteven marked this pull request as ready for review May 16, 2026 18:47
@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!

@EffortlessSteven EffortlessSteven merged commit 0e797f4 into main May 16, 2026
11 checks passed
@EffortlessSteven EffortlessSteven deleted the claude/improve-code-coverage-dZYp6-lsp-config 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

2 participants