Skip to content

test: Achieve 100% test coverage - all code must work #66

@EivMeyer

Description

@EivMeyer

Problem

Current test coverage is unacceptably low at 49.82% statements. Large parts of the codebase have 0% coverage:

Directory Files Current Coverage Status
src/agent/ 10 0% UNTESTED
src/attach/ 6 0% UNTESTED
cli/ 7 0% UNTESTED
lib/ 8 0% UNTESTED
src/tui/ - 18.95% Very Low
src/conductor/ - 60.36% Medium
src/schemas/ - 67.56% Medium

~13,500 lines of code are completely untested. This means bugs ship silently.

Why This Matters

  • Untested code = unknown bugs - We have zero confidence agent execution, CLI commands, or attach protocol work correctly
  • Refactoring is dangerous - Can't safely change code without tests proving it still works
  • Current 1% threshold is meaningless - codecov.yml threshold provides zero enforcement

Implementation Plan

Phase 1: Agent System Tests (10 files, highest priority)

  • agent-task-executor.test.js - Task execution flow, error handling
  • agent-lifecycle.test.js - Start, stop, restart, cleanup
  • agent-stuck-detector.test.js - Detection logic, thresholds
  • agent-trigger-evaluator.test.js - Trigger conditions, edge cases
  • agent-context-builder.test.js - Context assembly, validation
  • agent-config.test.js - Config parsing, defaults, validation
  • agent-hook-executor.test.js - Hook execution, failure handling
  • output-extraction.test.js - Parse agent output formats
  • output-reformatter.test.js - Output transformation
  • schema-utils.test.js - Schema validation utilities

Phase 2: Attach System Tests (6 files)

  • attach-client.test.js - Client connection, reconnection, errors
  • attach-server.test.js - Server lifecycle, client handling
  • socket-discovery.test.js - Socket discovery mechanisms
  • protocol.test.js - Protocol message handling
  • ring-buffer.test.js - Buffer operations, overflow handling
  • index.test.js - Module exports, integration

Phase 3: CLI Tests (7 files)

  • cli/index.test.js - CLI entry point, arg parsing
  • commands/providers.test.js - Provider command handling
  • message-formatters-normal.test.js - Normal output formatting
  • message-formatters-watch.test.js - Watch mode formatting
  • message-formatter-utils.test.js - Formatter utilities
  • lib/first-run.test.js - First-run experience
  • lib/update-checker.test.js - Update checking logic

Phase 4: Lib Tests (8 files)

  • settings.test.js - Settings load/save/validate (416 lines!)
  • provider-detection.test.js - Provider detection logic
  • provider-names.test.js - Provider name resolution
  • provider-defaults.test.js - Default configurations
  • docker-config.test.js - Docker configuration handling
  • id-detector.test.js - ID detection utilities
  • stream-json-parser.test.js - JSON stream parsing

Phase 5: Coverage Threshold Enforcement

  • Update codecov.yml threshold from 1% → 80% → 90% → 100%
  • Add pre-commit hook that fails if coverage drops
  • Add CI step that blocks merge if coverage < threshold

Testing Principles

  1. Test behavior, not implementation - Verify outputs given inputs
  2. Mock external dependencies - Docker, filesystem, network
  3. Test error paths - Invalid inputs, timeouts, failures
  4. Each test is independent - No shared state between tests

Acceptance Criteria

  • All 31 untested files have corresponding test files
  • Statement coverage ≥ 95%
  • Branch coverage ≥ 90%
  • Function coverage ≥ 95%
  • CI blocks merge if coverage drops below threshold
  • No /* istanbul ignore */ comments without justification

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions