Skip to content

fix(tests): isolate in_runner setting in cluster_jobs test fixture #3990

Closed

Description

@dan-petty

Problem Description

The test fixture cluster_jobs in tests/support/fakes/cluster_jobs.py does not isolate roadmap.implement.in_runner or DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER. When tests run in an environment where roadmap.implement.in_runner is true (such as inside the roadmap Service runner pod), the command roadmap implement takes the in-runner execution path rather than the outside-runner execution path. This causes 23 tests in tests/roadmap/implement/test_roadmap_implement_outside.py to fail with AssertionError: assert (0, True, False, []) == (0, True, True, []). In an implement run, these false failures cause the runner pod to start an unnecessary repair loop that spends the token budget and stops the item.

Reproduction Steps

  1. Run DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER=true uv run pytest tests/roadmap/implement/test_roadmap_implement_outside.py
  2. Observe 23 test failures.

Expected vs Actual Behavior

Expected: Tests in tests/roadmap/implement/test_roadmap_implement_outside.py isolate their environment and pass regardless of whether the outer environment runs inside a runner pod.
Actual: The tests inherit DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER=true and fail.

Environment Diagnostics

  • DevOps CLI Version: 0.77.2
  • Python Version: 3.14.10
  • Execution Environment: Kubernetes runner pod / Local DevContainer

Proposed design

Problem statement

The cluster_jobs test fixture does not clear DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER. When the outer environment sets it true, as the runner pod does, 23 tests in tests/roadmap/implement/test_roadmap_implement_outside.py take the in-runner path and fail. The false failures start an unnecessary repair loop in the runner pod. The fix isolates the setting in the fixture.

Acceptance criteria

Requirement: The fixture clears the in-runner variable

The cluster_jobs fixture SHALL remove DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER from the process environment for each test that uses it.

Scenario: The outer environment runs inside a runner

  • WHEN a test that uses the cluster_jobs fixture starts while DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER is true in the environment
  • THEN os.environ holds no DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER inside the test

Requirement: The outside-runner tests pass in a runner pod

The tests in tests/roadmap/implement/test_roadmap_implement_outside.py SHALL pass when DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER=true is set in the outer environment.

Scenario: The outside-runner suite runs with the variable set

  • WHEN the command DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER=true uv run pytest tests/roadmap/implement/test_roadmap_implement_outside.py runs
  • THEN pytest reports that all tests passed

Requirement: The runner guard test keeps its setting

The test test_in_a_runner_the_command_starts_no_job_and_keeps_the_guard MUST still take the in-runner path after the fixture change.

Scenario: The guard test sets the setting in the config

  • WHEN test_in_a_runner_the_command_starts_no_job_and_keeps_the_guard runs with roadmap.implement.in_runner true in the config
  • THEN the command exits with code 1, prints runs only as the GitHub App, and makes no kubectl call

Requirement: A test proves the isolation

A test SHALL prove that the cluster_jobs fixture removes the variable that the outer environment sets.

Scenario: A test sets the variable before it requests the fixture

  • WHEN a test sets DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER to true in a fixture that runs before cluster_jobs
  • THEN the test asserts that os.environ holds no DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER

Existing Tool Considered

No alternatives check has run. The need is covered by pytest's built-in monkeypatch fixture, which tests/support/fakes/cluster_jobs.py already uses to set DEVOPS_CLI_TELEMETRY_ENABLED. It lacks nothing for this change: monkeypatch.delenv(name, raising=False) removes the variable and restores it after the test. No new dependency and no custom isolation code are needed.

Key questions

  • Where should the test isolate roadmap.implement.in_runner?: In the shared cluster_jobs fixture, which already sets DEVOPS_CLI_TELEMETRY_ENABLED for the test. (best practice) [sources: tests/support/fakes/cluster_jobs.py, tests/roadmap/implement/test_roadmap_implement_outside.py, tests/commands/k8s/test_k8s_run_job.py]
    • Chosen: Shared cluster_jobs fixture. Both test files that start a Job use this fixture, and it already sets an environment variable for the test.
    • Rejected: Autouse fixture in test_roadmap_implement_outside.py. It leaves tests/commands/k8s/test_k8s_run_job.py exposed and repeats the setup.
    • Rejected: The cli fixture. Every command test uses it, so a broad environment change risks unrelated tests.
  • Should the fixture delete the variable or set it to false?: Delete it with monkeypatch.delenv("DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER", raising=False). (best practice) [sources: tests/support/fakes/cluster_jobs.py, docs/ENV_VARS.md:109]
    • Chosen: Delete with monkeypatch.delenv. The default is false, and the config file stays free to set in_runner true for the guard test.
    • Rejected: Set to false with monkeypatch.setenv. It sets one value for every test and can override the config file value that the guard test needs.
  • Does the guard test still pass after the fixture removes the variable?: Yes. The test sets roadmap.implement.in_runner to true in the config file, so it does not read the environment variable. [sources: tests/roadmap/implement/test_roadmap_implement_outside.py, docs/ENV_VARS.md:109]
  • How does the test suite prove the isolation?: A test sets the variable in a fixture that runs before cluster_jobs, and then asserts that the variable is absent. (best practice) [sources: tests/support/fakes/cluster_jobs.py, tests/commands/k8s/test_k8s_run_job.py]
    • Chosen: A test with an earlier fixture. It proves the fixture removes the outer value, and it runs offline.
    • Rejected: A CI job that sets the variable for the whole file. It adds a second test invocation and does not check the fixture itself.
    • Rejected: No new test. The regression can return without a failure.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-09: in-use.
The item already names this tool.
Tool: pytest (https://pypi.org/project/pytest), MIT, last activity 2026-10-27, maintained.

Activity

  1. added
    source/agent
    type/bug
    scope/tests
    status/new
    value/medium
    effort/low
    on Nov 7, 2026
  2. dan-petty commented on Nov 7, 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/bug. The fix prefix of the title gives the type.
    • Scope: scope/tests. The (tests) scope of the title gives the scope.
    • Priority: P2-Medium. False test failures cause the runner pod to start an unnecessary repair loop and stop the item, but only in the runner pod environment.
    • Value: Medium. It prevents 23 false test failures and the resulting operational damage in the runner pod.
    • Effort: Low. Isolating one environment variable in a single test fixture is a small, targeted change.
    • Related: test(roadmap): add the seams the serve and ci tests still lack #3885, which asks for a different change. Both address missing test isolation in the roadmap test suite, but #3885 adds seams for serve and CI tests while the candidate isolates an environment variable in the cluster_jobs fixture.
  3. added
    priority/p2-medium
    on Nov 7, 2026
  4. added
    status/ready
    and removed
    status/new
    on Nov 8, 2026
  5. devops-cli-service commented on Nov 8, 2026

    @devops-cli-service
    Contributor

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

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

    @devops-cli-service
    Contributor

    Alternatives check: in-use

    Reason: pytest's built-in monkeypatch.delenv(name, raising=False) removes the variable for one test and restores it afterwards. This covers the whole need. The issue says the fixture already uses monkeypatch, and pytest is maintained: the latest release is 9.2.0, uploaded 2026-10-27. My web search returned only unrelated pages. I did not read pytest's documentation, so this rests on the issue text and the PyPI facts.

    The item already names this tool.

    Tool: pytest (https://pypi.org/project/pytest)

    • License: MIT
    • Last activity: 2026-10-27
    • Maintained: yes

    Covers:

    • Removing an environment variable per test with automatic restore
    • Already used in the cluster_jobs fixture for DEVOPS_CLI_TELEMETRY_ENABLED

    Lacks:

    • The new test that proves the isolation still has to be written
    • The guard-test check still has to be done

    Tools considered:

    Searches run:

    • pytest monkeypatch.delenv raising=False remove environment variable test isolation, results: 5

    Sources:

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

  7. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 12, 2026
  8. removed
    status/in-review
    owner/agent
    on Nov 12, 2026
  9. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 12:40 UTC

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/testssource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions