Description
Problem or Motivation
Part of #1330. tests/security/test_builtin_tools.py (938 lines, 31 tests) tests the builtin agent tools. It patches internals for the tools that start a process, for rag_search, and for the OSV, Shodan and Radar clients. The tool rag_search also builds its own Qdrant client and embedder, so no fake can reach it.
Measured at origin/main 29309f0. The file has 23 patch calls:
- 6 aim at process code:
builtin_tools.run_subprocess(5) andbuiltin_tools._run_tool_cmd(1). - 8 aim at
rag_search:QdrantClient.is_alive(2),SemanticRetriever.retrieve_context(2),_is_safe_workspace_path(1),config.settings.load_settings,get_ai_api_keyandget_qdrant_api_key(1 each). - 2 aim at the stdlib:
time.sleep. - 7 aim at the OSV, Shodan and Radar clients:
OSVClient.query_package(2),ShodanInternetDBClient.check_ip(2),httpx2.Client.get(2) andhttpx2.Client.post(1). - The file imports two private names:
_is_safe_workspace_pathand_run_tool_cmd.
Already done in this file: the scanner tools run on scanner_fake, with recorded tool output. The file tests/ai/review/test_review_security_tools.py has no patch and no private import. No work remains there.
The OSV, Shodan and Radar clients are reachable by the HTTP fake. security/vulnerability_lookup.py builds all three clients through _public_api_client(). That function calls new_http_client (lines 29, 212-218, 234, 406, 554). The stub_web fixture (tests/support/web.py) answers every httpx2 client from canned pages. I ran two scratch tests on it. scan_osv("requests", "2.0.0") sent POST https://api.osv.dev/v1/query to the fake and gave the clean reply. With stub_web.fail(url, httpx2.ConnectError(...)) it gave "OSV lookup failed: connection refused". A Shodan answer needs the shape of InternetDBHost (ip, ports and vulns). A body without ip gave "the HTTP 200 reply is not from InternetDB". So this child needs no wait on #1314. #1314 plans a web fixture that replaces stub_web for some files. If it has landed when this child starts, use web.
Why the fakes do not reach rag_search today. The Qdrant override (install_qdrant_client) is read only by resolve_qdrant_client (ai/rag/indexer.py:440). The embedder override is read only by create_embedder (ai/rag/embeddings.py:429). rag_search calls QdrantClient(...) and EmbeddingsEngine(...) directly (ai/tools/builtin_tools.py:399, :410).
Proposed Solution & Architectural Design
- In
rag_search, get the Qdrant client fromresolve_qdrant_client(base_url=..., api_key=..., allow_private_network=...)and the embedder fromcreate_embedder(ai_config=..., api_key=...). Both functions exist.SemanticRetrieverholds only logic and needs no seam. test(ai): Wire rag once in ai/rag, test with edge fakes #1329 criterion 4 asks the same for the RAG investigator and may add one shared wiring function. Whichever pull request lands first does the work forrag_search. The other one reuses it. - Run the process tools on
process_fake. Compareprocess_fake.callswith the expected argv lists. - Run the RAG tests on the
qdrantandembedderfixtures, withkeyring_storefor the API key and theconfigfixture for the settings. A test that needs a dead Qdrant setsrefusingon theqdrantfake. The retry waits then do not occur, and bothtime.sleeppatches are deleted. If a test keepsrefusing_port, it uses theclockfixture of refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320. - Run the six OSV, Shodan and Radar tests on
stub_web. Register the OSV answer, the Shodan answer, a failure status and a connect error. Comparestub_web.sentwith the expected requests.
Two gaps that I found in the fakes. I ran a copy of the rag_search body. The copy calls resolve_qdrant_client and create_embedder. It ran on the qdrant, embedder and config fixtures with one seeded chunk. I did not change rag_search. I did not run a Radar case.
FakeEmbedderhas noembed_query.SemanticRetrievercallsembedder.embed_query(ai/rag/retriever.py:63), butEmbedderProtocoldeclares onlyembed_texts. The run failed withAttributeError. The fix: declareembed_queryinEmbedderProtocol, because a caller uses it, and add it toFakeEmbedder(embed_texts([text], is_query=True)[0]). With that method the run returned the chunk. An empty store gave no result. A refusingqdrantgave "unavailable". A failingembedderraisedEmbeddingsError.rag_searchcallsensure_knowledge_base_readybefore the search. On the first call it finds no point of the installed knowledge base, and starts a rebuild. The rebuild fails onFakeQdrantClient(no attribute 'api_key'), prints "Failed rebuilding knowledge base index" and goes on. The test then passes with a warning on the console. The fix: seed the docs collection with one point whose payload hasproject_name=CONST_RAG_KB_PROJECTandkb_digest=knowledge_base_digest(). With that seed the check returnedTrueand rebuilt nothing. Put the seed in one helper next to theqdrantfixture. The root conftest callsreset_kb_sync_stateafter each test, so the state of the first call does not leak.
Acceptance criteria
-
rag_searchbuilds noQdrantClientand noEmbeddingsEngineitself.git grep -nE 'QdrantClient\(|EmbeddingsEngine\(' -- src/devops_cli/ai/toolsreturns no line. -
EmbedderProtocoldeclaresembed_query, andFakeEmbedderimplements it. - A test with the
embedderfixture and theqdrantfixture shows thatrag_search("query")returns one indexed chunk and prints no rebuild warning. Theqdrantfake holds that chunk and the seeded knowledge base. A second test shows the "No semantic matches" reply for an empty store. A third shows the "unavailable" reply when the fake is refusing. - The embedding failure test (
test_rag_search_names_an_embedding_failure) makes theembedderfake raiseEmbeddingsError, and checks the reply. -
git grep -nE 'patch\("devops_cli\.|monkeypatch\.setattr\("devops_cli\.|patch\("time\.|setattr\("time\.' -- tests/security/test_builtin_tools.pyreturns no line. - The file imports no private name from
devops_cli. The tests of_run_tool_cmdand_is_safe_workspace_pathrun throughlist_files,read_file,git_status,git_diff,k8s_podsand the other public tools. - The tests of the tool wrappers compare
process_fake.callsargv with the expected list (kubectl get pods,argocd app list,git status,git diff). - Each of the six OSV, Shodan and Radar tests registers its answers on the HTTP fake. It compares the recorded requests (method, URL, body) with the expected list.
- A test shows that a target the tool excludes (private, loopback, link-local, example) sends no request: the fake records zero requests.
- A test shows that a failed OSV lookup gives a reply that says the lookup failed, and not a clean package.
- No test of this file reaches the network.
uv run devops cipasses. The pull request body gives the patch and private-import counts before and after.
Target Subsystem
src/devops_cli/ai/tools/builtin_tools.py (rag_search), src/devops_cli/ai/rag/embeddings.py (EmbedderProtocol), tests/support/fakes/embeddings.py, tests/support/fakes/qdrant.py, tests/security/test_builtin_tools.py.
Existing Tool Considered
No new tool. The project seams and fakes exist: process_fake, qdrant, embedder, keyring_store, clock, refusing_port and stub_web. The change calls resolve_qdrant_client and create_embedder, which are already in ai/rag/. The own code is one Protocol method, one fake method and one seed helper. Cost: about 15,000 tokens and 2 hours.
Activity
dan-petty commentedon Nov 6, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
testprefix of the title gives the type.(ai)scope of the title gives the scope.This is a test-quality migration with no user-facing defect, part of a larger tracked effort.It removes 23 patches and private imports from a 938-line test file, improving reliability, but does not change product behaviour.It requires rewiring rag_search, integrating process_fake, qdrant and embedder fixtures, and stub_web for three HTTP clients across 31 tests.Both wire rag_search to resolve_qdrant_client and create_embedder, but #1329 covers the RAG and library test files while the candidate covers test_builtin_tools.py including process and HTTP fakes.