# Flow SDK Test Suite

This directory contains the test suite for the Flow SDK.

## Structure

```
tests/
├── unit/              # Unit tests for individual components
│   ├── test_config.py     # Configuration tests
│   ├── test_errors.py     # Error handling tests
│   ├── test_flow.py       # Main Flow class tests
│   ├── test_http.py       # HTTP client tests
│   ├── test_models.py     # Data model tests
│   └── test_provider.py   # Provider architecture tests
├── integration/       # Integration tests
│   ├── test_end_to_end.py # End-to-end workflow tests
│   └── test_cli.py        # CLI integration tests
├── fixtures/          # Test fixtures and data
└── conftest.py        # Pytest configuration and shared fixtures
```

## Running Tests

### Run all tests
```bash
pytest tests/
```

### Run with coverage
```bash
pytest tests/ --cov=src/flow --cov-report=term-missing
```

### Run specific test module
```bash
pytest tests/unit/test_models.py
```

### Run specific test class
```bash
pytest tests/unit/test_models.py::TestTaskConfig
```

### Run specific test
```bash
pytest tests/unit/test_models.py::TestTaskConfig::test_minimal_config
```

### Run tests matching a pattern
```bash
pytest tests/ -k "config"
```

### Run tests in verbose mode
```bash
pytest tests/ -v
```

### Run tests and stop on first failure
```bash
pytest tests/ -x
```

## Test Categories

### Unit Tests
- **test_config.py**: Tests for configuration loading from environment
- **test_errors.py**: Tests for custom exception hierarchy
- **test_flow.py**: Tests for main Flow class API
- **test_http.py**: Tests for HTTP client functionality
- **test_models.py**: Tests for Pydantic models and validation
- **test_provider.py**: Tests for provider factory and FCP provider

### Integration Tests
- **test_end_to_end.py**: Complete workflow tests (find → run → status → complete)
- **test_cli.py**: CLI command tests with mocked Flow instance

## Writing Tests

### Test Structure
```python
class TestFeature:
    """Test feature description."""
    
    @pytest.fixture
    def setup_data(self):
        """Setup test data."""
        return {"key": "value"}
    
    def test_specific_behavior(self, setup_data):
        """Test specific behavior description."""
        # Arrange
        data = setup_data
        
        # Act
        result = function_under_test(data)
        
        # Assert
        assert result == expected_value
```

### Common Fixtures
See `conftest.py` for shared fixtures:
- `mock_env`: Mock environment variables
- `mock_http_client`: Mock HTTP client
- `sample_task_config`: Sample TaskConfig data
- `sample_instance`: Sample instance data
- `sample_volume`: Sample volume data

### Mocking Guidelines
- Use `unittest.mock` for mocking
- Mock external dependencies (HTTP, file system, etc.)
- Don't mock the code under test
- Use fixtures for reusable mocks

## Coverage Goals
- Aim for >90% code coverage
- Focus on testing behavior, not implementation
- Test error cases and edge conditions
- Ensure all public APIs are tested