Repository navigation
Closed
Labels
effort/mediumEffort Mediumpriority/p2-mediumPriority P2: standard worksource/agentFiled by an agenttype/refactorType refactor: a new structure, same behaviorvalue/mediumValue Medium
Description
Problem or Motivation
Part 1 of #1332. The security scanners look for test mocks in product code, which AGENTS.md rule 2 forbids ("make product code detect tests"). Measured on origin/main 1244cbf:
security/base.pyimportsunittest.mock.NonCallableMock._is_mockedand_patched_run_subprocesssearchsys.modulesfor a patchedis_dry_run,check_binaryorrun_subprocess, andBaseSecurityScanner._is_dry_run,_check_binaryand_run_toolcall the patched function in place of the real one.- Seven scanner modules re-import
run_subprocessoris_dry_runwith# noqa: F401only to be patch targets, andtflint.pyre-importsshutilthe same way:bandit,gitleaks,kubelinter,pluto,popeye,semgrep,tflint. - 62 patch sites in 11 test files patch
run_subprocess,is_dry_run,check_binaryorshutilonsecurity.baseor on one of the seven modules, so they rely on the mock detection or on the re-imports. Six of them are in 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's files (test_review_untrusted_tree.py4,test_review_static_analyzers.py2); test(security): scanner, secret and crypto tests run on the executor, process, http and keyring fakes, and scanners stop looking for mocks #1332's 2026-10-07 decision lets this item edit them.
Proposed Solution & Architectural Design
- Delete the
NonCallableMockimport,_is_mocked,_patched_run_subprocessand the mock-aware branches. A scanner asksdry_run.state.is_dry_run(),check_binary()and its tool executor directly. - Delete the
# noqa: F401re-imports in the seven scanner modules. - Rewrite the 62 sites onto the merged fakes:
scanner_fakeandToolExecutorFake(feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772) answer the tool runs and put the program on PATH; the dry-run state is set through its public API; a missing binary is a PATH without it.
Target Subsystem
src/devops_cli/security/ and the scanner tests.
Existing Tool Considered
The fakes exist: tests/support/fakes/tool_executor.py and tests/support/fakes/scanners.py (#772, #1666, #1982). Nothing new is built; the change deletes the accommodations.
Acceptance criteria
security/base.pyhas noNonCallableMock,_is_mockedor_patched_run_subprocess, and no scanner module has a# noqa: F401re-import ofrun_subprocess,is_dry_runorshutil.- No test patches
run_subprocess,is_dry_run,check_binaryorshutilonsecurity.baseor on a scanner module. - The rewritten tests pass on the fakes, offline.
Related
Parent: #1332. Owner of the accommodation: #1332 (#2512 named it). Bans at zero: #1336.
Source: #1332
Metadata
Metadata
Assignees
Labels
effort/mediumEffort Mediumpriority/p2-mediumPriority P2: standard worksource/agentFiled by an agenttype/refactorType refactor: a new structure, same behaviorvalue/mediumValue Medium
Activity
dan-petty commentedon Oct 28, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
The change removes mock-detection branches and re-imports from product code and rewrites tests onto existing fakes.It enforces an existing project rule but does not fix a defect or add user-facing behaviour.It removes 9 code violations of the no-test-accommodation rule and makes 62 test sites use the approved fakes.It touches base.py, seven scanner modules, and 62 patch sites across 11 test files, but no new code is written.Both remove test accommodations from product code; #2512 delivers the general ban and CI enforcement, while the candidate delivers the specific cleanup of security/base.py and seven scanner modules plus their 62 test sites.