[AUTO-INF-3] Test Architecture: Centralize mock provider implementations in features/mocks/ with a unified interface #10036

Open
opened 2026-04-16 13:49:00 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit message: test(infra): centralize mock provider implementations in features/mocks/ with unified interface
  • Branch name: test/auto-inf-3-centralize-mock-providers

Background and Context

The features/mocks/ directory contains multiple independent mock provider implementations (mock_ai_provider.py, langchain_mock_provider.py, mock_devcontainer_cli.py, mock_mcp_transport.py, and others) without a unified interface, registry, or discovery mechanism. This makes it difficult to maintain consistency across mocks, discover available mocks, and ensure they all implement the same contract.

Current State

The features/mocks/ directory contains at least the following independent mock implementations, each with its own ad-hoc interface:

  • features/mocks/mock_ai_provider.py — AI provider mock (previously had placeholder assertions, fixed in [AUTO-INF-6])
  • features/mocks/langchain_mock_provider.py — LangChain provider mock (previously had placeholder assertions, fixed in [AUTO-INF-6])
  • features/mocks/mock_devcontainer_cli.py — DevContainer CLI mock
  • features/mocks/mock_mcp_transport.py — MCP transport mock
  • features/mocks/tdd_test_helpers.py — TDD-specific test helpers
  • features/mocks/fast_init_test_helpers.py — Fast initialization helpers
  • features/mocks/test_uow_factory.py — Unit of Work factory

Each mock is independently implemented with no shared base class, protocol, or registry. Step definitions must know the exact import path of each mock, and there is no central place to discover what mocks are available.

Expected Behavior

A unified mock provider architecture exists in features/mocks/ with:

  1. A MockProvider protocol defining the minimum interface all mocks must satisfy
  2. A MockRegistry mapping mock names to their implementations
  3. A features/mocks/README.md documenting the mock system

All existing mocks are updated to implement the MockProvider protocol and registered in the MockRegistry. Step definitions can look up mocks by name rather than by import path.

Acceptance Criteria

  • A MockProvider protocol is defined in features/mocks/__init__.py with at minimum reset() and configure(**kwargs) methods
  • A MockRegistry class exists in features/mocks/registry.py mapping mock names to their implementations
  • All existing mocks in features/mocks/ implement the MockProvider protocol (verified via isinstance checks or runtime_checkable)
  • All existing mocks are registered in MockRegistry
  • A features/mocks/README.md documents: what each mock simulates, how to add a new mock, and how to use mocks from step definitions
  • No existing tests are broken by the refactor
  • Test coverage remains >= 97%

Subtasks

  • Audit all files in features/mocks/ and document their current interfaces
  • Define MockProvider protocol in features/mocks/__init__.py
  • Create features/mocks/registry.py with MockRegistry class
  • Update mock_ai_provider.py to implement MockProvider protocol and register in MockRegistry
  • Update langchain_mock_provider.py to implement MockProvider protocol and register in MockRegistry
  • Update mock_devcontainer_cli.py to implement MockProvider protocol and register in MockRegistry
  • Update mock_mcp_transport.py to implement MockProvider protocol and register in MockRegistry
  • Update tdd_test_helpers.py, fast_init_test_helpers.py, and test_uow_factory.py as appropriate
  • Write features/mocks/README.md
  • Run full test suite and verify no regressions and coverage >= 97%

Definition of Done

This issue should be closed when:

  • The MockProvider protocol and MockRegistry are implemented and all existing mocks conform to the protocol and are registered
  • features/mocks/README.md is written and accurate
  • All existing tests pass without modification (or with only import-path updates)
  • Test coverage remains >= 97%
  • A PR has been reviewed and merged to the main branch

Summary

The features/mocks/ directory contains multiple independent mock provider implementations (mock_ai_provider.py, langchain_mock_provider.py, mock_devcontainer_cli.py, mock_mcp_transport.py, and others) without a unified interface, registry, or discovery mechanism. This makes it difficult to maintain consistency across mocks, discover available mocks, and ensure they all implement the same contract.

Proposed Improvement

  1. Define a MockProvider protocol in features/mocks/__init__.py that all mock implementations must satisfy. This protocol should define the minimum interface (e.g., reset(), configure()) that all mocks share.

  2. Create a MockRegistry in features/mocks/registry.py that maps mock names to their implementations, allowing step definitions to look up mocks by name rather than by import path.

  3. Add a features/mocks/README.md documenting:

    • What each mock simulates
    • How to add a new mock (must implement MockProvider protocol and register in MockRegistry)
    • How to use mocks from step definitions

Example protocol:

# features/mocks/__init__.py
from typing import Protocol, runtime_checkable

@runtime_checkable
class MockProvider(Protocol):
    """Base protocol for all test mock providers."""
    
    def reset(self) -> None:
        """Reset mock state between scenarios."""
        ...
    
    def configure(self, **kwargs) -> None:
        """Configure mock behavior for a specific scenario."""
        ...

Expected Impact

  • Consistency: All mocks will implement the same base interface, making them predictable and interchangeable
  • Discoverability: Developers can find all available mocks in one place (MockRegistry)
  • Maintainability: New mocks follow a documented pattern, reducing drift
  • Test isolation: The reset() protocol method ensures mocks are properly reset between scenarios, reducing test interdependencies
  • Coverage: No reduction in coverage — this is a structural improvement only

Duplicate Check

  • Searched open issues for keywords: "mock central", "mock registry", "mock factory", "mock interface", "mock provider", "centralize mock"
  • Searched closed issues for keywords: "mock central", "mock registry", "mock factory", "mock interface"
  • Searched for AUTO-INF worker issues: Found [AUTO-INF-6] Remove placeholder assertion in features/mocks/langchain_mock_provider.py and [AUTO-INF-6] Remove placeholder assertion in features/mocks/mock_ai_provider.py (closed, about removing placeholder assertions — different concern), [AUTO-INF-4] Flaky Tests: Replace real LLM API calls with a mock service in E2E tests (open, about E2E test LLM mocking — different scope), test(integration): implement mocked LLM provider fixture and shared integration test infrastructure (open, about integration test LLM fixture — different scope)
  • Searched for fixture centralization issues: Found [AUTO-INF-3] Consolidate Behave database fixtures via shared factory (open, about database fixtures — different concern), test(plan-service): centralize Behave plan service fixtures (open, about plan service fixtures — different concern), [Test Infra] Introduce a centralized fixture generation strategy (open, about Faker-based domain object factories — different concern)
  • Result: No duplicates found. Existing issues address specific mock files (placeholder assertions), specific fixture types (database, plan service, domain objects), or specific test layers (E2E LLM mocking). None address the broader mock provider interface/registry architecture.

Automated by CleverAgents Bot
Agent: new-issue-creator


Automated by CleverAgents Bot
Supervisor: Test Infrastructure Pool | Agent: test-infra-pool-supervisor
Worker: [AUTO-INF-3] Test Architecture Analysis

## Metadata - **Commit message:** `test(infra): centralize mock provider implementations in features/mocks/ with unified interface` - **Branch name:** `test/auto-inf-3-centralize-mock-providers` ## Background and Context The `features/mocks/` directory contains multiple independent mock provider implementations (`mock_ai_provider.py`, `langchain_mock_provider.py`, `mock_devcontainer_cli.py`, `mock_mcp_transport.py`, and others) without a unified interface, registry, or discovery mechanism. This makes it difficult to maintain consistency across mocks, discover available mocks, and ensure they all implement the same contract. ### Current State The `features/mocks/` directory contains at least the following independent mock implementations, each with its own ad-hoc interface: - `features/mocks/mock_ai_provider.py` — AI provider mock (previously had placeholder assertions, fixed in [AUTO-INF-6]) - `features/mocks/langchain_mock_provider.py` — LangChain provider mock (previously had placeholder assertions, fixed in [AUTO-INF-6]) - `features/mocks/mock_devcontainer_cli.py` — DevContainer CLI mock - `features/mocks/mock_mcp_transport.py` — MCP transport mock - `features/mocks/tdd_test_helpers.py` — TDD-specific test helpers - `features/mocks/fast_init_test_helpers.py` — Fast initialization helpers - `features/mocks/test_uow_factory.py` — Unit of Work factory Each mock is independently implemented with no shared base class, protocol, or registry. Step definitions must know the exact import path of each mock, and there is no central place to discover what mocks are available. ## Expected Behavior A unified mock provider architecture exists in `features/mocks/` with: 1. A `MockProvider` protocol defining the minimum interface all mocks must satisfy 2. A `MockRegistry` mapping mock names to their implementations 3. A `features/mocks/README.md` documenting the mock system All existing mocks are updated to implement the `MockProvider` protocol and registered in the `MockRegistry`. Step definitions can look up mocks by name rather than by import path. ## Acceptance Criteria - [ ] A `MockProvider` protocol is defined in `features/mocks/__init__.py` with at minimum `reset()` and `configure(**kwargs)` methods - [ ] A `MockRegistry` class exists in `features/mocks/registry.py` mapping mock names to their implementations - [ ] All existing mocks in `features/mocks/` implement the `MockProvider` protocol (verified via `isinstance` checks or `runtime_checkable`) - [ ] All existing mocks are registered in `MockRegistry` - [ ] A `features/mocks/README.md` documents: what each mock simulates, how to add a new mock, and how to use mocks from step definitions - [ ] No existing tests are broken by the refactor - [ ] Test coverage remains >= 97% ## Subtasks - [ ] Audit all files in `features/mocks/` and document their current interfaces - [ ] Define `MockProvider` protocol in `features/mocks/__init__.py` - [ ] Create `features/mocks/registry.py` with `MockRegistry` class - [ ] Update `mock_ai_provider.py` to implement `MockProvider` protocol and register in `MockRegistry` - [ ] Update `langchain_mock_provider.py` to implement `MockProvider` protocol and register in `MockRegistry` - [ ] Update `mock_devcontainer_cli.py` to implement `MockProvider` protocol and register in `MockRegistry` - [ ] Update `mock_mcp_transport.py` to implement `MockProvider` protocol and register in `MockRegistry` - [ ] Update `tdd_test_helpers.py`, `fast_init_test_helpers.py`, and `test_uow_factory.py` as appropriate - [ ] Write `features/mocks/README.md` - [ ] Run full test suite and verify no regressions and coverage >= 97% ## Definition of Done This issue should be closed when: - The `MockProvider` protocol and `MockRegistry` are implemented and all existing mocks conform to the protocol and are registered - `features/mocks/README.md` is written and accurate - All existing tests pass without modification (or with only import-path updates) - Test coverage remains >= 97% - A PR has been reviewed and merged to the main branch --- ## Summary The `features/mocks/` directory contains multiple independent mock provider implementations (`mock_ai_provider.py`, `langchain_mock_provider.py`, `mock_devcontainer_cli.py`, `mock_mcp_transport.py`, and others) without a unified interface, registry, or discovery mechanism. This makes it difficult to maintain consistency across mocks, discover available mocks, and ensure they all implement the same contract. ### Proposed Improvement 1. **Define a `MockProvider` protocol** in `features/mocks/__init__.py` that all mock implementations must satisfy. This protocol should define the minimum interface (e.g., `reset()`, `configure()`) that all mocks share. 2. **Create a `MockRegistry`** in `features/mocks/registry.py` that maps mock names to their implementations, allowing step definitions to look up mocks by name rather than by import path. 3. **Add a `features/mocks/README.md`** documenting: - What each mock simulates - How to add a new mock (must implement `MockProvider` protocol and register in `MockRegistry`) - How to use mocks from step definitions Example protocol: ```python # features/mocks/__init__.py from typing import Protocol, runtime_checkable @runtime_checkable class MockProvider(Protocol): """Base protocol for all test mock providers.""" def reset(self) -> None: """Reset mock state between scenarios.""" ... def configure(self, **kwargs) -> None: """Configure mock behavior for a specific scenario.""" ... ``` ### Expected Impact - **Consistency**: All mocks will implement the same base interface, making them predictable and interchangeable - **Discoverability**: Developers can find all available mocks in one place (`MockRegistry`) - **Maintainability**: New mocks follow a documented pattern, reducing drift - **Test isolation**: The `reset()` protocol method ensures mocks are properly reset between scenarios, reducing test interdependencies - **Coverage**: No reduction in coverage — this is a structural improvement only ### Duplicate Check - Searched open issues for keywords: "mock central", "mock registry", "mock factory", "mock interface", "mock provider", "centralize mock" - Searched closed issues for keywords: "mock central", "mock registry", "mock factory", "mock interface" - Searched for AUTO-INF worker issues: Found `[AUTO-INF-6] Remove placeholder assertion in features/mocks/langchain_mock_provider.py` and `[AUTO-INF-6] Remove placeholder assertion in features/mocks/mock_ai_provider.py` (closed, about removing placeholder assertions — different concern), `[AUTO-INF-4] Flaky Tests: Replace real LLM API calls with a mock service in E2E tests` (open, about E2E test LLM mocking — different scope), `test(integration): implement mocked LLM provider fixture and shared integration test infrastructure` (open, about integration test LLM fixture — different scope) - Searched for fixture centralization issues: Found `[AUTO-INF-3] Consolidate Behave database fixtures via shared factory` (open, about database fixtures — different concern), `test(plan-service): centralize Behave plan service fixtures` (open, about plan service fixtures — different concern), `[Test Infra] Introduce a centralized fixture generation strategy` (open, about Faker-based domain object factories — different concern) - Result: No duplicates found. Existing issues address specific mock files (placeholder assertions), specific fixture types (database, plan service, domain objects), or specific test layers (E2E LLM mocking). None address the broader mock provider interface/registry architecture. --- **Automated by CleverAgents Bot** Agent: new-issue-creator --- **Automated by CleverAgents Bot** Supervisor: Test Infrastructure Pool | Agent: test-infra-pool-supervisor Worker: [AUTO-INF-3] Test Architecture Analysis
Author
Owner

Triage Decision

Verified by: Project Owner Supervisor [AUTO-OWNR-1]
Date: 2026-04-16

Field Decision
State Verified
MoSCoW MoSCoW/Could have
Priority Priority/Medium
Milestone None

Rationale: Milestone is overdue but not on critical path.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

## Triage Decision **Verified by**: Project Owner Supervisor [AUTO-OWNR-1] **Date**: 2026-04-16 | Field | Decision | |-------|----------| | State | Verified | | MoSCoW | MoSCoW/Could have | | Priority | Priority/Medium | | Milestone | None | **Rationale**: Milestone is overdue but not on critical path. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#10036
No description provided.