Repository navigation
test(review): scanner_fake answers the review scanners through the ToolExecutor fake, not through patched subprocess calls - #2121
Merged
Conversation
…olExecutor fake, not through patched subprocess calls ScannerFake is now a ToolExecutorFake, scripted with the recorded run of each scanner. The scanner_fake fixture sets DirectToolExecutor.run on the class, so every default executor answers through the fake, also the executors of the global scanner registry. A stand-in for each scanner that the fake answers is first on PATH. The fake patches no shutil or subprocess name. A request for another tool, and the canary run of a tool in a CONST_CANARY_WORKDIR_PREFIX working directory, go on to the run that the fixture replaced, so the recorded canary answers win. ToolExecutorFake takes require_commit and require_files. With both false, it records a run as the direct executor does, and the contract suite holds it to the direct executor. The agent scan tool tests script their answers with scanner_fake.script. docs/TESTING.md and the docstrings describe the new fake.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
scanner_fakedoubledshutil.whichandsubprocess.run. The review scanners and the agent scan tools start their tools through aToolExecutor(#1941, #1435), so the fake now answers them at that seam.What changes:
ScannerFake(tests/support/fakes/scanners.py) is aToolExecutorFake, scripted with the recorded run of each scanner. It answers a request for a scanner that it holds with the exit code, the standard output and the standard error of the run, and starts nothing.scanner_fakefixture setsDirectToolExecutor.runon the class. So every default executor answers through the fake, also the executors that the global scanner registry makes on import. A request for another tool goes on to therunthat the fixture replaced, under the floor's refusal of a real scanner.CONST_CANARY_WORKDIR_PREFIX, also goes on to thatrun. Since refactor(security): mypy and the review canary start their tools through a ToolExecutor #1978,pin_review_tool_canariesin the root conftest answers it with the recorded canary output, so the canary of a scanner that the fake holds still passes.bin_dir, and the fixture putsbin_dirfirst on PATH. The fake patches noshutilorsubprocessname.ToolExecutorFaketakesrequire_commitandrequire_files, which it gives torecord_tool_run. With both false, it records a run as the direct executor does.tests/test_tool_executor_contract.pyruns the two cases of an incomplete record over the direct executor and over this fake.tests/test_scanner_contract.pykeeps the recordings and the adapter cases. Its third case checks the stand-ins on PATH, the answer of the fake throughDirectToolExecutor, and a start of git through the direct executor. A new case checks that the canaries of Semgrep, Bandit, kube-linter and Pluto get the recorded canary answer when the fake holds an answer for the tool. Gitleaks and osv-scanner have no canary.ScannerRun.argvstarts with theprogramof the request when it names one, as the direct executor does.tests/test_builtin_tools.pyscript a failed scan or a Trivy report withscanner_fake.script(tool, ToolAnswer(...)), in place of a write toscanner_fake.recorded.tests/support/fakes/openspec.py,tests/test_scanner_contract.pyandtests/test_scanner_tool_executor.pydescribe the new fake.Evidence:
BaseSecurityScanner._run_toolis the only place undersrc/that makes aToolRequest.DirectToolExecutor, four registry tests oftests/test_security_semgrep.pyreached the real executor, and the floor refused Semgrep. So the fixture setsrunon the class.test_a_scan_of_a_checkout_that_git_cannot_read_still_runsgotfailedin place ofran. So the fake records as the direct executor does.test_pipeline_multi_scanner_aggregationandtest_review_pipeline_admit_inline_suppression_added_by_changeintests/test_review_security_tools.py, and two cached-ruleset tests intests/test_review_static_analyzers.py. When I removed the pass-through, all four parameters of the new canary case failed.scan_popeyeandscan_uv_auditstill run their own command lines (fix(security): the pluto, popeye and gitleaks adapters read what those tools actually write #1434, fix(security): scan_uv_audit runs a uv audit adapter, and the uv pip audit command that uv does not have goes #2106). No test reaches them throughscanner_fake.uv run devops ci testpassed 558 tests: the files that usescanner_fake, both contract suites,tests/test_security_gitleaks.py,tests/test_review_canary.pyandtests/test_review_tool_runs.py. The invariant tests passed too (123).The change alters no file under
src/, so it has no spec delta (skip_specs: true).Item
Closes #1982
Change:
openspec/changes/archive/2026-10-24-1982-scanner-fake-through-tool-executor/Fail-to-pass: not applicable: the change moves a fake and changes no product code, so the added and changed tests also pass over the base product code.