---
id: TASK-10.5
title: >-
  Cover remaining api.lua branches (default profile resolution, compile_commands
  link edge cases, pre-clean exit)
status: Done
assignee:
  - '@codex'
created_date: '2026-02-04 12:05'
updated_date: '2026-02-04 12:15'
labels: []
dependencies: []
references:
  - luacov.report.out
  - spec/zync_spec.lua
  - lua/zync/api.lua
parent_task_id: TASK-10
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Add zync API tests to cover remaining branches in `lua/zync/api.lua`, including resolve_default_profile fallbacks, compile_commands symlink edge cases, and pre-clean failure handling.
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 Tests cover resolve_default_profile returning nil when config/profiles missing and falling back to alphabetical order when no profile_order is available.
- [x] #2 Tests cover compile_commands link handling when Api.config is invalid, when profile is missing, when project_dir is empty, and when link target exists but is not link/file (should early return).
- [x] #3 Tests cover lfs.symlinkattributes absent path (using lfs.attributes branch) and lfs.link fallback to `ln -sf` when link creation fails.
- [x] #4 Tests cover pre-clean failure exiting with the non-zero exit code (assert exit handler).
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
1. Extend `spec/zync_spec.lua` with tests that force `resolve_default_profile` fallbacks:
   - No config/profiles → ensure compile_commands link creation is skipped.
   - No `profile_order` but profiles defined → ensure alphabetical fallback is used for symlink target.
2. Add compile_commands link edge-case tests:
   - Api.config invalid → no link creation.
   - Missing profile resolution → no link creation.
   - Empty project_dir → uses cwd.
   - link target exists with mode other than link/file (stub lfs.symlinkattributes) → early return.
3. Add tests for alternate link path branches:
   - When `lfs.symlinkattributes` is unavailable, use `lfs.attributes` path.
   - When `lfs.link` fails, ensure `os.execute('ln -sf …')` is used.
4. Add pre-clean failure test to assert `os.exit` is called with the non-zero pre-clean exit code.
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Added zync API specs for invalid config/no profiles, alphabetical fallback when profile_order is empty or invalid, non-link/non-file early return, symlinkattributes-absent attributes branch, lfs.link failure fallback to ln -sf, and project_dir empty handling via cwd.

Ran `busted spec/zync_spec.lua` (30/0/0/0).
<!-- SECTION:NOTES:END -->
