Skip to content

test(tests): the process fake skips the env check of the runner #5891

Done

Description

@dan-petty

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_async and spawn_detached run the same environment check as the real runner (build_subprocess_env with env, isolate_env and extra_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

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

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

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 15, 2026
  4. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Alternatives check: not-applicable (test item; no search).

  5. added
    status/ready
    and removed
    status/new
    on Nov 18, 2026
  6. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

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

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 25, 2026
  8. removed
    status/in-review
    owner/agent
    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