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
2 changes: 1 addition & 1 deletion docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Every new test follows these rules. Some of them name a path, fixture or check t

### Floor and ratchets

- Every test runs inside the hermetic floor, which the root conftest supplies: the network block, which also refuses a loopback connect to a port no socket in the test process binds and fails the test that made it, even when the code under test swallowed the refusal; the host path guard in `tests/conftest.py`, which fails a test that opens a file outside the checkout, the run's temporary directory and the interpreter. `tests/support/host_paths.py` holds the allowed roots. For a linked worktree it adds the common git directory. So a test in a worktree outside its main checkout can read the `HEAD` file of its own git directory. Such a worktree is the replay tree of `devops ci fail-to-pass` or the worktree of a runner. `tests/invariants/test_host_path_roots.py` holds the roots; the refusal to start a real gh or security scanner; the test's own data directory, config and gh config, with no way onto the session bus; a pinned GitHub identity, so a gh or git child gets a placeholder token, never the developer's login; a throwaway kubeconfig for the run; the config write guard, which fails a test when it opens a config file for writing, renames a file onto one or removes one outside the run's temporary directory, and names the test and the stack; the spend ledger write guard, which fails a test when it writes to the spend ledger outside the run's temporary directory; the home write guard, which fails a test when it opens a file for writing, renames a file onto one or removes one under the real home, the HOME that the floor replaces, outside the run's temporary directory, the checkout and the interpreter, and names the test and the stack; the refusal of a support helper to write outside the run's temporary directory, or at all outside a pytest run; and the workspace tripwire, which fails the run when a test writes to the workspace's `config.yaml` or to a tracked file.
- Every test runs inside the hermetic floor, which the root conftest supplies: the network block, which also refuses a loopback connect to a port no socket in the test process binds and fails the test that made it, even when the code under test swallowed the refusal; the host path guard in `tests/conftest.py`, which fails a test that opens a file outside the checkout, the run's temporary directory and the interpreter. `tests/support/host_paths.py` holds the allowed roots. For a linked worktree it adds the common git directory. So a test in a worktree outside its main checkout can read the `HEAD` file of its own git directory. Such a worktree is the replay tree of `devops ci fail-to-pass` or the worktree of a runner. `tests/invariants/test_host_path_roots.py` holds the roots; the refusal to start a real gh or security scanner; the test's own data directory, config and gh config, with no way onto the session bus; the removal of `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER`, which the pod of a runner Job sets and which wins over the config of the test, so a test is in a runner only when its config sets `roadmap.implement.in_runner`; a pinned GitHub identity, so a gh or git child gets a placeholder token, never the developer's login; a throwaway kubeconfig for the run; the config write guard, which fails a test when it opens a config file for writing, renames a file onto one or removes one outside the run's temporary directory, and names the test and the stack; the spend ledger write guard, which fails a test when it writes to the spend ledger outside the run's temporary directory; the home write guard, which fails a test when it opens a file for writing, renames a file onto one or removes one under the real home, the HOME that the floor replaces, outside the run's temporary directory, the checkout and the interpreter, and names the test and the stack; the refusal of a support helper to write outside the run's temporary directory, or at all outside a pytest run; and the workspace tripwire, which fails the run when a test writes to the workspace's `config.yaml` or to a tracked file.
- The floor fails a test that reaches a faked edge without its fake, with an error naming the edge.
- A test that checks a service that is down refuses it through `refusing_port`, a loopback port the test binds and never listens on, so the kernel refuses each connect as a stopped service would, and the service's retry waits return at once, as [Clock](#clock) says. A test that needs a service's answers fakes it at its edge, such as the model through `model_fake`.
- After every test, the floor calls the public reset of every process-wide cache and singleton, and an invariant test fails a module-level cache or `global` in `src/devops_cli` that has no reset there.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-11-12
skip_specs: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Design

## Decisions

- The floor removes `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER` in `isolate_devops_cli_config`. That fixture runs for each test and already sets `DEVOPS_CLI_CONFIG`, the variable of the config file. A setting variable wins over the config file, so the fixture that gives the test its config also removes the runner variable that would override that config.
- The fixture removes the variable, and does not set it to `false`. The default is false, and a test that needs the in-runner path sets `roadmap.implement.in_runner` in its config. A variable set to `false` would win over that config value.
- The new test runs the floor in pytester, with the variable set in the outer environment before the inner run starts. That is the order of the runner pod: the variable is in the environment before pytest starts. A fixture of the same test cannot set the variable before the autouse floor fixture runs.

## Rejected alternatives

- The removal in the `cluster_jobs` fixture of `tests/support/fakes/cluster_jobs.py`, as the issue proposes. With the variable set, `test_confirm_outside_a_runner_exits_1_and_runs_nothing`, `test_the_job_runs_no_step_unless_it_is_in_a_runner` and `test_a_job_outside_a_runner_does_not_touch_its_process` fail too, and none of them uses `cluster_jobs`. A removal in that fixture leaves these 3 tests failing in the runner pod.
- An autouse fixture in each affected test file. It repeats the setup in 3 files and leaves each new test file exposed. `test_roadmap_implement_records.py` shows this form: it removes the variable in the test itself.
- A removal of every `DEVOPS_CLI_` variable from the environment of the run. The floor sets `DEVOPS_CLI_CONFIG`, `DEVOPS_CLI_DATA_DIR`, `DEVOPS_CLI_USER_DATA_ROOT` and other variables itself, and a run can pass a variable on purpose. The runner manifest sets only one variable that the floor does not set.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Proposal: #3990

## Why

Issue #3990: the pod of a runner Job sets `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER=true`, and the implement job runs the test suite in that pod. A setting variable wins over the config file, and the floor of the suite does not remove this variable. So in the pod, `roadmap.implement.in_runner` is true in each test, also in a test that sets it false in its config. The tests of the outside-runner path then take the in-runner path and fail. In an implement run, these false failures start repair rounds that spend the token budget and stop the item.

## What Changes

- `isolate_devops_cli_config` in `tests/conftest.py`, the autouse fixture that gives each test its own config, removes `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER` for the test. With the `DEVOPS_CLI_CONFIG` and `DEVOPS_CLI_DATA_DIR` that the floor already sets, the floor now isolates each setting variable that the runner manifest sets. A test that needs the in-runner path sets `roadmap.implement.in_runner` in its config, as it does now.
- The test `test_the_job_runs_no_step_unless_the_setting_says_it_is_in_a_runner` in `tests/roadmap/implement/test_roadmap_implement_records.py` no longer removes the variable itself.
- A new test in `tests/invariants/test_hermetic_floor.py` runs the floor in pytester with the variable set in the outer environment, and the inner test sees no such variable and a false setting.
- `docs/TESTING.md` names the removal in the hermetic floor.
- The issue proposes the removal in the `cluster_jobs` fixture. The leak also fails 3 tests that do not use that fixture, so the change removes the variable in the floor (see `design.md`).
- The change alters no behavior a consumer observes. It changes only the test floor, its tests and a document. So it has no spec delta and sets `skip_specs: true`.
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

None.

## Impact

- Tests: the suite gives the same results in the pod of a runner Job and on a workstation.
- Files: `tests/conftest.py`, `tests/invariants/test_hermetic_floor.py`, `tests/roadmap/implement/test_roadmap_implement_records.py`, `docs/TESTING.md`.
- No path under `src/` changes.

## Feasibility

- The premise holds at `origin/main` (`f55a20b99`). `setting_sources` in `src/devops_cli/config/settings.py` puts `SettingVariables` before the config file, so the variable wins over the config of a test. `k8s/devops/cronjob-runner.yaml` sets 3 setting variables (`grep -c "name: DEVOPS_CLI_" k8s/devops/cronjob-runner.yaml` prints 3): `DEVOPS_CLI_CONFIG` and `DEVOPS_CLI_DATA_DIR`, which the floor already sets for each test, and `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER`, which no fixture of the floor removes.
- `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER=true uv run devops ci test tests/roadmap/implement/test_roadmap_implement_outside.py` gives 23 failed and 8 passed, as the issue says.
- The same variable also fails 3 tests that do not use `cluster_jobs`: `test_confirm_outside_a_runner_exits_1_and_runs_nothing` (`test_roadmap_implement_command.py`), and `test_the_job_runs_no_step_unless_it_is_in_a_runner` and `test_a_job_outside_a_runner_does_not_touch_its_process` (`test_roadmap_implement_job.py`). Each sets `in_runner` false in its config, and the variable wins.
- `test_roadmap_implement_records.py` holds the one test that removes the variable itself (`git grep -n "delenv(\"DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER\"" -- tests` prints 1 line).
- pytest 9.1.1 is in the lock. `monkeypatch.delenv(name, raising=False)` removes the variable for one test and puts it back at teardown.

## Existing Tool Considered

- pytest's built-in `monkeypatch` fixture covers the need: `monkeypatch.delenv(name, raising=False)`. The floor fixture already uses `monkeypatch.setenv` for the other variables. No new dependency and no new helper.
- The change deletes the `monkeypatch.delenv` call and the `monkeypatch` parameter of `test_the_job_runs_no_step_unless_the_setting_says_it_is_in_a_runner`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Tasks

## 1. The floor removes the runner variable from each test

Kind: behavior. Changes: `tests/invariants/test_hermetic_floor.py`, `tests/conftest.py`, `tests/roadmap/implement/test_roadmap_implement_records.py`.

- [x] 1.1 Write a failing test: in a pytester run whose outer environment sets `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER` to `true`, the inner test sees no such variable, and `roadmap.implement.in_runner` is false.
- Verification: `$ uv run devops ci test tests/invariants/test_hermetic_floor.py`
- [x] 1.2 Remove the variable in `isolate_devops_cli_config` of `tests/conftest.py`. Delete the removal in `test_the_job_runs_no_step_unless_the_setting_says_it_is_in_a_runner`.
- Verification: `$ uv run devops ci test tests/invariants/test_hermetic_floor.py tests/roadmap/implement/test_roadmap_implement_records.py`
- [x] 1.3 Run the tests that failed in the runner pod with the variable set.
- Verification: `$ env DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER=true uv run devops ci test tests/roadmap/implement/test_roadmap_implement_outside.py tests/roadmap/implement/test_roadmap_implement_command.py tests/roadmap/implement/test_roadmap_implement_job.py`

## 2. Documents

Kind: documents. Changes: `docs/TESTING.md`.

- [x] 2.1 Name the removal of the runner variable in the hermetic floor of `docs/TESTING.md`.
- Verification: `$ uv run devops ci --check --only docs`
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,10 @@ def isolate_devops_cli_config(
Telemetry export is off by default; when a test opts in through `config`, export goes to the
floor's refusing port, as the Valkey cache does. Qdrant's address is one no test binds, so a
test that reaches Qdrant without a double fails.

A setting variable wins over the config file, so the fixture also removes the one that the pod
of a runner Job sets and the floor does not: `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER` (#3990).
A test that needs the in-runner path sets `roadmap.implement.in_runner` through `config`.
"""
from devops_cli.config.settings import reset_settings_cache
from devops_cli.telemetry.tracer import reset_tracer
Expand All @@ -1003,6 +1007,7 @@ def isolate_devops_cli_config(
monkeypatch.setenv("DEVOPS_CLI_CONFIG", str(test_config))
monkeypatch.setenv("DEVOPS_CLI_TELEMETRY_ENDPOINT", f"http://{side_channel}")
monkeypatch.setenv("DEVOPS_CLI_AI_ALLOW_PRIVATE_NETWORK", "true")
monkeypatch.delenv("DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER", raising=False)
yield test_config
reset_settings_cache()
reset_tracer()
Expand Down
29 changes: 29 additions & 0 deletions tests/invariants/test_hermetic_floor.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,35 @@ def test_second_does_not_see_first_override(config):
result.assert_outcomes(passed=2)


def test_the_runner_variable_of_the_outer_environment_reaches_no_test(
pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch
) -> None:
"""The pod of a runner Job sets `DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER` before pytest starts,
and a variable wins over the config file (#3990). The floor removes the variable for each
test, so a test gets `roadmap.implement.in_runner` from its config alone."""
monkeypatch.setenv("DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER", "true")
result = _run_with_floor(
pytester,
monkeypatch,
"""
import os

from devops_cli.config.settings import load_settings

def test_the_default_is_outside_a_runner():
assert (
os.environ.get("DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER"),
load_settings().roadmap.implement.in_runner,
) == (None, False)

def test_the_config_puts_the_test_in_a_runner(config):
config(roadmap={"implement": {"in_runner": True}})
assert load_settings().roadmap.implement.in_runner is True
""",
)
result.assert_outcomes(passed=2)


def test_process_wide_state_resets_between_tests(
pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch
) -> None:
Expand Down
6 changes: 0 additions & 6 deletions tests/roadmap/implement/test_roadmap_implement_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from collections.abc import Callable
from pathlib import Path

import pytest

from devops_cli.config.constants import (
CONST_SERVICE_CONSECUTIVE_FAILURES_FILENAME,
CONST_SERVICE_METRIC_IMPLEMENT_CONSECUTIVE_FAILURES,
Expand Down Expand Up @@ -98,11 +96,7 @@ def test_implement_metric_constants_and_record_keys() -> None:

def test_the_job_runs_no_step_unless_the_setting_says_it_is_in_a_runner(
config: Callable[..., Path],
monkeypatch: pytest.MonkeyPatch,
) -> None:
# The pod of a runner Job sets the variable, and the suite runs in that pod.
monkeypatch.delenv("DEVOPS_CLI_ROADMAP_IMPLEMENT_IN_RUNNER", raising=False)

assert load_settings().roadmap.implement.in_runner is False

config(roadmap={"implement": {"in_runner": True}})
Expand Down