Skip to content

[Testing] Low test coverage for core components - docker-manager.ts 18%, cli.ts 0% #135

@Mossaka

Description

@Mossaka

Priority

P0 - Critical (for code quality)

Summary

Core components have critically low test coverage:

  • docker-manager.ts: 18% (handles all Docker orchestration)
  • cli.ts: 0% (main entry point)

These are the most important files in the codebase, yet they have the least test coverage.

Current Coverage

File Coverage Risk Level
src/docker-manager.ts 18% Critical - core orchestration
src/cli.ts 0% Critical - main entry point
src/squid-config.ts Good Lower risk
src/host-iptables.ts Moderate Medium risk

Impact

  • Regressions go undetected: Changes to Docker orchestration may break without tests
  • Refactoring risky: Cannot safely improve code without comprehensive tests
  • Bug fixes incomplete: Hard to verify fixes without test coverage
  • CI false confidence: Passing CI doesn't mean core functionality works

Target Coverage

File Current Target
src/docker-manager.ts 18% 80%
src/cli.ts 0% 60%

Test Cases Needed

docker-manager.ts

describe('Docker Manager', () => {
  describe('container lifecycle', () => {
    it('should start squid container with correct config');
    it('should start agent container after squid is healthy');
    it('should handle squid startup failure');
    it('should handle agent startup failure');
    it('should propagate exit codes correctly');
    it('should stream logs in real-time');
  });

  describe('network configuration', () => {
    it('should create awf-net with correct subnet');
    it('should assign correct IPs to containers');
    it('should handle network creation failure');
    it('should cleanup network on exit');
  });

  describe('cleanup', () => {
    it('should stop containers on normal exit');
    it('should stop containers on SIGINT');
    it('should stop containers on error');
    it('should preserve logs when keep-containers is set');
  });

  describe('log streaming', () => {
    it('should stream stdout in real-time');
    it('should stream stderr in real-time');
    it('should handle disconnection gracefully');
  });
});

cli.ts

describe('CLI', () => {
  describe('argument parsing', () => {
    it('should parse --allow-domains correctly');
    it('should parse multiple comma-separated domains');
    it('should parse --dns-servers correctly');
    it('should reject invalid domain formats');
    it('should handle --keep-containers flag');
    it('should handle --build-local flag');
    it('should handle --image-tag flag');
  });

  describe('workflow', () => {
    it('should call writeConfigs before startContainers');
    it('should call stopContainers in finally block');
    it('should exit with agent exit code');
    it('should handle SIGINT gracefully');
    it('should handle SIGTERM gracefully');
  });

  describe('error handling', () => {
    it('should show helpful error for missing domains');
    it('should show helpful error for missing command');
    it('should cleanup on error');
  });
});

Files to Create/Modify

  • Create/expand: src/docker-manager.test.ts
  • Create: src/cli.test.ts
  • Modify: jest.config.js - ensure coverage thresholds

Implementation Notes

  • Use mocking for Docker commands (execa)
  • Use Jest's mock filesystem for config files
  • Test signal handling carefully (may need child processes)
  • Integration tests separate from unit tests

Acceptance Criteria

  • docker-manager.ts coverage ≥ 80%
  • cli.ts coverage ≥ 60%
  • All tests pass in CI
  • No regression in existing tests

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions