Orchestrata Ultimate / Specs / 097-testing-standards

097-testing-standards: Testing Standards

This specification defines the testing standards, templates, coverage requirements, and quality gates for the orchestrata-ultimate system. All specifications MUST include test scenarios following these standards.

At a glance

Item Value
Spec directory specs/097-testing-standards/
Status line in the spec Complete
Requirement IDs defined 16
With a @traces citation in src/ 0 (0.0%)
With a @traces citation in tests/ 0 (0.0%)
Tracked files 4
RTM page 097-testing-standards

Reading this spec

This spec sets the testing standards, templates, coverage thresholds and quality gates for the whole orchestrata-ultimate system. It states that every specification must include test scenarios that follow these standards, so it works as the common contract between spec authors, developers, QA engineers and CI.

Four user stories frame it: a developer writing unit tests from clear templates and naming conventions (test_<module>.py files, test_<method>_<condition>_<expected> methods, fixtures for shared setup, descriptive assertions), a QA engineer running integration tests that check component interactions, a DevOps engineer running end-to-end tests, and a team lead enforcing coverage. The main body defines test types, execution requirements, coverage requirements, quality gates, required test scenarios and test data requirements, and its later sections cover data management, execution, naming, assertions, maintenance and performance testing.

Eleven general requirements (REQ-097-001 to 011) carry the substance. Coverage targets differ by component: Core Kernel 90% unit and 100% integration, CLI Commands 85% and 100%, Tool Implementations 80% and 100%, Integrations 70% and 80%. Suites run through standard pytest commands for unit, integration, end-to-end and coverage runs. Tests clean up after themselves, are deterministic and repeatable, and use factories and fakes instead of production data. Templates exist for unit (Arrange-Act-Assert), integration, end-to-end and property-based tests. Quality gates apply at pre-commit, pull request and release stages. Performance targets are P50 under 100 ms, P95 under 500 ms, at least 1000 requests per second and a baseline memory under 500 MB. A second group (REQ-097-101 to 105) comes from a Redis key-namespacing addendum for parallel safety: a gate that flags Redis writes in test files, allows a flagged site exactly two dispositions, limits a waiver marker to its own physical line, makes the gate blocking, and has the gate fall back to a regex-based scan when the AST parser cannot read a file.

This is a standards spec, so no code module cites it. The requirements traceability matrix lists every ID. The spec's own status line reads Complete and it tracks 4 files. No src/ symbol cites any of the 16 requirements, so measured trace coverage is 0.0%, and in tests/, 0 requirements are cited by a test-side @traces. All 16 requirements have no citing symbol; the standards are enforced through gates and review rather than through code annotations.

Requirements

Checkbox is the state recorded in the requirements checklist; Traced by is the count of src/ symbols whose @traces names the ID.

ID Done Requirement Traced by
REQ-097-001 no All specifications MUST include test scenarios following defined templates — test files follow the test_&lt;module>.py naming convention, test methods follow test_&lt;method>_&lt;condition>_&lt;expected>, and fixtures are used for common setup. none
REQ-097-002 no All code MUST achieve minimum coverage thresholds by component: Core Kernel 90% unit / 100% integration, CLI Commands 85% unit / 100% integration, Tool Implementations 80% unit / 100% integration, Integrations 70% unit / 80% integration, UI Components 80% unit. none
REQ-097-003 no Test suites MUST be executable via standardized commands: pytest tests/unit/ -v (unit), pytest tests/integration/ -v -m integration (integration), pytest tests/e2e/ -v -m e2e (E2E), pytest tests/ --cov=src --cov-report=html (coverage). none
REQ-097-004 no All test suites MUST clean up after execution — test data removed after completion, temporary files cleaned up, mock/test-double resources released, and database state reset. none
REQ-097-005 no Tests MUST be deterministic and repeatable — no flakiness due to timing, no test-order dependencies, no reliance on external state, and no random behavior without seeding. none
REQ-097-006 no Test frameworks and tools MUST be properly configured — pytest configured for async support, coverage reporting enabled, proper markers for test categories, and parallel execution enabled where safe. none
REQ-097-007 no Test templates MUST be provided for all test types — unit (Arrange-Act-Assert), integration (real dependencies), E2E (complete workflows), and property-based (invariants across randomized inputs). none
REQ-097-008 no Quality gates MUST enforce standards at each CI/CD stage — pre-commit (unit tests pass, coverage meets target, no linting errors), PR (integration tests pass, E2E tests pass for changed functionality, no coverage regression), release (full suite passes, benchmarks met, no critical vulnerabilities). none
REQ-097-009 no Test data MUST use factories and fakes, never production data — test data factories for common types, Faker for realistic test data, no sensitive data in tests, safe test data isolation. none
REQ-097-010 no Error conditions MUST have corresponding test coverage — all error scenarios tested, edge cases validated, exception handling verified, error messages validated. none
REQ-097-011 no Performance benchmarks MUST be defined and enforced — response time targets (P50 < 100ms, P95 < 500ms), throughput minimums (1000 requests/second), memory limits (< 500MB baseline), load testing at 10x expected capacity. none
REQ-097-101 yes A Redis write (REDIS_WRITE_VERBS) under tests/test_*.py none
REQ-097-102 yes A flagged site SHALL have exactly two legitimate dispositions: none
REQ-097-103 yes A waiver marker SHALL cover only its own physical line and the none
REQ-097-104 yes Gate 0.4 SHALL be a blocking gate in none
REQ-097-105 yes A file the AST parser cannot read SHALL fall back to a none

Code that traces this spec

No src/ symbol cites a requirement of this spec.

Checklists

checklists/requirements.md

The requirement list above comes from this file; 5 of 16 checkbox items are ticked.

Other tracked files

Full spec text

Verbatim from specs/097-testing-standards/spec.md; headings are pushed down two levels.

SPEC-097: Testing Standards

Metadata


Testing Requirements

Test Types
Type Scope Dependencies Coverage Target
Unit Tests Individual functions/methods Mocked 80% minimum
Integration Tests Component interactions Real (DB, cache) 100% of API contracts
End-to-End Tests Complete workflows Real system Critical paths
Property-Based Tests Invariants across inputs Randomized All transformations
Test Execution Requirements
Coverage Requirements
Quality Gates
Stage Requirements
Pre-Commit Unit tests pass, coverage meets target, no linting errors
PR Integration tests pass, E2E tests pass for changed functionality, no coverage regression
Release Full test suite passes, performance benchmarks within limits, no critical vulnerabilities
Required Test Scenarios

Every specification MUST include tests for:

  1. Happy Path: Valid input produces expected output
  2. Invalid Input: Invalid input produces appropriate error
  3. Edge Cases: Boundary conditions handled correctly
  4. Error Handling: All error conditions have test coverage
  5. Concurrent Access: Thread-safety for shared resources
  6. Graceful Degradation: System handles component failures
  7. Security: Authorization and authentication enforced
Test Data Requirements

Overview

This specification defines the testing standards, templates, coverage requirements, and quality gates for the orchestrata-ultimate system. All specifications MUST include test scenarios following these standards.


User Scenarios

US-001: Developer Writing Unit Tests

As a developer, I want clear test templates so I can write consistent unit tests that follow project conventions.

Acceptance Criteria:

US-002: QA Engineer Running Integration Tests

As a QA engineer, I want integration tests that verify component interactions so I can detect integration issues before deployment.

Acceptance Criteria:

US-003: DevOps Running E2E Tests

As a DevOps engineer, I want E2E tests that verify complete workflows so I can validate production readiness.

Acceptance Criteria:

US-004: Team Lead Enforcing Coverage

As a team lead, I want coverage requirements and quality gates so I can ensure code quality standards are met.

Acceptance Criteria:


Terminology

Test

A function or method that verifies expected behavior under specific conditions.

Fixture

Reusable test setup code that provides consistent initial state for tests.

Coverage

Percentage of code executed during test runs (line, branch, function).

Quality Gate

Automated check that must pass before code can proceed to next stage.

Test Stub

Simplified implementation that replaces external dependencies.

Mock

Object that simulates behavior of real dependencies for testing.

Test Doubles

Generic term for test objects (stubs, mocks, spies, fakes).

Assertion

Statement that verifies expected vs actual result.

Test Suite

Collection of related tests executed together.


Functional Requirements

FR-001: All specifications MUST include test scenarios following defined templates

FR-002: All code MUST achieve minimum coverage thresholds

FR-003: Test suites MUST be executable via standardized commands

FR-004: All test suites MUST clean up after execution

FR-005: Tests MUST be deterministic and repeatable

FR-006: Test frameworks and tools MUST be properly configured

FR-007: Test templates MUST be provided for all test types

FR-008: Quality gates MUST enforce standards at each CI/CD stage

FR-009: Test data MUST use factories and fakes, never production data

FR-010: Error conditions MUST have corresponding test coverage

FR-011: Performance benchmarks MUST be defined and enforced


Error Conditions

ID Condition Handling
ERR-001 Test timeout exceeded Mark as failed, log timeout details, capture partial results
ERR-002 Missing test dependency Skip test, log warning with dependency name, continue with other tests
ERR-003 Assertion failure detected Mark as failed, show expected vs actual diff, log assertion details
ERR-004 Fixture setup error Mark as error, show fixture traceback, mark dependent tests as skipped
ERR-005 Coverage below threshold Block PR, generate coverage report, show uncovered lines
ERR-006 Test database connection failed Mark tests as skipped, log database error, attempt cleanup
ERR-007 Mock/stub resource unavailable Mark as error, log mock error, continue with other independent tests
ERR-008 Parallel test execution conflict Mark affected tests as failed, retry with sequential execution
ERR-009 Test data factory error Mark test as failed, log data generation error, skip dependent tests
ERR-010 Environment variable missing Mark test as skipped, log missing variable, show required setup
ERR-011 Permission denied for test file Mark test as error, log permission issue, skip filesystem tests
ERR-012 External API timeout in test Mark as failed, log API timeout, retry with shorter timeout
ERR-013 Concurrent test modification conflict Mark as error, log file lock error, abort conflicting tests
ERR-014 Test output too large Mark as warning, truncate output, log size details
ERR-015 Benchmark regression detected Mark as failed, show benchmark diff, block performance-sensitive PRs

Data Models

TestConfiguration
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["test_type", "coverage_target"],
  "properties": {
    "test_type": {
      "type": "string",
      "enum": ["unit", "integration", "e2e", "property"]
    },
    "coverage_target": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
    },
    "timeout_seconds": {
      "type": "integer",
      "minimum": 1
    },
    "retry_count": {
      "type": "integer",
      "minimum": 0
    }
  }
}
TestResult
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["test_id", "status", "timestamp"],
  "properties": {
    "test_id": {
      "type": "string"
    },
    "status": {
      "type": "string",
      "enum": ["passed", "failed", "skipped", "error"]
    },
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "duration_ms": {
      "type": "number"
    },
    "error_message": {
      "type": "string"
    },
    "stack_trace": {
      "type": "string"
    }
  }
}
CoverageReport
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["timestamp", "line_coverage"],
  "properties": {
    "timestamp": {
      "type": "string",
      "format": "date-time"
    },
    "line_coverage": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
    },
    "branch_coverage": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
    },
    "files_covered": {
      "type": "integer"
    },
    "files_total": {
      "type": "integer"
    }
  }
}

Visual Architecture

Class Diagram

Diagram source shown as text: Mermaid could not parse it (Error: Parse error on line 2:).

classDiagram-direction LR
    <<dataclass>>
    class TraceInfo <<dataclass>> {
        -spec: str = ''
        -story: str = ''
        -reqs: List[str] = field(default_factory=list)
        -module: str = ''
        -class_name: str = ''
        -method: str = ''
        -file_path: str = ''
        -line_number: int = 0
        ---
        +to_dict(): Dict[str, Any]
    }
    <<dataclass>>
    class Requirement <<dataclass>> {
        -id: str
        -description: str
        -story_id: str = ''
        -spec_id: str = ''
        -priority: str = 'NORMAL'
        -category: str = ''
        ---
    }
    <<dataclass>>
    class UserStory <<dataclass>> {
        -id: str
        -title: str
        -as_a: str = ''
        -i_want: str = ''
        -so_that: str = ''
        -acceptance_criteria: List[str] = field(default_factory=list)
        -requirements: List[Requirement] = field(default_factory=list)
        -spec_id: str = ''
        ---
        +to_dict(): Dict[str, Any]
    }
    <<dataclass>>
    class ValidationReport <<dataclass>> {
        -verified: List[str] = field(default_factory=list)
        -missing: List[str] = field(default_factory=list)
        -orphan: List[str] = field(default_factory=list)
        -duplicates: Dict[str, List[str]] = field(default_factory=dict)
        ---
        {@property} +total_verified(): int
        {@property} +total_missing(): int
        {@property} +total_orphan(): int
        {@property} +coverage_percent(): float
        +to_dict(): Dict[str, Any]
    }
    <<dataclass>>
    class RTMReport <<dataclass>> {
        -entries: List[Dict[str, Any]] = field(default_factory=list)
        -validation: Optional[ValidationReport] = None
        -generated_at: str = ''
        -project: str = ''
        ---
        +to_dict(): Dict[str, Any]
    }
    UserStory *-- Requirement "1" "requirements" "1"
    RTMReport *-- ValidationReport "1" "validation" "1"
Test Standard Modification
Quality Gate Enforcement

API Contracts

Test Runner Interface
async def run_tests(
    test_path: str,
    test_type: TestType,
    coverage_target: float,
    timeout_seconds: int = 300
) -> TestResult:
    """Execute test suite with configuration.
    
    Args:
        test_path: Path to test files
        test_type: Unit, integration, or e2e
        coverage_target: Minimum coverage percentage
        timeout_seconds: Maximum execution time
    
    Returns:
        TestResult with status, duration, coverage metrics
    """
Coverage Reporter Interface
def generate_coverage_report(
    source_path: str,
    report_format: str = "html"
) -> CoverageReport:
    """Generate coverage report for source code.
    
    Args:
        source_path: Source directory to analyze
        report_format: Output format (html, xml, json)
    
    Returns:
        CoverageReport with metrics and file counts
    """
Quality Gate Checker Interface
def check_quality_gates(
    test_results: TestResult[],
    coverage_report: CoverageReport,
    gate_type: GateType
) -> QualityGateResult:
    """Verify quality gates are met.
    
    Args:
        test_results: Latest test execution results
        coverage_report: Current coverage metrics
        gate_type: pre-commit, pr, or release
    
    Returns:
        QualityGateResult with pass/fail and details
    """
Test Data Factory Interface
class TestDataFactory:
    """Factory for generating test data."""
    
    def create_user(self, **overrides) -> User:
        """Create test user with realistic data."""
    
    def create_resource(self, **overrides) -> Resource:
        """Create test resource with valid state."""
    
    def cleanup_all(self):
        """Clean up all generated test data."""

Non-Functional Requirements

Performance
Scalability
Reliability
Usability

Technical Design

Test Execution Architecture
┌─────────────────────────────────────────┐
│           Test Command Line             │
│         (pytest with plugins)           │
└────────────────┬────────────────────────┘
                 │
┌────────────────▼────────────────────────┐
│         Test Collection Phase           │
│  - Discover all test modules            │
│  - Load fixtures and plugins            │
│  - Parse markers and configurations     │
└────────────────┬────────────────────────┘
                 │
┌────────────────▼────────────────────────┐
│         Test Execution Phase            │
│  - Run tests in parallel workers        │
│  - Collect real-time coverage data      │
│  - Stream results to reporters          │
└────────────────┬────────────────────────┘
                 │
┌────────────────▼────────────────────────┐
│         Result Aggregation Phase        │
│  - Merge coverage data                  │
│  - Generate final reports               │
│  - Check quality gates                  │
│  - Update tracking metrics              │
└─────────────────────────────────────────┘
Coverage Tracking Design
Quality Gate Implementation

Examples

Example 1: Complete Unit Test
import pytest
from orchestrata_ultimate.core import ConfigManager

class TestConfigManager:
    """Unit tests for ConfigManager."""
    
    @pytest.fixture
    def temp_dir(self, tmp_path):
        """Create temporary config directory."""
        return tmp_path / "config"
    
    @pytest.fixture
    def subject(self, temp_dir):
        """Create config manager under test."""
        return ConfigManager(config_dir=temp_dir)
    
    def test_load_config_given_valid_file_returns_config(
        self, subject, temp_dir
    ):
        """Test loading valid configuration file."""
        # Arrange
        config_file = temp_dir / "settings.yaml"
        config_file.write_text("key: value\ntimeout: 30")
        
        # Act
        config = subject.load_config("settings.yaml")
        
        # Assert
        assert config["key"] == "value"
        assert config["timeout"] == 30
    
    def test_load_config_given_missing_file_raises_error(self, subject):
        """Test handling of missing configuration file."""
        # Act/Assert
        with pytest.raises(FileNotFoundError):
            subject.load_config("nonexistent.yaml")
Example 2: Integration Test Suite
import pytest
import httpx
from orchestrata_ultimate.api import app

@pytest.mark.integration
class TestUserAPI:
    """Integration tests for user API endpoints."""
    
    @pytest.fixture
    async def client(self):
        """Create test client."""
        async with httpx.AsyncClient(
            app=app,
            base_url="http://test"
        ) as client:
            yield client
    
    async def test_create_user_given_valid_data_returns_201(
        self, client
    ):
        """Test successful user creation."""
        # Act
        response = await client.post(
            "/api/v1/users",
            json={"username": "testuser", "email": "test@example.com"}
        )
        
        # Assert
        assert response.status_code == 201
        assert response.json()["username"] == "testuser"
Example 3: E2E Workflow Test
import pytest
import subprocess
import json

@pytest.mark.e2e
class TestFullWorkflow:
    """End-to-end workflow tests."""
    
    def test_complete_development_cycle(self):
        """Test full development workflow from intent to deployment."""
        # Step 1: Create project
        result = subprocess.run(
            ["ultimate", "init", "test-project"],
            capture_output=True,
            text=True
        )
        assert result.returncode == 0
        
        try:
            # Step 2: Submit intent
            result = subprocess.run(
                ["ultimate", "intent", "Add user authentication"],
                capture_output=True,
                text=True
            )
            assert result.returncode == 0
            assert "Task created" in result.stdout
            
            # Step 3: Monitor progress
            for _ in range(30):  # Wait up to 5 minutes
                result = subprocess.run(
                    ["ultimate", "status", "--json"],
                    capture_output=True,
                    text=True
                )
                status = json.loads(result.stdout)
                if status["state"] == "completed":
                    break
            
            assert status["state"] == "completed"
            
        finally:
            # Cleanup
            subprocess.run(
                ["rm", "-rf", "test-project"],
                check=False
            )

Security

Test Environment Security
Code Security
Test Data Security
Dependency Security

Integration Points

CI/CD Pipeline Integration
IDE Integration
Monitoring Integration
Documentation Integration

Success Criteria

Test Framework Adoption
Quality Standards Met
Developer Experience
Automated Enforcement

Observability

Logging Requirements
  1. Component Logging
    • Log all major operations with appropriate log levels
    • Include correlation IDs for request tracing
    • Log performance metrics for critical operations
    • Log errors with full context for debugging
Metrics Requirements
  1. Performance Metrics
    • Operation duration histograms
    • Request/error rate counters
    • Resource utilization gauges
    • Business metrics relevant to domain
Tracing Requirements
  1. Distributed Tracing
    • Trace propagation across component boundaries
    • Span attributes for domain-specific context
    • Trace sampling based on operational needs
Alerting Requirements
  1. Critical Alerts
    • Error rate spikes
    • Performance degradation
    • Resource exhaustion
    • Business metric anomalies
Dashboard Requirements
  1. Operational Dashboard
    • Real-time system health
    • Performance trends
    • Error analysis
    • Resource monitoring

Revision History

Version Date Author Changes
1.0.0 2026-04-08 Mohamed Initial specification with test templates and quality gates
1.1.0 2026-04-09 Mohamed Added missing sections per SPEC_STANDARD.md, expanded error conditions to 15, added functional requirements FR-001 through FR-011

1.1 Unit Tests
1.2 Integration Tests
1.3 End-to-End Tests
1.4 Property-Based Tests

2. Test Templates

2.1 Unit Test Template
import pytest
from unittest.mock import Mock, patch

# Module under test
from orchestrata_ultimate.module import ClassUnderTest

class TestClassUnderTest:
    """Unit tests for ClassUnderTest."""
    
    @pytest.fixture
    def subject(self):
        """Create subject under test."""
        return ClassUnderTest()
    
    @pytest.fixture
    def mock_dependency(self):
        """Mock external dependency."""
        return Mock()
    
    # Happy path tests
    def test_method_name_given_condition_expected_result(self, subject, mock_dependency):
        """Test method returns expected result for valid input."""
        # Arrange
        subject.dependency = mock_dependency
        mock_dependency.method.return_value = "expected"
        
        # Act
        result = subject.method("valid_input")
        
        # Assert
        assert result == "expected"
        mock_dependency.method.assert_called_once_with("valid_input")
    
    # Edge case tests
    def test_method_name_given_blank_string_returns_blank_string(self, subject):
        """Test method handles blank string input."""
        # Act
        result = subject.method("")
        
        # Assert
        assert result == ""
    
    def test_method_name_given_none_raises_error(self, subject):
        """Test method raises TypeError for None input."""
        # Act/Assert
        with pytest.raises(TypeError):
            subject.method(None)
    
    # Error handling tests
    def test_method_name_given_invalid_input_raises_custom_error(self, subject):
        """Test method raises ValidationError for invalid input."""
        # Act/Assert
        with pytest.raises(ValidationError) as exc_info:
            subject.method("invalid")
        
        assert "validation failed" in str(exc_info.value).lower()
2.2 Integration Test Template
import pytest
import httpx
from unittest.mock import Mock, patch

# For integration tests, use real components where possible
class TestAPIEndpoint:
    """Integration tests for API endpoint."""
    
    @pytest.fixture
    def base_url(self):
        """Base URL for API."""
        return "http://localhost:8080/api/v1"
    
    @pytest.fixture
    def auth_headers(self):
        """Authentication headers."""
        return {"Authorization": "Bearer test-token"}
    
    @pytest.mark.integration
    async def test_endpoint_returns_200_with_valid_request(self, base_url, auth_headers):
        """Test endpoint returns success for valid request."""
        # Act
        async with httpx.AsyncClient() as client:
            response = await client.get(
                f"{base_url}/resource",
                headers=auth_headers
            )
        
        # Assert
        assert response.status_code == 200
        assert "data" in response.json()
    
    @pytest.mark.integration
    async def test_endpoint_returns_401_without_auth(self, base_url):
        """Test endpoint returns 401 without authentication."""
        # Act
        async with httpx.AsyncClient() as client:
            response = await client.get(f"{base_url}/resource")
        
        # Assert
        assert response.status_code == 401
    
    @pytest.mark.integration
    async def test_endpoint_returns_429_when_rate_limited(self, base_url, auth_headers):
        """Test endpoint returns 429 when rate limited."""
        # Act - make many requests
        async with httpx.AsyncClient() as client:
            for _ in range(70):
                response = await client.get(
                    f"{base_url}/resource",
                    headers=auth_headers
                )
                if response.status_code == 429:
                    break
        
        # Assert
        assert response.status_code == 429
        assert "Retry-After" in response.headers
2.3 End-to-End Test Template
import pytest
import subprocess
import time
import os

class TestUserWorkflow:
    """End-to-end tests for complete user workflows."""
    
    @pytest.fixture(autouse=True)
    def setup_and_teardown(self):
        """Setup and teardown for each test."""
        # Setup: Start runtime
        subprocess.run(["ultimate", "init", "test-project"], check=True)
        subprocess.run(["ultimate", "start", "--daemon"], check=True)
        
        yield
        
        # Teardown: Stop runtime
        subprocess.run(["ultimate", "stop"], check=False)
        subprocess.run(["rm", "-rf", "test-project"], check=False)
    
    @pytest.mark.e2e
    def test_full_development_workflow(self):
        """Test complete development workflow."""
        # Step 1: Submit intent
        result = subprocess.run(
            ["ultimate", "intent", "Add user authentication"],
            capture_output=True,
            text=True
        )
        assert result.returncode == 0
        assert "Task created" in result.stdout
        
        # Step 2: Check status
        result = subprocess.run(
            ["ultimate", "status", "--json"],
            capture_output=True,
            text=True
        )
        assert result.returncode == 0
        status = json.loads(result.stdout)
        assert status["state"] == "running"
        
        # Step 3: Create checkpoint
        result = subprocess.run(
            ["ultimate", "checkpoint", "Before auth"],
            capture_output=True,
            text=True
        )
        assert result.returncode == 0

3. Coverage Requirements

3.1 Coverage Targets
Component Unit Integration E2E
Core Kernel 90% 100% Critical paths
CLI Commands 85% 100% All commands
Tool Implementations 80% 100% All tools
Integrations 70% 80% Happy path
UI Components 80% - Critical flows
3.2 Required Test Scenarios

For each specification, the following MUST be tested:

  1. Happy Path: Valid input produces expected output
  2. Invalid Input: Invalid input produces appropriate error
  3. Edge Cases: Boundary conditions handled correctly
  4. Error Handling: All error conditions have test coverage
  5. Concurrent Access: Thread-safety for shared resources
  6. Graceful Degradation: System handles component failures
  7. Security: Authorization and authentication enforced

4. Quality Gates

4.1 Pre-Commit Gate
4.2 PR Gate
4.3 Release Gate

5. Test Data Management

5.1 Fixtures
5.2 Mocking Rules

6. Test Execution

6.1 Commands
# Run all tests
pytest tests/ -v

# Run unit tests only
pytest tests/unit/ -v

# Run with coverage
pytest tests/ --cov=src --cov-report=html

# Run specific test
pytest tests/unit/test_module.py::TestClass::test_method -v

# Run integration tests
pytest tests/integration/ -v -m integration

# Run E2E tests
pytest tests/e2e/ -v -m e2e

# Run with performance profiling
pytest tests/ --profile
6.2 CI/CD Integration
# .github/workflows/test.yml
name: Test

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      
      - name: Install dependencies
        run: pip install -e .[test]
      
      - name: Run unit tests
        run: pytest tests/unit/ --cov
      
      - name: Run integration tests
        run: pytest tests/integration/ -v -m integration
      
      - name: Upload coverage
        uses: codecov/codecov-action@v4

7. Test Naming Conventions

7.1 Test File Names
7.2 Test Method Names

Format: test_<method>_<condition>_<expected>

Examples:


8. Assertion Guidelines

8.1 Use Descriptive Assertions
# Bad
assert result

# Good
assert result is not None, "Result should not be None"
assert result.status == "success", f"Expected success, got {result.status}"
8.2 Test One Thing Per Test
# Bad
def test_method(self):
    result = subject.method(input)
    assert result.value == expected
    assert result.timestamp is not None

# Good
def test_method_returns_expected_value(self):
    result = subject.method(input)
    assert result.value == expected

def test_method_returns_timestamp(self):
    result = subject.method(input)
    assert result.timestamp is not None

9. Test Maintenance

9.1 Test Review Checklist
9.2 Test Documentation

Each test file MUST have:


10. Performance Testing

10.1 Benchmarks
10.2 Load Testing