Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-01
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Design

## Decisions

- **Create stand-in files on PATH in the fixture, the same mechanism scanner_fake uses internally, rather than using scanner_fake directly.**: The test uses tool_executor_fake (a plain ToolExecutorFake) in most cases and needs only the PATH stand-ins so that shutil.which finds the tool. scanner_fake carries recorded answers that this test does not need. The design of #1982 confirms this: a test that needs a scanner missing gives it a PATH without the program.
- **Keep the fixture autouse and scoped to this test file.**: The fixture is local to tests/test_scanner_tool_executor.py and is not shared. Making it autouse keeps every test in the file covered without changing each test's signature.

## Rejected alternatives

- **Use scanner_fake directly in the test file.**: The test uses tool_executor_fake (a plain ToolExecutorFake) in most cases. scanner_fake is a ToolExecutorFake that carries recorded answers for Semgrep, Gitleaks, Bandit and osv-scanner. The test needs only the PATH stand-ins, not the recorded answers. Using scanner_fake would change the executor the test scripts and break the test's assertions on tool_executor_fake.requests.
- **Keep the shutil.which patch and add a noqa or exception to the convention.**: docs/TESTING.md states: A test doubles only edges. Everything inside the process runs for real. Patching a stdlib or SDK object itself, such as subprocess.run or time.sleep, is a fallback for stdlib edges only. The stand-in-on-PATH mechanism is the established pattern since #1982 and requires no exception.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Proposal

## Why

#2116: tests/test_scanner_tool_executor.py has an autouse fixture scanners_installed that patches shutil.which. docs/TESTING.md says tests double only process edges through shared fakes. Since #1982, scanner_fake puts an executable stand-in for each recorded scanner first on PATH and patches no shutil or subprocess name. The fixture in this file violates that convention.

## What Changes

- Replace the scanners_installed fixture in tests/test_scanner_tool_executor.py to create executable stand-in files in a temp directory and prepend that directory to PATH, instead of patching shutil.which.
- Remove the shutil import if it is no longer used in the file.
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `review-tool-runs`: test-fixture-makes-scanner-findable-on-path

## Impact

- Tests: `tests/test_scanner_tool_executor.py`

## Feasibility

- The premise is confirmed: tests/test_scanner_tool_executor.py:77 defines def scanners_installed(monkeypatch: pytest.MonkeyPatch) -> None: which patches shutil.which, as cited in the issue body and in openspec/changes/archive/2026-10-24-1982-scanner-fake-through-tool-executor/tasks.md:23.
- The stand-in-on-PATH pattern is established in tests/support/fakes/scanners.py (ScannerFake.script writes an executable stand-in in bin_dir, and the fixture puts bin_dir first on PATH), as documented in the design of #1982.
- First check: run grep -n 'shutil.which' tests/test_scanner_tool_executor.py to confirm the patch exists before the change.
- Second check: run uv run pytest tests/test_scanner_tool_executor.py -x to confirm all tests pass after the change.
- Third check: run grep -n 'monkeypatch.setattr.*shutil\|monkeypatch.setattr.*subprocess' tests/test_scanner_tool_executor.py to confirm no shutil or subprocess name is patched.

## Existing Tool Considered

No external tool is needed. The stand-in-on-PATH pattern already exists in tests/support/fakes/scanners.py (ScannerFake.script). This change reuses the same mechanism in the test fixture. No internal code is deleted; the fixture body is rewritten in place.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## ADDED Requirements

### Requirement: test-fixture-makes-scanner-findable-on-path
A test fixture that makes a review scanner findable SHALL place an executable stand-in file in a directory on PATH. It SHALL NOT patch a shutil or subprocess name.

#### Scenario: stand-in on PATH
- **WHEN** a test fixture makes a scanner binary findable for the tool executor
- **THEN** an executable file named after the scanner exists in a directory that is first on PATH, and no shutil.which or subprocess.run name is patched
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Tasks

## 1. Replace shutil.which patch with PATH stand-ins

Reads: none. Changes: `tests/test_scanner_tool_executor.py`.

- [ ] 1.1 Write a test that asserts the fixture creates an executable file in a directory on PATH and does not patch shutil.which. The test fails with the old fixture (which patches shutil.which) and passes with the new one (which creates a file on PATH), and verify that `uv run pytest tests/test_scanner_tool_executor.py -x` fails on the base
- [ ] 1.2 Rewrite the scanners_installed fixture. Remove the monkeypatch.setattr call on shutil.which. Instead, create a bin_dir under tmp_path, write an executable stand-in file for each scanner name the test needs, set the executable bit on each file, and prepend bin_dir to PATH with monkeypatch.setenv. Remove the shutil import if no other code in the file uses it, and verify that `uv run pytest tests/test_scanner_tool_executor.py -x` passes
- [ ] 1.3 Change no document, run `uv run devops docs generate --sync-readme`, and verify that `uv run devops ci docs` passes

## Workflow follow-up

- Pending a person: review the diff in tuicr (tuicr -r <base>..HEAD).
Loading