Testing Guide
Running Tests
Section titled “Running Tests”Unit Tests
Section titled “Unit Tests”# Run all unit testsbun test tests/unit
# Run specific test filebun test tests/unit/state-manager.test.ts
# Run tests with coveragebun test tests/unit --coverageCoverage Reports
Section titled “Coverage Reports”Text Coverage Report
Section titled “Text Coverage Report”# Get coverage with text outputbun run test:coverageCoverage Summary Only
Section titled “Coverage Summary Only”# Get just the coverage summarybun run test:coverage:summaryLCOV Coverage File
Section titled “LCOV Coverage File”The --coverage flag writes coverage data to coverage/lcov.info.
Coverage Configuration
Section titled “Coverage Configuration”Coverage is configured in bunfig.toml:
- Coverage Directory:
coverage/ - Coverage Threshold: 80%
- Included Files:
src/**/*.{ts,tsx,js,jsx} - Excluded Files: Test files, TUI components, build artifacts
Test Structure
Section titled “Test Structure”tests/├── unit/ # Unit tests (Bun)│ ├── state-manager.test.ts│ ├── experience-tracker.test.ts│ └── ...├── integration/ # AI agent tests with mocked LLM├── node/ # Node.js build smoke tests├── regression/ # End-to-end runs with real AI└── mocks/ # Test mocksThis page covers unit tests. The other suites: integration tests exercise AI agents against a mocked LLM via aimock — see AI integration tests. Node smoke tests in tests/node/ verify the compiled npm build and run in CI (bun run test:node). Regression tests run Explorbot with real AI against a local fixture app — see regression tests.
Writing Tests
Section titled “Writing Tests”Best Practices
Section titled “Best Practices”- Happy path focus: Test successful scenarios and core functionality.
- Test isolation: Make each test independent and clean up after itself.
- Descriptive names: Name tests for what they check.
- Mock external dependencies: Use
MockAIProviderfor AI-related tests. - Temp directories: Use
/tmp/paths for file system tests.
Mock AI Provider
Section titled “Mock AI Provider”import { MockAIProvider } from '../mocks/ai-provider.mock';
const mockAI = new MockAIProvider();mockAI.setResponses([ { text: 'Mock response 1' }, { text: 'Mock response 2' }]);
// Use mockAI.getModel() in your testsCI/CD Integration
Section titled “CI/CD Integration”Generate coverage reports for your CI pipeline:
# Generate coverage for CIbun test tests/unit --coverage --coverage-reporter=lcov
# Check coverage threshold (exits with error if below 80%)bun test tests/unit --coverage --coverage-reporter=textUpload the LCOV file (coverage/lcov.info) to a coverage service like Codecov or Coveralls.