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
1 change: 1 addition & 0 deletions docs/SDLC.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ CI is the authoritative gate ([ADR 0004](adr/0004-ci-is-the-authoritative-gate.m
12. `lockfile`: Verifies lockfile synchronization via `uv lock --check`.
13. `outdated`: Inspects dependency tree for outdated packages via `uv tree --outdated`.
14. `openspec`: Runs `devops openspec check`, the OpenSpec gate: `openspec validate --all --strict` and `--archived`, a regeneration of the committed skills under the isolated profile compared with the tree, the instructions of a probe change with nothing on standard error, and a check that no requirement is rewritten by two active changes. It needs Node and the pinned `openspec` (`uv run devops install-tools --tool openspec --only-missing`), runs in every `devops ci` and in the `static` job with no path filter and no exemption, and runs alone in a commit hook when a commit touches `openspec/` or the generated skills ([ADR 0010](adr/0010-openspec-is-the-spec-and-change-proposal-layer.md)).
15. `bwrap`: Runs the tests marked `bwrap` of the two contract suites of the sandbox (`pytest -m bwrap -n 0 --timeout=60`) in the real sandbox. It runs where the host can make the sandbox of a review: in the devcontainer, and in `Static Analysis` on its GitHub-hosted runner, with no install. On a host that cannot, it starts no test and shows as skipped with the cause.

#### Where a Check Runs
- A check that does not apply to a change does not run for it: scope its trigger, for example with a path filter, as the jobs below do. Do not add an escape, an exemption or a special case to make a check pass.
Expand Down
6 changes: 3 additions & 3 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ Every new test follows these rules. Some of them name a path, fixture or check t
- **Real**: the filesystem under `tmp_path`; environment and config, through the hermetic floor and the `config` fixture; in-process servers, such as FastAPI's `TestClient` and loopback servers; randomness; host identity; and stdin, through `CliRunner(input=...)`.
- A test of `src/` starts no system program. Real child processes stay only in the contract suite of the process runner (`tests/core/test_process_contract.py` and the process-group tests of `core/process.py`).
- Every other real tool goes to one of two places: a contract suite that replays recorded transcripts of the tool, or a row of `devops ci`. A check of committed files or of tool configuration is a row of `devops ci`, not a pytest test. The code of these rows is in `tests/gate/`, one module for each row, outside `tests/support/` because a pytest process imports a support module that imports pytest or another support module, and it runs none of these checks. The rows are `lint` (the settings of Ruff), `constructs` (`ast-grep test` and the construct gate), `k8s` (the `kubectl kustomize` renders of the committed manifests, each rendered once), `test-tree` (the invariants that read every Python file of `src/` and `tests/`), `startup-imports` and `swallowed-failures`. A check is a function named `check_*` that asserts, and the runner `tests/gate/runner.py` runs it as pytest would, with `parametrize` marks and `tmp_path`. A test of the logic of a check gives it a small tree or canned output and starts no program.
- The bwrap cases are an opt-in contract suite that a person runs in the devcontainer. CI does not run them, and a default test run does not run them.
- The bwrap cases are an opt-in contract suite: a default test run deselects them, and `-m bwrap` selects them. The `bwrap` row of `devops ci` runs them where the host can make the sandbox of a review: in the devcontainer, and in `Static Analysis` on its GitHub-hosted runner, with no install. On a host that cannot, the row starts no test and shows as skipped with the cause. The row gives each test a bound of 60 s, shorter than the limit of the gate step of `Static Analysis`. A bwrap case that reads the process table of the host starts `ps` under `@pytest.mark.live("ps")`, because the floor keeps the test process out of `/proc`.
- A test must not skip based on host state. A test that cannot run the same on every host is a contract case or a `devops ci` row.
- No test starts a real gh, which would act as the developer's own login: a gh command a test reaches goes to a fake, and the floor fails a test that starts gh.
- No test starts a real security scanner either: a scanner fetches rule packs and advisories from a child process the network block does not see. The floor refuses gh and the binary of every scanner the security scanner registry holds, names `tests/support/refused_programs.py` reads from the registry when the run starts, so a scanner added there is refused with no list to edit. The refusal sits at `subprocess.Popen`, beneath every seam, and fails the test with `pytest.fail`, which no `except Exception` in the code under test hides. A test whose code starts a scanner asks for `scanner_fake`, which answers the scanner's request to the tool executor with the scanner's run recorded from the real tool.
- No test of `src/` starts a real sandbox. A review runs its tools in the bubblewrap sandbox by default, so a real scanner would start as the program that bubblewrap confines, where the refusal by name does not see it. The floor refuses bwrap in tests. The bwrap cases are an opt-in contract suite that a person runs in the devcontainer; CI does not run them. A test of the sandbox executor fakes the process edge with `process_fake`.
- No test of `src/` starts a real sandbox. A review runs its tools in the bubblewrap sandbox by default, so a real scanner would start as the program that bubblewrap confines, where the refusal by name does not see it. The floor refuses bwrap in tests. The bwrap cases are an opt-in contract suite that the `bwrap` row of `devops ci` runs. A test of the sandbox executor fakes the process edge with `process_fake`.
- No test starts sudo, which changes the host, or uv installing or syncing from PyPI, and the floor refuses both. The gate's own `uv audit`, `npm audit`, `uv tree --outdated` and `uv check` are its intended network checks, run by `devops ci`, never by a test.
- A detached child, which runs on after the command that started it, such as the forward of `devops k8s tunnel start` or of `devops k8s port-forward`, starts through the process runner's `spawn_detached`. `process_fake` records it as a call with `detached` set, and answers with the `process` of its `ProcessAnswer`: a process that the test started itself, such as `git hash-object --stdin` in a session of its own, or a callable that takes the call and returns one. With no `process`, the child has ended at once. A call also records `extra_allowed_env`, the names of ambient variables that the caller lets the child inherit besides the base set, so a test can assert that a program gets only the variables it needs.
- git has one seam, the process runner: every start of git in `src/devops_cli` goes through `run_subprocess`, and no module imports GitPython or starts git with `subprocess`, which an invariant test enforces. The `git_fake` fixture installs `GitFake` (`tests/support/fakes/git.py`) through that seam. `GitFake` is a `ProcessFake` that answers a git command from a transcript, a file of `tests/fixtures/git/` that records one scenario of `tests/support/git_scenarios.py` with the real git: the arguments, the directory, the standard input, the environment that the caller sets, the exit code, the standard output and the standard error of each command, and the result the scenario gave. The fake finds a record by the first four, so a commit with another message, author or date has no record. It does not see the files of a directory: a test that checks what a file holds reads the file under `tmp_path`, and tests start no real git. A test names the scenarios it needs with `git_fake.replay(...)`, and puts the repositories of a scenario at the same names under `tmp_path`, which stands in for `{root}`. A git command with no record fails the test and names the command. A test with the fixture cannot start a real git. A transcript holds no host path, user name, host name or e-mail address except `example.com`, and the recorder runs git with no user or system configuration file. A test that needs a command with no record adds a scenario and records it again with `uv run python -c "import sys; from tests.support.git_recording import main; sys.exit(main([]))"`; the `git` row of `devops ci` records every scenario again on the stock runner and fails when a transcript differs.
Expand Down Expand Up @@ -252,7 +252,7 @@ The suite moves to these conventions package by package ([ADR 0007](adr/0007-tes
- **Review tools**: `ToolExecutor` in `src/devops_cli/security/tool_executor.py` is the seam of the review-tool edge, and `ToolExecutorFake` in `tests/support/fakes/tool_executor.py` is its fake, behind the `tool_executor_fake` fixture. A test scripts a tool with `ToolAnswer` (version, binary digest, exit code, output, `timed_out`) and reads the requests back from `requests`. `answer_with(tool, responder)` answers each run of a tool with what the responder gives for its request, for a tool whose output depends on its arguments and its files, and `fail(tool, error)` raises the error from each run, as an executor that cannot start the tool raises. A timed-out answer carries `CONST_SANDBOX_TIMEOUT_EXIT_CODE`. On `ScannerFake`, both put a stand-in for the tool first on PATH, as `script` does. No scanner looks for a patched `run_subprocess`, `check_binary` or `is_dry_run`: a test that needs a scanner missing gives it a PATH without the program, and a test of dry-run mode calls `set_dry_run`. The fake builds the rest of each `ToolRun` with the `record_tool_run` that the real executor calls.
- **Review tools, programs and canaries**: a request for a tool that the PATH does not name, such as mypy from the interpreter of a `.venv`, names that interpreter as its `program`, and the fake answers it as it answers the tool. Mypy and the canary of each tool take a `tool_executor`, and a review gives them its own. `ScannerFake` answers each canary run, in a working directory named with `CONST_CANARY_WORKDIR_PREFIX`, with the output in `tests/fixtures/review_canary/recorded_outputs.json`, and keeps it in `canaries.requests`, apart from the runs of the scans. A test that builds an orchestrator gives it `scanner_fake` through the constructor (`tool_executor=scanner_fake`), and a test that starts a review through a command asks for `scanner_fake`, so no review starts a real tool for its canaries. The root conftest does not wrap `DirectToolExecutor.run` or `SandboxToolExecutor.run`.
- **Review tools, records**: the fake names itself `fake` in the record (`FAKE_EXECUTOR`). A review wraps its executor in a `RecordingToolExecutor`. A test that gives the orchestrator the fake reads the records from `orchestrator.tool_executor.runs`, from `profile.tool_runs` and from the Tool Runs table of the report. The settle of the fake does nothing, as the settle of a real executor does. A test that reads how a run ended, its `exit_code` and `success`, wraps the fake in a `RecordingToolExecutor`.
- **Review tools, contract suite**: `tests/ai/test_tool_executor_contract.py` runs each shared case over the fake and over `SandboxToolExecutor`, with a stand-in for the tool on disk. The bwrap cases are an opt-in contract suite that a person runs in the devcontainer; CI does not run them. The cases for `DirectToolExecutor`, the executor of a scanner that gets no other, run through the git fake. The cases of a record that the direct executor cannot complete, and of the network of a direct run, also run over `ToolExecutorFake(require_commit=False, require_files=False, network=CONST_TOOL_NETWORK_HOST)`, the fake that stands in for the direct executor: it records the network `host` and refuses a network profile, as the direct executor does. The scanners and the review pipeline take a `tool_executor`, and `tests/security/test_scanner_tool_executor.py` gives them the fake. A scan that gets no executor of its own runs on `DirectToolExecutor`, except a Popeye scan, which runs on `SandboxToolExecutor` with the network profile `kube-api`. An orchestrator that gets no executor runs its tools on `SandboxToolExecutor`. `scanner_fake` makes every `DirectToolExecutor` and every `SandboxToolExecutor` answer through `ScannerFake`, so no sandbox starts. `ScannerFake` records the commit and the digests as the direct executor does, and the network profile of the request, else `none`, as the sandbox executor does. It puts a stand-in for each scanner that it answers first on PATH, and it patches no `shutil` or `subprocess` name. A request for another tool goes on to the `run` that the fixture replaced, under the floor's refusal of a real scanner and of a real sandbox. `tests/sandbox/test_sandbox_tool_executor.py` holds the sandbox executor to its check of the host, its binds and its limits over `process_fake`, with a stand-in for bubblewrap that nothing starts. A canary run goes to the fake, which answers it with the recorded canary output.
- **Review tools, contract suite**: `tests/ai/test_tool_executor_contract.py` runs each shared case over the fake and over `SandboxToolExecutor`, with a stand-in for the tool on disk. The bwrap cases are an opt-in contract suite that the `bwrap` row of `devops ci` runs. The cases for `DirectToolExecutor`, the executor of a scanner that gets no other, run through the git fake. The cases of a record that the direct executor cannot complete, and of the network of a direct run, also run over `ToolExecutorFake(require_commit=False, require_files=False, network=CONST_TOOL_NETWORK_HOST)`, the fake that stands in for the direct executor: it records the network `host` and refuses a network profile, as the direct executor does. The scanners and the review pipeline take a `tool_executor`, and `tests/security/test_scanner_tool_executor.py` gives them the fake. A scan that gets no executor of its own runs on `DirectToolExecutor`, except a Popeye scan, which runs on `SandboxToolExecutor` with the network profile `kube-api`. An orchestrator that gets no executor runs its tools on `SandboxToolExecutor`. `scanner_fake` makes every `DirectToolExecutor` and every `SandboxToolExecutor` answer through `ScannerFake`, so no sandbox starts. `ScannerFake` records the commit and the digests as the direct executor does, and the network profile of the request, else `none`, as the sandbox executor does. It puts a stand-in for each scanner that it answers first on PATH, and it patches no `shutil` or `subprocess` name. A request for another tool goes on to the `run` that the fixture replaced, under the floor's refusal of a real scanner and of a real sandbox. `tests/sandbox/test_sandbox_tool_executor.py` holds the sandbox executor to its check of the host, its binds and its limits over `process_fake`, with a stand-in for bubblewrap that nothing starts. A canary run goes to the fake, which answers it with the recorded canary output.
- **Docker engine**: `DockerEngineService` in `src/devops_cli/docker/engine.py` is the seam of the Docker engine edge. It resolves and checks the endpoint, and then builds the docker SDK client with a `ClientFactory`; `DockerEngineService.install` gives it another factory. `devops_cli/docker/sdk.py` names the SDK calls that devops-cli makes as Protocols. `DockerEngineFake` in `tests/support/fakes/docker_engine.py` is the fake, behind the `docker_daemon` fixture, which installs it and holds `alpine:3`. A test gives the fake its images, containers, networks, volumes and build cache, scripts what a container prints and exits with (`script_run`, or `script_every_run` for a container whose name the test cannot know), an exec (`script_exec`) and stats frames (`script_stats`), makes a call fail with `fail`, and reads the calls back from `calls`. The fake answers the service's log read (`api.get` of `GET /containers/{id}/logs`) with the multiplexed frames of what `script_run` scripts. `unreachable` makes the client fail to build as the SDK fails when no daemon listens. The socket path of the fixture is in a directory beside `tmp_path`, so a workspace under `tmp_path` never overlaps the engine's socket directory. The `register_sandbox` fixture in `tests/support/sandbox.py` registers a sandbox as `devops sandbox deploy` leaves it: a record in the test's own registry and a container of the same name in the fake, which `script_exec`, `script_run` and `script_stats` then take by the instance id. The `docker_engine` factory, which installs a test's own client, stays until the tests of each package move to the fake.
- **Docker engine, contract suite**: `tests/docker/test_engine_contract.py` runs each scenario of `tests/support/docker_engine_scenarios.py` over the fake and over a real `docker.DockerClient` that reads the Engine API's answers, recorded from a local engine in `tests/fixtures/docker_engine/recorded_exchanges.json`. `RecordedEngine` in `tests/support/docker_engine_replay.py` replays them in order on a Unix socket that the test binds. `tests/support/docker_engine_recording.py` records them again, on a host with a local engine; its docstring gives the command.
- **Valkey**: `ValkeyProtocol` in `src/devops_cli/valkey/client.py` is the seam of the Valkey edge. `install_valkey_client` sets the client override for tests, and `resolve_valkey_client` returns either the override or a new `ValkeyClient`. The root `valkey` fixture installs `FakeValkeyClient` through this seam and cleans up after each test.
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/0007-tests-double-only-process-edges.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ This decision removes the following earlier allowances:
- bwrap with the `bwrap` mark.
- `@pytest.mark.live` for live local tools.

Real child processes stay only in the contract suite of the process runner (`tests/test_process_contract.py` and the process-group tests of `core/process.py`). Every other real tool goes to a contract suite that replays recorded transcripts or to a `devops ci` row. Checks of committed files and tool configuration belong in `devops ci`. The bwrap suite is an opt-in contract suite that a person runs in the devcontainer. A test must not skip based on host state.
Real child processes stay only in the contract suite of the process runner (`tests/test_process_contract.py` and the process-group tests of `core/process.py`). Every other real tool goes to a contract suite that replays recorded transcripts or to a `devops ci` row. Checks of committed files and tool configuration belong in `devops ci`. The bwrap suite is an opt-in contract suite that the `bwrap` row of `devops ci` runs where the host can make the sandbox, as in the devcontainer. A test must not skip based on host state.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-11-12
skip_specs: false
Loading