Skip to content

test(review): scanner_fake answers the review scanners through the ToolExecutor fake, not through patched subprocess calls - #2121

Merged
dan-petty merged 1 commit into
mainfrom
test/1982-scanner-fake-through-tool-executor
Oct 24, 2026
Merged

dan-petty merged 1 commit into
mainfrom
test/1982-scanner-fake-through-tool-executor

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Summary

scanner_fake doubled shutil.which and subprocess.run. The review scanners and the agent scan tools start their tools through a ToolExecutor (#1941, #1435), so the fake now answers them at that seam.

What changes:

  • ScannerFake (tests/support/fakes/scanners.py) is a ToolExecutorFake, 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.
  • The scanner_fake fixture sets DirectToolExecutor.run on 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 the run that the fixture replaced, under the floor's refusal of a real scanner.
  • A canary run, in a working directory named with CONST_CANARY_WORKDIR_PREFIX, also goes on to that run. Since refactor(security): mypy and the review canary start their tools through a ToolExecutor #1978, pin_review_tool_canaries in the root conftest answers it with the recorded canary output, so the canary of a scanner that the fake holds still passes.
  • The fake puts an executable stand-in for each scanner that it answers in bin_dir, and the fixture puts bin_dir first on PATH. The fake patches no shutil or subprocess name.
  • ToolExecutorFake takes require_commit and require_files, which it gives to record_tool_run. With both false, it records a run as the direct executor does. tests/test_tool_executor_contract.py runs the two cases of an incomplete record over the direct executor and over this fake.
  • tests/test_scanner_contract.py keeps the recordings and the adapter cases. Its third case checks the stand-ins on PATH, the answer of the fake through DirectToolExecutor, 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.argv starts with the program of the request when it names one, as the direct executor does.
  • The agent scan tool tests in tests/test_builtin_tools.py script a failed scan or a Trivy report with scanner_fake.script(tool, ToolAnswer(...)), in place of a write to scanner_fake.recorded.
  • docs/TESTING.md and the docstrings of tests/support/fakes/openspec.py, tests/test_scanner_contract.py and tests/test_scanner_tool_executor.py describe the new fake.

Evidence:

  • BaseSecurityScanner._run_tool is the only place under src/ that makes a ToolRequest.
  • When the fixture replaced only the name DirectToolExecutor, four registry tests of tests/test_security_semgrep.py reached the real executor, and the floor refused Semgrep. So the fixture sets run on the class.
  • A fake in the default mode refuses a checkout that git cannot read. With it, test_a_scan_of_a_checkout_that_git_cannot_read_still_runs got failed in place of ran. So the fake records as the direct executor does.
  • If the fake also answered the canary runs of its scanners, four review tests failed: test_pipeline_multi_scanner_aggregation and test_review_pipeline_admit_inline_suppression_added_by_change in tests/test_review_security_tools.py, and two cached-ruleset tests in tests/test_review_static_analyzers.py. When I removed the pass-through, all four parameters of the new canary case failed.
  • scan_popeye and scan_uv_audit still 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 through scanner_fake.
  • On main 35b5632, uv run devops ci test passed 558 tests: the files that use scanner_fake, both contract suites, tests/test_security_gitleaks.py, tests/test_review_canary.py and tests/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.

…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.
@dan-petty
dan-petty marked this pull request as ready for review October 24, 2026 15:29
@dan-petty
dan-petty merged commit b26caf9 into main Oct 24, 2026
17 checks passed
@dan-petty
dan-petty deleted the test/1982-scanner-fake-through-tool-executor branch October 24, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(review): scanner_fake answers the review scanners through the ToolExecutor fake, not through patched subprocess calls

1 participant