---
id: TASK-27.3
title: >-
  Add unit tests for cmd args merge, compile_commands link, cache parsing, and
  clean_dir_safe branches
status: Done
assignee:
  - codex
created_date: '2026-03-03 09:14'
updated_date: '2026-03-03 09:31'
labels:
  - tests
  - coverage
dependencies: []
references:
  - src/core/cmd.rs
parent_task_id: TASK-27
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Cover uncovered cmd.rs branches related to argument filtering, compile_commands link handling, cache parsing, and safe cleanup, per the 2026-03-03 llvm-cov report.
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 merge_args and push_filtered_args skip empty/whitespace args and preserve ordering for non-empty args.
- [x] #2 ensure_compile_commands_link returns early for: no profiles, link_compile_commands=false, and no default/first profile; handles existing symlink (no-op), existing file (removed then linked), and existing directory (skip) cases.
- [x] #3 resolve_default_profile covers valid default_profile and fallback-to-first-profile cases.
- [x] #4 get_cache_var ignores malformed cache lines (no '=' or missing ':') and returns None for missing keys.
- [x] #5 clean_dir_safe with dry_run=false removes an in-project directory and logs removal (covering the remove_dir_all path).
- [x] #6 All new tests pass with `cargo llvm-cov --lib --bins`.
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
1) Add unit tests in `src/core/cmd.rs` for merge_args/push_filtered_args filtering and ordering.
2) Add tests for ensure_compile_commands_link early returns (no profiles, link disabled, no default/first profile) and existing symlink/file/dir handling; cover resolve_default_profile default and fallback.
3) Add tests for get_cache_var skipping malformed lines and returning None for missing keys.
4) Add test for clean_dir_safe removing an in-project directory with dry_run=false.
5) Run `cargo llvm-cov --lib --bins` and update acceptance criteria.
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Added cmd tests for merge_args/push_filtered_args filtering, compile_commands link early returns and symlink/file/dir handling, resolve_default_profile default/fallback, get_cache_var malformed lines, and clean_dir_safe remove path.

Ran `cargo llvm-cov --lib --bins --text --show-missing-lines --output-path /tmp/llvm-cov.txt` (115 unit tests + main test passed).
<!-- SECTION:NOTES:END -->
