Skip to content

test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331

Closed

Description

@dan-petty

Problem

Phase E migration of the rest of ai/: the top-level ai modules and every ai/ subpackage outside ai/{review,rag,library,mcp,agents,harness,tools,toolsets}, from ai/analyze to ai/template. This item owns the 81 test files named below, by today's flat names (22,271 lines, 878 tests) [measured: AST pass at 5c45b1e]. #1313 places most of them under tests/ai/ outside the directories of #1328, #1329 and #1330; a file named here belongs to this item wherever #1313 places it.

  • ai/client: test_ai_client_{credentials,finish_reasons,network,providers_and_embeddings,retries,security,structured,telemetry}.py, test_ai_gateway_base_url.py, test_ai_request_priority.py, test_ai_streaming.py, test_ollama_dynamic_leasing.py, test_thinking_providers.py.
  • ai/spend: test_ai_spend_{dispatch,ledger,payoff,pricing,prometheus}.py, test_ai_served_by.py.
  • ai/analyze, ai/ast, ai/benchmark and ai/personas: test_ai_analyze_outlines.py, test_analyze.py, test_ai_init.py, test_ast_more_languages.py, test_treesitter_{engine,native_symbols}.py, test_ai_benchmark.py, test_embedding_benchmark.py, test_personas.py, test_custom_personas.py.
  • ai/chaos, ai/controller, ai/diff, ai/models and ai/spec: test_ai_chaos_model.py, test_ai_controller.py, test_difftastic.py, test_pydantic_ai_ollama.py, test_ai_spec.py.
  • ai/providers: test_providers.py, test_openai_auth.py.
  • The library-named files: test_pydantic_ai_{concurrency,direct,durable,format_prompt,function_signature,output,profiles_and_providers,result,retries,run,settings,template,workflows}.py.
  • The top-level modules: test_ai_{capability,diagram,explain,fixer,gateway,gateway_portkey,gateway_tune,inspection,prompt_eval,repomap,task_loader,test_gen}.py, test_ast_stream.py, test_{common_tools,native_common_tools}.py, test_consolidation_ast_cache.py, test_context_budget.py, test_context_packer.py, test_ext_langchain.py, test_finding_repetition_compression.py, test_instruction_generator.py, test_kb.py, test_model_bundle.py, test_pipeline_protocol.py, test_repomap.py, test_response_cache.py, test_review_{finding_losses,location_paths}.py, test_run_comparison.py, test_run_store.py, test_schema_reflection.py, test_thinking.py.

25 of these files also drive their module through a command, with 128 CliRunner invocations in all; test_analyze.py (20) and test_run_comparison.py (18) have the most.

The evidence:

  • Tests patch internals. 151 of the 242 patch sites target a devops_cli name, in 40 files, and the files import 88 private names: 25 from ai/analyze/outlines in test_ai_analyze_outlines.py and 15 in test_analyze.py [measured: census AST pass, recounted at 5c45b1e].
    • LLMClient and its private methods are patched 15 times. track_request_spend 10, count_tokens 7, new_http_client 6.
    • Seven sites shrink a module constant to reach a size limit, for example MAX_REPOMAP_FILE_SIZE_BYTES and DEFAULT_AI_MAX_RESPONSE_BYTES.
    • test_analyze.py alone has 28 internal sites, most of them commands.analyze and git.operations names. test_run_store.py has 15, reaching into review, gateway and settings.
    • At the edges: ai.gateway_tune.subprocess.run 7, sys.modules 7, sleeps 7.
    • tests/llm_stream_fakes.py installs its transport by patching the private _shared_client/_create_http_client [code: tests/llm_stream_fakes.py:98-101, :120-127]. Eleven files of this item use it.
    • test_embedding_benchmark.py uses stub_web, which refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 keeps only for it and test_github_client.py.
  • The legacy provider layer has no production caller.
  • Edges are reached without a seam.
  • Durable backends. Temporal, DBOS and Prefect are built in resolve_durability_capability [code: ai/durable.py:472, :524, :539, :554]. Its only caller is create_durable_pydantic_agent [code: ai/durable.py:571], which nothing in src calls. Tests fake their availability through sys.modules (6 sites).
  • A mock fallback. LLMClient.backend_type returns "mock" when the configured provider is not a string [code: ai/client/unified.py:255-258].
  • Logic in commands (Q19).
    • The gateway liveness and model probe, with its own httpx2.Client [code: commands/ai_gateway.py:165, :174].
    • The benchmark runners [code: commands/benchmark.py:117, :162].
    • Baseline lookup [code: commands/ai_runs.py:556].
  • Shape.
    • The 14 test_pydantic_ai_* files are named after the library rather than the module they test.
    • test_common_tools.py and test_native_common_tools.py test one module, and so do test_repomap.py and test_ai_repomap.py.
    • Catch-alls include test_outline_extended_branches [code: tests/test_ai_analyze_outlines.py:260] and test_llm_client_streaming_and_error_branches [code: tests/test_ai_client_providers_and_embeddings.py:288].
    • 21 module-level runner = CliRunner() and 14 redundant @pytest.mark.asyncio markers.

Acceptance criteria

Doubles only at edges

Dead code and accommodations (Q22, Q25, Q27)

Logic out of commands/ (Q19)

Behaviour files and names

Ratchets and coverage

Key questions

Strategic alignment

Update 2026-10-08: refinement

Per the owner's #1001 decision, #1005 keeps the pydantic-ai route, so this item alone deletes the legacy layer: the classes, _PROVIDERS, register_provider and get_provider (ai/providers/__init__.py:15-39), their re-exports (ai/__init__.py:267, :276; ai/agents/__init__.py:438, :447), and tests/mock_provider.py with its fixture. It keeps ai/providers/__init__.py:42-110 and ai/direct.py.

Proposed design

Problem statement

The 81 test files in this item test AI modules by patching internals, importing private names, and reaching edges without a seam. They also test a legacy provider layer that no production code calls. This item migrates all 81 files to test through public interfaces on edge fakes, deletes the dead provider layer and unreachable durable backends, moves command-level logic into the ai/ packages it tests, and renames files to match their subject.

Acceptance criteria

Key questions

Open questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#1313, #1314, #1317, #1318, #1319

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

Activity

  1. added
    type/test
    scope/ai
    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. A large but non-blocking Phase E migration that improves test maintainability and removes dead code, with no user-facing defect or security risk.
    • Value: High. Decoupling 878 tests from 151 internal patch sites and deleting an unreferenced provider layer significantly reduces brittleness and maintenance cost for the AI runtime.
    • Effort: High. 81 test files spanning 22,271 lines and 878 tests must be rewritten to use public interfaces, plus the legacy provider layer and its re-exports must be removed from source.
  3. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #1381 leaves the legacy providers' raw clients to this item. #1121 deletes the three durable engines; this item's Q22 decision deletes the rest of the durable layer, and whichever lands second drops what the other removed. Found by the 2026-10-08 backlog review.

  4. dan-petty commented on Oct 26, 2026

    @dan-petty
    OwnerAuthor

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

    • Priority: P2-Medium. The item improves test coverage and quality but is not critical for immediate delivery.
    • Value: High. Improving test coverage for AI modules helps ensure better stability and correctness of the system.
    • Effort: Medium. The effort involves significant refactoring of tests and migration to edge fakes, which is moderately complex.
  5. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    Refine cannot set this item to Ready at 0b76871 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

  6. added
    status/new
    effort/medium
    value/high
    on Oct 28, 2026
  7. 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.

  8. added a commit that references this issue on Oct 31, 2026
    261cc1e
  9. added
    status/in-review
    and removed
    status/new
    on Oct 31, 2026
  10. removed
    status/in-review
    on Oct 31, 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