UAT: Production code in application/container.py imports mock implementation from features/mocks/ — violates no-mock-in-production rule #1693

Open
opened 2026-04-02 23:30:40 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: fix/remove-mock-import-from-production
  • Commit Message: fix(container): remove mock AI provider import from production get_ai_provider()
  • Milestone: v3.5.0
  • Parent Epic: #397

Background and Context

The production file src/cleveragents/application/container.py contains a runtime import of MockAIProvider from the test-only features/mocks/ directory. The project specification and CONTRIBUTING.md explicitly state that "Production code must never contain mock implementations or conditional testing behavior" and that "All mocks, test doubles, and mock implementations must be located exclusively in the features/mocks/ directory."

Current Behavior

src/cleveragents/application/container.py lines 184–200 contain:

use_mock_ai = resolved_settings.mock_providers or (
    os.environ.get("CLEVERAGENTS_TESTING_USE_MOCK_AI", "").lower()
    in ("true", "1", "yes")
)

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 code:

  1. Checks for a testing-specific environment variable (CLEVERAGENTS_TESTING_USE_MOCK_AI)
  2. Dynamically adds the features/ test directory to sys.path
  3. Imports MockAIProvider from features/mocks/ — a test-only directory
  4. Returns the mock in production code

This is a direct violation of the rule that production code must never contain mock implementations or conditional testing behavior.

Additional violation: The Settings model has a mock_providers field that is checked in production code, which is also a form of conditional testing behavior embedded in production configuration.

Steps to reproduce:

grep -n "mock\|Mock\|TESTING" src/cleveragents/application/container.py
# Lines 172, 184-200 show the mock import

Code location: src/cleveragents/application/container.py — the get_ai_provider() function

Expected Behavior

Per CONTRIBUTING.md and the project specification:

"Production code must never contain mock implementations or conditional testing behavior."
"All mocks, test doubles, and mock implementations must be located exclusively in the features/mocks/ directory."

The get_ai_provider() function in container.py should only build real AI providers. Mock injection for testing should happen at the test level (e.g., via dependency injection in Behave steps), not inside production code.

Acceptance Criteria

  • src/cleveragents/application/container.py contains no imports from features/mocks/ or any test directory
  • get_ai_provider() contains no conditional logic gated on testing environment variables or mock_providers settings
  • The Settings model no longer contains a mock_providers field (or any field whose sole purpose is enabling mock behavior in production)
  • BDD tests that previously relied on the mock injection via CLEVERAGENTS_TESTING_USE_MOCK_AI or mock_providers are updated to inject MockAIProvider directly via dependency injection in Behave step definitions
  • All existing BDD scenarios continue to pass after the change
  • No type: ignore comments remain in container.py related to mock imports

Supporting Information

  • CONTRIBUTING.md: "Test Isolation and Mock Placement" section — strict separation of test support code from production code
  • CONTRIBUTING.md: "No Conditional Test Behavior" — production code must not contain if testing: guards or test-only code paths
  • CONTRIBUTING.md: "Dependency Injection" — use DI to swap implementations during tests, not production-code conditionals

Subtasks

  • Remove the use_mock_ai conditional block (lines 184–200) from get_ai_provider() in src/cleveragents/application/container.py
  • Remove the mock_providers field from the Settings model (if its sole purpose is enabling mock injection)
  • Remove the CLEVERAGENTS_TESTING_USE_MOCK_AI environment variable check from production code
  • Update Behave step definitions that relied on CLEVERAGENTS_TESTING_USE_MOCK_AI or mock_providers to inject MockAIProvider directly via dependency injection
  • Verify no remaining type: ignore comments in container.py related to mock imports
  • Run nox (all default sessions) and fix any errors
  • Verify coverage >= 97% via nox -s coverage_report

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly (fix(container): remove mock AI provider import from production get_ai_provider()), followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly (fix/remove-mock-import-from-production).
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.
  • All nox stages pass.
  • Coverage >= 97%.

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

## Metadata - **Branch**: `fix/remove-mock-import-from-production` - **Commit Message**: `fix(container): remove mock AI provider import from production get_ai_provider()` - **Milestone**: v3.5.0 - **Parent Epic**: #397 ## Background and Context The production file `src/cleveragents/application/container.py` contains a runtime import of `MockAIProvider` from the test-only `features/mocks/` directory. The project specification and CONTRIBUTING.md explicitly state that "Production code must never contain mock implementations or conditional testing behavior" and that "All mocks, test doubles, and mock implementations must be located exclusively in the `features/mocks/` directory." ## Current Behavior `src/cleveragents/application/container.py` lines 184–200 contain: ```python use_mock_ai = resolved_settings.mock_providers or ( os.environ.get("CLEVERAGENTS_TESTING_USE_MOCK_AI", "").lower() in ("true", "1", "yes") ) 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 code: 1. Checks for a testing-specific environment variable (`CLEVERAGENTS_TESTING_USE_MOCK_AI`) 2. Dynamically adds the `features/` test directory to `sys.path` 3. Imports `MockAIProvider` from `features/mocks/` — a test-only directory 4. Returns the mock in production code This is a direct violation of the rule that production code must never contain mock implementations or conditional testing behavior. **Additional violation:** The `Settings` model has a `mock_providers` field that is checked in production code, which is also a form of conditional testing behavior embedded in production configuration. **Steps to reproduce:** ```bash grep -n "mock\|Mock\|TESTING" src/cleveragents/application/container.py # Lines 172, 184-200 show the mock import ``` **Code location:** `src/cleveragents/application/container.py` — the `get_ai_provider()` function ## Expected Behavior Per CONTRIBUTING.md and the project specification: > "Production code must never contain mock implementations or conditional testing behavior." > "All mocks, test doubles, and mock implementations must be located exclusively in the `features/mocks/` directory." The `get_ai_provider()` function in `container.py` should only build real AI providers. Mock injection for testing should happen at the test level (e.g., via dependency injection in Behave steps), not inside production code. ## Acceptance Criteria - `src/cleveragents/application/container.py` contains no imports from `features/mocks/` or any test directory - `get_ai_provider()` contains no conditional logic gated on testing environment variables or `mock_providers` settings - The `Settings` model no longer contains a `mock_providers` field (or any field whose sole purpose is enabling mock behavior in production) - BDD tests that previously relied on the mock injection via `CLEVERAGENTS_TESTING_USE_MOCK_AI` or `mock_providers` are updated to inject `MockAIProvider` directly via dependency injection in Behave step definitions - All existing BDD scenarios continue to pass after the change - No `type: ignore` comments remain in `container.py` related to mock imports ## Supporting Information - CONTRIBUTING.md: "Test Isolation and Mock Placement" section — strict separation of test support code from production code - CONTRIBUTING.md: "No Conditional Test Behavior" — production code must not contain `if testing:` guards or test-only code paths - CONTRIBUTING.md: "Dependency Injection" — use DI to swap implementations during tests, not production-code conditionals ## Subtasks - [ ] Remove the `use_mock_ai` conditional block (lines 184–200) from `get_ai_provider()` in `src/cleveragents/application/container.py` - [ ] Remove the `mock_providers` field from the `Settings` model (if its sole purpose is enabling mock injection) - [ ] Remove the `CLEVERAGENTS_TESTING_USE_MOCK_AI` environment variable check from production code - [ ] Update Behave step definitions that relied on `CLEVERAGENTS_TESTING_USE_MOCK_AI` or `mock_providers` to inject `MockAIProvider` directly via dependency injection - [ ] Verify no remaining `type: ignore` comments in `container.py` related to mock imports - [ ] Run `nox` (all default sessions) and fix any errors - [ ] Verify coverage >= 97% via `nox -s coverage_report` ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly (`fix(container): remove mock AI provider import from production get_ai_provider()`), followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly (`fix/remove-mock-import-from-production`). - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. - All nox stages pass. - 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-02 23:31:21 +00:00
freemo modified the milestone from v3.2.0 to v3.5.0 2026-04-02 23:31:56 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Priority/High (confirmed) — production code importing mocks violates CONTRIBUTING.md
  • MoSCoW: MoSCoW/Must Have — CONTRIBUTING.md explicitly states: "Production code must not contain any test-only logic or implementations." A mock import in application/container.py is a direct violation. Must Have.

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

Issue triaged by project owner: - **State**: Verified - **Priority**: Priority/High (confirmed) — production code importing mocks violates CONTRIBUTING.md - **MoSCoW**: MoSCoW/Must Have — CONTRIBUTING.md explicitly states: "Production code must not contain any test-only logic or implementations." A mock import in `application/container.py` is a direct violation. Must Have. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
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.

Blocks
#397 Epic: Server & Autonomy Infrastructure
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#1693
No description provided.