Skip to content

test(scan): fake the scanners in the scan command tests - #4440

Merged
dan-petty merged 2 commits into
mainfrom
test/4321-fake-the-scanners-in-the-scan
Nov 11, 2026
Merged

dan-petty merged 2 commits into
mainfrom
test/4321-fake-the-scanners-in-the-scan

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Two tests of tests/commands/test_scan.py ran devops scan trivy, secrets and sast with no fake. In the devcontainer the real scanners are on PATH, and the floor refused them: 4 failures and 4 errors in each full local CI run. On the GitHub runner no scanner is on PATH, so each scan reported unavailable and the tests tested no scan that ran. The tests now use scanner_fake, script a clean Trivy run, and assert the full output and the scanner that each command started. The result is the same with and without the scanners on the host. It also delivers #4288.

Closes #4321

Change: openspec/changes/archive/2026-11-11-4321-fake-the-scanners-in-the-scan/

test_scan_individual_tools and the three cases of
test_scan_serialized_output_holds_status_reason_and_findings ran
devops scan trivy, secrets and sast with no fake. In the devcontainer
the real trivy, gitleaks and semgrep are on PATH, and the floor of the
suite refused them: 4 failures and 4 errors. On the GitHub runner no
scanner is on PATH, so each scan reported unavailable and the tests
tested no scan that ran.

The tests now ask for scanner_fake, which puts a stand-in for each
scanner on PATH and answers it at the tool executor seam. They script a
Trivy run that finds nothing, because the fake has no recorded Trivy
run. They assert the full output of a clean scan and the scanner that
each command started. The result is the same with and without the
scanners on the host.

Closes #4321
@dan-petty dan-petty added type/test Type test: a new or changed test scope/scan The devops scan command and its scanners labels Nov 11, 2026
@dan-petty

Copy link
Copy Markdown
Owner Author

Test evidence for this change (devcontainer, branch rebased on origin/main 6a09588).

Fail-to-pass. uv run devops ci fail-to-pass --base origin/main reports 0 failed on base (0 failed and 25 passed in tests/commands/test_scan.py; 0 errored). The replay runs the changed tests on the src/ tree of the base. This change edits no file under src/, so the changed tests also pass there. CONTRIBUTING.md gives no fail-to-pass check to a change of tests only, and the fail-to-pass workflow does not run for a test(...) title.

The defect is in the old tests. With the test file of origin/main in the devcontainer, where trivy, gitleaks and semgrep are on PATH:

  • uv run pytest tests/commands/test_scan.py -n 0 gives 4 failed, 21 passed, 4 errors. The floor reports "host path reached without a fake" for the trivy and gitleaks binaries and "process edge reached without a fake" for semgrep scan.
  • With a PATH that holds no scanner, the same file gives 25 passed, and each scan reports unavailable. So on the GitHub runner the old tests tested no scan that ran.

With this change:

  • uv run pytest tests/commands/test_scan.py -n 0 gives 25 passed with the scanners on PATH.
  • env PATH=/usr/local/bin:/usr/bin:/bin uv run pytest tests/commands/test_scan.py -n 0 gives 25 passed with no scanner on PATH.
  • uv run devops ci test tests/commands/test_scan.py tests/commands/test_scan_outcomes_and_gating.py tests/security/test_scanner_contract.py gives 62 passed.
  • uv run devops openspec check and uv run devops ci --check --only lint,format pass.

I did not run the full local devops ci: the shared CI lock was held with other runs in the queue. The GitHub checks cover the rest.

The guard that would stop the next test of this type on the GitHub runner is out of scope here. It is filed as #4439.

@dan-petty
dan-petty marked this pull request as ready for review November 11, 2026 01:08
@dan-petty
dan-petty merged commit 8f55fdd into main Nov 11, 2026
31 checks passed
@dan-petty
dan-petty deleted the test/4321-fake-the-scanners-in-the-scan branch November 11, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/scan The devops scan command and its scanners type/test Type test: a new or changed test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ci): scan tests reach the host scanner tools

1 participant