Skip to content

test(security): scanner, secret and crypto tests run on the executor, process, http and keyring fakes, and scanners stop looking for mocks #1332

Closed
4 of 4 issues completed

Description

@dan-petty

Problem

Phase E migration of security/ and crypto/. This item owns the 28 test files named below, by today's flat names (10,683 lines, 526 tests) [measured: AST pass at 5c45b1e]. #1313 places most of them under tests/security/ and tests/crypto/; a file named here belongs to this item wherever #1313 places it.

  • Scanners: test_security_{bandit,checkov,dive,gitleaks,kubeconform,semgrep,tflint,threat_intel,sarif,sandbox_and_protection}.py, test_tflint.py, test_consolidation_security_{scanner_base,sanitizer}.py, test_scan_{outcomes_and_gating,complexity}.py, test_sbom.py, test_aibom.py, test_secops.py, test_structural_invariant_hook.py, test_k8s_manifest_validation.py, test_reference_extractor.py, test_dependency_remediator.py, test_vulnerability_lookup.py.
  • Secrets: test_secret_resolution.py, test_vault_broker.py.
  • Crypto: test_crypto_tls.py, test_ssh.py, test_ssh_host_keys.py.

The evidence:

  • Tests patch internals. 159 of the 223 patch sites target a devops_cli name, in 15 files, and the files import 34 private names, 13 of them in test_reference_extractor.py [measured: census AST pass, files unchanged at 5c45b1e].
    • Process layer: run_subprocess 45, check_binary 14, is_dry_run 7.
    • Settings and the Vault lease: load_settings 12, vault_lease._post 11.
    • Registry and HTTP broker: ScannerRegistry methods 11, the HTTP broker 9.
    • Keyring and GitHub: get_keyring_secret 7, github.ssh.register_key_on_github 4.
    • At the edges: shutil.which 17, subprocess.run 15, httpx2.Client.get 13.
  • Scanners look for mocks.
    • security/base.py imports unittest.mock.NonCallableMock [code: security/base.py:17]. _is_mocked searches sys.modules for a patched is_dry_run, check_binary or run_subprocess and calls it instead of the real function [code: security/base.py:327-335, :388-417].
    • Seven scanner modules re-import run_subprocess or is_dry_run under # noqa: F401 only to be patch targets, and tflint.py re-imports shutil the same way [code: security/bandit.py:12; gitleaks.py:17, :19; kubelinter.py:15-16; pluto.py:14-15; popeye.py:11-12; semgrep.py:18-19; tflint.py:6, :12-13].
    • 58 patch sites in 10 test files aim at run_subprocess, is_dry_run, check_binary or shutil on security.base or one of these seven modules, so they rely on the mock detection or the re-imports. 27 of them use the re-imports. Six sit 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.py 4, test_review_static_analyzers.py 2).
  • Edges are reached without a seam.
  • Logic in commands (Q19).
    • The devops scan gate lives in the command: fail-on evaluation, failed and requested-but-not-run scanners, and policy loading [code: commands/scan.py:773, :797, :805, :820]. Its tests patch commands.scan names 10 times.
    • The Vault lease registry is a module global in the command, with a reset "for clean test isolation" [code: commands/vault.py:27-41].
    • _configure_git_signing runs git config --global from the command [code: commands/ssh.py:41-50].
  • Shape.
    • test_security_sarif.py is 1,462 lines with 124 tests. test_reference_extractor.py is 1,269 lines with four catch-alls (:592, :719, :816, :832).
    • More catch-alls: test_classify_license_all_branches [code: tests/test_aibom.py:149], test_crypto_ssh_keys_edge_cases [code: tests/test_ssh.py:538], test_vault_broker_error_branches [code: tests/test_vault_broker.py:142].
    • test_tflint.py and test_security_tflint.py test one module. Two files are named after a consolidation refactor.
    • Ten module-level runner = CliRunner() instances.

Acceptance criteria

Doubles only at edges

Accommodations (Q27)

Logic out of commands/ (Q19)

Behaviour files and names

Ratchets and coverage

Key questions

Strategic alignment

Proposed design

Problem statement

The security and crypto tests patch internal names and import private names. The scanners detect mocks and call patched functions. Some logic lives in commands instead of modules. This item moves the tests to the approved fakes and removes the mock accommodations.

Acceptance criteria

Key questions

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

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

Sub-issues

Sub-issues

4 of 4 Issues completed
Loading 4 sub-issues

Activity

  1. added
    type/test
    scope/security
    priority/p2-medium
    on Oct 7, 2026
  2. 16 remaining items

  3. dan-petty commented on Oct 28, 2026

    @dan-petty
    OwnerAuthor

    This item is larger than one pull request, so it is split into four sub-issues. Each has its own change and pull request. Measured on origin/main 1244cbf (2026-10-28).

    Evidence for the split:

    The parts:

    1. test(security): the scanners stop looking for mocks, and their tests run on the scanner fake #2542: the scanners stop looking for mocks. It deletes NonCallableMock, _is_mocked, _patched_run_subprocess and the mock-aware branches in security/base.py, deletes the # noqa: F401 re-imports in seven scanner modules, and rewrites the 62 dependent patch sites in 11 test files (the issue counted 58 in 10) onto the merged fakes. Built now.
    2. test(security): the security and crypto tests run on the process, clock and GitHub session fakes, and the scan gate, the Vault lease registry and git signing leave commands #2543: the other process, clock, settings and GitHub SSH-key patches move onto the merged fakes (refactor(cli): one process runner owns execution, process groups and dry-run #775, refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320, refactor(github): the github session owns transport, ledger, error classes and link pagination #983), and the scan gate, the Vault lease registry and the git-signing configuration leave commands/ (Q19). After part 1.
    3. test(security): Run security tests on HTTP, Valkey, keyring and OTLP fakes #2544: the HTTP, Valkey, secret and span tests move onto the fakes of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314, refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317, refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318 and refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319. After those merge.
    4. test(security): the security and crypto test files split by behaviour, with document snapshots, property tests and the shared builders #2545: the test files split by behaviour, with syrupy snapshots, Hypothesis property tests, make_finding and the cli fixture.

    #1309 is closed (2026-10-28), so the ratchet criteria of this item do not apply. #1336 bans the accommodations at zero after part 1.

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

  5. added
    status/in-review
    and removed
    status/ready
    on Oct 31, 2026
  6. removed
    status/in-review
    on Oct 31, 2026
  7. added a commit that references this issue on Nov 1, 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/highpriority/p1-highscope/securitytype/testvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions