From 99cfe978cf6e19b8bec239344e61b2a90924aabe Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 12 Nov 2026 14:56:26 +0000 Subject: [PATCH 1/3] fix(tests): repair the bwrap contract suite and gate it The two process-tree tests of the bwrap contract suite read /proc in the test process, which the host path guard refuses, so the suite gave 2 failed, 53 passed and 2 errors. They now read the process table with ps under @pytest.mark.live("ps"). The new bwrap row of devops ci runs pytest -m bwrap over the two sandbox contract suites after the host check of the sandbox executor. On a host that cannot make the sandbox, the row starts no test, passes, and shows the cause, also in a cached verdict. Closes #4715 --- docs/SDLC.md | 1 + docs/TESTING.md | 6 +- .../0007-tests-double-only-process-edges.md | 2 +- .../4715-bwrap-contract-suite/.openspec.yaml | 3 + .../4715-bwrap-contract-suite/design.md | 18 ++++ .../4715-bwrap-contract-suite/proposal.md | 40 ++++++++ .../specs/ci-gate-rows/spec.md | 16 ++++ .../4715-bwrap-contract-suite/tasks.md | 24 +++++ pyproject.toml | 2 +- src/devops_cli/ci/cache.py | 2 + src/devops_cli/commands/ci.py | 52 ++++++++++- src/devops_cli/lang/en/messages.py | 2 + src/devops_cli/roadmap/runner_tools.py | 8 +- src/devops_cli/security/tool_executor.py | 15 ++- tests/ai/test_tool_executor_contract.py | 16 ++-- tests/commands/test_ci_bwrap_row.py | 91 +++++++++++++++++++ tests/commands/test_ci_shard.py | 13 ++- tests/support/ci_root.py | 30 +++++- 18 files changed, 314 insertions(+), 27 deletions(-) create mode 100644 openspec/changes/4715-bwrap-contract-suite/.openspec.yaml create mode 100644 openspec/changes/4715-bwrap-contract-suite/design.md create mode 100644 openspec/changes/4715-bwrap-contract-suite/proposal.md create mode 100644 openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md create mode 100644 openspec/changes/4715-bwrap-contract-suite/tasks.md create mode 100644 tests/commands/test_ci_bwrap_row.py diff --git a/docs/SDLC.md b/docs/SDLC.md index e2f18fec94..733fe950df 100644 --- a/docs/SDLC.md +++ b/docs/SDLC.md @@ -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`) in the real sandbox. It runs where the host can make the sandbox of a review, as in the devcontainer. On a host that cannot, such as the GitHub-hosted runner of `Static Analysis`, 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. diff --git a/docs/TESTING.md b/docs/TESTING.md index 508eba5eb1..b6065fcc47 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -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, as in the devcontainer. On a host that cannot, such as a GitHub-hosted runner, the row starts no test and shows as skipped with the cause. 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. @@ -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. diff --git a/docs/adr/0007-tests-double-only-process-edges.md b/docs/adr/0007-tests-double-only-process-edges.md index 94b6107030..dbd435805d 100644 --- a/docs/adr/0007-tests-double-only-process-edges.md +++ b/docs/adr/0007-tests-double-only-process-edges.md @@ -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. diff --git a/openspec/changes/4715-bwrap-contract-suite/.openspec.yaml b/openspec/changes/4715-bwrap-contract-suite/.openspec.yaml new file mode 100644 index 0000000000..0bc22675ad --- /dev/null +++ b/openspec/changes/4715-bwrap-contract-suite/.openspec.yaml @@ -0,0 +1,3 @@ +schema: spec-driven +created: 2026-11-12 +skip_specs: false diff --git a/openspec/changes/4715-bwrap-contract-suite/design.md b/openspec/changes/4715-bwrap-contract-suite/design.md new file mode 100644 index 0000000000..1d3360c450 --- /dev/null +++ b/openspec/changes/4715-bwrap-contract-suite/design.md @@ -0,0 +1,18 @@ +# Design + +## Decisions + +- **`ps` reads the process table.** The two process-tree tests need to see each process of the host, in each namespace below it. `ps -e -ww -o args=` gives the full command line of each process, and the test looks for its temporary path in the text. `@pytest.mark.live("ps")` lets the floor start it. The guard that keeps the test process out of `/proc` does not change. +- **The row uses the host check of the sandbox executor.** `SandboxToolExecutor.host_refusal()` checks that bubblewrap and prlimit are installed and that bubblewrap can make a sandbox with `prlimit -- true` in it. It runs one time for each executor. A check of the binary alone passes on Ubuntu 24.04 when bubblewrap is installed and AppArmor refuses it a user namespace, and the row would then fail 55 tests for a cause of the host. +- **A skipped row passes and shows the cause.** `CheckResult.skipped` holds the cause, the summary shows `skipped: ` with no duration, and `CICachedCheck.skipped` keeps it, so a cached verdict does not show the row as passed. The skip is no failure: the host cannot give what the row needs, as `docs/TESTING.md` asks for a test that needs a capability of the host. +- **The host check runs in a thread.** It starts bubblewrap with a timeout of 30 s, and `asyncio.to_thread` keeps the other rows running while it waits. +- **One process.** The row passes `-n 0`. The 55 tests take 3.6 s in one process, and xdist would start one interpreter for each CPU beside the test row of a full gate. +- **Gate tests do not read the bubblewrap of the host.** `sandbox_host` puts stand-ins for bubblewrap and prlimit first on PATH for each test that uses `ci_root` or `ci_head`, and the process fake answers the check. A full gate in a test runs the row on every host. + +## Rejected alternatives + +- **Let a `bwrap` test open `/proc//cmdline` through the host path guard.** It adds an exemption to the floor to make a check pass. The project rule (`docs/SDLC.md`, "Where a Check Runs") refuses an escape or a special case, and `ps` gives the same data with no change to the floor. +- **`pgrep -f `.** pgrep reads its pattern as an extended regular expression. A temporary path needs escaping, and `re.escape` writes escapes, such as `\-`, that POSIX leaves undefined. +- **`HostSandbox().is_available()` as the host check, as the issue text says.** It reads only that the binary is a file. On a host where bubblewrap cannot make a user namespace, the row would run and fail. The check of the sandbox executor gives the cause that a review gives on the same host. +- **Add `bwrap` to the `--skip` list of `Static Analysis`.** The row already skips on the runner with the cause, at the cost of one file check. The change would also touch `ci.yml`, which other open work changes. +- **Install bubblewrap on the runner.** The owner rule is that a GitHub-hosted runner gets no package install or host change. diff --git a/openspec/changes/4715-bwrap-contract-suite/proposal.md b/openspec/changes/4715-bwrap-contract-suite/proposal.md new file mode 100644 index 0000000000..6c9f71cd16 --- /dev/null +++ b/openspec/changes/4715-bwrap-contract-suite/proposal.md @@ -0,0 +1,40 @@ +# Proposal: #4715 + +## Why + +No automatic run selects the 55 tests with the `bwrap` mark: the root conftest deselects them unless `-m bwrap` is given, and no row of `devops ci` and no CI job gives it (change #2149). When a person runs them in the devcontainer, 2 tests fail and 2 tests give a teardown error: `_running` in `tests/ai/test_tool_executor_contract.py` reads `/proc//cmdline` in the test process, and the host path guard of the floor refuses `/proc` (#2165). The marker text in `pyproject.toml` does not say that a default run deselects these tests. Closes #4715. + +## What Changes + +- `_running` reads the process table of the host with `ps -e -ww -o args=`. The two tests that call it carry `@pytest.mark.live("ps")`. The floor and its host path guard do not change. +- `devops ci` gets the row `bwrap`. It runs `uv run pytest -m bwrap -n 0` over `tests/sandbox/test_host_sandbox.py` and `tests/ai/test_tool_executor_contract.py`. +- A row can have a host check (`CheckSpec.host_refusal`). The `bwrap` row uses the host check of `SandboxToolExecutor`, which `host_refusal()` now makes public: bubblewrap and prlimit are installed, and bubblewrap can make a sandbox. On a host that fails it, the row starts no command, passes, and shows `skipped: ` in its line and in the summary. The CI cache keeps the cause. +- `sandbox_host` in `tests/support/ci_root.py` puts a stand-in for bubblewrap and prlimit on PATH for every gate test that uses `ci_root` or `ci_head`, so no gate test reads the bubblewrap of the host. +- `RUNNER_TOOLS` names the row as a reason for pytest. `NOT_IN_RUNNER` gives the new reason for `bwrap` and names `ps`. +- The marker text, `docs/TESTING.md`, `docs/SDLC.md` and ADR 0007 say that the `bwrap` row runs the suite where the host can make the sandbox and skips with the cause elsewhere. +- The change adds a row and a message to `devops ci`, which a consumer sees, so it has a spec delta. + +## Capabilities + +- `ci-gate-rows`: the `bwrap` row runs the sandbox contract suites where the host can make a sandbox, and skips with the cause where it cannot. + +## Impact + +- The full `devops ci` in the devcontainer runs the contract suite of the real sandbox: 55 tests, 9.3 s for the row. +- `Static Analysis` runs `devops ci --check --no-cache --skip test,outdated,actionlint`, so it runs the row. The GitHub-hosted runner has no bubblewrap, so the row skips there with the cause. No workflow changes and no package is installed on a runner. +- The change fits one pull request. + +## Feasibility + +- At `origin/main` 310981773, `uv run pytest -m bwrap tests/sandbox/test_host_sandbox.py tests/ai/test_tool_executor_contract.py -n 0` gives `2 failed, 53 passed, 2 errors`. Both failures are `host path reached without a fake: /proc/1/cmdline` from `_running`. Each teardown error is the same refusal, which the floor records and reports again after the test. +- With this change the same command gives `55 passed in 3.58s`, and `uv run devops ci --only bwrap --check --no-cache` passes in 9.27 s in the devcontainer. +- The installed apt packages of the GitHub runner image `ubuntu-24.04` (`actions/runner-images`, `images/ubuntu/Ubuntu2404-Readme.md`) hold no bubblewrap. Its host check gives `bubblewrap (/usr/bin/bwrap) is not installed`. +- `SandboxToolExecutor._host_cause` (`src/devops_cli/security/tool_executor.py`) already finds a host where AppArmor refuses bubblewrap a user namespace, which a check of the binary alone does not find. +- The tests of `tests/commands/` and `tests/ci/` pass in the devcontainer and with a plugin that removes bubblewrap from the host (3,780 passed). + +## Existing Tool Considered + +- `ps` of procps reads the process table of the host, so the test process does not read `/proc` and the floor needs no exemption. +- pytest markers select the suite (`-m bwrap`) and allow `ps` (`live`). The host check is the existing check of the sandbox executor. +- The skip state of a row is new code in `src/devops_cli/commands/ci.py` and `src/devops_cli/ci/cache.py`, about 40 lines: no tool gives a row of `devops ci` a host check. Cost: about 60,000 tokens to build and about 5,000 tokens a year to keep, with 2 hours of elapsed time. +- The change deletes the loop over `/proc/*/cmdline` in `_running`. diff --git a/openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md b/openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md new file mode 100644 index 0000000000..d18f283a76 --- /dev/null +++ b/openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md @@ -0,0 +1,16 @@ +## ADDED Requirements + +### Requirement: The bwrap row runs the sandbox contract suites where the host can make a sandbox +The table of `devops ci` SHALL hold a row `bwrap` that runs `pytest -m bwrap -n 0` over the two contract suites of the sandbox, after the host check of the sandbox executor. On a host that fails the check, the row SHALL start no test, SHALL pass, and SHALL show `skipped: `, also in a cached verdict. + +#### Scenario: A host that can make the sandbox +- **WHEN** `devops ci --only bwrap` runs and bubblewrap makes a sandbox on the host +- **THEN** the row starts `uv run pytest -m bwrap -n 0` with `tests/sandbox/test_host_sandbox.py` and `tests/ai/test_tool_executor_contract.py` + +#### Scenario: A host that cannot make the sandbox +- **WHEN** `devops ci --only bwrap` runs and bubblewrap exits 1 with `bwrap: setting up uid map: Permission denied` +- **THEN** the row starts no test, the gate exits 0, and the output shows `[bwrap] skipped: bubblewrap cannot make a sandbox on this host: bwrap: setting up uid map: Permission denied` + +#### Scenario: A cached verdict keeps the skip +- **WHEN** a full gate passed with the row skipped, and the gate runs again on the same tree +- **THEN** the cached summary shows the row as skipped and starts no command diff --git a/openspec/changes/4715-bwrap-contract-suite/tasks.md b/openspec/changes/4715-bwrap-contract-suite/tasks.md new file mode 100644 index 0000000000..a3d61b5e0c --- /dev/null +++ b/openspec/changes/4715-bwrap-contract-suite/tasks.md @@ -0,0 +1,24 @@ +# Tasks + +## 1. Repair the bwrap contract suite + +Kind: test-only edit. Changes: `tests/ai/test_tool_executor_contract.py`, `src/devops_cli/roadmap/runner_tools.py`. + +- [x] 1.1 `_running` reads the process table of the host with `ps`, and its two tests carry `@pytest.mark.live("ps")`. `NOT_IN_RUNNER` names `ps`. + - Verification: `$ uv run pytest -m bwrap -n 0 tests/sandbox/test_host_sandbox.py tests/ai/test_tool_executor_contract.py` + +## 2. The bwrap row of devops ci + +Kind: behavior. Changes: `src/devops_cli/commands/ci.py`, `src/devops_cli/ci/cache.py`, `src/devops_cli/security/tool_executor.py`, `src/devops_cli/lang/en/messages.py`, `src/devops_cli/roadmap/runner_tools.py`, `tests/support/ci_root.py`. + +- [x] 2.1 Write the tests first: the row runs `pytest -m bwrap -n 0` over the two suites, starts them after the host check passes, skips with the cause and starts nothing when bubblewrap cannot make a sandbox, and a cached verdict keeps the skip. + - Verification: `$ uv run devops ci test tests/commands/test_ci_bwrap_row.py` +- [x] 2.2 Add `CheckSpec.host_refusal`, `CheckResult.skipped` and `CICachedCheck.skipped`, the public `SandboxToolExecutor.host_refusal()`, and the `bwrap` row. `sandbox_host` gives the gate tests stand-ins for bubblewrap and prlimit, and `RUNNER_TOOLS` names the row as a reason for pytest. + - Verification: `$ uv run devops ci test tests/commands/test_ci_bwrap_row.py tests/commands/test_ci.py tests/commands/test_ci_shard.py tests/ci/test_ci_gate_admission.py tests/sandbox/test_sandbox_tool_executor.py tests/roadmap/test_roadmap_runner_tools.py` + +## 3. Documents + +- [x] 3.1 Correct the text of the `bwrap` marker in `pyproject.toml`, and state in `docs/TESTING.md`, `docs/SDLC.md` and ADR 0007 that the `bwrap` row runs the suite where the host can make the sandbox and skips with the cause elsewhere. + - Verification: `$ uv run devops ci --check --only docs` + +- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD). diff --git a/pyproject.toml b/pyproject.toml index 600cce0058..d77d2e08b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -231,7 +231,7 @@ timeout_method = "signal" # of a test that passed and keeps the directory of a test that failed, for its debugging. tmp_path_retention_policy = "failed" markers = [ - "bwrap: live sandbox tests requiring bubblewrap; skipped where bwrap is not installed", + "bwrap: live sandbox tests requiring bubblewrap; a default run deselects them, -m bwrap (the bwrap row of devops ci) selects them, and they skip where bwrap is not installed", "live: live tests requiring the named local tool binaries; skipped where a binary is not installed", "unreachable: tests that exercise a refused endpoint before its fake lands", ] diff --git a/src/devops_cli/ci/cache.py b/src/devops_cli/ci/cache.py index b61c33cca5..cf8f6c437b 100644 --- a/src/devops_cli/ci/cache.py +++ b/src/devops_cli/ci/cache.py @@ -50,6 +50,8 @@ class CICachedCheck(BaseModel): duration_seconds: float stdout: str = "" stderr: str = "" + # Why the host could not run the check, which then started nothing and did not fail. + skipped: str | None = None class CICacheEntry(BaseModel): diff --git a/src/devops_cli/commands/ci.py b/src/devops_cli/commands/ci.py index 5879e9fe5b..3bb9948242 100644 --- a/src/devops_cli/commands/ci.py +++ b/src/devops_cli/commands/ci.py @@ -61,6 +61,7 @@ from devops_cli.dry_run.requests import PlannedRequest, render_request_plan from devops_cli.lang import HELP, MESSAGES from devops_cli.output import ( + escape_text, print_error, print_info, print_muted, @@ -141,6 +142,8 @@ class CheckResult(BaseModel): timeout_seconds: float | None = None dry_run: bool = False requests: tuple[PlannedRequest, ...] = () + # Why the host could not run the check, which then started nothing and did not fail. + skipped: str | None = None class CheckSpec(BaseModel): @@ -163,6 +166,9 @@ class CheckSpec(BaseModel): # Whether the check keeps the host's CPUs busy for minutes: a p90 above 200 s in the CI cache # of the host (#2336). A run that selects one waits for a gate slot (`_gate_slot`). heavy: bool = False + # The check of the host that the row needs: it returns why the host cannot run the row, or + # None when it can. A row whose host cannot run it starts no command and shows as skipped. + host_refusal: Callable[[], str | None] | None = None @property def commands(self) -> list[list[str]]: @@ -546,6 +552,21 @@ async def _execute_check_async( requests=_planned_requests(check_spec), ) + if check_spec.host_refusal is not None: + refusal = await asyncio.to_thread(check_spec.host_refusal) + if refusal is not None: + print_muted( + f" – [{check_spec.name}] {MESSAGES.ci.row_skipped.format(cause=refusal)}", + safe=True, + ) + return CheckResult( + name=check_spec.name, + display_title=check_spec.display_title, + passed=True, + duration_seconds=0.0, + skipped=refusal, + ) + start_time = clock.monotonic() root = _get_project_root() @@ -740,6 +761,22 @@ def _npm_audit_cmds() -> list[list[str]]: ) +# The contract suites that run the real sandbox: the cases with the `bwrap` mark, which a default +# test run deselects (#2149, #4715). +_BWRAP_SUITE_FILES: Final[tuple[str, ...]] = ( + "tests/sandbox/test_host_sandbox.py", + "tests/ai/test_tool_executor_contract.py", +) + + +def _sandbox_host_refusal() -> str | None: + """Why this host cannot make the sandbox of a review, from the check of the sandbox executor: + bubblewrap and prlimit are installed, and bubblewrap can make a sandbox. None when it can.""" + from devops_cli.security.tool_executor import SandboxToolExecutor + + return SandboxToolExecutor().host_refusal() + + def _python_check_cmd(module: str) -> list[str]: """The command that runs the `main` of a module of `tests/gate`: a check of committed files and tool configuration, which is a row of `devops ci` and no pytest test (#2164).""" @@ -907,6 +944,14 @@ def get_check_specs() -> list[CheckSpec]: span_name="ci.step.test_settings", metric_step="test_settings", ), + CheckSpec( + name="bwrap", + display_title=MESSAGES.ci.bwrap_contract, + cmd=["uv", "run", "pytest", "-m", "bwrap", "-n", "0", *_BWRAP_SUITE_FILES], + span_name="ci.step.bwrap", + metric_step="bwrap", + host_refusal=_sandbox_host_refusal, + ), CheckSpec( name="k8s", display_title=MESSAGES.ci.k8s_manifests, @@ -1287,6 +1332,9 @@ def _print_summary( if res.timed_out: limit_str = f"{res.timeout_seconds:g}s" if res.timeout_seconds else "limit" status_text = f"[red]✗ fail (timed out after {limit_str})[/red]" + elif res.skipped is not None: + reason = escape_text(MESSAGES.ci.row_skipped.format(cause=res.skipped)) + status_text = f"[yellow]– {reason}[/yellow]" elif cached and res.passed: status_text = "[green]✓ pass (cached)[/green]" elif res.passed: @@ -1295,7 +1343,7 @@ def _print_summary( status_text = "[red]✗ fail[/red]" dur_text = ( "-" - if res.name == "coverage" + if res.name == "coverage" or res.skipped is not None else (format_duration(res.duration_seconds) if res.duration_seconds > 0 else "<0.01s") ) rows.append([res.name, status_text, dur_text]) @@ -1349,6 +1397,7 @@ def _try_get_ci_cache( duration_seconds=c.duration_seconds, stdout=c.stdout, stderr=c.stderr, + skipped=c.skipped, ) for c in entry.checks ] @@ -1372,6 +1421,7 @@ def _try_save_ci_cache( duration_seconds=res.duration_seconds, stdout=res.stdout, stderr=res.stderr, + skipped=res.skipped, ) for res in results ] diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index 35fdb1e602..e91397aa25 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -1812,6 +1812,8 @@ class CIMessages: test_tree: str = "test tree (invariants over the Python files of src and tests)" startup_imports: str = "startup imports (modules that each command imports at start)" swallowed_failures: str = "swallowed failures (ratchet of blind excepts and unread check=False)" + bwrap_contract: str = "bwrap contract suites (the tests marked bwrap, in the real sandbox)" + row_skipped: str = "skipped: {cause}" ci_summary_title: str = "CI Summary" col_check: str = "Check" col_result: str = "Result" diff --git a/src/devops_cli/roadmap/runner_tools.py b/src/devops_cli/roadmap/runner_tools.py index 636a57be5b..80717fd742 100644 --- a/src/devops_cli/roadmap/runner_tools.py +++ b/src/devops_cli/roadmap/runner_tools.py @@ -129,7 +129,7 @@ def _base(name: str, *needed_by: str) -> RunnerTool: pin=f"v{NODE_MAJOR}.", ), _locked("openspec", "ci:openspec", "hook:openspec-gate"), - _dev("pytest", "ci:test", package="pytest"), + _dev("pytest", "ci:test", "ci:bwrap", package="pytest"), _dev("ruff", "ci:lint", "ci:format", "hook:ruff-check", "hook:ruff-format"), _dev("mypy", "ci:typecheck"), _dev("bandit", "ci:security"), @@ -239,7 +239,11 @@ def hooks_without_programs(search_path: str | None = None) -> tuple[str, ...]: "zsh": ( "The image of the GitHub runner has no zsh, so the tests that need it skip in the gate too." ), - "bwrap": "The tests marked `bwrap` run only with `-m bwrap`, and the gate does not select it.", + "bwrap": ( + "Only the `bwrap` row runs the tests marked `bwrap`, and it skips with the cause on a host " + "that cannot make the sandbox." + ), + "ps": "Only the tests marked `bwrap` start it, and the image holds no bubblewrap for them.", } diff --git a/src/devops_cli/security/tool_executor.py b/src/devops_cli/security/tool_executor.py index fec8120b07..36330cb6f1 100644 --- a/src/devops_cli/security/tool_executor.py +++ b/src/devops_cli/security/tool_executor.py @@ -782,14 +782,19 @@ def _host_cause(self) -> str | None: detail = next(iter(done.stderr.strip().splitlines()), f"exit code {done.returncode}") return f"bubblewrap cannot make a sandbox on this host: {detail}" - def _check_host(self) -> None: - """Raise `SandboxUnavailableError` when this host cannot start the sandbox. The host is - checked one time.""" + def host_refusal(self) -> str | None: + """Why this host cannot start the sandbox, or None when it can. The host is checked one + time, and `refusal` keeps the cause.""" if not self._checked: self._refusal = self._host_cause() self._checked = True - if self._refusal is not None: - raise SandboxUnavailableError(self._refusal) + return self._refusal + + def _check_host(self) -> None: + """Raise `SandboxUnavailableError` when this host cannot start the sandbox.""" + refusal = self.host_refusal() + if refusal is not None: + raise SandboxUnavailableError(refusal) def command(self, request: ToolRequest, relay: KubeApiRelay | None = None) -> list[str]: """The whole command that runs `request`: bubblewrap, its options, `prlimit` and the tool. diff --git a/tests/ai/test_tool_executor_contract.py b/tests/ai/test_tool_executor_contract.py index 91559718da..aa509aadfa 100644 --- a/tests/ai/test_tool_executor_contract.py +++ b/tests/ai/test_tool_executor_contract.py @@ -1320,17 +1320,16 @@ def shown(limit: int) -> str: def _running(marker: str) -> bool: - """Whether any process of the host, in any namespace below it, has `marker` in its command.""" - for cmdline in Path("/proc").glob("[0-9]*/cmdline"): - try: - if marker.encode() in cmdline.read_bytes(): - return True - except OSError: # the process ended between the listing and the read - continue - return False + """Whether any process of the host, in any namespace below it, has `marker` in its command. + `ps` reads the process table of the host: the floor keeps the test process out of `/proc`.""" + table = subprocess.run( + ["ps", "-e", "-ww", "-o", "args="], capture_output=True, text=True, check=True + ) + return marker in table.stdout @pytest.mark.bwrap +@pytest.mark.live("ps") def test_the_process_scan_sees_a_running_process(tmp_path: Path) -> None: """The control for the next test: the scan finds a process while it runs and not after.""" repo = tmp_path / "scan-marker" @@ -1363,6 +1362,7 @@ def test_the_process_scan_sees_a_running_process(tmp_path: Path) -> None: @pytest.mark.bwrap +@pytest.mark.live("ps") def test_a_tool_that_runs_out_of_time_ends_with_its_whole_process_tree( scenario: Scenario, ) -> None: diff --git a/tests/commands/test_ci_bwrap_row.py b/tests/commands/test_ci_bwrap_row.py new file mode 100644 index 0000000000..6568adf008 --- /dev/null +++ b/tests/commands/test_ci_bwrap_row.py @@ -0,0 +1,91 @@ +"""The `bwrap` row of `devops ci`: the contract suite of the real sandbox, which runs where the +host can make a sandbox and skips with the cause where it cannot (#4715).""" + +from __future__ import annotations + +from pathlib import Path + +import pytest +from typer.testing import CliRunner + +from devops_cli.commands.ci import app, get_check_spec +from devops_cli.core.process import prepare_tool_cmd +from tests.support.fakes.process import ProcessAnswer, ProcessFake +from tests.support.paths import REPO_ROOT + +pytestmark = pytest.mark.usefixtures("refuse_nested_test_runs") + +runner = CliRunner() + +_NAMESPACE_REFUSED = "bwrap: setting up uid map: Permission denied" +_CAUSE = f"bubblewrap cannot make a sandbox on this host: {_NAMESPACE_REFUSED}" + + +def _programs(process_fake: ProcessFake) -> list[str]: + """The program of each command that the gate started, other than git.""" + return [call.argv[0] for call in process_fake.calls if call.argv[0] != "git"] + + +def test_the_bwrap_row_runs_the_tests_marked_bwrap_of_the_sandbox_contract_suites() -> None: + """The row selects the `bwrap` mark in the two contract suites of the sandbox, in one process, + and each file is in the tree.""" + cmd = get_check_spec("bwrap").cmd + files = cmd[cmd.index("0") + 1 :] + + assert (cmd[: cmd.index("0") + 1], files, all((REPO_ROOT / f).is_file() for f in files)) == ( + ["uv", "run", "pytest", "-m", "bwrap", "-n", "0"], + ["tests/sandbox/test_host_sandbox.py", "tests/ai/test_tool_executor_contract.py"], + True, + ) + + +@pytest.mark.usefixtures("ci_root") +def test_the_bwrap_row_runs_the_suite_where_the_host_can_make_a_sandbox( + sandbox_host: Path, process_fake: ProcessFake +) -> None: + """The row checks the host with the check of the sandbox executor, then starts the suite.""" + result = runner.invoke(app, ["--only", "bwrap", "--check", "--no-cache"]) + + assert (result.exit_code, _programs(process_fake), process_fake.calls[-1].argv) == ( + 0, + [str(sandbox_host), "uv"], + tuple(prepare_tool_cmd(get_check_spec("bwrap").cmd)), + ) + + +@pytest.mark.usefixtures("ci_root") +def test_the_bwrap_row_skips_with_the_cause_where_the_host_cannot_make_a_sandbox( + sandbox_host: Path, process_fake: ProcessFake +) -> None: + """The row starts no suite, passes, and names the cause in its line and in the summary.""" + process_fake.answer( + str(sandbox_host), ProcessAnswer(returncode=1, stderr=f"{_NAMESPACE_REFUSED}\n") + ) + + result = runner.invoke(app, ["--only", "bwrap", "--check", "--no-cache"]) + + said = " ".join(result.output.split()) + assert (result.exit_code, _programs(process_fake), f"[bwrap] skipped: {_CAUSE}" in said) == ( + 0, + [str(sandbox_host)], + True, + ) + + +def test_a_cached_verdict_keeps_the_skip_of_a_row( + ci_root: Path, ci_head: ProcessFake, sandbox_host: Path +) -> None: + """A gate that passed with the row skipped reads back from the cache as skipped, not passed.""" + ci_head.answer(str(sandbox_host), ProcessAnswer(returncode=1, stderr=f"{_NAMESPACE_REFUSED}\n")) + first = runner.invoke(app, ["--check"]) + ci_head.calls.clear() + + cached = runner.invoke(app, ["--check"]) + + rows = [line for line in cached.output.splitlines() if " bwrap " in line] + assert (first.exit_code, cached.exit_code, _programs(ci_head), "skip" in rows[0]) == ( + 0, + 0, + [], + True, + ) diff --git a/tests/commands/test_ci_shard.py b/tests/commands/test_ci_shard.py index a7205301cd..f3bf5ca65d 100644 --- a/tests/commands/test_ci_shard.py +++ b/tests/commands/test_ci_shard.py @@ -240,6 +240,15 @@ def test_a_shard_outside_the_total_is_refused_before_any_check_starts( assert (result.exit_code, process_fake.calls) == (2, []) +def _test_row_runs(process_fake: ProcessFake) -> list[list[str]]: + """The pytest commands of the test row: every pytest command but that of the `bwrap` row.""" + return [ + list(call.argv) + for call in process_fake.calls + if "pytest" in call.argv and "bwrap" not in call.argv + ] + + def test_a_sharded_run_uses_the_sharded_row_and_leaves_the_gate_cache_alone( ci_root: Path, ci_head: ProcessFake ) -> None: @@ -250,12 +259,12 @@ def test_a_sharded_run_uses_the_sharded_row_and_leaves_the_gate_cache_alone( first = runner.invoke(app, ["--check", *sharded_options]) recorded = resolve_ci_cache_path(ci_root).is_file() - ran_first = [list(call.argv) for call in ci_head.calls if "pytest" in call.argv] + ran_first = _test_row_runs(ci_head) runner.invoke(app, ["--check"]) ci_head.calls.clear() second = runner.invoke(app, ["--check", *sharded_options]) - ran_second = [list(call.argv) for call in ci_head.calls if "pytest" in call.argv] + ran_second = _test_row_runs(ci_head) assert (first.exit_code, second.exit_code, recorded, ran_first, ran_second) == ( 0, diff --git a/tests/support/ci_root.py b/tests/support/ci_root.py index d9ea5d792a..33403e77da 100644 --- a/tests/support/ci_root.py +++ b/tests/support/ci_root.py @@ -4,10 +4,15 @@ current directory. A test that starts the gate in the repository's own root lets the gate clean the `.coverage.*` files of the run that tests it. `ci_root` makes a tree under `tmp_path` and makes it the current directory, so a gate run in a test cleans and caches only there. + +The `bwrap` row of the gate checks whether the host can make the sandbox of a review before it +runs. `sandbox_host` gives that check a stand-in for bubblewrap and for prlimit on PATH, so a gate +run in a test reads no tool of the host and runs the row on every host. """ from __future__ import annotations +import os from collections.abc import Mapping from pathlib import Path @@ -20,8 +25,24 @@ @pytest.fixture -def ci_root(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: - """An empty work tree under `tmp_path`, the current directory, as the root a gate verifies.""" +def sandbox_host(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: + """A host whose PATH finds a stand-in for bubblewrap and for prlimit. Nothing starts them: the + process fake answers the check of the host, with success unless a test scripts a refusal. + Returns the stand-in for bubblewrap.""" + bin_dir = tmp_path / "sandbox-host-bin" + bin_dir.mkdir() + for name in ("bwrap", "prlimit"): + stand_in = bin_dir / name + stand_in.write_text("#!/bin/sh\nexit 99\n", encoding="utf-8") + stand_in.chmod(0o755) + monkeypatch.setenv("PATH", f"{bin_dir}{os.pathsep}{os.environ['PATH']}") + return bin_dir / "bwrap" + + +@pytest.fixture +def ci_root(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, sandbox_host: Path) -> Path: + """An empty work tree under `tmp_path`, the current directory, as the root a gate verifies, on + the host of `sandbox_host`.""" root = tmp_path / "tree" (root / ".git").mkdir(parents=True) monkeypatch.chdir(root) @@ -29,8 +50,9 @@ def ci_root(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: @pytest.fixture -def ci_head(process_fake: ProcessFake) -> ProcessFake: - """The process fake of a tree with a commit, so the gate takes a fingerprint of its files. +def ci_head(process_fake: ProcessFake, sandbox_host: Path) -> ProcessFake: + """The process fake of a tree with a commit, so the gate takes a fingerprint of its files, on + the host of `sandbox_host`. Git answers `rev-parse HEAD` with a commit and every other command with success and no output, which is a clean tree with no tracked file. From 141cbd2733651c20239b8cf597a222e727863564 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 12 Nov 2026 15:07:51 +0000 Subject: [PATCH 2/3] fix(tests): bound each bwrap test below the gate step limit Static Analysis runs the bwrap row on its GitHub-hosted runner, where bubblewrap can make the sandbox. The row gives each test a bound of 60 s, which is shorter than the 3-minute limit of the gate step, so a hung test fails with its own report. The documents and the change folder say that the row runs on that runner. --- docs/SDLC.md | 2 +- docs/TESTING.md | 2 +- .../4715-bwrap-contract-suite/design.md | 3 ++- .../4715-bwrap-contract-suite/proposal.md | 6 ++--- .../specs/ci-gate-rows/spec.md | 4 ++-- .../4715-bwrap-contract-suite/tasks.md | 4 ++-- src/devops_cli/commands/ci.py | 16 ++++++++++++- tests/commands/test_ci_bwrap_row.py | 24 ++++++++++++++++--- 8 files changed, 47 insertions(+), 14 deletions(-) diff --git a/docs/SDLC.md b/docs/SDLC.md index 733fe950df..0c01e2e13f 100644 --- a/docs/SDLC.md +++ b/docs/SDLC.md @@ -216,7 +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`) in the real sandbox. It runs where the host can make the sandbox of a review, as in the devcontainer. On a host that cannot, such as the GitHub-hosted runner of `Static Analysis`, it starts no test and shows as skipped with the cause. +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. diff --git a/docs/TESTING.md b/docs/TESTING.md index b6065fcc47..dc3fa9f33a 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -70,7 +70,7 @@ 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: 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, as in the devcontainer. On a host that cannot, such as a GitHub-hosted runner, the row starts no test and shows as skipped with the cause. 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`. +- 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. diff --git a/openspec/changes/4715-bwrap-contract-suite/design.md b/openspec/changes/4715-bwrap-contract-suite/design.md index 1d3360c450..bb616601bd 100644 --- a/openspec/changes/4715-bwrap-contract-suite/design.md +++ b/openspec/changes/4715-bwrap-contract-suite/design.md @@ -6,6 +6,7 @@ - **The row uses the host check of the sandbox executor.** `SandboxToolExecutor.host_refusal()` checks that bubblewrap and prlimit are installed and that bubblewrap can make a sandbox with `prlimit -- true` in it. It runs one time for each executor. A check of the binary alone passes on Ubuntu 24.04 when bubblewrap is installed and AppArmor refuses it a user namespace, and the row would then fail 55 tests for a cause of the host. - **A skipped row passes and shows the cause.** `CheckResult.skipped` holds the cause, the summary shows `skipped: ` with no duration, and `CICachedCheck.skipped` keeps it, so a cached verdict does not show the row as passed. The skip is no failure: the host cannot give what the row needs, as `docs/TESTING.md` asks for a test that needs a capability of the host. - **The host check runs in a thread.** It starts bubblewrap with a timeout of 30 s, and `asyncio.to_thread` keeps the other rows running while it waits. +- **A bound for each test.** The row passes `--timeout=60`. `Static Analysis` runs the row on its GitHub-hosted runner, and its gate step stops after 3 minutes, so the default bound of 600 s from `pyproject.toml` could not fire there. A test checks that the bound is shorter than the limit of the step. The slowest test takes 2 s in the devcontainer. - **One process.** The row passes `-n 0`. The 55 tests take 3.6 s in one process, and xdist would start one interpreter for each CPU beside the test row of a full gate. - **Gate tests do not read the bubblewrap of the host.** `sandbox_host` puts stand-ins for bubblewrap and prlimit first on PATH for each test that uses `ci_root` or `ci_head`, and the process fake answers the check. A full gate in a test runs the row on every host. @@ -14,5 +15,5 @@ - **Let a `bwrap` test open `/proc//cmdline` through the host path guard.** It adds an exemption to the floor to make a check pass. The project rule (`docs/SDLC.md`, "Where a Check Runs") refuses an escape or a special case, and `ps` gives the same data with no change to the floor. - **`pgrep -f `.** pgrep reads its pattern as an extended regular expression. A temporary path needs escaping, and `re.escape` writes escapes, such as `\-`, that POSIX leaves undefined. - **`HostSandbox().is_available()` as the host check, as the issue text says.** It reads only that the binary is a file. On a host where bubblewrap cannot make a user namespace, the row would run and fail. The check of the sandbox executor gives the cause that a review gives on the same host. -- **Add `bwrap` to the `--skip` list of `Static Analysis`.** The row already skips on the runner with the cause, at the cost of one file check. The change would also touch `ci.yml`, which other open work changes. +- **Add `bwrap` to the `--skip` list of `Static Analysis`.** The runner of the job can make the sandbox, so the row runs the suite there with no install and is not on the critical path of the step. The change would also touch `ci.yml`, which other open work changes. - **Install bubblewrap on the runner.** The owner rule is that a GitHub-hosted runner gets no package install or host change. diff --git a/openspec/changes/4715-bwrap-contract-suite/proposal.md b/openspec/changes/4715-bwrap-contract-suite/proposal.md index 6c9f71cd16..9592892f42 100644 --- a/openspec/changes/4715-bwrap-contract-suite/proposal.md +++ b/openspec/changes/4715-bwrap-contract-suite/proposal.md @@ -7,7 +7,7 @@ No automatic run selects the 55 tests with the `bwrap` mark: the root conftest d ## What Changes - `_running` reads the process table of the host with `ps -e -ww -o args=`. The two tests that call it carry `@pytest.mark.live("ps")`. The floor and its host path guard do not change. -- `devops ci` gets the row `bwrap`. It runs `uv run pytest -m bwrap -n 0` over `tests/sandbox/test_host_sandbox.py` and `tests/ai/test_tool_executor_contract.py`. +- `devops ci` gets the row `bwrap`. It runs `uv run pytest -m bwrap -n 0 --timeout=60` over `tests/sandbox/test_host_sandbox.py` and `tests/ai/test_tool_executor_contract.py`. The bound of 60 s for each test is shorter than the 3-minute limit of the gate step of `Static Analysis`. - A row can have a host check (`CheckSpec.host_refusal`). The `bwrap` row uses the host check of `SandboxToolExecutor`, which `host_refusal()` now makes public: bubblewrap and prlimit are installed, and bubblewrap can make a sandbox. On a host that fails it, the row starts no command, passes, and shows `skipped: ` in its line and in the summary. The CI cache keeps the cause. - `sandbox_host` in `tests/support/ci_root.py` puts a stand-in for bubblewrap and prlimit on PATH for every gate test that uses `ci_root` or `ci_head`, so no gate test reads the bubblewrap of the host. - `RUNNER_TOOLS` names the row as a reason for pytest. `NOT_IN_RUNNER` gives the new reason for `bwrap` and names `ps`. @@ -21,14 +21,14 @@ No automatic run selects the 55 tests with the `bwrap` mark: the root conftest d ## Impact - The full `devops ci` in the devcontainer runs the contract suite of the real sandbox: 55 tests, 9.3 s for the row. -- `Static Analysis` runs `devops ci --check --no-cache --skip test,outdated,actionlint`, so it runs the row. The GitHub-hosted runner has no bubblewrap, so the row skips there with the cause. No workflow changes and no package is installed on a runner. +- `Static Analysis` runs `devops ci --check --no-cache --skip test,outdated,actionlint`, so it runs the row. On its `ubuntu-26.04` runner, bubblewrap makes the sandbox with no install, so the suite of the real sandbox gates each pull request. The row took 49 s there, beside the `security` row of 81 s, which sets the time of the step. No workflow changes and no package is installed on a runner. - The change fits one pull request. ## Feasibility - At `origin/main` 310981773, `uv run pytest -m bwrap tests/sandbox/test_host_sandbox.py tests/ai/test_tool_executor_contract.py -n 0` gives `2 failed, 53 passed, 2 errors`. Both failures are `host path reached without a fake: /proc/1/cmdline` from `_running`. Each teardown error is the same refusal, which the floor records and reports again after the test. - With this change the same command gives `55 passed in 3.58s`, and `uv run devops ci --only bwrap --check --no-cache` passes in 9.27 s in the devcontainer. -- The installed apt packages of the GitHub runner image `ubuntu-24.04` (`actions/runner-images`, `images/ubuntu/Ubuntu2404-Readme.md`) hold no bubblewrap. Its host check gives `bubblewrap (/usr/bin/bwrap) is not installed`. +- `Static Analysis` runs on `ubuntu-26.04`. The list of installed apt packages of that image (`actions/runner-images`, `images/ubuntu/Ubuntu2604-Readme.md`) does not name bubblewrap, but the first CI run of this change shows that the runner has it and can make the sandbox: the row passed in 49 s, and the gate step took 82 s, against 90 s on `main` at 310981773. A host with no bubblewrap gets the cause `bubblewrap (/usr/bin/bwrap) is not installed`. - `SandboxToolExecutor._host_cause` (`src/devops_cli/security/tool_executor.py`) already finds a host where AppArmor refuses bubblewrap a user namespace, which a check of the binary alone does not find. - The tests of `tests/commands/` and `tests/ci/` pass in the devcontainer and with a plugin that removes bubblewrap from the host (3,780 passed). diff --git a/openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md b/openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md index d18f283a76..0a6b5f623e 100644 --- a/openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md +++ b/openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md @@ -1,11 +1,11 @@ ## ADDED Requirements ### Requirement: The bwrap row runs the sandbox contract suites where the host can make a sandbox -The table of `devops ci` SHALL hold a row `bwrap` that runs `pytest -m bwrap -n 0` over the two contract suites of the sandbox, after the host check of the sandbox executor. On a host that fails the check, the row SHALL start no test, SHALL pass, and SHALL show `skipped: `, also in a cached verdict. +The table of `devops ci` SHALL hold a row `bwrap` that runs `pytest -m bwrap -n 0` with a bound for each test over the two contract suites of the sandbox, after the host check of the sandbox executor. On a host that fails the check, the row SHALL start no test, SHALL pass, and SHALL show `skipped: `, also in a cached verdict. #### Scenario: A host that can make the sandbox - **WHEN** `devops ci --only bwrap` runs and bubblewrap makes a sandbox on the host -- **THEN** the row starts `uv run pytest -m bwrap -n 0` with `tests/sandbox/test_host_sandbox.py` and `tests/ai/test_tool_executor_contract.py` +- **THEN** the row starts `uv run pytest -m bwrap -n 0 --timeout=60` with `tests/sandbox/test_host_sandbox.py` and `tests/ai/test_tool_executor_contract.py` #### Scenario: A host that cannot make the sandbox - **WHEN** `devops ci --only bwrap` runs and bubblewrap exits 1 with `bwrap: setting up uid map: Permission denied` diff --git a/openspec/changes/4715-bwrap-contract-suite/tasks.md b/openspec/changes/4715-bwrap-contract-suite/tasks.md index a3d61b5e0c..35b869d9e2 100644 --- a/openspec/changes/4715-bwrap-contract-suite/tasks.md +++ b/openspec/changes/4715-bwrap-contract-suite/tasks.md @@ -11,9 +11,9 @@ Kind: test-only edit. Changes: `tests/ai/test_tool_executor_contract.py`, `src/d Kind: behavior. Changes: `src/devops_cli/commands/ci.py`, `src/devops_cli/ci/cache.py`, `src/devops_cli/security/tool_executor.py`, `src/devops_cli/lang/en/messages.py`, `src/devops_cli/roadmap/runner_tools.py`, `tests/support/ci_root.py`. -- [x] 2.1 Write the tests first: the row runs `pytest -m bwrap -n 0` over the two suites, starts them after the host check passes, skips with the cause and starts nothing when bubblewrap cannot make a sandbox, and a cached verdict keeps the skip. +- [x] 2.1 Write the tests first: the row runs `pytest -m bwrap -n 0` over the two suites with a bound for each test that is shorter than the limit of the gate step of `Static Analysis`, starts them after the host check passes, skips with the cause and starts nothing when bubblewrap cannot make a sandbox, and a cached verdict keeps the skip. - Verification: `$ uv run devops ci test tests/commands/test_ci_bwrap_row.py` -- [x] 2.2 Add `CheckSpec.host_refusal`, `CheckResult.skipped` and `CICachedCheck.skipped`, the public `SandboxToolExecutor.host_refusal()`, and the `bwrap` row. `sandbox_host` gives the gate tests stand-ins for bubblewrap and prlimit, and `RUNNER_TOOLS` names the row as a reason for pytest. +- [x] 2.2 Add `CheckSpec.host_refusal`, `CheckResult.skipped` and `CICachedCheck.skipped`, the public `SandboxToolExecutor.host_refusal()`, and the `bwrap` row with `--timeout=60`. `sandbox_host` gives the gate tests stand-ins for bubblewrap and prlimit, and `RUNNER_TOOLS` names the row as a reason for pytest. - Verification: `$ uv run devops ci test tests/commands/test_ci_bwrap_row.py tests/commands/test_ci.py tests/commands/test_ci_shard.py tests/ci/test_ci_gate_admission.py tests/sandbox/test_sandbox_tool_executor.py tests/roadmap/test_roadmap_runner_tools.py` ## 3. Documents diff --git a/src/devops_cli/commands/ci.py b/src/devops_cli/commands/ci.py index 3bb9948242..7ae5120ab0 100644 --- a/src/devops_cli/commands/ci.py +++ b/src/devops_cli/commands/ci.py @@ -767,6 +767,10 @@ def _npm_audit_cmds() -> list[list[str]]: "tests/sandbox/test_host_sandbox.py", "tests/ai/test_tool_executor_contract.py", ) +# The bound of each bwrap test, in seconds. `Static Analysis` runs the row on a GitHub-hosted +# runner, and its gate step has a longer limit (`timeout-minutes` in `ci.yml`), so a hung test +# fails with its own report before the step stops the job. The slowest test takes 2 s locally. +_BWRAP_TEST_TIMEOUT_SECONDS: Final[int] = 60 def _sandbox_host_refusal() -> str | None: @@ -947,7 +951,17 @@ def get_check_specs() -> list[CheckSpec]: CheckSpec( name="bwrap", display_title=MESSAGES.ci.bwrap_contract, - cmd=["uv", "run", "pytest", "-m", "bwrap", "-n", "0", *_BWRAP_SUITE_FILES], + cmd=[ + "uv", + "run", + "pytest", + "-m", + "bwrap", + "-n", + "0", + f"--timeout={_BWRAP_TEST_TIMEOUT_SECONDS}", + *_BWRAP_SUITE_FILES, + ], span_name="ci.step.bwrap", metric_step="bwrap", host_refusal=_sandbox_host_refusal, diff --git a/tests/commands/test_ci_bwrap_row.py b/tests/commands/test_ci_bwrap_row.py index 6568adf008..220b8baf15 100644 --- a/tests/commands/test_ci_bwrap_row.py +++ b/tests/commands/test_ci_bwrap_row.py @@ -6,6 +6,7 @@ from pathlib import Path import pytest +import yaml from typer.testing import CliRunner from devops_cli.commands.ci import app, get_check_spec @@ -26,19 +27,36 @@ def _programs(process_fake: ProcessFake) -> list[str]: return [call.argv[0] for call in process_fake.calls if call.argv[0] != "git"] +def _test_bound(cmd: list[str]) -> int: + """The seconds that the row gives each test, from its `--timeout=` option.""" + return int(next(word for word in cmd if word.startswith("--timeout=")).split("=")[1]) + + def test_the_bwrap_row_runs_the_tests_marked_bwrap_of_the_sandbox_contract_suites() -> None: """The row selects the `bwrap` mark in the two contract suites of the sandbox, in one process, - and each file is in the tree.""" + with a bound on each test, and each file is in the tree.""" cmd = get_check_spec("bwrap").cmd - files = cmd[cmd.index("0") + 1 :] + files = [word for word in cmd if word.startswith("tests/")] - assert (cmd[: cmd.index("0") + 1], files, all((REPO_ROOT / f).is_file() for f in files)) == ( + assert (cmd[:7], files, all((REPO_ROOT / f).is_file() for f in files)) == ( ["uv", "run", "pytest", "-m", "bwrap", "-n", "0"], ["tests/sandbox/test_host_sandbox.py", "tests/ai/test_tool_executor_contract.py"], True, ) +def test_a_hung_bwrap_test_fails_before_the_gate_step_of_static_analysis_stops() -> None: + """`Static Analysis` runs the row on its GitHub-hosted runner, where bubblewrap can make the + sandbox. The bound of each test is shorter than the limit of the gate step, so a hung test + fails with its own report before the step stops the job.""" + ci = yaml.safe_load((REPO_ROOT / ".github/workflows/ci.yml").read_text(encoding="utf-8")) + step = next( + step for step in ci["jobs"]["static"]["steps"] if "devops ci" in step.get("run", "") + ) + + assert _test_bound(get_check_spec("bwrap").cmd) < step["timeout-minutes"] * 60 + + @pytest.mark.usefixtures("ci_root") def test_the_bwrap_row_runs_the_suite_where_the_host_can_make_a_sandbox( sandbox_host: Path, process_fake: ProcessFake From b5223688c9e39158f899d89a7e0a014b11671542 Mon Sep 17 00:00:00 2001 From: Daniel Petty Date: Thu, 12 Nov 2026 15:08:08 +0000 Subject: [PATCH 3/3] docs(openspec): archive 4715-bwrap-contract-suite --- .../.openspec.yaml | 0 .../design.md | 0 .../proposal.md | 0 .../specs/ci-gate-rows/spec.md | 0 .../tasks.md | 0 openspec/specs/ci-gate-rows/spec.md | 15 +++++++++++++++ 6 files changed, 15 insertions(+) rename openspec/changes/{4715-bwrap-contract-suite => archive/2026-11-12-4715-bwrap-contract-suite}/.openspec.yaml (100%) rename openspec/changes/{4715-bwrap-contract-suite => archive/2026-11-12-4715-bwrap-contract-suite}/design.md (100%) rename openspec/changes/{4715-bwrap-contract-suite => archive/2026-11-12-4715-bwrap-contract-suite}/proposal.md (100%) rename openspec/changes/{4715-bwrap-contract-suite => archive/2026-11-12-4715-bwrap-contract-suite}/specs/ci-gate-rows/spec.md (100%) rename openspec/changes/{4715-bwrap-contract-suite => archive/2026-11-12-4715-bwrap-contract-suite}/tasks.md (100%) diff --git a/openspec/changes/4715-bwrap-contract-suite/.openspec.yaml b/openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/.openspec.yaml similarity index 100% rename from openspec/changes/4715-bwrap-contract-suite/.openspec.yaml rename to openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/.openspec.yaml diff --git a/openspec/changes/4715-bwrap-contract-suite/design.md b/openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/design.md similarity index 100% rename from openspec/changes/4715-bwrap-contract-suite/design.md rename to openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/design.md diff --git a/openspec/changes/4715-bwrap-contract-suite/proposal.md b/openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/proposal.md similarity index 100% rename from openspec/changes/4715-bwrap-contract-suite/proposal.md rename to openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/proposal.md diff --git a/openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md b/openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md similarity index 100% rename from openspec/changes/4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md rename to openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/specs/ci-gate-rows/spec.md diff --git a/openspec/changes/4715-bwrap-contract-suite/tasks.md b/openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/tasks.md similarity index 100% rename from openspec/changes/4715-bwrap-contract-suite/tasks.md rename to openspec/changes/archive/2026-11-12-4715-bwrap-contract-suite/tasks.md diff --git a/openspec/specs/ci-gate-rows/spec.md b/openspec/specs/ci-gate-rows/spec.md index c8832d1247..f638acb526 100644 --- a/openspec/specs/ci-gate-rows/spec.md +++ b/openspec/specs/ci-gate-rows/spec.md @@ -41,3 +41,18 @@ The `startup-imports` row SHALL run `devops config get ai.provider` in a fresh i #### Scenario: A decisions probe that imports pydantic_ai - **WHEN** the decisions probe prints that `pydantic_ai` is loaded - **THEN** the row names the probe and its value as a problem + +### Requirement: The bwrap row runs the sandbox contract suites where the host can make a sandbox +The table of `devops ci` SHALL hold a row `bwrap` that runs `pytest -m bwrap -n 0` with a bound for each test over the two contract suites of the sandbox, after the host check of the sandbox executor. On a host that fails the check, the row SHALL start no test, SHALL pass, and SHALL show `skipped: `, also in a cached verdict. + +#### Scenario: A host that can make the sandbox +- **WHEN** `devops ci --only bwrap` runs and bubblewrap makes a sandbox on the host +- **THEN** the row starts `uv run pytest -m bwrap -n 0 --timeout=60` with `tests/sandbox/test_host_sandbox.py` and `tests/ai/test_tool_executor_contract.py` + +#### Scenario: A host that cannot make the sandbox +- **WHEN** `devops ci --only bwrap` runs and bubblewrap exits 1 with `bwrap: setting up uid map: Permission denied` +- **THEN** the row starts no test, the gate exits 0, and the output shows `[bwrap] skipped: bubblewrap cannot make a sandbox on this host: bwrap: setting up uid map: Permission denied` + +#### Scenario: A cached verdict keeps the skip +- **WHEN** a full gate passed with the row skipped, and the gate runs again on the same tree +- **THEN** the cached summary shows the row as skipped and starts no command