Skip to content

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

Closed

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.

  • Files (59; 28,716 lines, 850 tests [measured: AST pass at 5c45b1e]): the 49 whose primary package is ai/review/, test_review_admission (review/), and 9 more that import ai/review/ and that the census left unclaimed.
    • test_ai_review_pool, test_category_metrics, test_common_hallucinations, test_common_hallucinations_hardening, test_construct_aware_location, test_contract_injection, test_executable_criteria, test_hallucination_catalog_learning, test_mitigated_perimeter, test_verdict_polarity, test_verdict_writers.
    • test_review_* with these suffixes: adjudication, admission, advisory_backing, backend_activity, classification, console_report, defects, defects_comments, defects_infra, defects_languages, defenses_and_verification, exporter, history, judged_claims, loop_calibration, none_dereference_check, page_line_numbers, path, path_classes, path_routing, pipeline, profile, project_conventions, prompt_consistency, prompt_guardrails, report_integrity, report_summary, runner, sample_validation, samples, scope, static_analyzers, symbol_delta, taxonomy_and_severity, template_sweep, untrusted_tree, verification, verification_task, worktree_regression.
    • The 9 more (1,637 lines, 69 tests): test_batch_2_review_defects, test_prompt_programmatic_functions, test_review_location_anchoring, test_review_loop_hardening, test_review_regression_harness, test_review_reply_caps, test_review_stages, test_review_verifier_self_refutation and test_structural_positional_oracles.
  • Coupling. 237 internal patch sites (one through an f-string, test_review_adjudication.py:518) and 299 private imports in 44 files [measured].
    • Private imports reach ai/review/verification 132 times, runner 78 and pipeline 24; test_review_verification.py imports 75 private names, and test_review_runner.py imports 42 and patches 48 internals.
    • Patched most often: runner._run_subprocess 12, runner._get_reviews_base_dir 10, core.process.run_subprocess 10, commands.review._make_review_clients 7, _execute_review_workflow 7, investigate_rag_context 7, run_bandit_scan 6, security.base.run_subprocess 5, run_gitleaks_scan 4, _run_mcp_cmd 4, HostSandbox 3, GitHubClient 3.
  • Product code shaped for tests (Q27). _is_scannable_manifest returns True for a missing path when run_kubelinter_scan is a NonCallableMock [code: ai/review/pipeline.py:708-715]. run_subprocess is imported as _run_subprocess [code: ai/review/runner.py:72], the name tests patch.
  • Edges outside a seam.
  • Dead code. _terminate_process_group has no caller [code: ai/review/review_environment.py:396]; refactor(cli): one process runner owns execution, process groups and dry-run #775 consolidates the process-group copies.
  • Doubles and data.
    • 12 files define their own _finding(...); DummyClient is defined 5 times in test_review_path.py (:248-:395); _FakeGitHub appears at test_review_path_routing.py:111 and test_review_scope.py:28; 11 files build a module-level runner = CliRunner().
    • The three tests/golden files have no regeneration: criteria_replay.json and criteria_direction.json (test_executable_criteria.py:723, :751) and review_findings.json (test_review_regression_harness.py:46).
  • Files and names.
    • test_common_hallucinations, test_common_hallucinations_hardening and test_hallucination_catalog_learning use a term CONTEXT.md lists under Avoid for "Known false positive".
    • Files named after work rather than behaviour: test_review_worktree_regression (a defect), test_batch_2_review_defects (a work batch) and test_review_loop_hardening (a *_hardening file, which Q13 sends to the package that owns the behaviour).
    • Large files: test_review_verification.py 2,435 lines (72 tests), test_review_pipeline.py 1,573, test_verdict_writers.py 1,553, test_executable_criteria.py 1,206, test_review_untrusted_tree.py 1,169, test_review_adjudication.py 1,136.
    • Catch-alls: test_review_verification.py:907, test_review_pipeline.py:957, test_review_runner.py:58, :100, :194, :287.
  • Code already being deleted. refactor(review): the model verifier, the hallucination catalog and the model-claim guards are deleted, and person-recorded verdicts become suppressions #1150 deletes the model verifier, the hallucination catalog and the model-claim guards; refactor(review): the persona review stage, the legacy segment engine and review-time RAG are deleted, and devops review builds a model client only for the explanation stages #1151 deletes the persona stage, the legacy segment engine and review-time RAG. 29 of these 59 files import a module refactor(review): the model verifier, the hallucination catalog and the model-claim guards are deleted, and person-recorded verdicts become suppressions #1150 deletes or cuts (verification, common_hallucinations, construct_validator, criteria_evidence, judged_claims, mitigations) [measured: grep at 5c45b1e].

Acceptance criteria

Key questions

Strategic alignment

Proposed design

Problem statement

The 59 test files for ai/review/ and review/ reach into package internals with 237 patch sites and 299 private imports. Product code in ai/review/ contains a mock-detection branch and a test-only alias. Edges (model, scanners, enrichers, processes, GitHub, RAG, waits) are built inline or called directly, so tests must patch them. Test files are organized by work batch rather than behaviour, and they define local builders and fakes that duplicate shared support. This item routes every edge through its established seam, removes all internal patches and private imports, reorganizes tests by behaviour, and deletes the mock-detection code and dead code it exposes.

Acceptance criteria

  • Criterion 1: No test file under tests/ai/review/ or tests/review/ patches a devops_cli internal or imports a private name.
    Verification: Run rg -n 'monkeypatch.setattr|unittest.mock.patch|from devops_cli.ai.review.[a-z_]+ import _' tests/ai/review/ tests/review/ and confirm zero matches.
  • Criterion 2: ai/review/ exposes one public interface for running a review and reading its session; commands/review.py imports no private ai/review name.
    Verification: Run rg -n 'from devops_cli.ai.review.[a-z_]+ import _' src/devops_cli/commands/review.py and confirm zero matches.
  • Criterion 3: The NonCallableMock branch in _is_scannable_manifest and the _run_subprocess alias are deleted.
    Verification: Run rg -n 'unittest.mock|NonCallableMock' src/devops_cli/ai/review and confirm zero matches.
  • Criterion 4: Scanners reach the orchestrator through the tool-executor seam; no test patches run_subprocess, _run_subprocess, a scanner entry point, or HostSandbox.
    Verification: Run rg -n 'run_subprocess|_run_subprocess|HostSandbox' tests/ai/review/ tests/review/ and confirm zero matches.
  • Criterion 5: Enricher clients (OSV, Shodan, Cloudflare Radar) are built through the constructor seam and their HTTP goes through the HTTP fake; no test passes a double of an enricher class.
    Verification: Run rg -n 'OSVClient(|ShodanClient(|CloudflareRadarClient(' src/devops_cli/ai/review and confirm zero matches outside the factory.
  • Criterion 6: Processes in template_sweep.py go through the process fake; shutil.which and subprocess.run are not called directly.
    Verification: Run rg -n 'shutil.which|subprocess.run' src/devops_cli/ai/review/template_sweep.py and confirm zero matches.
  • Criterion 7: The model goes through the model seam; no inline LLMClient construction remains in ai/review/.
    Verification: Run rg -n 'LLMClient(' src/devops_cli/ai/review and confirm zero matches.
  • Criterion 8: GitHub access goes through the session seam; the PR fetch does not use PyGithub.
    Verification: Run rg -n 'PyGithub|github.PyGithub' src/devops_cli/ai/review/runner.py and confirm zero matches.
  • Criterion 9: Waits go through the clock fixture; no test sleeps for real or patches time or asyncio.sleep.
    Verification: Run rg -n 'time.sleep|asyncio.sleep' tests/ai/review/ tests/review/ and confirm zero matches.
  • Criterion 10: _terminate_process_group is gone from review_environment.py.
    Verification: Run rg -n 'os.killpg' src/devops_cli/ai/review and confirm zero matches.
  • Criterion 11: The six large test files are deleted and their tests live in behaviour-named files.
    Verification: Confirm test_review_verification.py, test_review_pipeline.py, test_verdict_writers.py, test_executable_criteria.py, test_review_untrusted_tree.py, and test_review_adjudication.py do not exist under tests/.
  • Criterion 12: Work-named and catalog-named files are dissolved into behaviour files; names use CONTEXT.md terms.
    Verification: Confirm test_review_worktree_regression.py, test_batch_2_review_defects.py, test_review_loop_hardening.py, and the three hallucination-catalog files do not exist under tests/.
  • Criterion 13: The 12 local _finding factories and 5 DummyClient classes are deleted; tests use the shared make_finding and make_verdict from tests/support/builders.py.
    Verification: Run rg -n 'def _finding|class DummyClient' tests/ai/review/ tests/review/ and confirm zero matches.
  • Criterion 14: Prompts and rendered review.md are syrupy snapshots; the three golden files are converted; tests/golden/ no longer exists.
    Verification: Run ls tests/golden/ and confirm the directory does not exist. Run rg -n 'syrupy' tests/ai/review/ tests/review/ and confirm snapshot assertions are present.
  • Criterion 15: CLI tests use the cli fixture; the 11 module-level CliRunner() instances are removed.
    Verification: Run rg -n 'CliRunner()' tests/ai/review/ tests/review/ and confirm zero matches.
  • Criterion 16: The fixture path class in .devops/review.toml and config/constants.py uses tests//snapshots/ instead of tests/golden/**.
    Verification: Run rg -n 'tests/golden' .devops/review.toml src/devops_cli/config/constants.py and confirm zero matches; confirm snapshots is present in both.
  • Criterion 17: No interim unreachable(...) marker from 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 remains in this item's test files.
    Verification: Run rg -n 'unreachable(' tests/ai/review/ tests/review/ and confirm zero matches.
  • Criterion 18: The 90% coverage gate passes and uv run devops ci succeeds.
    Verification: Run uv run devops ci and confirm it exits 0.

Key questions

Fit

Needs splitting into 4 items:

  1. Remove mock detection from ai/review/ src: delete the NonCallableMock branch in _is_scannable_manifest (pipeline.py:708-715) and the _run_subprocess alias (runner.py:72).
  2. Wire all edges through their seams (model, scanners, enrichers, processes, GitHub, RAG, waits) and remove all 237 internal patch sites and 299 private imports from the 59 test files.
  3. Reorganize test files by behaviour: split the 6 large files, dissolve the 3 work-named files and 3 catalog files, rename per CONTEXT.md, consolidate local builders and fakes into shared support, and replace 11 module-level runners with the cli fixture.
  4. Migrate the 3 golden files to syrupy snapshots, update fixture path classes in .devops/review.toml and config/constants.py, and delete _terminate_process_group from review_environment.py.

Suspected block

None.

Dependencies

#1313, #1314, #1317

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

Activity

  1. added
    type/test
    scope/review
    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. Large test-coupling debt that hinders maintenance but does not block a release or cause user-facing defects.
    • Value: High. 237 internal patch sites, 299 private imports, and mock-detection in src make the suite brittle and the product code test-shaped, so decoupling yields major maintainability gains.
    • Effort: High. 59 files, 28,716 lines and 850 tests must be rewritten against public seams, plus product-code edges (inline client construction, direct subprocess calls, real sleeps) must be refactored first.
  3. 1 remaining item

  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 is important for code quality but not critical.
    • Value: High. Improves testing of ai/review and review/ which are core components.
    • Effort: Medium. Requires moderate effort to implement proper testing with fakes.
    • Possible duplicate: test(ai): the remaining ai modules are tested through their public interfaces on edge fakes, and the legacy provider layer leaves src #1331, which may ask for the same change. The model names ai/review and review/ are tested through one public interface over the model, tool-executor and process fakes, with no mock detection in src as the change that both ask for. Both items ask for testing ai modules through public interfaces with fakes. A person closes one of the two if that is so.
  5. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    The proposal at 0b76871 needs splitting into 4 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. Remove mock detection from ai/review/ src: delete the NonCallableMock branch in _is_scannable_manifest (pipeline.py:708-715) and the _run_subprocess alias (runner.py:72).
    2. Wire all edges through their seams (model, scanners, enrichers, processes, GitHub, RAG, waits) and remove all 237 internal patch sites and 299 private imports from the 59 test files.
    3. Reorganize test files by behaviour: split the 6 large files, dissolve the 3 work-named files and 3 catalog files, rename per CONTEXT.md, consolidate local builders and fakes into shared support, and replace 11 module-level runners with the cli fixture.
    4. Migrate the 3 golden files to syrupy snapshots, update fixture path classes in .devops/review.toml and config/constants.py, and delete _terminate_process_group from review_environment.py.
  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
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Oct 31, 2026
  9. 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/reviewtype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions