---
id: TASK-38
title: Add workspace command coverage tests (init/export/apply/is_ws_initialized)
status: Done
assignee:
  - codex
created_date: '2026-03-04 22:30'
updated_date: '2026-03-04 22:49'
labels: []
dependencies: []
references:
  - src/core/cmd.rs
  - /tmp/coverage.txt
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Coverage report shows many uncovered lines in `src/core/cmd.rs` for workspace helpers (`is_ws_initialized`, `cmd_ws_init`, `cmd_ws_export`, `cmd_ws_apply`) and workspace match branches. Add dry-run unit tests to cover these paths without invoking `west`.
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 Add tests for `is_ws_initialized` true/false with a temp `.west` directory.
- [x] #2 Add tests for `cmd_ws_init` covering: already-initialized + force=false error, and force=true path that removes `.west` (dry_run ok).
- [x] #3 Add tests for `cmd_ws_export` and `cmd_ws_apply` using `Runner { dry_run: true }` and a temp workspace to cover success paths.
- [x] #4 Add a `cmd_workspace` test that selects Init/Export/Apply branches (using dry_run) to exercise match coverage.
- [x] #5 Tests live in `src/core/cmd.rs` and pass under `just check`.
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
1) Add is_ws_initialized tests in src/core/cmd.rs for true/false using a temp dir with/without .west.
2) Add cmd_ws_init tests for already-initialized + force=false error and force=true path (dry-run; ensure .west gets removed or no error).
3) Add cmd_ws_export and cmd_ws_apply tests using Runner { dry_run: true } and a temp workspace to cover success paths.
4) Add a cmd_workspace test to hit Init/Export/Apply match branches with dry-run.
5) Run just check to confirm.
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Added tests for is_ws_initialized true/false, cmd_ws_init force/non-force, cmd_ws_export/cmd_ws_apply dry-run paths, and cmd_workspace Init/Export/Apply branches. Ran `just check -- -D warnings` (passes).
<!-- SECTION:NOTES:END -->

## Final Summary

<!-- SECTION:FINAL_SUMMARY:BEGIN -->
Added workspace helper and command coverage tests (init/export/apply/is_ws_initialized) using dry-run paths and temp .west directories. Tests: `just check -- -D warnings`.
<!-- SECTION:FINAL_SUMMARY:END -->
