Skip to content

[Audit] MEDIUM: Missing test coverage for critical modules #7

@NickCalabs

Description

@NickCalabs

Severity: MEDIUM

Description

Several critical source files lack corresponding test files, meaning core functionality is not being tested.

Missing Test Files

1. src/config.ts - No tests

Why Critical: Handles API key loading, config file parsing, directory initialization
Risk: Bugs in API key loading could break all Anthropic runs
Recommendation: Create test/config.test.ts

Test cases needed:

  • API key loading from environment
  • API key loading from config file
  • Config file parsing with various formats
  • Default config when file missing
  • Directory creation

2. src/daemon.ts - No tests

Why Critical: Process lifecycle management, PID files, health checks
Risk: Bugs could leave zombie processes or prevent startup
Recommendation: Create test/daemon.test.ts

Test cases needed:

  • Start/stop/status commands
  • Stale PID file cleanup
  • Health check polling
  • Port conflict detection
  • Graceful vs forced shutdown

3. src/index.ts - No tests

Why Critical: CLI entry point, command routing
Risk: CLI bugs affect all users
Recommendation: Create test/cli.test.ts or test/index.test.ts

Test cases needed:

  • All CLI commands parse correctly
  • Help text displays
  • Error handling for invalid commands
  • Exit codes

4. src/ollama.ts - Partial coverage

Status: test/model-routing.test.ts exists but only tests routing logic
Missing: Actual Ollama API interaction, error handling, retry logic
Recommendation: Expand to full test/ollama.test.ts

Test cases needed:

  • Connection failures (Ollama not running)
  • Timeout handling
  • Tool call execution in Ollama loop
  • Token counting
  • Response parsing

5. src/state.ts - No tests

Why Critical: Database initialization, schema migrations
Risk: Schema bugs could corrupt user data
Recommendation: Create test/state.test.ts or test/database.test.ts

Test cases needed:

  • Database creation
  • Schema initialization
  • Concurrent access
  • Database cleanup

Test Coverage Statistics

src/ files: 10
test/ files: 11
Untested modules: 4 (40%)

Recommendation

Prioritize adding tests for config.ts and daemon.ts first, as they handle critical infrastructure.

Use mocking for:

  • File system operations (fs module)
  • Network calls (fetch, child processes)
  • External dependencies (Anthropic SDK, Ollama)

Impact

  • Bugs in untested code go undetected
  • Regressions introduced during refactoring
  • Harder to onboard new contributors
  • Lower confidence in production deployments

Created by security audit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions