This guide explains how to run tests for the AI Council Proxy, including unit tests, property tests, and integration tests.
npm test# 1. Start the test database
docker compose --profile test up -d
# 2. Run all tests
npm test
# 3. Stop the test database (optional)
docker compose --profile test downIntegration tests require a PostgreSQL test database. We use Docker Compose with a separate test database profile to avoid interfering with your development database.
The test database is configured with the test profile, which means it won't start with the regular services unless explicitly requested.
Start test database:
docker compose --profile test up -d postgres-testCheck test database status:
docker compose ps postgres-testStop test database:
docker compose --profile test downConfiguration:
- Host:
localhost - Port:
5433(different from main database on 5432) - Database:
ai_council_test - User:
postgres - Password:
postgres
If you prefer not to use Docker:
# Create test database
createdb ai_council_test
# Initialize schema
psql ai_council_test < database/schema.sqlThen set environment variables:
export TEST_DATABASE_HOST=localhost
export TEST_DATABASE_PORT=5432
export TEST_DATABASE_NAME=ai_council_test
export TEST_DATABASE_USER=postgres
export TEST_DATABASE_PASSWORD=your_passwordnpm testUnit Tests:
npm test -- src/synthesis/__tests__/engine.test.tsProperty Tests:
npm test -- src/synthesis/__tests__/engine.property.test.tsIntegration Tests:
# Requires test database to be running
docker compose --profile test up -d postgres-test
npm test -- src/__tests__/integration/iterative-consensus.integration.test.tsnpm test -- --watchnpm test -- --coveragenpm test -- -t "should achieve consensus when members converge"Test individual components in isolation with mocked dependencies.
Location: src/**/__tests__/*.test.ts
Examples:
src/synthesis/__tests__/engine.test.ts- Synthesis engine unit testssrc/providers/__tests__/pool.test.ts- Provider pool unit testssrc/session/__tests__/manager.test.ts- Session manager unit tests
Run:
npm test -- --testPathPattern="test.ts$" --testPathIgnorePatterns="property|integration"Test system properties with automatically generated test cases using fast-check.
Location: src/**/__tests__/*.property.test.ts
Examples:
src/synthesis/__tests__/engine.property.test.ts- Synthesis strategy propertiessrc/synthesis/iterative-consensus/__tests__/synthesizer.property.test.ts- Iterative consensus propertiessrc/embedding/__tests__/service.property.test.ts- Embedding service properties
Properties Tested:
- Consensus threshold enforcement
- Negotiation round progression
- Similarity calculation symmetry
- Early termination correctness
- Fallback invocation conditions
- Deadlock detection accuracy
- Agreement transitivity
- And more...
Run:
npm test -- --testPathPattern="property.test.ts$"Test complete workflows with real database and Redis connections.
Location: src/__tests__/integration/*.integration.test.ts
Examples:
src/__tests__/integration/iterative-consensus.integration.test.ts- Iterative consensus end-to-end testssrc/__tests__/metrics-tracking.integration.test.ts- Metrics tracking integration tests
Requirements:
- PostgreSQL test database (port 5433)
- Redis (port 6379)
Run:
# Start test infrastructure
docker compose --profile test up -d postgres-test redis
# Run integration tests
npm test -- --testPathPattern="integration.test.ts$"Iterative Consensus Feature:
- ✅ 13/13 Property tests passing (100%)
- ✅ 9/9 Integration tests passing (100%)
- ✅ All core components unit tested
Overall System:
- Unit tests: ~85% coverage
- Property tests: 100+ properties validated
- Integration tests: Full end-to-end flows
npm test -- --coverageCoverage report will be generated in coverage/lcov-report/index.html
Tests automatically use test-specific environment variables when available:
# Test Database (automatically used by integration tests)
TEST_DATABASE_HOST=localhost
TEST_DATABASE_PORT=5433
TEST_DATABASE_NAME=ai_council_test
TEST_DATABASE_USER=postgres
TEST_DATABASE_PASSWORD=postgres
# Redis (shared with development)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_URL=redis://localhost:6379
# Property Test Configuration
PROPERTY_TEST_RUNS=100 # Number of iterations per property testSee jest.config.js for test configuration:
- Test match patterns
- Coverage thresholds
- Test environment setup
- Timeout settings
Problem: Database tables don't exist in test database.
Solution:
# Recreate test database with schema
docker compose --profile test down -v
docker compose --profile test up -d postgres-test
# Wait for database to initialize (check logs)
docker compose logs postgres-test
# Run tests
npm test -- src/__tests__/integration/Problem: Database or Redis not accessible.
Solution:
# Check services are running
docker compose ps
# Check test database specifically
docker compose --profile test ps
# Start missing services
docker compose --profile test up -d
# Check connectivity
telnet localhost 5433 # Test database
telnet localhost 6379 # RedisProblem: Port 5433 (test database) is already in use.
Solution:
# Option 1: Stop conflicting service
lsof -i :5433 # Find process using port
kill <PID> # Stop the process
# Option 2: Change test database port
export TEST_DATABASE_PORT=5434
# Update docker-compose.yml TEST_DATABASE_PORT accordinglyProblem: Property tests are statistical and may occasionally fail.
Solution:
# Increase number of iterations for more confidence
export PROPERTY_TEST_RUNS=1000
# Run specific property test multiple times
for i in {1..10}; do npm test -- -t "Property 1: Consensus Threshold"; doneProblem: Tests using real API keys instead of mocks.
Solution:
# Enable mock providers for testing
export USE_MOCK_PROVIDERS=true
# Or unset API keys for test environment
unset OPENAI_API_KEY
unset ANTHROPIC_API_KEY
unset GOOGLE_API_KEYTests run automatically on:
- Pull requests
- Pushes to main branch
- Manual workflow dispatch
Workflow: .github/workflows/test.yml
Run the full CI test suite locally:
# Start all test infrastructure
docker compose --profile test up -d
# Run linting
npm run lint
# Run type checking
npm run type-check
# Run all tests
npm test -- --coverage
# Cleanup
docker compose --profile test down-
Use descriptive test names:
test("should achieve consensus when members converge", async () => { // Test implementation });
-
Use property-based tests for invariants:
fc.assert( fc.asyncProperty(arbitraryInput, async (input) => { const result = await systemUnderTest(input); expect(result).toSatisfyProperty(); }), { numRuns: 100 } );
-
Clean up resources in tests:
afterEach(async () => { await pool.query("DELETE FROM test_data WHERE id LIKE 'test-%'"); });
-
Use test isolation:
- Each test should be independent
- Use unique IDs (prefixed with 'test-')
- Clean up after each test
# Watch mode for rapid feedback
npm test -- --watch --testPathPattern="your-feature"
# Run only changed tests
npm test -- --onlyChanged
# Debug specific test
node --inspect-brk node_modules/.bin/jest --runInBand -t "your test name"If you encounter issues not covered in this guide:
- Check existing GitHub issues
- Review test logs:
npm test -- --verbose - Check Docker logs:
docker compose logs postgres-test - Open a new issue with:
- Test output
- Environment details
- Steps to reproduce