Skip to content

test(ai): devops review, devops analyze and the devops ai commands are thin adapters tested over the model seam and edge fakes #1326

Description

@dan-petty

Problem

Counts come from one AST pass over tests/test_*.py at 5c45b1e, the head of release/v0.2.28, and [code: …] lines are at the same commit. A file belongs to the package it references most, as in the census.

Acceptance criteria

Key questions

Strategic alignment

Proposed design

Problem statement

The 11 test files for the devops review, devops analyze and devops ai commands hold 136 internal patch sites and 20 private imports. The command modules contain logic that belongs in the ai/ package. This item rewrites the tests over shared fakes and moves the command logic into its owning package.

Acceptance criteria

  • Criterion 1: The 11 owned test files have zero patch sites aimed at devops_cli internals and zero private imports.
    Verification: Run rg -n 'monkeypatch\.setattr|patch\(' tests/test_ai_cmd.py tests/test_ai_prewarm.py tests/test_ai_ast_cli.py tests/test_ai_spend_cli.py tests/test_gateway_review_stall.py tests/test_llm_pool_metrics.py tests/test_library_vector_tier.py tests/test_review.py tests/test_review_pr_post.py tests/test_review_stage_flags.py tests/test_review_repos.py and confirm no hits target devops_cli internals. Run rg -n 'from devops_cli\..* import _' on the same files and confirm no hits.
  • Criterion 2: No inline LLMClient( construction remains in commands/.
    Verification: Run rg -n "LLMClient\(" src/devops_cli/commands and confirm it prints nothing.
  • Criterion 3: No test patches an LLMClient method, model_request, _make_review_clients or a PydanticAgent method.
    Verification: Run rg -n 'monkeypatch\.setattr.*(LLMClient|model_request|_make_review_clients|PydanticAgent)' tests/ and confirm no hits in the 11 owned files.
  • Criterion 4: HTTP and DNS calls resolve through the refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 DNS and HTTP fakes.
    Verification: Confirm validate_service_url calls resolve through the DNS fake and gateway HTTP calls are answered by the HTTP fake. No test constructs a raw httpx2.Client for an edge call.
  • Criterion 5: Valkey, Qdrant and embeddings calls use the refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317 fakes.
    Verification: Run rg -n 'ValkeyClient|QdrantClient|EmbeddingsEngine' tests/test_ai_cmd.py tests/test_ai_prewarm.py tests/test_ai_ast_cli.py tests/test_ai_spend_cli.py tests/test_library_vector_tier.py and confirm no direct construction outside the refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317 fake.
  • Criterion 6: The keyring uses the refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318 fake and commands/ai.py no longer imports _keyring_has.
    Verification: Run rg -n '_keyring_has' src/devops_cli/commands/ai.py and confirm it prints nothing.
  • Criterion 7: Spans and metrics use the refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319 OTLP fake; no test patches record_metric or trace_span.
    Verification: Run rg -n 'monkeypatch\.setattr.*(record_metric|trace_span)' tests/ and confirm no hits in the 11 owned files.
  • Criterion 8: GitHub calls use the refactor(github): the github session owns transport, ledger, error classes and link pagination #983 session fake, including devops review pr and devops analyze pr.
    Verification: Run rg -n 'PyGithub|github\.PyGithub' src/devops_cli/commands/review.py src/devops_cli/commands/analyze.py and confirm no hits.
  • Criterion 9: Scanners use the feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772 executor fake; no test patches a scanner entry point.
    Verification: Run rg -n 'monkeypatch\.setattr.*(bandit|semgrep|scanner)' tests/test_gateway_review_stall.py tests/test_review_stage_flags.py and confirm no hits.
  • Criterion 10: Git runs for real in a temporary repository; no test patches _run_subprocess.
    Verification: Run rg -n '_run_subprocess' tests/test_review_repos.py and confirm no hits.
  • Criterion 11: No test patches _init_logfire_if_enabled.
    Verification: Run rg -n '_init_logfire_if_enabled' tests/ and confirm no hits in the 11 owned files.
  • Criterion 12: No interim unreachable(...) marker remains in the 11 owned test files.
    Verification: Run rg -n 'unreachable\(' tests/test_ai_cmd.py tests/test_ai_prewarm.py tests/test_ai_ast_cli.py tests/test_ai_spend_cli.py tests/test_gateway_review_stall.py tests/test_llm_pool_metrics.py tests/test_library_vector_tier.py tests/test_review.py tests/test_review_pr_post.py tests/test_review_stage_flags.py tests/test_review_repos.py and confirm no hits.
  • Criterion 13: The review command logic (PR review posting, verdict judgment, finding tally, corpus scoring, sample selection) lives in ai/review/ behind public functions.
    Verification: Run rg -n 'def _execute_review_workflow|def _find_session_dir|def _judge_verdict' src/devops_cli/commands/review.py and confirm the logic is in src/devops_cli/ai/review/ instead.
  • Criterion 14: The ai and analyze command logic lives in ai/, ai/analyze/ or ai/rag/.
    Verification: Run rg -n 'def _retrieve_rag_context|def _collect_project_context|def _generate_agents_file' src/devops_cli/commands/ai.py and confirm the logic is in the ai/ package.
  • Criterion 15: CLI tests use the shared cli fixture and check only parsing, wiring, output and exit codes.
    Verification: Run rg -n 'CliRunner\(\)' tests/test_ai_cmd.py tests/test_ai_prewarm.py tests/test_ai_ast_cli.py tests/test_ai_spend_cli.py tests/test_gateway_review_stall.py tests/test_llm_pool_metrics.py tests/test_library_vector_tier.py tests/test_review.py tests/test_review_pr_post.py tests/test_review_stage_flags.py tests/test_review_repos.py and confirm no module-level CliRunner() instances.
  • Criterion 16: Command output is compared as syrupy snapshots.
    Verification: Run rg -n 'snapshot' tests/test_ai_cmd.py tests/test_review.py tests/test_review_pr_post.py and confirm syrupy assertions are present.
  • Criterion 17: Findings are built with the shared make_finding builder from tests/support/builders.py.
    Verification: Run rg -n 'make_finding' tests/test_review.py tests/test_review_pr_post.py tests/test_review_stage_flags.py and confirm the builder is used.
  • Criterion 18: Test names state behaviour in CONTEXT.md terms; catch-all names are dissolved.
    Verification: Run rg -n 'def test.*(_success|_failure|_basic|_command)\b' tests/test_ai_cmd.py tests/test_review.py and confirm no hits.
  • Criterion 19: Dead code is deleted and the 90% coverage gate passes.
    Verification: Run uv run devops ci and confirm it passes, including the coverage gate.

Key questions

Fit

Needs splitting into 5 items:

  1. Move commands/review.py logic (PR review posting, verdict judgment, finding tally, corpus scoring, sample selection) into ai/review/ behind public functions
  2. Move commands/ai.py logic (RAG retrieval, project context, agents file, prewarm URLs, endpoint probes) into ai/ or ai/rag/
  3. Move commands/analyze.py symbol-delta logic into ai/analyze/
  4. Rewrite the 11 test files to use shared fakes and seams with zero internal patches or private imports
  5. Wire all edges (HTTP, Valkey, keyring, OTLP, GitHub, kubectl, scanners, git, settings) through their named fakes in the rewritten tests

Suspected block

None.

Dependencies

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

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

Activity

  1. added
    type/test
    scope/ai
    scope/cli
    scope/review
    priority/p2-medium
    on Oct 7, 2026
  2. 9 remaining items

  3. 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.

  4. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    The proposal at 0b76871 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. Move commands/review.py logic (PR review posting, verdict judgment, finding tally, corpus scoring, sample selection) into ai/review/ behind public functions
    2. Move commands/ai.py logic (RAG retrieval, project context, agents file, prewarm URLs, endpoint probes) into ai/ or ai/rag/
    3. Move commands/analyze.py symbol-delta logic into ai/analyze/
    4. Rewrite the 11 test files to use shared fakes and seams with zero internal patches or private imports
    5. Wire all edges (HTTP, Valkey, keyring, OTLP, GitHub, kubectl, scanners, git, settings) through their named fakes in the rewritten tests
  5. added
    status/new
    effort/medium
    value/high
    on Oct 28, 2026
  6. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Tool: none found

    Checked on 2026-10-30. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    status/in-progress
    and removed
    status/new
    on Oct 31, 2026
  8. removed
    status/in-progress
    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/aiscope/cliscope/reviewtype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions