---
id: TASK-14.5
title: Add coverage tests for utils edge cases
status: Done
assignee:
  - '@codex'
created_date: '2026-02-19 09:12'
updated_date: '2026-02-19 12:06'
labels: []
dependencies: []
references:
  - lua/zync/lib/utils.lua
  - spec/
  - luacov.report.out
parent_task_id: TASK-14
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Add tests for uncovered branches in `lua/zync/lib/utils.lua` (copy_table cycles, tonumber conversion, exit_code_from_execute fallbacks).
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 New or updated specs cover the missing utils branches reported by luacov.
- [x] #2 Utility behavior is verified with explicit assertions for edge cases.
- [x] #3 Tests pass under `busted -c`.
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
1) Review lua/zync/lib/utils.lua, spec/lib_spec/utils_spec.lua, and luacov.report.out to identify missing branches.
2) Add focused specs to cover Utils.copy_table cycle handling, Utils.tonumber_if_possible returning number vs string, and Utils.exit_code_from_execute fallbacks when ok is false without exit info or ok is neither number nor boolean.
3) Ask user to run busted -c and regenerate luacov.report.out to confirm coverage.
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Luacov gaps in utils.lua include: Utils.copy_table cycle handling (seen table), Utils.tonumber_if_possible returning number vs string, and Utils.exit_code_from_execute fallbacks when ok is boolean false without exit_type/code or when ok is neither number nor boolean.

Added utils edge-case tests in spec/lib_spec/utils_spec.lua for copy_table cycle handling, tonumber_if_possible returning number vs string, and exit_code_from_execute fallbacks (false without exit info and non-boolean ok). Please run busted -c and regenerate luacov.report.out to confirm coverage.
<!-- SECTION:NOTES:END -->

## Final Summary

<!-- SECTION:FINAL_SUMMARY:BEGIN -->
Added utils edge-case tests in spec/lib_spec/utils_spec.lua covering copy_table cycle handling, tonumber_if_possible numeric vs string conversion, and exit_code_from_execute fallback branches. User regenerated luacov.report.out confirming utils.lua at 100% coverage and overall suite passes.
<!-- SECTION:FINAL_SUMMARY:END -->
