Repository navigation
Description
Problem
ProcessFake.run (tests/support/fakes/process.py) records the environment of a call and returns its answer. It does not run build_subprocess_env (src/devops_cli/core/process.py), which the real runner calls before a child starts. So a test with process_fake does not see an environment key that the real runner refuses with SecurityError, such as PYTEST_ADDOPTS (#2747).
#5887 is one result: the strength check of the implement job set PYTEST_ADDOPTS, every unit test passed over process_fake, and three implement runs stopped in production. The fix of #5887 adds one test that gives the recorded environment to build_subprocess_env. Other callers that pass env= have no such test.
Expected behavior
ProcessFake.run,run_asyncandspawn_detachedrun the same environment check as the real runner (build_subprocess_envwithenv,isolate_envandextra_allowed_env), so a refused key fails the test as it fails in production.- A census of the tests that the change makes fail decides each case: a fix of the caller, or a test that expects the refusal.
Related
- fix(roadmap): the strength check sets a denied env key #5887 (the strength check), fix(security): the subprocess environment guard accepts the pytest and npm keys that make a child write a file #2747 (the env deny list), ADR 0007 (tests double only process edges).
Alternatives check of 2026-11-17: not-applicable.
Class: test, no search.
Tool: none found.
Proposed design
Problem statement
The process fake does not run the runner's environment check, so a denied key such as PYTEST_ADDOPTS passes in tests and fails in production. The change makes ProcessFake.run, run_async and spawn_detached call build_subprocess_env with the same inputs as the runner. It then fixes each test that the check makes fail or adds a test that expects SecurityError.
Acceptance criteria
Requirement: Sync run refuses denied environment
ProcessFake.run SHALL call build_subprocess_env with the call's env, isolate_env and extra_allowed_env before it returns an answer.
Scenario: Denied key fails a sync run
- WHEN a test calls process_fake.run(["cmd"], env={"PYTEST_ADDOPTS": "-n 2"})
- THEN SecurityError is raised with the message "Prohibited dangerous environment variable override: 'PYTEST_ADDOPTS'".
Requirement: Async run refuses denied environment
ProcessFake.run_async SHALL call build_subprocess_env with the call's env, isolate_env and extra_allowed_env before it returns an answer.
Scenario: Denied key fails an async run
- WHEN a test awaits process_fake.run_async(["cmd"], env={"PYTEST_ADDOPTS": "-n 2"})
- THEN SecurityError is raised with the message "Prohibited dangerous environment variable override: 'PYTEST_ADDOPTS'".
Requirement: Detached spawn refuses denied environment
ProcessFake.spawn_detached SHALL accept an optional env mapping and call build_subprocess_env with it, isolate_env and extra_allowed_env before it returns a child.
Scenario: Denied key fails a detached spawn
- WHEN a test calls process_fake.spawn_detached(["cmd"], env={"PYTEST_ADDOPTS": "-n 2"})
- THEN SecurityError is raised with the message "Prohibited dangerous environment variable override: 'PYTEST_ADDOPTS'".
Requirement: Environment flags reach the check
ProcessFake.run, run_async and spawn_detached SHALL pass isolate_env and extra_allowed_env to build_subprocess_env and record them on the ProcessCall.
Scenario: Flags are forwarded
- WHEN a test calls each entry point with isolate_env=False and extra_allowed_env={"FOO"} and spies on build_subprocess_env
- THEN each spy call receives isolate_env false and extra_allowed_keys containing FOO, and each recorded call holds the same flags.
Requirement: Allowed environment still returns the answer
ProcessFake.run SHALL keep the scripted answer when the environment passes the check.
Scenario: Allowed env passes
- WHEN a test calls process_fake.run(["cmd"], env={"PATH": "/usr/bin"}) after scripting a zero exit
- THEN the call returns the scripted CompletedProcess with returncode 0 and records the caller env.
Existing Tool Considered
The alternatives check in the issue body records not-applicable for this test item (class test, no search) and names no tool. The change uses the existing ProcessFake and build_subprocess_env; no external tool covers the need. The written cost is about 2 to 4 hours and 30k to 60k tokens to change, keep and fix the fake and its tests.
Key questions
- Which ProcessFake entry points must run the runner's environment check?: ProcessFake.run, run_async and spawn_detached must each call build_subprocess_env before they return an answer or a child. [sources: tests/support/fakes/process.py, src/devops_cli/core/process.py:196]
- How should the fake apply build_subprocess_env?: Call build_subprocess_env with the call's env, isolate_env and extra_allowed_env as extra_allowed_keys, and let SecurityError propagate. Also record isolate_env and extra_allowed_env on the ProcessCall of run_async, as run does. Keep the recorded ProcessCall.env as the caller supplied it, so existing assertions stay valid. (best practice) [sources: src/devops_cli/core/process.py:196, tests/support/fakes/process.py]
- Chosen: Call build_subprocess_env and keep the caller env. It applies the real refusal check with the smallest change to recorded calls.
- Rejected: Call build_subprocess_env and record its sanitized result. It changes many ProcessCall.env assertions beyond the refusal behavior.
- Rejected: Copy the deny-list logic into ProcessFake. It duplicates the runner rule and can drift from build_subprocess_env.
- Should ProcessFake.spawn_detached accept an env mapping?: Yes. Add an optional env parameter to mirror the real runner, pass it to build_subprocess_env, and record it in ProcessCall.env. (best practice) [sources: tests/support/fakes/process.py, src/devops_cli/core/process.py:196]
- Chosen: Add optional env to spawn_detached. It gives the detached path the same refusal check as run and run_async.
- Rejected: Keep spawn_detached without env. It cannot refuse an explicit denied key, so it still differs from the runner.
- What should the implementer do with tests that the new check makes fail?: Run the full test suite. For each failure, fix the caller when it passes a denied key by mistake, or add a test that expects SecurityError when the refusal is the intended behavior. Record the census in the pull request body. (best practice) [sources: tests/support/fakes/process.py, src/devops_cli/core/process.py:196, tests/core/test_subprocess_env_boundary.py]
- Chosen: Fix callers and add refusal tests. It keeps the fake faithful to the runner and makes each failure explicit.
- Rejected: Disable the check for tests. It keeps the production-only failure that fix(roadmap): the strength check sets a denied env key #5887 exposed.
- Rejected: Change the deny list. It weakens the runner security rule to satisfy tests.
- Which test files should hold the new checks?: Add focused tests in tests/support/test_process_fake_env.py for run, run_async and spawn_detached. Extend tests/core/test_subprocess_env_boundary.py only if a shared boundary case belongs there. (best practice) [sources: tests/support/fakes/process.py, tests/core/test_subprocess_env_boundary.py]
- Chosen: New focused test file under tests/support. It keeps the fake's contract next to the fake and avoids a large existing module.
- Rejected: Add to tests/core/test_process.py. It tests the real runner, not the test fake.
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Activity
dan-petty commentedon Nov 15, 2026
Both address the PYTEST_ADDOPTS denial, but #5887 fixes the one caller while the candidate makes the fake reject all denied keys for every caller.fix(roadmap): the strength check sets a denied env key (#5892)
devops-cli-service commentedon Nov 17, 2026
Alternatives check: not-applicable (test item; no search).
devops-cli-service commentedon Nov 18, 2026
Status set to Ready at 86358b6 (see proposed design in issue body).