Open Bedrock Server

A unified, provider-agnostic chat completions API server supporting OpenAI and AWS Bedrock

View the Project on GitHub teabranch/open-bedrock-server

Test Suite Organization

This directory contains a comprehensive test suite organized for different CI/CD scenarios. The tests are carefully separated to ensure safe CI execution while still providing real API validation.

๐ŸŽฏ Test Categories

1. Unit Tests (unit marker)

2. Integration Tests (integration marker)

3. Real API Tests (real_api marker)

๐Ÿš€ Running Tests

Quick Start

# Run all safe tests (recommended for CI)
python run_tests.py --mode mock

# Run only unit tests (fastest)
python run_tests.py --mode unit

# Run integration tests with mocks
python run_tests.py --mode integration

CI/CD Modes

# CI Safe modes (no API calls, no costs)
python run_tests.py --mode unit           # Unit tests only
python run_tests.py --mode integration    # Integration tests with mocks
python run_tests.py --mode mock           # All safe tests (default)
python run_tests.py --mode all-safe       # All safe tests (explicit)

# Manual/Scheduled modes (cost money)
python run_tests.py --mode real-api       # Real API tests (with confirmation)
python run_tests.py --mode all            # Everything (with confirmation)

Direct pytest Usage

# Safe for CI (no API calls)
pytest -m "not real_api"                  # All safe tests
pytest -m "unit"                          # Unit tests only
pytest -m "integration and not real_api"  # Integration tests with mocks

# Costs money (manual only)
pytest -m "real_api"                      # Real API tests
pytest -m "openai_integration"            # OpenAI specific tests
pytest -m "bedrock_integration"           # Bedrock specific tests

๐Ÿ”ง GitHub Actions Integration

CI Workflow (Automatic)

File: .github/workflows/ci-tests.yml

# Runs on every push/PR - SAFE
- Push to main/develop
- Pull requests
- Multiple Python versions
- Coverage reporting
- No API calls, no costs

Real API Workflow (Manual)

File: .github/workflows/real-api-tests.yml

# Manual trigger only - COSTS MONEY
- workflow_dispatch with confirmation
- Optional scheduled runs
- Uses secrets for API keys
- Cost acknowledgment required

๐Ÿ“Š Test Organization

Directory Structure

tests/
โ”œโ”€โ”€ test_*.py                    # Main test files
โ”œโ”€โ”€ api/                         # API-specific tests
โ”œโ”€โ”€ core/                        # Core functionality tests
โ”œโ”€โ”€ services/                    # Service layer tests
โ”œโ”€โ”€ utils/                       # Utility tests
โ”œโ”€โ”€ conftest.py                  # Test configuration
โ”œโ”€โ”€ README.md                    # This file
โ””โ”€โ”€ README_REAL_API_TESTS.md     # Real API test details

Test File Organization

File Type Markers Description
test_models.py Unit unit Data model validation
test_auth.py Unit unit Authentication logic
test_chat.py Mixed integration, some real_api Chat functionality
test_bedrock_chat.py Mixed integration, some real_api Bedrock integration
test_real_api_integration.py Real API real_api Comprehensive API tests

๐Ÿ”’ Safety Features

1. Marker Protection

2. Cost Warnings

3. CI/CD Safety

๐Ÿ“‹ Test Markers Reference

Marker Purpose CI Safe Cost Usage
unit Fast unit tests โœ… ๐Ÿ†“ -m unit
integration Integration with mocks โœ… ๐Ÿ†“ -m integration
real_api Real API calls โŒ ๐Ÿ’ฐ -m real_api
openai_integration OpenAI specific โŒ ๐Ÿ’ฐ -m openai_integration
bedrock_integration Bedrock specific โŒ ๐Ÿ’ฐ -m bedrock_integration
slow Slow tests โœ… ๐Ÿ†“ -m "not slow"

๐ŸŽฎ Development Workflow

During Development

# Quick validation
python run_tests.py --mode unit --verbose

# Full local validation (safe)
python run_tests.py --mode mock --verbose

# Before committing
python run_tests.py --mode all-safe

Before Release

# Validate real API integration (costs money)
python run_tests.py --mode real-api

CI/CD Pipeline

# Automated (safe)
- Every commit: unit tests
- Every PR: all safe tests
- Merge to main: full safe test suite

# Manual (costs money)  
- Release validation: real API tests
- Weekly scheduled: comprehensive API tests

๐Ÿ›ก๏ธ Best Practices

For CI/CD

  1. Never run real API tests automatically - always require manual trigger
  2. Use cost confirmations - require explicit acknowledgment of costs
  3. Set spending limits - configure API key spending limits
  4. Monitor usage - set up billing alerts for API usage
  5. Separate environments - use different API keys for testing vs production

For Development

  1. Start with unit tests - write fast, isolated tests first
  2. Mock external dependencies - use mocks for integration tests
  3. Validate with real APIs sparingly - only when necessary
  4. Document cost implications - clearly mark expensive tests
  5. Use minimal API calls - keep real API tests lightweight

For Testing

  1. Layer your tests - unit โ†’ integration โ†’ real API
  2. Mark tests appropriately - use correct markers for each test
  3. Handle credentials safely - never commit API keys
  4. Test error scenarios - include negative test cases
  5. Monitor test costs - track spending on API calls

๐Ÿ” Troubleshooting

Common Issues

  1. Tests not running in CI
    • Check that youโ€™re using safe markers (not real_api)
    • Verify GitHub Actions workflow configuration
  2. Real API tests failing
    • Check API credentials in environment/secrets
    • Verify API key permissions and limits
    • Check service availability and quotas
  3. Unexpected costs
    • Ensure real API tests have real_api marker
    • Check that CI workflows exclude expensive tests
    • Review API usage dashboards

Debugging Commands

# Check test discovery
pytest --collect-only

# Dry run without execution
pytest --collect-only -m real_api

# Run with maximum verbosity
python run_tests.py --mode unit --verbose -v

# Check marker filtering
pytest -m "not real_api" --collect-only

๐Ÿ“ˆ Continuous Improvement

Metrics to Track

Regular Reviews

This organization ensures safe, fast CI execution while maintaining comprehensive validation through carefully managed real API testing.