Skip to content

test(tests): fail a scan test without fake on every host #4439

Done

Description

@dan-petty

Problem Description

The floor of the test suite refuses a real security scanner only when the host has that scanner on PATH. A test that starts a scan command with no scanner_fake therefore gives two results:

  • In the devcontainer, trivy, gitleaks and semgrep are on PATH (links in ~/.local/bin). The scanner starts, and the floor fails the test with "host path reached without a fake" or "process edge reached without a fake".
  • On the GitHub runner, no scanner is on PATH. shutil.which finds nothing, the scan reports unavailable, and the test passes.

So the required GitHub checks pass such a test, it merges, and every full local devops ci run then fails. This occurred with tests/commands/test_scan.py (#4321, #4288). The pull request of #4321 fixes those tests, but nothing stops the next test of this type.

Reproduction Steps

  1. On origin/main before the fix of fix(ci): scan tests reach the host scanner tools #4321, run env PATH=/usr/local/bin:/usr/bin:/bin uv run pytest tests/commands/test_scan.py -n 0. Result: 25 passed.
  2. Run uv run pytest tests/commands/test_scan.py -n 0 in the devcontainer, with the scanners on PATH. Result: 4 failed and 4 errors.

Expected vs Actual Behavior

Expected: a test that reaches a scanner with no fake fails on every host, also on the GitHub runner, so the required checks stop it before the merge.

Actual: the test fails only on a host where the scanner is installed.

A possible fix: for each name of tests/support/refused_programs.py, the floor puts a stand-in first on PATH, so shutil.which finds the scanner on every host and the refusal at subprocess.Popen fails the test. scanner_fake and a test that sets its own PATH (docs/TESTING.md: "a test that needs a scanner missing gives it a PATH without the program") replace PATH, so they keep their behavior. Confirm the premise against the full suite on the runner first.

Environment Diagnostics

Devcontainer on origin/main 1ca0133 (2026-11-11). GitHub runner: the Tests & Coverage check, which installs no scanner.

Logs, Traces, or Terminal Output

FAILED tests/commands/test_scan.py::test_scan_individual_tools - Failed: host path reached without a fake: ~/.local/share/devops-cli/tools/trivy/0.75.0/trivy
4 failed, 21 passed, 4 errors in 4.21s

Proposed design

Problem statement

The test floor refuses a real scanner only when the host has the scanner on PATH. A test without scanner_fake passes on the GitHub runner where no scanner is present. The same test fails in the devcontainer where the scanner is present. The change puts a stand-in for each refused program first on PATH. The refusal at subprocess.Popen then fails the test on every host.

Acceptance criteria

Requirement: Floor PATH holds refused programs

The test floor SHALL put an executable stand-in first on PATH for each program that refused_programs() returns.

Scenario: Host without a refused program

  • WHEN the floor builds PATH for a test on a host that has no refused program
  • THEN shutil.which finds each refused program in the floor's stand-in directory.

Requirement: Scan without fake fails

A test that starts a refused scanner without its fake MUST fail at the floor's subprocess.Popen refusal.

Scenario: Scan command without scanner fake

  • WHEN a test invokes a scan command that starts a refused scanner and gives no scanner_fake
  • THEN the test fails with the floor's refusal message and not with an unavailable scan result.

Requirement: Scanner fake keeps priority

The scanner_fake MUST keep its stand-in ahead of the floor stand-in on PATH.

Scenario: Scripted scanner run

  • WHEN a test scripts a scanner run through scanner_fake
  • THEN the scan uses the scripted answer and the floor stand-in does not run.

Requirement: Explicit PATH hides a program

A test that sets its own PATH without a refused program SHALL see that program as unavailable.

Scenario: Test removes a scanner from PATH

  • WHEN a test sets PATH to a directory that holds no refused program and asks shutil.which for that program
  • THEN shutil.which returns None.

Requirement: Stand-in directory is temporary

The floor MUST create the stand-ins under the run's temporary directory.

Scenario: Stand-in location

  • WHEN the floor creates the stand-ins for a test run
  • THEN the stand-in directory is under the run's temporary directory and no stand-in file is in the repository.

Existing Tool Considered

No alternatives check has run. No open, maintained tool covers a project-specific pytest floor that makes refused programs visible on every host. The change builds a small helper and a conftest hook. Build cost: about 2,000 tokens to write, 1,000 tokens to keep and fix, and about 1 hour elapsed.

Key questions

  • Which programs must get a stand-in?: Every name that refused_programs() returns: gh and each scanner binary in the scanner registry. [sources: tests/support/refused_programs.py, docs/TESTING.md:76]
  • How should the floor make a refused program visible on every host?: Prepend a directory of executable stand-ins to PATH in the floor fixture. Do not patch shutil.which. (best practice) [sources: docs/TESTING.md:76, docs/TESTING.md:244, tests/support/refused_programs.py]
    • Chosen: PATH stand-ins in the floor fixture. This matches the existing scanner fake and keeps a test's own PATH override authoritative.
    • Rejected: Patch shutil.which. The project avoids patches, and the refusal must stay at subprocess.Popen.
    • Rejected: Skip scan tests on a host without a scanner. A skip hides the defect and breaks the rule that a test must not skip on host state.
  • Where should the stand-ins live?: In a directory under the run's temporary directory. The floor prepends that directory to PATH for each test and restores PATH after. (best practice) [sources: docs/TESTING.md:242]
    • Chosen: Run temporary directory. The host path guard allows it, and the run removes it.
    • Rejected: System temporary directory outside the run. The host path guard can fail a test that opens it.
    • Rejected: Committed directory under tests/fixtures. Committed executables add files to the repository and can start by mistake.
  • How do scanner_fake and a test's own PATH keep their behavior?: scanner_fake puts its stand-in first on PATH after the floor. A test that sets PATH replaces the floor entry, so a missing scanner stays missing. [sources: docs/TESTING.md:244]
  • Should the change add a regression test?: Yes. Extend tests/invariants/test_suite_refuses_real_programs.py to check the floor PATH and the refusal of a scan without scanner_fake. (best practice) [sources: docs/TESTING.md, tests/invariants/test_suite_refuses_real_programs.py]
    • Chosen: Extend the existing invariant test. The file already owns the refusal of real programs.
    • Rejected: Add a new invariant file. The test documents keep one invariant file for each subject.
    • Rejected: Add no test. The defect passed CI because no test checked the floor on a host without scanners.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-11: not-applicable.
Class: test, no search.
Tool: none found.

Activity

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

    @dan-petty
    OwnerAuthor

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

    • Type: type/test. The test prefix of the title gives the type.
    • Scope: scope/tests. The (tests) scope of the title gives the scope.
    • Priority: P2-Medium. A gap in the test floor lets bad tests merge on the runner, but the immediate failing tests are already being fixed by #4321.
    • Value: Medium. Prevents a whole class of future scan tests from passing on the runner while failing locally.
    • Effort: Medium. Requires modifying the floor to inject PATH stand-ins and confirming the premise against the full suite on the runner.
    • Related: test(floor): every test sees the same tokenizer cache, mounts, process table, PATH and programs on every host, and no skip depends on the host #2165, which asks for a different change. Both address the floor leaving host state visible so tests differ across hosts, but #2165 was a broad audit of tokenizer cache, mounts, and PATH, while the candidate adds a specific mechanism: the floor injects stand-in executables on PATH
  3. added
    priority/p2-medium
    on Nov 11, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 11, 2026
  5. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

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

  6. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable

    Class: test. The check makes no search and no model call for an item of this class.

    Tool: none found

    Checked on 2026-11-11. A person decides what this means for the item. The check changes no label and closes no issue.

  7. added
    owner/service
    and removed
    owner/service
    on Nov 22, 2026
  8. 24 remaining items

  9. added
    status/planned
    owner/service
    status/in-progress
    and removed
    status/ready
    status/planned
    on Nov 24, 2026
  10. devops-cli-service commented on Nov 24, 2026

    @devops-cli-service
    Contributor

    Stopped at group 1.

    Failed check: uv run devops ci test.

    Failure class: limit_reached.
    Action taken: repair, 1 fix round(s).
    Action left: raise_limit: raise the limit that the run went over.

    Step Status Attempts Tokens in/out Last failing command
    group 1 stopped 2 9563138/81558 uv run devops ci test

    Reason:

    LimitReached: The step spent its budget `roadmap.implement.step_time_limit_seconds=10800`.
    Refused commands: uv 1, other:9d1e30b32c01 1. Other retries: 3.
    

    Last message of the agent (a claim that no check verified): The suite needs ~3300 s at 1 worker here, but the test row of devops ci stops at 1800 s. Let me check whether more workers help on this pod:

    The job discarded this work. Read it before you retry:

    diff --git a/openspec/changes/4439-fail-a-scan-test-without-fake/tasks.md b/openspec/changes/4439-fail-a-scan-test-without-fake/tasks.md
    index 1c5d95224..b5235b689 100644
    --- a/openspec/changes/4439-fail-a-scan-test-without-fake/tasks.md
    +++ b/openspec/changes/4439-fail-a-scan-test-without-fake/tasks.md
    @@ -4,7 +4,7 @@
     
     Kind: other. Reads: `tests/support/refused_programs.py`, `tests/conftest.py`, `tests/support/host_paths.py`, `tests/support/fakes/scanners.py`. Changes: `tests/support/refused_programs.py`, `tests/conftest.py`.
     
    -- [ ] 1.1 In `tests/support/refused_programs.py`, add the constant `REFUSED_STAND_IN_DIRNAME` with the value `refused-program-bin` and the function `stand_in_directory(directory: Path) -> Path`. It makes the directory, writes for each name that `refused_programs()` returns the file `directory / name` with the two lines `#!/bin/sh` and `exit 127`, sets mode 0o755, and returns the directory. In `tests/conftest.py`, add the session-scoped autouse fixture `refused_program_stand_ins(tmp_path_factory)` beside `tests/conftest.py:def refuse_real_programs`. It calls `stand_in_directory(tmp_path_factory.getbasetemp() / REFUSED_STAND_IN_DIRNAME)`, puts that path first on `os.environ["PATH"]`, and restores the earlier value in a `finally`. Leave `tests/support/fakes/scanners.py` unchanged, because `scanner_fake` replaces PATH with its own directory and the interpreter directory
    +- [x] 1.1 In `tests/support/refused_programs.py`, add the constant `REFUSED_STAND_IN_DIRNAME` with the value `refused-program-bin` and the function `stand_in_directory(directory: Path) -> Path`. It makes the directory, writes for each name that `refused_programs()` returns the file `directory / name` with the two lines `#!/bin/sh` and `exit 127`, sets mode 0o755, and returns the directory. In `tests/conftest.py`, add the session-scoped autouse fixture `refused_program_stand_ins(tmp_path_factory)` beside `tests/conftest.py:def refuse_real_programs`. It calls `stand_in_directory(tmp_path_factory.getbasetemp() / REFUSED_STAND_IN_DIRNAME)`, puts that path first on `os.environ["PATH"]`, and restores the earlier value in a `finally`. Leave `tests/support/fakes/scanners.py` unchanged, because `scanner_fake` replaces PATH with its own directory and the interpreter directory
       - Verification: `$ uv run devops ci test` passes
     
     ## 2. Fail a scan that runs with no scanner_fake
    diff --git a/tests/conftest.py b/tests/conftest.py
    index 71bb720dd..5c3ede17a 100755
    --- a/tests/conftest.py
    +++ b/tests/conftest.py
    @@ -618,6 +618,30 @@ def refuse_real_programs() -> None:
         setattr(subprocess.Popen, "__init__", refusing_init)
     
     
    +@pytest.fixture(autouse=True, scope="session")
    +def refused_program_stand_ins(tmp_path_factory: pytest.TempPathFactory) -> Iterator[None]:
    +    """Put an executable stand-in for each refused program first on PATH for the whole run (#4439).
    +
    +    A test that starts a refused program with no fake then finds it on every host, so the
    +    `subprocess.Popen` refusal of `refuse_real_programs` fails it on a GitHub runner that holds no
    +    scanner as it does in the devcontainer. The stand-ins sit under the run's temporary directory,
    +    so no file of the repository holds one. A test that installs `scanner_fake`, or that sets its
    +    own PATH, still hides them.
    +    """
    +    from tests.support.refused_programs import REFUSED_STAND_IN_DIRNAME, stand_in_directory
    +
    +    directory = stand_in_directory(tmp_path_factory.getbasetemp() / REFUSED_STAND_IN_DIRNAME)
    +    previous = os.environ.get("PATH")
    +    os.environ["PATH"] = os.pathsep.join([str(directory), *([previous] if previous else [])])
    +    try:
    +        yield
    +    finally:
    +        if previous is None:
    +            os.environ.pop("PATH", None)
    +        else:
    +            os.environ["PATH"] = previous
    +
    +
     _HOST_PATH_GUARD_INSTALLED = False
     
     
    diff --git a/tests/support/refused_programs.py b/tests/support/refused_programs.py
    index 940d2294b..06bd2b24a 100644
    --- a/tests/support/refused_programs.py
    +++ b/tests/support/refused_programs.py
    @@ -7,10 +7,21 @@ suite's in-process network block cannot see. They are read from the registry whe
     starts, so a scanner added to it is refused with no list to edit. Building the registry once a
     worker has collected its tests took 0.02-0.08 s on 2026-10-20: the conftest has already loaded
     the modules it imports.
    +
    +`stand_in_directory` writes an executable stand-in for each of those names, and the root
    +conftest's `refused_program_stand_ins` puts that directory first on PATH for the whole run
    +(#4439). A test that starts a refused program with no fake then finds it on every host, so the
    +refusal fails the test on a GitHub runner that holds no scanner as it does in the devcontainer.
     """
     
     from __future__ import annotations
     
    +from pathlib import Path
    +
    +# The name of the directory of stand-ins under the run's temporary directory, which the fixture
    +# that builds them and the invariant that checks them both name.
    +REFUSED_STAND_IN_DIRNAME = "refused-program-bin"
    +
     
     def refused_programs() -> frozenset[str]:
         """gh, and the binary of every scanner the security scanner registry holds."""
    @@ -22,3 +33,18 @@ def refused_programs() -> frozenset[str]:
         return frozenset(
             {CONST_GH_CLI, *(scanner.binary_name for scanner in scanners if scanner is not None)}
         )
    +
    +
    +def stand_in_directory(directory: Path) -> Path:
    +    """Make `directory` hold an executable stand-in for each refused program, and return it.
    +
    +    Nothing starts a stand-in: the floor refuses the program by its name at `subprocess.Popen`
    +    before any process runs. The file exists so that `shutil.which` finds the program on a host
    +    that holds none, which makes a test with no fake fail there as it does on a workstation.
    +    """
    +    directory.mkdir(parents=True, exist_ok=True)
    +    for name in refused_programs():
    +        stand_in = directory / name
    +        stand_in.write_text("#!/bin/sh\nexit 127\n", encoding="utf-8")
    +        stand_in.chmod(0o755)
    +    return directory

    The item is Blocked, and the job will not run it. Fix the cause. Then comment implement: retry. The Service clears the stop on its own when a new runner image rolls out, but only if a retry can fix the class of the stop and the limits of roadmap.implement.digest_clears_per_class and roadmap.implement.digest_clears_per_item allow it.

  11. added
    status/blocked
    and removed
    status/in-progress
    owner/service
    on Nov 24, 2026
  12. added
    status/in-progress
    status/in-review
    and removed
    status/blocked
    status/in-progress
    on Nov 25, 2026
  13. removed
    status/in-review
    on Nov 25, 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/mediumpriority/p2-mediumscope/testssource/agenttype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions