---
id: TASK-10.1
title: Add unit tests for core command dispatch and handlers
status: Done
assignee:
  - codex
created_date: '2026-02-26 12:52'
updated_date: '2026-02-26 12:59'
labels: []
dependencies: []
references:
  - src/core/cmd.rs
  - src/core/exec.rs
  - tests/integration_tests.rs
  - tests/e2e_tests.rs
parent_task_id: TASK-10
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Cover the untested branches and functions in the command execution layer so `core/cmd.rs` has high coverage without changing runtime behavior.
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 `just coverage` reports >=90% line coverage for `src/core/cmd.rs`.
- [x] #2 Tests cover both success and error paths for command dispatch and command-specific handlers.
- [x] #3 Tests are hermetic and do not require external toolchain binaries or network access.
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
Plan:
1) Review `src/core/config.rs` and build minimal helpers to construct `ResolvedConfig` for tests.
2) Add `#[cfg(test)] mod tests` in `src/core/cmd.rs` using temp directories and `Runner { dry_run: true }`.
3) Add tests for: `cmd_init`, `cmd_profiles` (empty/non-empty), `clean_dir_safe` (nonexistent, outside root, root itself, dry-run), `is_configured`, `get_cache_var` (missing/matching/ignored lines), `ensure_configured` (configured and board mismatch), `cmd_run` (zephyr binary present vs ninja fallback), `cmd_runners` (missing file vs valid YAML), and `run_cmd` dispatch.
4) Run `just coverage` to verify `src/core/cmd.rs` >=90% line coverage; then run `just test`.
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Ran `just coverage`; `src/core/cmd.rs` line coverage 93.70%, total 92.16%. Added hermetic unit tests in `src/core/cmd.rs` covering command dispatch, clean safety, cache parsing, runners YAML, run/all paths, and run/flash/build paths (dry-run).
<!-- SECTION:NOTES:END -->

## Final Summary

<!-- SECTION:FINAL_SUMMARY:BEGIN -->
Added comprehensive unit tests in `src/core/cmd.rs` to cover command dispatch, clean safety guards, CMake cache parsing, runners YAML handling, run/flash/build paths (dry-run), and run/all profile behavior. Coverage for `src/core/cmd.rs` reached 93.70% line coverage and overall coverage 92.16% per `just coverage`.

Tests: `just coverage`
<!-- SECTION:FINAL_SUMMARY:END -->
