UAT: application/container.py imports MockAIProvider from features/mocks/ test directory — production code depends on test infrastructure #4121

Open
opened 2026-04-06 10:29:16 +00:00 by freemo · 0 comments
Owner

Metadata

  • Branch: fix/providers-mock-provider-architecture
  • Commit Message: fix(providers): move MockAIProvider to providers layer, remove test-directory import from container
  • Milestone: (none — backlog)
  • Parent Epic: #3365 (Epic: Additional LLM Provider Integrations — Cohere, Groq, Together AI, and Provider Abstraction)

Backlog note: This issue was discovered during autonomous UAT testing
on the LLM Provider Integration feature area. It does not block milestone
completion and has been placed in the backlog for human review and future
milestone assignment.

Bug Report

What was tested: Application container mock provider loading against architectural rules

Expected behavior (from CONTRIBUTING.md):

"All mocking code is strictly confined to the features/mocks/ directory."

Production code should never import from the test infrastructure directory. The features/ directory is for tests only.

Actual behavior (from code analysis):

src/cleveragents/application/container.py in get_ai_provider() (lines 190-203) dynamically adds the features/ directory to sys.path and imports MockAIProvider from the test mocks directory:

if use_mock_ai:
    try:
        import sys
        from pathlib import Path

        features_path = Path(__file__).parent.parent.parent.parent / "features"
        if features_path.exists() and str(features_path) not in sys.path:
            sys.path.insert(0, str(features_path))

        from mocks.mock_ai_provider import MockAIProvider  # type: ignore

        return MockAIProvider()  # type: ignore
    except ImportError:
        return None

This is an architectural violation:

  1. Production code imports from test directory: features/mocks/ is the test mocks directory, not a production module
  2. # type: ignore violations: Two prohibited type suppression comments
  3. Dynamic sys.path manipulation: Fragile path manipulation that breaks when the package is installed
  4. Silent failure: If the import fails, None is returned silently — the caller gets no provider without any error

Code location:

  • src/cleveragents/application/container.pyget_ai_provider() function (lines 190-203)
  • features/mocks/mock_ai_provider.pyMockAIProvider class (test infrastructure)

Steps to reproduce:

  1. Install the package: pip install -e .
  2. Set CLEVERAGENTS_MOCK_PROVIDERS=true
  3. Call get_ai_provider()
  4. Observe: features/ directory may not exist in installed package → ImportErrorNone returned silently

Severity: Medium — architectural violation that makes the mock provider fragile and couples production code to test infrastructure. The # type: ignore violations also violate CONTRIBUTING.md.

Suggested Fix:
Move MockAIProvider to src/cleveragents/providers/llm/mock_provider.py (guarded by mock_providers=True check) and import it properly without # type: ignore.

Subtasks

  • Create src/cleveragents/providers/llm/mock_provider.py with MockAIProvider class
  • Remove dynamic sys.path manipulation from container.py
  • Remove # type: ignore comments from container.py
  • Update get_ai_provider() to import MockAIProvider from the providers layer
  • Add guard to prevent MockAIProvider use in production (env != 'test')
  • Add Behave scenarios for mock provider loading
  • Verify nox -e typecheck passes
  • Run nox (all default sessions)

Definition of Done

  • MockAIProvider lives in src/cleveragents/providers/llm/mock_provider.py
  • container.py imports MockAIProvider without # type: ignore or sys.path manipulation
  • Mock provider is guarded against production use
  • All existing mock provider tests continue to pass
  • New Behave scenarios cover mock provider loading
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: UAT Testing | Agent: ca-new-issue-creator

## Metadata - **Branch**: `fix/providers-mock-provider-architecture` - **Commit Message**: `fix(providers): move MockAIProvider to providers layer, remove test-directory import from container` - **Milestone**: *(none — backlog)* - **Parent Epic**: #3365 (Epic: Additional LLM Provider Integrations — Cohere, Groq, Together AI, and Provider Abstraction) > **Backlog note:** This issue was discovered during autonomous UAT testing > on the LLM Provider Integration feature area. It does not block milestone > completion and has been placed in the backlog for human review and future > milestone assignment. ## Bug Report **What was tested:** Application container mock provider loading against architectural rules **Expected behavior (from CONTRIBUTING.md):** > "All mocking code is strictly confined to the `features/mocks/` directory." Production code should never import from the test infrastructure directory. The `features/` directory is for tests only. **Actual behavior (from code analysis):** `src/cleveragents/application/container.py` in `get_ai_provider()` (lines 190-203) dynamically adds the `features/` directory to `sys.path` and imports `MockAIProvider` from the test mocks directory: ```python if use_mock_ai: try: import sys from pathlib import Path features_path = Path(__file__).parent.parent.parent.parent / "features" if features_path.exists() and str(features_path) not in sys.path: sys.path.insert(0, str(features_path)) from mocks.mock_ai_provider import MockAIProvider # type: ignore return MockAIProvider() # type: ignore except ImportError: return None ``` This is an architectural violation: 1. **Production code imports from test directory**: `features/mocks/` is the test mocks directory, not a production module 2. **`# type: ignore` violations**: Two prohibited type suppression comments 3. **Dynamic `sys.path` manipulation**: Fragile path manipulation that breaks when the package is installed 4. **Silent failure**: If the import fails, `None` is returned silently — the caller gets no provider without any error **Code location:** - `src/cleveragents/application/container.py` — `get_ai_provider()` function (lines 190-203) - `features/mocks/mock_ai_provider.py` — `MockAIProvider` class (test infrastructure) **Steps to reproduce:** 1. Install the package: `pip install -e .` 2. Set `CLEVERAGENTS_MOCK_PROVIDERS=true` 3. Call `get_ai_provider()` 4. Observe: `features/` directory may not exist in installed package → `ImportError` → `None` returned silently **Severity:** Medium — architectural violation that makes the mock provider fragile and couples production code to test infrastructure. The `# type: ignore` violations also violate CONTRIBUTING.md. **Suggested Fix:** Move `MockAIProvider` to `src/cleveragents/providers/llm/mock_provider.py` (guarded by `mock_providers=True` check) and import it properly without `# type: ignore`. ## Subtasks - [ ] Create `src/cleveragents/providers/llm/mock_provider.py` with `MockAIProvider` class - [ ] Remove dynamic `sys.path` manipulation from `container.py` - [ ] Remove `# type: ignore` comments from `container.py` - [ ] Update `get_ai_provider()` to import `MockAIProvider` from the providers layer - [ ] Add guard to prevent `MockAIProvider` use in production (`env != 'test'`) - [ ] Add Behave scenarios for mock provider loading - [ ] Verify `nox -e typecheck` passes - [ ] Run `nox` (all default sessions) ## Definition of Done - [ ] `MockAIProvider` lives in `src/cleveragents/providers/llm/mock_provider.py` - [ ] `container.py` imports `MockAIProvider` without `# type: ignore` or `sys.path` manipulation - [ ] Mock provider is guarded against production use - [ ] All existing mock provider tests continue to pass - [ ] New Behave scenarios cover mock provider loading - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: UAT Testing | Agent: ca-new-issue-creator
freemo added this to the v3.2.0 milestone 2026-04-06 18:06:55 +00:00
freemo removed this from the v3.2.0 milestone 2026-04-06 20:42:50 +00:00
HAL9000 added this to the v3.5.0 milestone 2026-04-09 03:10:50 +00:00
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.

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