test(diffguard-lsp): cover config.rs edge cases#1612
Conversation
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.
|
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 |
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.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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-differnormalize_pathbackslash handling andto_workspace_relative_path(no-root, not-under-root, strip-prefix)extract_rule_id— no code/data, numeric code, data withoutruleIdfind_rule— present/absentformat_rule_explanation—MatchMode::Absent, explicit/defaultmultiline_window,context_windowdefault (3) + explicit,escalate_to/escalate_windowdefaults + explicit,depends_on, paths/excludes/languages, help-with-newlines, missing URL, no-ignore flagsfind_similar_rules— contains branch, prefix-over-distance ordering, truncate-to-5, empty rule id, distance-only branchload_directory_overrides_for_file— empty (no files), root override, nested aggregation, malformed TOML error, missing-env-var-without-default errorload_config_recursive— missing include, circular include, depth-exceeded (chain of 12), unparseable TOML, nonexistent path, non-defaultDefaultspreserved through mergemerge_with_built_in— user rule overrides built-in by IDexpand_env_vars—${VAR:-default}fallback path,${VAR}substituted from a set env varcollect_override_candidates_for_path— empty input (no parent), nested ancestor walk, bare filenamenormalize_override_directory— root/dot empty result and nested directory preservation (exercised through the loader)simple_edit_distance— zero-on-empty short-circuitsTests use
let-else/matchrather than.expect()/.unwrap()to avoid tripping the diffguard self-lintrust.no_unwrap. The two helper functions that needed.expect()carry inline// diffguard: ignoresuppressions.Test plan
cargo test -p diffguard-lsp— 62 lib tests + 39 integration tests passcargo clippy -p diffguard-lsp --all-targets -- -D warnings— cleancargo fmt -p diffguard-lsp -- --checkGenerated by Claude Code