Skip to content

test(ai): Wire rag once in ai/rag, test with edge fakes #1329

Closed
3 of 3 issues completed
Closed

Description

@dan-petty

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}.py and test_embedding_{cache,config_retention}.py;
  • test_docs_ingester.py, test_library_drift_auditor.py and test_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 private commands.ai._try_retrieve_rag_context [code: commands/ai.py:190], a wrapper that returns investigate_rag_context's text or None.

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: QdrantClient 10, SemanticRetriever 7, EmbeddingsEngine 6 and its private _dispatch_embed 5.
    • Patched to skip DNS or the keyring: validate_configured_service_url and validate_service_url 14, get_qdrant_api_key 8.
    • Patched to observe or reroute: the metric emit 8, commands.rag._get_rag_components 4, the private k8s _kube_configuration 4.
    • test_ai_subcommands_rag.py's 4 sites are all internal: load_settings twice, QdrantClient.is_alive and SemanticRetriever.retrieve_context.
    • At the edges: httpx2.Client.post 19.
  • 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.
    • EmbeddingsEngine opens four httpx2.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 QdrantClient and EmbeddingsEngine inline [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_components and the investigator also derive the collection names.
    • _build_runtime_vector_store and _load_local_contracts are library logic [code: commands/ai_ingest.py:254, :115].
    • _resolve_runtime_valkey_client imports the private commands.valkey._resolve_client [code: commands/ai_ingest.py:221, :224].
    • commands/rag.py:63 is a pass-through load_settings.
  • 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-level runner = CliRunner().

Acceptance criteria

Doubles only at edges

Logic out of commands/ (Q19)

Behaviour files and names

Ratchets and coverage

Key questions

Strategic alignment

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

Key questions

Fit

Needs splitting into 4 items:

  1. 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
  2. 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
  3. 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/
  4. 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

Sub-issues

3 of 3 Issues completed
Loading 3 sub-issues

Activity

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

    @dan-petty
    OwnerAuthor

    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) subclasses html.parser.HTMLParser to 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.
    • web_fetch already converts pages with BeautifulSoup and markdownify (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

    • The ingester renders HTML through the same converter as web_fetch, as one public function both import. It takes links from soup.find_all("a", href=True), resolved and filtered to the same origin as today.
    • Sections are split by the markdown-it section function from the RAG chunker item filed from the same audit. If that item has not landed, this item adds the shared function.
    • Delete _HTMLContentExtractor and _HEADING_PATTERN.
    • The crawler's own client moves onto the egress-checked factory under fix(security): move the remaining HTTP clients onto the egress-checked factory and delete the pre-flight resolve paths #1381, not here.

    Acceptance criteria

    • One HTML page (a heading, a list, a link, a code block and a script) gives the same markdown through the ingester as through the shared converter. The test fails on the current code.
    • A # line inside a fenced code block does not start a section. The test fails on the current code.
    • A crawl of three pages under 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/library prints nothing.
    • Tests run offline, with fakes only at the HTTP edge (an httpx2 MockTransport, through tests/llm_stream_fakes.route_client or refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's fixture) or the process edge. No test patches a devops_cli name.
    • Each new or changed test runs in under 1 s.
    • changelog.d/<n>.md records the change; CHANGELOG.md is not edited.
    • uv run devops ci passes.

    Related: #896, #1381, #1112, #1036, #1329

    Found by the 2026-10-08 client-library audit.

  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    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.

  4. 7 remaining items

  5. added
    effort/medium
    value/high
    on Oct 28, 2026
  6. devops-cli-service commented on Oct 31, 2026

    @devops-cli-service
    Contributor

    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.

  7. changed the title [-]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[/+] on Nov 6, 2026
  8. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    The job shortened the title of this item. The summary had 111 characters, and the limit is 60. The type and the scope stay.

    • Before: test(ai): rag and library tests run on edge fakes, and rag components are wired once in ai/rag instead of in the commands
    • After: test(ai): Wire rag once in ai/rag, test with edge fakes
    • Source of the summary: the background model
  9. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 9, 2026
  10. removed
    status/in-review
    on Nov 9, 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/mediumpriority/p2-mediumscope/aitype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions