Skip to content

refactor(ai): test-only model request hooks leave src #3759

Closed

Description

@dan-petty

Problem or Motivation

Child A of the tracker #1330. Product code in src holds switches that only tests use. This breaks the rule that tests double only edges and that src holds no test switch (ADR 0007).

Measured at origin/main 44d9196 (2026-11-06):

  • ALLOW_MODEL_REQUESTS is a module flag in src/devops_cli/ai/agents/agent.py:91 and in src/devops_cli/ai/agents/testing.py:16. PydanticAgent.run reads both (agent.py:875-888) and raises ModelNotAllowedError for a client that is not a TestModel or FunctionModel.
  • src/devops_cli/ai/pydantic_ai_bridge.py:145 _is_testing_mode_active() reads the same flags. resolve_pydantic_ai_model returns a pydantic-ai TestModel when it is true.
  • _RUN_MESSAGES_CAPTURE is a ContextVar in ai/agents/testing.py. agent.py:970 and :996 copy the messages of each run into it.
  • src/devops_cli/ai/agents/testing.py holds a home-made TestModel, FunctionModel, AgentInfo and capture_run_messages. Only tests use them. config/constants.py:156 lists the module as a domain exception module, and docs/ERRORS.md:83 lists ModelNotAllowedError.
  • Test files that use these names: tests/ai/agents/test_ai_agent_capabilities.py, tests/ai/mcp/test_pydantic_ai_mcp.py, tests/ai/models/test_pydantic_ai_ollama.py, tests/invariants/test_architectural_invariants.py, tests/ai/client/test_gateway_caller_headers.py, tests/ai/test_pydantic_ai_profiles_and_providers.py, tests/roadmap/test_roadmap_implement_step_output_cap.py.

Proposed Solution & Architectural Design

Delete the hooks and move the tests to the model seam that exists.

  • Delete ai/agents/testing.py, ALLOW_MODEL_REQUESTS in agent.py, the check in PydanticAgent.run, _is_testing_mode_active, and the capture buffer in agent.py.
  • Remove devops_cli.ai.agents.testing from CONST_DOMAIN_EXCEPTION_MODULES and regenerate docs/ERRORS.md.
  • Tests that used the home-made TestModel use the model_fake fixture (tests/support/fakes/model.py). Tests that monkeypatched _is_testing_mode_active to false drop that line, because it was already false. The test of the removed flag goes. The hermetic floor already fails a test that reaches a model without a fake, so no new fake and no new seam is needed.
  • No change to resolve_pydantic_ai_model("test"): test is the name that pydantic-ai gives to its own TestModel.

Out of scope: children B to F of #1330, and the hand-rolled loop that #2489 deletes.

Target Subsystem

AI & Agentic Review Pipeline

Existing Tool Considered

pydantic-ai TestModel and FunctionModel, and the project fake ModelFake (model_fake fixture), cover every use. No new code is built. The change deletes about 120 lines of own code.

Acceptance criteria

  • git grep -nE 'ALLOW_MODEL_REQUESTS|ModelNotAllowedError|MODEL_REQUESTS_DISABLED|_RUN_MESSAGES_CAPTURE|_is_testing_mode_active|agents\.testing' -- src tests docs ':!docs/agent/archive' returns no line.
  • src/devops_cli/ai/agents/testing.py does not exist.
  • The seven test files above keep their behavior coverage on model_fake.
  • uv run devops ci passes.

Related

Related: #1330 (parent tracker), #2489 (deletes the hand-rolled agent loop).

Activity

  1. added
    source/agent
    type/refactor
    scope/ai
    status/new
    value/medium
    effort/medium
    on Nov 6, 2026
  2. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/refactor. The refactor prefix of the title gives the type.
    • Scope: scope/ai. The (ai) scope of the title gives the scope.
    • Priority: P2-Medium. It removes architectural violations but blocks no user-facing feature.
    • Value: Medium. It removes about 120 lines of test-only code and restores the ADR 0007 rule for src.
    • Effort: Medium. It deletes one module, edits two files, and updates seven test files to use model_fake.
    • Related: test(mcp): mcp, agent and tool tests run on edge fakes #1330, which asks for a different change. Both target test-only code in src for ai/agents, but #1330 is the umbrella tracker and the candidate is its child A covering only model request hooks.
  3. added
    priority/p2-medium
    on Nov 6, 2026
  4. added
    status/in-review
    and removed
    status/new
    on Nov 6, 2026
  5. removed
    status/in-review
    on Nov 6, 2026
  6. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-06 08:16 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p2-mediumscope/aisource/agenttype/refactorvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions