Comprehensive test suite for GitGang CLI tool with 123 passing tests across 3 test files achieving high code coverage.
Tests for core utility functions and business logic:
- ANSI color code formatting
- TAG generation for different agents
- Bold, dim, and color functions
- Timestamp generation
- Line separator creation
- JSON parsing from mixed output
- Edge case handling
- Positional arguments
- Flag-based arguments
- Boolean flags (--yolo, --no-yolo, --no-pr)
- Numeric arguments (--rounds, --timeoutMs)
- Default values
- JSON stream line parsing
- Message type filtering
- Message formatting for display
- Handling various CLI output formats
- Claude/Gemini/Codex message types
- System constraints prompts
- Feature implementation prompts
- Reviewer JSON prompts
- Complex command-line parsing
- Reviewer decision JSON parsing
- Revisions request handling
- Empty inputs
- Whitespace handling
- Timestamp consistency
- Invalid JSON handling
Real-world integration tests with actual git operations:
- Repository initialization
- Branch management
- Working tree status checks
- Root directory discovery
- Error handling for git commands
- Worktree creation and deletion
- Worktree isolation
- Multiple worktree handling
- Worktree listing
- stdout/stderr capture
- Exit code handling
- Working directory context
- Command error handling
- Streaming output
- Directory creation (nested)
- File read/write
- File appending
- Existence checks
- Recursive deletion
- Data streaming
- Multiline streaming
- Empty stream handling
- Multiple parallel processes
- Mixed success/failure handling
- Complete agent workflow simulation
- Multiple parallel worktrees
- Git errors in non-repo directories
- Missing directory handling
- Permission error handling
Tests for agent-specific functionality:
- Gemini CLI arguments with/without yolo
- Claude CLI arguments with/without permissions
- Codex CLI arguments with different modes
- Directory structure creation
- Log file path management
- Branch name sanitization
- Multi-agent support
- Model name validation
- Agent-to-model mapping
- Special character handling
- Multiline prompt handling
- Empty prompt handling
- Consistency verification
- CLI flag verification for each agent
- Command structure validation
- Unique branch name generation
- Agent name inclusion
- Valid directory name creation
- Log file writing
- Separate logs per agent
- Log appending
- Multiple agent tracking
- Worktree-to-agent mapping
- Command construction for all agents
- Reviewer command building
- High reasoning effort configuration
- Invalid agent type handling
- Missing directory handling
- Configuration validation
- ✅ Color utilities (C.b, C.red, C.green, etc.)
- ✅ TAG generation
- ✅ line() separator function
- ✅ ts() timestamp function
- ✅ parseArgs() argument parser
- ✅ parseStreamLine() JSON parser
- ✅ shouldDisplayLine() filter
- ✅ formatMessage() formatter
- ✅ parseFirstJson() JSON extractor
- ✅ systemConstraints() prompt builder
- ✅ featurePrompt() prompt builder
- ✅ reviewerPromptJSON() prompt builder
- ✅ Git operations (git, ensureCleanTree, repoRoot, currentBranch)
- ✅ Worktree management (createWorktree, cleanup)
- ✅ Agent command builders (Gemini, Claude, Codex)
- ✅ Command-line argument parsing
- ✅ Git repository operations
- ✅ Git worktree management
- ✅ Process spawning and streaming
- ✅ File system operations
- ✅ JSON message parsing and formatting
- ✅ Agent configuration and coordination
- ✅ Error handling and edge cases
- ✅ Concurrent operations
- ✅ Real-world workflow simulation
- ✅ Empty and whitespace inputs
- ✅ Special characters in prompts
- ✅ Multiline content
- ✅ Invalid JSON
- ✅ Missing files/directories
- ✅ Git command errors
- ✅ Non-existent commands
- ✅ Permission errors
- ✅ macOS path normalization (/private/var)
- ✅ Mixed success/failure scenarios
# Run all tests
npm test
# Run specific test file
npx vitest run src/cli.test.ts
npx vitest run src/cli.integration.test.ts
npx vitest run src/cli.agents.test.ts
# Run with verbose output
npx vitest run --reporter=verbose
# Run and stop on first failure
npx vitest run --bail- Total Tests: 123
- Passing: 123
- Failing: 0
- Test Files: 3
- Expect Calls: 314
- Execution Time: ~637ms
- Argument parsing
- Color utilities
- Stream message parsing
- JSON parsing
- Prompt generation
- Agent configuration
- Git operations
- File system operations
- Error handling
- Real git repository operations
- Actual worktree creation/deletion
- Process spawning with real commands
- File system operations
- Concurrent workflow simulation
- Add coverage reporting with Bun's built-in coverage tool
- Add performance benchmarks
- Add tests for interactive command palette
- Add tests for full end-to-end workflow
- Add mock tests for actual AI agent calls
- Add tests for PR creation workflow