Skip to content

test(scan): scan command tests reach real trivy and semgrep #4288

Closed as not planned

Description

@dan-petty

Problem

Three tests in tests/commands/test_scan.py fail on main in the devcontainer. Each one reaches a real tool without a fake:

  • test_scan_individual_tools and test_scan_serialized_output_holds_status_reason_and_findings[trivy] reach the host path ~/.local/share/devops-cli/tools/trivy/0.75.0/trivy.
  • test_scan_serialized_output_holds_status_reason_and_findings[sast] starts a real semgrep scan process.

The edge guard of the test floor reports each one as "reached without a fake" and fails the test and its teardown (3 failures and 3 errors).

Steps to reproduce

  1. Use the devcontainer on current main (commit 84117ac).
  2. Run uv run pytest tests/commands/test_scan.py -q.

Expected

The tests fake the scanners at their seam. They pass on any host, with or without trivy, gitleaks and semgrep installed (rule: every test works in the devcontainer and on the GitHub runner).

Notes

The fix is to fake each scanner at its edge (docs/TESTING.md), or to mark a real run @pytest.mark.live. Found while checking the full CI run of PR #4285; the failures are not part of that PR.

Proposed design

Problem statement

Three tests in tests/commands/test_scan.py reach a real trivy binary or a real semgrep process. The edge guard of the hermetic floor fails each one as "reached without a fake". The tests are test_scan_individual_tools and the trivy and sast cases of test_scan_serialized_output_holds_status_reason_and_findings. They must pass on any host, with or without the scanners installed.

Acceptance criteria

Requirement: Individual scan tools use the scanner fake

The test test_scan_individual_tools SHALL run trivy, secrets and sast through scanner_fake and SHALL start no real scanner program.

Scenario: Individual tools with the fake

  • WHEN The test runs on a host with no trivy, gitleaks or semgrep installed
  • THEN Each scan command exits 0 and the floor reports no unfaked edge

Requirement: Serialized output tests use the scanner fake

The test test_scan_serialized_output_holds_status_reason_and_findings SHALL give each of the trivy, secrets and sast cases a scripted answer from scanner_fake.

Scenario: JSON and YAML output with the fake

  • WHEN The test invokes each scan subcommand with --json and with --format yaml
  • THEN The output holds the status, reason and findings keys and the test passes with no real tool

Requirement: The scan test file passes on any host

The file tests/commands/test_scan.py SHALL pass in the devcontainer and on the GitHub runner, with or without the scanners installed.

Scenario: Whole file run

  • WHEN uv run pytest tests/commands/test_scan.py -q runs on main with the fix
  • THEN No test fails and no teardown error occurs

Existing Tool Considered

The need is covered by the project's own fake, ScannerFake in tests/support/fakes/scanners.py behind the scanner_fake fixture (docs/TESTING.md, ADR 0007). It already exists and test_scan_serialized_output_with_findings uses it. No new code or outside tool is needed. The cost is a small edit of one test file, with a few thousand tokens and under one hour.

Key questions

  • Which seam fakes the scanners in these tests?: Use the scanner_fake fixture. docs/TESTING.md says a test whose code starts a scanner asks for scanner_fake, which answers the scanner request with a recorded run. The test test_scan_serialized_output_with_findings in the same file already does this for trivy. (best practice) [sources: docs/TESTING.md, tests/commands/test_scan.py]
    • Chosen: scanner_fake with scripted ToolAnswer. It is the one fake of the scanner edge and it is the project rule.
    • Rejected: Mark the tests @pytest.mark.live. The tests check CLI output, not the real tools, and a live run would not pass on every host.
    • Rejected: Patch the scan functions of devops_cli. docs/TESTING.md bans a patch of a devops-cli name.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/test
    scope/scan
    status/new
    value/medium
    effort/low
    on Nov 9, 2026
  2. dan-petty commented on Nov 9, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

  3. added
    priority/p2-medium
    on Nov 9, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 10, 2026
  5. devops-cli-service commented on Nov 10, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at e99dc01 (see proposed design in issue body).

  6. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    This issue is a duplicate of #4321. Pull request #4440, which closes #4321, delivers it: test_scan_individual_tools and the three cases of test_scan_serialized_output_holds_status_reason_and_findings now use scanner_fake. The file tests/commands/test_scan.py gives 25 passed with and without the scanners on PATH. I close this issue as not planned (duplicate).

  7. removed
    status/ready
    on Nov 11, 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/lowpriority/p2-mediumscope/scansource/agenttype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions