---
id: TASK-27.5
title: Make CLI entrypoint testable and add unit tests for main path
status: Done
assignee:
  - codex
created_date: '2026-03-03 09:15'
updated_date: '2026-03-03 09:47'
labels:
  - tests
  - coverage
dependencies: []
references:
  - src/main.rs
  - src/core/cmd.rs
  - src/core/cli.rs
parent_task_id: TASK-27
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Improve unit test coverage for src/main.rs by making the CLI entrypoint testable without process::exit and adding unit tests for success and error paths.
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 Main entrypoint logic is refactored into a testable function (e.g., returns Result or exit code) while preserving CLI behavior.
- [x] #2 Unit tests cover both success path and error path without calling process::exit.
- [x] #3 Unit tests do not invoke integration tests and pass via `cargo llvm-cov --lib --bins`.
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
1) Refactor `src/main.rs` to move CLI execution into a testable function (returning Result or exit code) while keeping `main()` behavior unchanged.
2) Add unit tests for success and error paths using a test-only injection hook without calling process::exit.
3) Run `cargo llvm-cov --lib --bins` and update acceptance criteria.
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Refactored main to use run_main_with(cli, run_fn) and test-only injection via TEST_RUN_FN mutex; added tests for success and error paths without process::exit or clap parsing.

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