Repository navigation
Description
Problem
Phase E migration of ai/rag/ and ai/library/. This item owns the 27 test files named below, by today's flat names (5,668 lines, 220 tests) [measured: AST pass at 5c45b1e]. #1313 places most of them under tests/ai/rag/ and tests/ai/library/; a file named here belongs to this item wherever #1313 places it.
test_rag_{aimd,chunker,cli,drift,embeddings,hybrid_search,indexer_retriever,investigator,loopback_policy,metadata_extraction,multi_project_indexer,polyglot_chunker,qdrant,qdrant_keyring,query_telemetry,reranker,retriever_filters,rrf}.py;test_qdrant_{cluster_addressing,timeout_setting}.pyandtest_embedding_{cache,config_retention}.py;test_docs_ingester.py,test_library_drift_auditor.pyandtest_library_ingest.py;test_review_embeddings_unserved.py, which tests the investigator's stop on an unserved embedding model;test_ai_subcommands_rag.py, whose retrieval cases test the investigator through the privatecommands.ai._try_retrieve_rag_context[code: commands/ai.py:190], a wrapper that returnsinvestigate_rag_context's text orNone.
The evidence:
- Tests patch internals. 107 of the 156 patch sites target a devops_cli name, in 15 files, and the files import 23 private names, 12 of them in
test_rag_embeddings.py[measured: census AST pass, files unchanged at 5c45b1e].- Patched clients and engines:
QdrantClient10,SemanticRetriever7,EmbeddingsEngine6 and its private_dispatch_embed5. - Patched to skip DNS or the keyring:
validate_configured_service_urlandvalidate_service_url14,get_qdrant_api_key8. - Patched to observe or reroute: the metric
emit8,commands.rag._get_rag_components4, the private k8s_kube_configuration4. test_ai_subcommands_rag.py's 4 sites are all internal:load_settingstwice,QdrantClient.is_aliveandSemanticRetriever.retrieve_context.- At the edges:
httpx2.Client.post19.
- Patched clients and engines:
- Hand-rolled doubles. The test files define 14 Qdrant, Valkey and embedder doubles across 6 files, for example
FakeQdrantClient[code: tests/test_rag_indexer_retriever.py:17] and_MockValkey[code: tests/test_rag_embeddings.py:554]. - Edges are reached without a seam.
EmbeddingsEngineopens fourhttpx2.Clients of its own [code: ai/rag/embeddings.py:380, :629, :659, :796]. The docs ingester opens one [code: ai/library/docs_ingester.py:247].- With default arguments the engine pings Valkey through a sentinel and sets a timeout on the Valkey client's private socket [code: ai/rag/embeddings.py:73, :433-434].
- The investigator builds
QdrantClientandEmbeddingsEngineinline [code: ai/rag/investigator.py:215, :227]. - Drift detection runs git with
subprocess.run, one of the 11 direct spawners [code: ai/rag/drift.py:54].
- The commands wire RAG (Q19).
- The same settings-to-components code exists three times:
_get_rag_components[code: commands/rag.py:69],_resolve_runtime_qdrant_and_embedder[code: commands/ai_ingest.py:233] and the investigator [code: ai/rag/investigator.py:214-230]. Each turns settings into a Qdrant client and an embedder;_get_rag_componentsand the investigator also derive the collection names. _build_runtime_vector_storeand_load_local_contractsare library logic [code: commands/ai_ingest.py:254, :115]._resolve_runtime_valkey_clientimports the privatecommands.valkey._resolve_client[code: commands/ai_ingest.py:221, :224].commands/rag.py:63is a pass-throughload_settings.
- The same settings-to-components code exists three times:
- Writes outside the data directory. By default the docs ingester writes to a cwd-relative
.data/docs_ingest[code: ai/library/docs_ingester.py:193, :241]. fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036 (consolidated from fix(k8s): resolve the port-forward state file under the repo data root #810) already moves that default under the data directory, so this item does not. - Shape. One catch-all,
test_rag_error_branches[code: tests/test_rag_cli.py:131]. Five module-levelrunner = CliRunner().
Acceptance criteria
Doubles only at edges
- No test of this item patches a devops_cli name or imports a private one. Today that is 107 sites and 23 imports.
- Each edge is faked through its own seam:
- Qdrant, embeddings and Valkey through refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317;
- HTTP and DNS through refactor(cli): Unify HTTP and DNS seams with shared fakes #1314;
- Qdrant cluster addressing through refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315's Kubernetes fake;
- API keys through refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318;
- metrics and spans through refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319's OTLP fake;
- the investigator's cache TTL and circuit breaker through refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320's clock.
- The 14 hand-rolled doubles are deleted.
- The investigator gets its Qdrant client and embedder from refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317's seam (
ai/rag/investigator.py:215,:227). - The docs ingester takes its HTTP client from refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's seam.
EmbeddingsEngineopens nohttpx2.Clientof its own: the requests refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001's adapters carry, once refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 has landed, stay with them, and the rest take their client from refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's seam. - The engine reads no private attribute of the Valkey client.
- Drift detection runs git through refactor(cli): one process runner owns execution, process groups and dry-run #775's runner, and its tests run real git in a temporary repository (Q23).
Logic out of commands/ (Q19)
- One public function in
ai/rag/builds the configured Qdrant client and embedder, and the collection names.commands/rag.py,commands/ai_ingest.pyand the investigator call it. -
_build_runtime_vector_storeand_load_local_contractsmove behind public functions inai/library/orai/rag/library_store.py, and are tested there. - The Valkey client comes from refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317's seam, not
commands.valkey._resolve_client. - The pass-through
load_settingsis gone. -
test_rag_cli.pydissolves:- its domain cases become
ai/ragbehaviour tests; - its parsing, output and exit-code cases become CLI tests under
tests/commands/on test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310'sclifixture (Q14).
- its domain cases become
-
test_ai_subcommands_rag.pydissolves: its retrieval cases testinvestigate_rag_contextdirectly, and itsdevops --dry-run ai pipelinecase becomes a CLI test undertests/commands/.
Behaviour files and names
- One file per behaviour of the package, named after it (Q10).
- Test names state behaviour (Q8). The catch-all is split by behaviour.
- The five module-level
CliRunner()s give way to test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310'sclifixture (Q14). - The source chunkers (
ai/rag/chunker.py) get Hypothesis property tests (Q21: parsers over open-ended input).
Ratchets and coverage
- If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its ceilings drop by this item's removals, and the PR body states the counts before and after.
- If test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 added its interim
unreachable(...)marker, none remains in this item's files. A test that relied on the refusal installs the edge's fake in its refusing state. - Lines in these packages that no public behaviour reaches are deleted (Q22). Coverage stays at or above 90%.
-
uv run devops cipasses.
Key questions
- Which test files belong here? Decided 2026-10-07: each file goes to the package that owns most of what it tests (Q3, Q9, Q17). Every test file is named in exactly one child's list, so the list above is this item's share wherever test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 places a file.
test_library_vector_tier.pymostly drivesdevops ai index-librariesand is test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326's; its cases of_build_runtime_vector_storefollow that function here.test_ai_subcommands_rag.pyis named here because both of its retrieval cases test the investigator. - Who moves the wiring out of
commands/rag.pyandcommands/ai_ingest.py? Decided 2026-10-07: this item, the migration item of the domain package (Q19). test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326's CLI tests then check only parsing, wiring, output and exit codes (Q14). - Where does the wiring function live? (proposed) In
ai/rag/indexer.py, next toresolve_qdrant_client(:397), which already resolves the client from settings.
Strategic alignment
- Depends on: test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313, refactor(cli): one process runner owns execution, process groups and dry-run #775, refactor(cli): Unify HTTP and DNS seams with shared fakes #1314, refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315, refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317, refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318, refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319, refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320. Blocks: test(cli): Convert ratchets to bans and merge invariant tests #1336. Related: test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 (ratchets), test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326 (AI commands, including
commands/ai.py), test(review): ai/review and review/ are tested through one public interface over the model, tool-executor and process fakes, with no mock detection in src #1328 (review), refactor(ai): one model seam: llmclient over three wire adapters behind one factory, no second provider stack #1001 (model seam, embeddings), fix(ai): the durable-run store resolves under the data directory, so tests never write .data/durable_runs.db into the checkout #1036 (the docs-ingest directory under the data directory), fix(config): service clients use only configured urls and never fall back to an unconfigured localhost default #1165 (no unconfigured service-URL fallbacks). - Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase E).
- Evidence tags are explained in test(cli): tests double only process edges and mirror the source tree #1307. Here [code: path:line] lines are at 5c45b1e, the release/v0.2.28 head, and the per-item counts were recounted there.
Proposed design
Problem statement
The 27 test files for ai/rag/ and ai/library/ patch 107 internal names and define 14 hand-rolled doubles. The RAG component wiring is duplicated in three files: commands/rag.py, commands/ai_ingest.py, and ai/rag/investigator.py. This item moves the wiring into one public function in ai/rag/. It replaces all internal patches with edge fakes from the shared seams. It restructures the tests into one file per behaviour.
Acceptance criteria
- Criterion 1: No test in this item patches a devops_cli name or imports a private one.
Verification: Run rg -n 'mock.patch|monkeypatch' tests/ai/rag/ tests/ai/library/ and confirm no devops_cli name appears. Run rg -n 'from devops_cli.*import _' tests/ai/rag/ tests/ai/library/ and confirm no output. - Criterion 2: Each edge is faked through its own seam: Qdrant, embeddings, Valkey through refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317; HTTP and DNS through refactor(cli): Unify HTTP and DNS seams with shared fakes #1314; Qdrant cluster addressing through refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315; API keys through refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318; metrics through refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319; clock through refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320.
Verification: Run the full test suite for this item with network disabled. Confirm no test opens a real socket or makes a real HTTP call. Confirm each fake is imported from the named seam module. - Criterion 3: The 14 hand-rolled doubles (FakeQdrantClient, _MockValkey, etc.) are deleted.
Verification: Run rg -n 'class Fake|class _Mock|class _Fake' tests/ai/rag/ tests/ai/library/ and confirm no output. - Criterion 4: The investigator gets its Qdrant client and embedder from refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317's seam instead of building them inline.
Verification: Read ai/rag/investigator.py at lines 215 and 227. Confirm the client and embedder come from the refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317 seam function, not from inline construction. - Criterion 5: One public function in ai/rag/ builds the configured Qdrant client, embedder, and collection names. commands/rag.py, commands/ai_ingest.py, and the investigator call it.
Verification: Read the new public function in ai/rag/indexer.py. Confirm commands/rag.py:69, commands/ai_ingest.py:233, and ai/rag/investigator.py:214-230 all call it. Confirm no duplicate settings-to-components logic remains. - Criterion 6: _build_runtime_vector_store and _load_local_contracts move behind public functions in ai/library/ or ai/rag/library_store.py.
Verification: Run rg -n '_build_runtime_vector_store|_load_local_contracts' src/devops_cli/commands/ and confirm no output. Confirm the public functions exist in ai/library/ or ai/rag/library_store.py with tests. - Criterion 7: test_rag_cli.py dissolves: domain cases become ai/rag behaviour tests, parsing and exit-code cases become CLI tests under tests/commands/.
Verification: Confirm tests/test_rag_cli.py no longer exists. Confirm the domain cases are in tests/ai/rag/ and the CLI cases are in tests/commands/ using test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310's cli fixture. - Criterion 8: test_ai_subcommands_rag.py dissolves: retrieval cases test investigate_rag_context directly, the dry-run case becomes a CLI test.
Verification: Confirm tests/test_ai_subcommands_rag.py no longer exists. Confirm the retrieval cases call investigate_rag_context and the dry-run case is under tests/commands/. - Criterion 9: One test file per behaviour of the package, named after it.
Verification: List files in tests/ai/rag/ and tests/ai/library/. Confirm each file name matches the behaviour it tests and no file covers multiple unrelated behaviours. - Criterion 10: The source chunkers in ai/rag/chunker.py have Hypothesis property tests.
Verification: Run rg -n 'hypothesis|@given' tests/ai/rag/ and confirm property tests exist for the chunker. Run the tests and confirm they pass. - Criterion 11: The five module-level CliRunner() instances are replaced by test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310's cli fixture.
Verification: Run rg -n 'CliRunner()' tests/ai/rag/ tests/ai/library/ and confirm no output. Confirm the cli fixture is used instead. - Criterion 12: Coverage stays at or above 90% and uv run devops ci passes.
Verification: Run uv run devops ci. Confirm the exit code is 0 and the coverage report shows at least 90% for ai/rag/ and ai/library/. - Criterion 13: The docs ingester renders HTML through the same converter as web_fetch and splits markdown with markdown-it.
Verification: Run rg -n '_HTMLContentExtractor|_HEADING_PATTERN|HTMLParser' src/devops_cli/ai/library/ and confirm no output. Run the test with a page containing a heading, list, link, code block, and script. Confirm the ingester and the shared converter produce the same markdown.
Key questions
- Which test files belong here?: Decided 2026-10-07: each file goes to the package that owns most of what it tests. The 27 files listed in the body are this item's share wherever test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 places them. test_library_vector_tier.py is test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326's; its cases of _build_runtime_vector_store follow that function here. test_ai_subcommands_rag.py is here because both retrieval cases test the investigator. (proposed)
- Who moves the wiring out of commands/rag.py and commands/ai_ingest.py?: Decided 2026-10-07: this item, the migration item of the domain package. test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326's CLI tests then check only parsing, wiring, output, and exit codes. (proposed)
- Where does the wiring function live?: Proposed: in ai/rag/indexer.py, next to resolve_qdrant_client at line 397, which already resolves the client from settings. (proposed)
Fit
Needs splitting into 4 items:
- Wire RAG components once: move settings-to-components into one public function in ai/rag/indexer.py, move _build_runtime_vector_store and _load_local_contracts to ai/library/, remove the pass-through load_settings in commands/rag.py
- Migrate the 23 ai/rag/ test files (test_rag_, test_qdrant_, test_embedding_*, test_review_embeddings_unserved) to edge fakes, one file per behaviour, delete the 14 hand-rolled doubles, add Hypothesis tests for chunkers
- Migrate the 4 ai/library/ and command-level test files (test_docs_ingester, test_library_drift_auditor, test_library_ingest, test_ai_subcommands_rag) to edge fakes and CLI tests under tests/commands/
- Docs ingester: render HTML through the shared web_fetch converter, split markdown with markdown-it, delete _HTMLContentExtractor and _HEADING_PATTERN
Suspected block
None.
Dependencies
#1313, #1314, #1315, #1317, #1318, #1319
Alternatives check of 2026-10-31: not-applicable.
Tool: none found.
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNew
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 8, 2026
Folded here instead of a new issue: the agent filing quota (#1153) is spent for this cycle, and this refactor shares this item's change surface. It is recorded here in full so it is not lost.
refactor(ai): the docs ingester renders HTML with web_fetch's converter and splits markdown with markdown-it
Problem
Checked at release/v0.2.29 (05e9388).
_HTMLContentExtractor(ai/library/docs_ingester.py:40-97) subclasseshtml.parser.HTMLParserto turn HTML into markdown and collect links by hand._chunk_markdown_content(:135-167) splits sections on a heading regex (:23), so a#line inside a fenced code block starts a section.ai/common_tools.py:16-17), both direct dependencies (feat(ai): web_fetch renders pages as untrusted, escaped markdown within a budget #896). The two paths render the same page differently.Proposed remedy
soup.find_all("a", href=True), resolved and filtered to the same origin as today._HTMLContentExtractorand_HEADING_PATTERN.Acceptance criteria
#line inside a fenced code block does not start a section. The test fails on the current code.https://example.com, served by the HTTP edge fake, follows only same-origin links, as today.rg -n '_HTMLContentExtractor|_HEADING_PATTERN|HTMLParser' src/devops_cli/ai/libraryprints nothing.MockTransport, throughtests/llm_stream_fakes.route_clientor refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's fixture) or the process edge. No test patches a devops_cli name.changelog.d/<n>.mdrecords the change;CHANGELOG.mdis not edited.uv run devops cipasses.Related: #896, #1381, #1112, #1036, #1329
Found by the 2026-10-08 client-library audit.
dan-petty commentedon Oct 8, 2026
Linked: #1381, which moves the embedding clients this item takes onto a seam (
ai/rag/embeddings.py:380-796); whichever lands second builds on the other. Found by the 2026-10-08 backlog review.7 remaining items
devops-cli-service commentedon Oct 31, 2026
Alternatives check: not-applicable
Tool: none found
Checked on 2026-10-31. A person decides what this means for the item. The check changes no label and closes no issue.
[-]test(ai): rag and library tests run on edge fakes, and rag components are wired once in ai/rag instead of in the commands[/-][+]test(ai): Wire rag once in ai/rag, test with edge fakes[/+]dan-petty commentedon Nov 6, 2026
The job shortened the title of this item. The summary had 111 characters, and the limit is 60. The type and the scope stay.
test(ai): rag and library tests run on edge fakes, and rag components are wired once in ai/rag instead of in the commandstest(ai): Wire rag once in ai/rag, test with edge fakestest(ai): wire rag once in ai/rag, test with edge fakes (#4245)