---
id: TASK-14.1
title: Add coverage tests for api.lua edge branches
status: Done
assignee:
  - codex
created_date: '2026-02-19 09:11'
updated_date: '2026-02-19 10:57'
labels: []
dependencies: []
references:
  - lua/zync/api.lua
  - spec/zync_spec.lua
  - luacov.report.out
parent_task_id: TASK-14
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Add tests that exercise currently uncovered branches in `lua/zync/api.lua` as reported by luacov (profile resolution, compile_commands link handling, and --all error paths).
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 New or updated specs cover the uncovered branches in `lua/zync/api.lua` shown in `luacov.report.out`.
- [x] #2 Behavior remains consistent with existing CLI semantics for profiles and `--all`.
- [x] #3 Tests pass under `busted -c`.
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
1) Review luacov gaps in api.lua and map to specific branch targets.
2) Add targeted specs in spec/zync_spec.lua to exercise missing branches (compile_commands early returns, lfs.link fallback, --all exit path, alphabetical profile order, helper nil cases).
3) Run/verify busted -c and inspect luacov report to confirm api.lua gaps are closed.
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Luacov gaps in api.lua include: resolve_default_profile nil-profiles return; ensure_compile_commands_link early returns (invalid config / empty profile), non-link path when lfs.link is nil, and symlinkattributes branch already. resolve_profiles branch when profile_order empty (alphabetical), and --all loop exit-on-nonzero path. Use spec/zync_spec.lua or new spec to hit these via Api.run with controlled config and stubs.

Implemented additional specs in spec/zync_spec.lua to cover api.lua branches (compile_commands early returns, lfs.link fallback, --all failure exit, alphabetical order, helper nil cases). Need approval to proceed with any further changes and to run tests.

Ran `busted -c` (117 successes). api.lua now 100% coverage per luacov report. Overall total is 94.75%. Next gaps remain in configurator, sandbox, manager, utils for other subtasks.

Test run: `busted -c` passed (117 successes).
<!-- SECTION:NOTES:END -->

## Final Summary

<!-- SECTION:FINAL_SUMMARY:BEGIN -->
Added targeted api.lua coverage tests in spec/zync_spec.lua to hit compile_commands early returns, lfs.link fallback, --all failure exit path, alphabetical profile order, and helper nil branches. User confirmed tests pass; api.lua now 100% coverage in luacov.
<!-- SECTION:FINAL_SUMMARY:END -->
