Repository navigation
Description
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_subprocess45,check_binary14,is_dry_run7. - Settings and the Vault lease:
load_settings12,vault_lease._post11. - Registry and HTTP broker:
ScannerRegistrymethods 11, the HTTP broker 9. - Keyring and GitHub:
get_keyring_secret7,github.ssh.register_key_on_github4. - At the edges:
shutil.which17,subprocess.run15,httpx2.Client.get13.
- Process layer:
- Scanners look for mocks.
security/base.pyimportsunittest.mock.NonCallableMock[code: security/base.py:17]._is_mockedsearchessys.modulesfor a patchedis_dry_run,check_binaryorrun_subprocessand calls it instead of the real function [code: security/base.py:327-335, :388-417].- Seven scanner modules re-import
run_subprocessoris_dry_rununder# noqa: F401only to be patch targets, andtflint.pyre-importsshutilthe 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_binaryorshutilonsecurity.baseor 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.py4,test_review_static_analyzers.py2).
- Edges are reached without a seam.
DependencyRemediator.scan_and_planbuildsOSVClient()inline [code: security/dependency_remediator.py:214].- The vulnerability lookups open three
httpx2.Clients [code: security/vulnerability_lookup.py:185, :307, :377]. - The Cloudflare Radar client builds a
ValkeyClientinline when no client is passed [code: security/vulnerability_lookup.py:392]. - SSH-key registration goes through PyGithub [code: github/ssh.py:37-45], which keeps its own HTTP stack until refactor(github): pull request, repository and ssh key calls move from pygithub onto the github session #891 moves those calls onto refactor(github): the github session owns transport, ledger, error classes and link pagination #983's GitHub session.
- The secret resolver builds
VaultSecretBroker()lazily [code: security/secrets.py:230]. global_scanner_registryis built at import [code: security/registry.py:98].
- Logic in commands (Q19).
- The
devops scangate 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 patchcommands.scannames 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_signingrunsgit config --globalfrom the command [code: commands/ssh.py:41-50].
- The
- Shape.
test_security_sarif.pyis 1,462 lines with 124 tests.test_reference_extractor.pyis 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.pyandtest_security_tflint.pytest one module. Two files are named after a consolidation refactor.- Ten module-level
runner = CliRunner()instances.
Acceptance criteria
Doubles only at edges
- No test of this item patches a devops_cli name or imports a private one. Today that is 159 sites and 34 imports.
- Scanner tests install feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772's executor fake with recorded tool output and assert the argv it received.
- Other processes go through refactor(cli): one process runner owns execution, process groups and dry-run #775's process fake. Git runs for real in temporary repositories with
HOMEundertmp_path(Q23). - OSV, Shodan, threat-intel and Vault HTTP goes through refactor(cli): Unify HTTP and DNS seams with shared fakes #1314's seam and fake. The inline clients above take theirs from it, and no test patches
vault_lease._postor the broker. - The Cloudflare Radar client's default Valkey client (
security/vulnerability_lookup.py:392) comes from refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317's seam, and its tests use refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317's Valkey fake. - Secrets come from refactor(security): one keyring seam owns the keyring and the Secret Service lock check, with a shared keyring fake and its contract suite #1318's keyring fake through the
SecretProviderseam [code: security/secrets.py:116]. - SSH-key registration runs on refactor(github): the github session owns transport, ledger, error classes and link pagination #983's GitHub session fake, which reaches it once refactor(github): pull request, repository and ssh key calls move from pygithub onto the github session #891 has moved it off PyGithub. No test patches
github.ssh.register_key_on_github. - Key-age checks use refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320's clock instead of patching
datetime. - Secret-masking checks on span attributes, among them the error-sample check that patches
core.process.trace_span[code: tests/test_security_sandbox_and_protection.py:150], read the exported spans from refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319's OTLP fake, opted into per test (Q28).
Accommodations (Q27)
- These are deleted, and scanners call
is_dry_run,check_binaryand the runner directly:- the
NonCallableMockimport (security/base.py:17); _is_mocked;- the three mock-aware wrappers.
- the
- The
# noqa: F401re-imports in the seven scanner modules are gone. All 58 dependent patch sites are rewritten onto the fakes, including the six 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.
Logic out of commands/ (Q19)
- The scan gate moves into
security/behind a public function and is tested there.commands/scan.pyrenders and exits. - The Vault lease registry moves into
security/vault_lease.py, and 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's floor resets it. - Git-signing configuration moves into
crypto/behind a public function.
Behaviour files and names
-
test_security_sarif.pyandtest_reference_extractor.pysplit by behaviour (Q10), and the catch-alls dissolve (Q8). - The two tflint files merge, and the consolidation-named files are renamed after their behaviour.
- SARIF, SBOM and AIBOM documents are syrupy snapshots (Q18).
- Hypothesis property tests (Q21) cover:
- redaction (
security/sanitizer.py); - suppression-policy evaluation (
security/suppression.py); - the known_hosts parser (
crypto/known_hosts.py).
- redaction (
- Findings are built with
make_finding, the builder test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312 puts intests/support/builders.py(Q20), in place of the local factories. - The ten module-level
CliRunner()s give way to 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'sclifixture (Q14).
Ratchets and coverage
- If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its ceilings, the accommodation ratchet included, drop by this item's removals, and the PR body states the counts before and after.
- If 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 added its interim
unreachable(...)marker, none remains in this item's files. A test that relied on the refusal installs the edge's fake in its refusing state. - Unreachable lines are deleted (Q22). Coverage stays at or above 90%.
-
uv run devops cipasses.
Key questions
- May this item edit tests 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 directory? Decided 2026-10-07: yes, for the six dependent sites. The item that owns an accommodation deletes it (Q27), and it cannot go while a test still relies on it.
- Do scanners get faked by feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772's executor or by refactor(cli): one process runner owns execution, process groups and dry-run #775's process fake? (proposed) By feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772's. Q24 gives each edge one seam, and once feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772 lands the scanners start their tools through its executor, so scanner tests install its fake. Processes the executor does not start use refactor(cli): one process runner owns execution, process groups and dry-run #775's fake.
- Which files? Decided 2026-10-07: each file goes to the package owning most of what it tests (Q17). Every test file is named in exactly one child's list, so the list above is this item's share wherever test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 places a file.
test_review_static_analyzers.pyis 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, andtest_review_security_tools.pyreferencesai/toolsmost and is test(mcp): mcp, agent and tool tests run on edge fakes #1330's. - Where does git-signing configuration live? (proposed)
crypto/ssh_keys.py, next to key generation.
Strategic alignment
- Depends on: test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313, feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772, refactor(cli): one process runner owns execution, process groups and dry-run #775, refactor(github): pull request, repository and ssh key calls move from pygithub onto the github session #891, refactor(github): the github session owns transport, ledger, error classes and link pagination #983, 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, refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319, refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320. Blocks: test(cli): Convert ratchets to bans and merge invariant tests #1336. Related: test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 (ratchets), test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327 (scan, vault and config commands), 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 (review uses the scanners), test(mcp): mcp, agent and tool tests run on edge fakes #1330 (builtin tools call the scanners), fix(security): each finding keeps its own fingerprint across unrelated edits, and deduplication and correlation give one result in every input order, in devops scan and in reviews #1141 (fingerprints), feat(cli): structured fuzzing of parsers and schema boundaries #416 (parser fuzzing).
- Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase E).
- Evidence tags are explained in test(cli): tests double only process edges and mirror the source tree #1307. Here [code: path:line] lines are at 5c45b1e, the release/v0.2.28 head, and the per-item counts were recounted there.
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
- Criterion 1: No test in this item patches a devops_cli name or imports a private name.
Verification: Run the patch census and confirm zero devops_cli patch targets and zero private imports. - Criterion 2: Scanner tests install the feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772 executor fake with recorded tool output.
Verification: Run scanner tests and confirm the fake records the argv it received. - Criterion 3: Other processes use the refactor(cli): one process runner owns execution, process groups and dry-run #775 process fake.
Verification: Run process tests and confirm git uses a temporary repository with HOME under tmp_path. - Criterion 4: OSV, Shodan, threat-intel and Vault HTTP use the refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 seam and fake.
Verification: Run HTTP tests and confirm no test patches vault_lease._post or the broker. - Criterion 5: Inline clients take their HTTP client from the refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 seam.
Verification: Inspect the code and confirm the tests build no inline client. - Criterion 6: The Cloudflare Radar default Valkey client comes from the refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317 seam.
Verification: Run Radar tests and confirm the tests use the refactor(ai): Valkey, Qdrant and the embedder each have one seam, with shared fakes and contract suites #1317 Valkey fake. - Criterion 7: Secrets come from 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 keyring fake through the SecretProvider seam.
Verification: Run secret tests and confirm no test patches the keyring. - Criterion 8: SSH-key registration runs on the refactor(github): the github session owns transport, ledger, error classes and link pagination #983 GitHub session fake.
Verification: Run SSH tests and confirm no test patches github.ssh.register_key_on_github. - Criterion 9: Key-age checks use the refactor(cli): tests control time: time-machine fakes wall-clock reads, and retry and rate-limit waits return at once and are recorded #1320 clock.
Verification: Run key-age tests and confirm no test patches datetime. - Criterion 10: Secret-masking checks read exported spans from the refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319 OTLP fake.
Verification: Run masking tests and confirm each test opts into the OTLP fake. - Criterion 11: Delete the NonCallableMock import, _is_mocked, and the mock-aware wrappers.
Verification: Inspect security/base.py and confirm the code has no accommodations. - Criterion 12: Delete the # noqa: F401 re-imports in the seven scanner modules.
Verification: Inspect the seven scanner modules and confirm no re-imports remain. - Criterion 13: Rewrite the 58 dependent patch sites onto the fakes.
Verification: Run the affected tests and confirm zero patches to the old targets. - Criterion 14: Move the scan gate into security/ behind a public function.
Verification: Run scan tests and confirm commands/scan.py renders and exits. - Criterion 15: Move the Vault lease registry into security/vault_lease.py.
Verification: Inspect the command and confirm it has no lease registry global. - Criterion 16: Move git-signing configuration into crypto/ssh_keys.py behind a public function.
Verification: Inspect commands/ssh.py and confirm it calls the public function. - Criterion 17: Split test_security_sarif.py and test_reference_extractor.py by behaviour.
Verification: Inspect the new files and confirm no catch-all tests remain. - Criterion 18: Merge the two tflint test files and rename consolidation names.
Verification: Inspect the test tree and confirm one tflint file exists. - Criterion 19: SARIF, SBOM and AIBOM documents use syrupy snapshots.
Verification: Run the document tests and confirm the syrupy assertions pass. - Criterion 20: Add Hypothesis property tests for redaction, suppression, and known_hosts parsing.
Verification: Run the property tests and confirm they cover the three modules. - Criterion 21: Build findings with make_finding from tests/support/builders.py.
Verification: Inspect the tests and confirm no local finding factories remain. - Criterion 22: Replace module-level CliRunner instances with the 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 cli fixture.
Verification: Inspect the tests and confirm no module-level CliRunner instances remain. - Criterion 23: If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, lower its ceilings by this item's removals.
Verification: Inspect the PR body and confirm it states before and after counts. - Criterion 24: Remove 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 unreachable markers and delete unreachable lines.
Verification: Run coverage and confirm no markers remain and coverage is at least 90%. - Criterion 25: The change passes the CI gate.
Verification: Run uv run devops ci and confirm it exits 0.
Key questions
- May this item edit tests 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 directory?: Yes, only for the six dependent patch sites. (proposed)
- Do scanners get faked by feat(review): review tools run through one injectable executor in a network-less sandbox with CPU, memory and time limits #772's executor or by refactor(cli): one process runner owns execution, process groups and dry-run #775's process fake?: 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. Processes the executor does not start use the refactor(cli): one process runner owns execution, process groups and dry-run #775 process fake. (proposed)
- Which files?: Each file goes to the package that owns most of what it tests. The named list is this item's share wherever test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313 places a file. test_review_static_analyzers.py belongs to 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. test_review_security_tools.py belongs to test(mcp): mcp, agent and tool tests run on edge fakes #1330. (proposed)
- Where does git-signing configuration live?: It lives in crypto/ssh_keys.py, next to key generation. (proposed)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Alternatives check of 2026-10-31: not-applicable.
Tool: none found.
Sub-issues
Collapse Sub-issuesSub-issues
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
16 remaining items
refactor(security): one keyring seam owns the keyring and the Secret …
dan-petty commentedon Oct 28, 2026
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:
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 parts:
NonCallableMock,_is_mocked,_patched_run_subprocessand the mock-aware branches insecurity/base.py, deletes the# noqa: F401re-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.commands/(Q19). After part 1.make_findingand theclifixture.#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.
refactor(security): the scanners stop looking for mocks, and their te…
test(security): the security and crypto tests split by behaviour, wit…
test(security): the security and crypto tests run on the process, clo…
devops-cli-service commentedon Oct 31, 2026
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.
docs(openspec): plan #2166 Remove dead imports and add F401 ratchet (#…