Skip to content

test(mcp): mcp, agent and tool tests run on edge fakes #1330

Closed
7 of 7 issues completed
Closed

Description

@dan-petty

Problem or Motivation

Phase E migration of the tests of ai/mcp/, ai/agents/, ai/harness/, ai/tools/ and ai/toolsets/. The goal: these tests double only edges, and src holds no test switch.

This text replaces the body of 2026-10-07. That body was written at v0.2.28 and is mostly stale. Refine ruled twice that one pull request cannot carry the work. This item is now a tracker. Six child items carry the work. Each child is one reviewable pull request.

Measured at origin/main 29309f0 (2026-11-06). The files named below are identical at 4a2d958, where the first count was made.

Already delivered. No work remains.

  • The mock check in ai/mcp/server.py is gone.
  • PlaywrightBrowser is gone. ai/harness/ holds only skills.py and slots.py. It has no process spawn and no process-group signal.
  • No LLMClient( construction remains in ai/agents/, ai/harness/, ai/mcp/ or ai/tools/.
  • These test files do not exist: test_harness.py, test_synthesis_protocol.py, test_runtime_security_and_ssrf_hardening.py, and the five test_ai_agent_* files for guardrails, media, prompt, spend and step persistence.
  • The scanner tools in tests/security/test_builtin_tools.py already run on scanner_fake. tests/ai/review/test_review_security_tools.py has no patch and no private import.

Dropped as stale.

Handed to other open items. Two parts of the old text have an owner now.

Still open, one child each.

Child Work Size at 29309f0
A ALLOW_MODEL_REQUESTS, ModelNotAllowedError, _RUN_MESSAGES_CAPTURE and ai/agents/testing.py in src 4 source files, 1 doc, 11 test files
B The MCP tool tests patch _run_mcp_cmd by name 20 times and run_subprocess 4 times 3 files, 2,837 lines, 35 string patches, 7 more patch targets, 12 private imports
C test_builtin_tools.py: 23 patches on processes, RAG, keys, the clock and the OSV, Shodan and Radar clients 1 file, 938 lines
D Outbound MCP code that no command, setting or tool reaches 5 source files, 2 KB pages, 1 doc, 2 test files
E test_harness_slots.py: 1 internal patch, 2 private imports, and one misplaced client test 2 files
F File names and file size of the MCP tests, the toolset and tool tests, and the tool-listing snapshot 5 files and 1 new snapshot

Proposed Solution & Architectural Design

Close this item when all six children are closed. Open the children in this order.

Child Blocked by Why
A none First. It removes switches and the tests that use them.
B none Adds one seam, install_mcp_dispatcher, and deletes the dead process branch of the MCP server.
C none The process, Qdrant, embedder, HTTP and clock fakes exist at 29309f0. C wires rag_search to the RAG seam and adds one method to the embedder fake.
D none Deletion after a caller search. It edits two tests that A also edits. The second to land rebases.
E none A small change in the harness tests.
F B F moves and renames the files that B edits. F goes last to avoid conflicts.

Issue numbers of the children are added to this table after the children exist.

Decisions made in this plan.

  1. Outbound MCP is deleted (child D). The caller search found no command, setting, tool or entry point that reaches it. The class MCPToolset in ai/agents/tools.py does not even connect. Its close does nothing and its get_tools returns the list it was given. A seam for code with no caller would be zombie code. Open feat(roadmap): let a job call the tools of the MCP server #3221 plans a job-side MCP client. It uses pydantic-ai's own MCPToolset, not the deleted wrapper, so the deletion does not block it.
  2. The MCP seam is the dispatcher, not the process runner (child B). The 2026-10-07 text said that uv run devops calls go through the process fake. That is false at 29309f0. InProcessDispatcher._dispatch_typer runs the Typer app in the same process, so fake.requests never sees these calls. Every call site in ai/mcp/server.py and the one in generator.py passes a uv run devops argv. So the subprocess branches run only in tests. Child B deletes them and adds a hook to install a dispatcher fake.
  3. The dispatcher seam is a deliberate step beyond "edges only". docs/TESTING.md lists "uv run devops calling itself" as a faked process edge. That is wrong for the MCP layer, because nothing starts a process. The dispatcher is the one place where an MCP tool hands a devops argv to the CLI app. A test can assert the argv of a tool only there. Child B corrects docs/TESTING.md and adds a contract suite that holds the fake to the real dispatcher.
  4. The OSV, Shodan and Radar tests need no wait on refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 (child C). security/vulnerability_lookup.py already builds its clients through new_http_client, and the stub_web fixture answers them. refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 lists this item as blocked by it. That block is not needed. A person may drop the line from refactor(cli): Unify HTTP and DNS seams with shared fakes #1314.
  5. The ratchet criteria fold into nothing. Each child removes the sites in its own files. test(cli): Convert ratchets to bans and merge invariant tests #1336 bans the forms for the whole suite.
  6. Files outside the list are not touched. 16 sites in 10 test files outside tests/ai/mcp/ patch ai.mcp.server._run_mcp_cmd. They are in the argo, roadmap, commands, docs, telemetry, tf and ai tests. Four more sites are in 3 files of tests/ai/mcp/ that this item does not name: test_path_confinement.py, test_mcp_tool_secrets.py and test_ai_gateway.py. Each belongs to the item that owns its package. The dispatcher fake of child B is the replacement. test(cli): Convert ratchets to bans and merge invariant tests #1336 finds what remains.

Exit check for this item. All commands run at the commit that closes the last child.

  • 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.
  • git grep -nE 'devops_cli\.ai\.agents\.tools import .*MCPToolset|ai\.mcp\.toolset|create_mcp_toolset|create_devops_mcp_toolset|load_devops_mcp_toolsets|get_devops_mcp_toolset|set_mcp_sampling_model' -- src tests docs ':!docs/agent/archive' returns no line. Pydantic-ai's own MCPToolset stays in the knowledge base.
  • git grep -nE 'run_subprocess|import subprocess' -- src/devops_cli/ai/mcp returns no line.
  • The files that the children name hold no patch of a devops_cli name: patch("devops_cli., monkeypatch.setattr("devops_cli. and patch.object on a devops_cli object all return no line. They also import no _-name from devops_cli. Each child states the final file names. The files handed to refactor(ai): Replace PydanticAgent with pydantic-ai Agent #2489 are not in this check.
  • ls tests/ai/mcp/test_fastmcp_*.py tests/ai/mcp/test_mcp.py tests/ai/agents/test_pydantic_ai_toolsets.py tests/ai/tools/test_pydantic_ai_tools.py lists no file, and no test name in tests/ai/mcp/ ends in _and_error_branches.
  • uv run devops ci passes.

This tracker blocks #1336.

Target Subsystem

src/devops_cli/ai/mcp/, ai/agents/, ai/harness/, ai/tools/, ai/toolsets/, ai/pydantic_ai_bridge.py, commands/mcp.py, and their test directories under tests/ai/ and tests/security/test_builtin_tools.py.

Existing Tool Considered

The alternatives check of 2026-10-31 recorded not-applicable. The children reuse open tools. These are pytest, syrupy for the tool listing, pydantic-ai TestModel and FunctionModel, and FastMCP Client(server) over its in-memory transport. They also reuse the project fakes in tests/support/fakes/: model_fake, process_fake, scanner_fake, qdrant, embedder, keyring_store and clock, and the stub_web fixture. The only new own code is the dispatcher fake and its hook in child B. Its cost is written in child B. Nothing else is built in this item.

Alternatives check of 2026-10-31: not-applicable.
Tool: none found.

Proposed design

Problem statement

The tests of ai/mcp/, ai/agents/, ai/harness/, ai/tools/ and ai/toolsets/ patch devops-cli names and import private ones, and src holds test switches. This item is the tracker of that migration and delivers no code. Six child items carry the work, and each child is one reviewable pull request. A person closes this item when all six children are closed.

Acceptance criteria

Requirement: No model-request switch in the tree

The tree SHALL hold no ALLOW_MODEL_REQUESTS, ModelNotAllowedError, MODEL_REQUESTS_DISABLED, _RUN_MESSAGES_CAPTURE, _is_testing_mode_active or agents.testing name outside docs/agent/archive.

Scenario: The exit check finds no switch

  • WHEN The last child merges into the default branch
  • THEN 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' exits 1 and prints no line.

Requirement: No outbound MCP wrapper in the tree

The tree SHALL hold no MCPToolset wrapper, create_mcp_toolset, create_devops_mcp_toolset, load_devops_mcp_toolsets, get_devops_mcp_toolset or set_mcp_sampling_model name.

Scenario: The exit check finds no wrapper

  • WHEN The last child merges into the default branch
  • THEN git grep -nE 'devops_cli\.ai\.agents\.tools import .*MCPToolset|ai\.mcp\.toolset|create_mcp_toolset|create_devops_mcp_toolset|load_devops_mcp_toolsets|get_devops_mcp_toolset|set_mcp_sampling_model' -- src tests docs ':!docs/agent/archive' exits 1 and prints no line.

Requirement: The MCP server starts no process

src/devops_cli/ai/mcp/ SHALL hold no run_subprocess name and no import subprocess.

Scenario: The MCP package holds no process call

  • WHEN The last child merges into the default branch
  • THEN git grep -nE 'run_subprocess|import subprocess' -- src/devops_cli/ai/mcp exits 1 and prints no line.

Requirement: The named test files patch no devops-cli name

Each test file that a child names SHALL hold no patch of a devops_cli name and SHALL import no private devops_cli name.

Scenario: A named test file holds no devops-cli patch

  • WHEN The exit grep runs over the test files that the children name
  • THEN git grep -nE 'patch\("devops_cli\.|monkeypatch\.setattr\("devops_cli\.' exits 1 on those files, and no from devops_cli import line names a name that starts with _.

Requirement: The old MCP test file names are gone

The MCP, toolset and tool test files SHALL carry behaviour names, and no test name in tests/ai/mcp/ SHALL end in _and_error_branches.

Scenario: The old file names are gone

  • WHEN A person lists the six old paths at the default branch
  • THEN ls tests/ai/mcp/test_fastmcp_*.py tests/ai/mcp/test_mcp.py tests/ai/agents/test_pydantic_ai_toolsets.py tests/ai/tools/test_pydantic_ai_tools.py lists no file, and git grep -n 'def test_.*_and_error_branches' -- tests/ai/mcp exits 1.

Requirement: The gate passes at the last child

The default branch MUST pass uv run devops ci at the commit that closes the last child.

Scenario: The gate is green

  • WHEN The last child merges into the default branch
  • THEN uv run devops ci exits 0.

Existing Tool Considered

The alternatives check of 2026-10-31 recorded not-applicable for this test item, and named no tool. The work reuses open, maintained tools. These are pytest, syrupy for the tool-listing snapshot, pydantic-ai TestModel and FunctionModel, and FastMCP Client(server) over its in-memory transport. The project fakes in tests/support/fakes/ cover the process, scanner, Qdrant, embedder, keyring and clock edges. None of these covers the MCP layer's own seam. pytest can patch a name, and a patch of devops_cli is what this item removes. So child B adds a dispatcher fake and its install_mcp_dispatcher hook. Cost of that own code: about 400 lines of test support code and one contract suite. Build cost: about 80,000 tokens. Keep and fix cost until the last child merges: about 30,000 tokens. Elapsed time: about 2 person-days.

Key questions

  • Does one pull request carry the work of this item?: No. This item is a tracker and delivers no code. Six child items carry the work, and each child is one reviewable pull request. F lands last, after B. (proposed)
    • Rejected: One pull request. Refine ruled twice that one pull request cannot carry the work of five packages.
    • Chosen: Six child items, one pull request each. Each child is one reviewable pull request with its own exit check.
  • Which source names hold the model-request switch that child A removes?: ALLOW_MODEL_REQUESTS is at src/devops_cli/ai/agents/agent.py:91, and its check is at line 877 of the same file. docs/ERRORS.md:83 names ModelNotAllowedError with the code MODEL_REQUESTS_DISABLED, and ai/agents/testing.py holds the test module. [sources: src/devops_cli/ai/agents/agent.py:91, src/devops_cli/ai/agents/agent.py:877, src/devops_cli/ai/agents/testing.py, docs/ERRORS.md:83]
  • Which seam replaces the _run_mcp_cmd and run_subprocess patches of the MCP tool tests?: The in-process dispatcher. Every call site passes a uv run devops argv, and InProcessDispatcher._dispatch_typer runs the Typer app in the same process. So no process starts, and a process fake sees nothing. Child B adds install_mcp_dispatcher and deletes the subprocess branch. (best practice) [sources: src/devops_cli/ai/mcp/server.py, tests/ai/mcp/test_mcp.py, docs/TESTING.md]
    • Chosen: Dispatcher fake and install hook. It is the one place where an MCP tool hands a devops argv to the CLI app, so a test can assert the argv there.
    • Rejected: Process fake through run_subprocess. No process starts, so the subprocess branch runs only in tests.
    • Rejected: Keep the patches of _run_mcp_cmd. It patches a devops-cli name and imports a private one, which the testing conventions forbid.
  • Does the dispatcher seam go beyond the edge-only rule?: Yes, on purpose. docs/TESTING.md lists uv run devops calling itself as a faked process edge, and that is wrong for the MCP layer because nothing starts a process. Child B corrects docs/TESTING.md and adds a contract suite that holds the fake to the real dispatcher. (best practice) [sources: docs/TESTING.md]
    • Chosen: Add the dispatcher seam and correct docs/TESTING.md. The document names a process edge that the MCP layer does not have.
    • Rejected: Keep the process fake as the only seam. The process fake never sees a call that runs in the same process.
  • What happens to the outbound MCP wrapper MCPToolset and its factories?: Child D deletes them. No command, setting, tool or entry point reaches them. The wrapper does not connect, its close does nothing and its get_tools returns the list it was given. Open feat(roadmap): let a job call the tools of the MCP server #3221 uses pydantic-ai's own MCPToolset, so the deletion blocks it in no way. (best practice) [sources: src/devops_cli/ai/agents/tools.py:120, src/devops_cli/ai/agents/tools.py:211, docs/MCP_TOOLS.md]
    • Chosen: Delete the wrapper and its factories. A seam for code with no caller is zombie code.
    • Rejected: Add a seam and keep the wrapper. No caller reaches it, so the seam would have no test.
    • Rejected: Wire it to a real client. feat(roadmap): let a job call the tools of the MCP server #3221 builds its client on pydantic-ai's own MCPToolset instead.
  • Does the OSV, Shodan and Radar test wait on refactor(cli): Unify HTTP and DNS seams with shared fakes #1314?: No. security/vulnerability_lookup.py already builds its clients through new_http_client, and the stub_web fixture answers them. Child C needs no wait, and a person may drop the line from refactor(cli): Unify HTTP and DNS seams with shared fakes #1314. [sources: tests/security/test_builtin_tools.py, src/devops_cli/security/vulnerability_lookup.py]
  • What replaces the ratchet and ceiling criteria of the old body?: Nothing in this item. Each child removes the sites in its own files, and test(cli): Convert ratchets to bans and merge invariant tests #1336 turns the counts into bans at zero. The project keeps no ceiling table and no baseline. (best practice) [sources: docs/TESTING.md]
  • Does this item keep a separate coverage criterion?: No. Each child runs uv run devops ci, which holds the floor of 85% of src/ and the 90% changed-line step. (best practice) [sources: docs/TESTING.md]
    • Chosen: Let the gate hold coverage. The gate already fails a child below the floor and the changed-line step.
    • Rejected: Add a coverage criterion to each child. It repeats what the gate checks.
  • Does this item replace every patch of _run_mcp_cmd in the suite?: No. 16 sites in 10 test files outside tests/ai/mcp/, and 4 sites in 3 unnamed files of tests/ai/mcp/, stay with the item that owns their package. The dispatcher fake of child B is their replacement, and test(cli): Convert ratchets to bans and merge invariant tests #1336 finds what remains. (best practice) [sources: tests/ai/mcp/test_mcp.py, docs/TESTING.md]
    • Chosen: Each package's item replaces its own sites. A test of another package belongs to the item that owns that package.
    • Rejected: This item replaces every site. It would edit 10 test files of other packages in one pull request.
  • Does this item rename or split the tests of PydanticAgent, MultiAgentPipeline and AgentMemory?: No. refactor(ai): Replace PydanticAgent with pydantic-ai Agent #2489 deletes that code and moves the surviving tests to edge fakes in its own pull request. test(ai): Wire rag once in ai/rag, test with edge fakes #1329 criterion 4 wires the RAG investigator, and this item does not touch it. [sources: tests/ai/rag/test_pipeline_context_budget.py, src/devops_cli/ai/agents/agent.py:237]

Fit

Needs splitting into 6 items:

  1. A: remove ALLOW_MODEL_REQUESTS, ModelNotAllowedError, _RUN_MESSAGES_CAPTURE and ai/agents/testing.py from src, with the 11 test files that use them (4 source files, 1 doc).
  2. B: add install_mcp_dispatcher, delete the dead subprocess branch of the MCP server, and move the MCP tool tests off _run_mcp_cmd and run_subprocess (3 files).
  3. C: move tests/security/test_builtin_tools.py off its 23 patches on processes, RAG, keys, the clock and the OSV, Shodan and Radar clients (1 file).
  4. D: delete the outbound MCP code that no command, setting or tool reaches (5 source files, 2 KB pages, 1 doc, 2 test files).
  5. E: remove the internal patch and the private imports of the harness slot tests, and move the misplaced client test (2 files).
  6. F: rename and split the MCP, toolset and tool test files and add the tool-listing snapshot (5 files, 1 snapshot). It lands last, after B.

Suspected block

None.

Dependencies

None.

Sub-issues

Sub-issues

7 of 7 Issues completed
Loading 7 sub-issues

Activity

  1. added
    type/test
    scope/ai
    scope/mcp
    priority/p2-medium
    on Oct 7, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P2-Medium. It is a large but non-urgent Phase E migration that improves test robustness and removes production test switches, with no security or blocking defect driving it.
    • Value: High. Removing 110 internal patch sites, duplicate test-mode flags, and mock-branching from production code makes the test suite and the shipped code significantly more maintainable and trustworthy.
    • Effort: High. 26 test files (12,025 lines, 389 tests) must be rewritten against edge fakes, and production code in ai/mcp, ai/agents, ai/harness, ai/tools, and ai/toolsets must be refactored to drop test switches and inline constructions.
  3. 12 remaining items

  4. devops-cli-service commented on Nov 5, 2026

    @devops-cli-service
    Contributor

    The proposal at f6d57ec needs splitting into 5 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.

    1. A: remove ALLOW_MODEL_REQUESTS, ModelNotAllowedError, _RUN_MESSAGES_CAPTURE and ai/agents/testing.py from src, move the test users to pydantic-ai's TestModel/FunctionModel or the refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 fake, and add the no-model-fake test.
    2. B: replace the _run_mcp_cmd patches in tests/ai/mcp/ with the real dispatcher and the refactor(cli): one process runner owns execution, process groups and dry-run #775 process fake, split test_fastmcp_contracts.py and test_mcp.py by behaviour, and add the one tool-listing syrupy snapshot.
    3. C: move test_builtin_tools.py and test_review_security_tools.py onto the refactor(cli): Unify HTTP and DNS seams with shared fakes #1314, refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317 and refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318 seams and the feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772 executor fake; start it after refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 closes.
    4. D: build the outbound MCP Protocol, supplier, fake and contract suite, or delete the code after the caller search.
    5. E: rename test_pydantic_ai_{exceptions,native_capabilities,tools,toolsets} and test_agent_invariants.py by behaviour, split test_pydantic_agent.py, dissolve its web-search catch-all, move the chat-turn cases to the public CLI or agent entry, and remove the redundant asyncio markers.
  5. changed the title [-]test(mcp): mcp, agent, harness and tool tests run on edge fakes, and the mcp server and agents stop branching on mocks and test-mode flags[/-] [+]test(mcp): mcp, agent and tool tests run on edge fakes[/+] on Nov 6, 2026
  6. devops-cli-service commented on Nov 6, 2026

    @devops-cli-service
    Contributor

    The proposal at dc9815e needs splitting into 6 items. A person splits the item into the items below, or replies in a comment or edits the body to keep one item, and the next refine round looks at the item again.

    1. A: remove ALLOW_MODEL_REQUESTS, ModelNotAllowedError, _RUN_MESSAGES_CAPTURE and ai/agents/testing.py from src, with the 11 test files that use them (4 source files, 1 doc).
    2. B: add install_mcp_dispatcher, delete the dead subprocess branch of the MCP server, and move the MCP tool tests off _run_mcp_cmd and run_subprocess (3 files).
    3. C: move tests/security/test_builtin_tools.py off its 23 patches on processes, RAG, keys, the clock and the OSV, Shodan and Radar clients (1 file).
    4. D: delete the outbound MCP code that no command, setting or tool reaches (5 source files, 2 KB pages, 1 doc, 2 test files).
    5. E: remove the internal patch and the private imports of the harness slot tests, and move the misplaced client test (2 files).
    6. F: rename and split the MCP, toolset and tool test files and add the tool-listing snapshot (5 files, 1 snapshot). It lands last, after B.
  7. removed
    status/new
    on Nov 10, 2026
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/highpriority/p1-highscope/aiscope/mcptype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions