Skip to content

refactor(ci): ci installs nothing on the runner, and live bubblewrap tests skip where bwrap is missing #832

Closed

Description

@dan-petty

Problem Statement

The Tests & Coverage job changes the runner in one step at .github/workflows/ci.yml:90-94. No other workflow or composite action does: grep -rnE 'apt-get|sudo|sysctl' .github/ matches only those lines (checked at 9da1309, re-checked at 9c879ae). The step:

  • runs sudo apt-get update -y and sudo apt-get install -y bubblewrap python-is-python3;
  • runs sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0 || true, which turns off Ubuntu 24.04's AppArmor limit on unprivileged user namespaces for the whole runner. That sysctl is mentioned nowhere else in the repository.

It arrived with v0.2.23 (ea49d6e, #681) so that the live bubblewrap tests from #592 and #663 could run in CI.

What the step does in practice, taken from run 36895839743 (2026-10-01):

  • It takes 10 s per run and downloads bubblewrap 0.9.0-1ubuntu0.3 from the Ubuntu mirror.
  • python-is-python3 is already in the runner image ("already the newest version (3.11.4-1)"), so that half of the step does nothing.
  • None of the 161 failed CI runs on record failed in this step.

So the problem is hermeticity, not flakiness. Every run depends on a package mirror and weakens a kernel security setting. It also tests the sandbox against Ubuntu's bwrap and system Python, not the devcontainer's (#847).

The devcontainer already installs bubblewrap (.devcontainer/Dockerfile:23). The pre-push hook runs uv run devops ci there (.pre-commit-config.yaml:70-77, AGENTS.md:59-62), so the live tests keep running before every push.

Removing the step on its own breaks CI. With /usr/bin/bwrap masked, the three affected files at 9da1309 end with 17 failed and 43 passed (re-measured during refinement; the issue's full-suite figure at ef21785 was 17 failed, 6491 passed). The failures are in three files, not only tests/test_host_sandbox.py:

  • tests/test_host_sandbox.py has 8 live tests (:16, :30, :41, :54, :68, :172, :187, :208). It also has test_host_sandbox_handles_namespace_refusal (:125). That test patches subprocess.Popen, but HostSandbox.execute checks is_available() first (src/devops_cli/sandbox/host.py:430-438), so it still needs a real bwrap. test_host_sandbox_build_args_structure (:108) and test_host_sandbox_consumes_custom_policy (:146) only call build_bwrap_args and pass without bwrap; test_host_sandbox_fails_closed_when_bwrap_missing (:90) passes a nonexistent binary on purpose.
  • tests/test_executable_criteria.py has 7 tests that run criteria through the sandbox (:169, :184, :195, :211, :225, :254, :283).
  • tests/test_verdict_writers.py:116 (test_criteria_execution_verdict_finality).

HostSandbox.__init__ resolves the binary as bwrap_binary or shutil.which("bwrap") or DEFAULT_HOST_SANDBOX_BINARY (sandbox/host.py:325; /usr/bin/bwrap at config/defaults.py:415), and is_available() checks that the path is an executable file (sandbox/host.py:329-331). Once is_available() is true, a patched subprocess.Popen returning a MagicMock takes the explicit mock branch in _communicate_bounded (sandbox/host.py:226, _is_mock_subprocess at :71), so a stub binary is enough to make the refusal test hermetic (verified during refinement: a #!/bin/sh stub under a temp dir plus the test's mock yields passed=False, exit_code=1, error="Host sandbox error: bwrap: Setting up uid map: Permission denied" with the system bwrap masked). No test skips on is_available() today, and pyproject.toml:101-105 registers no pytest markers.

Coverage: CI enforces fail_under = 90 (pyproject.toml:113). The last green CI run reached 90.43%. Measured locally over the full suite (73,372 statements):

  • With bwrap present: 90.46%.
  • With bwrap hidden: 90.34%. That is 85 more statements missed, mostly in sandbox/host.py, which drops from 86% to 48%.

Proposed Solution

  • Delete the "Install bubblewrap host sandbox dependencies" step (ci.yml:90-94). No workflow runs apt-get, sudo or sysctl afterwards.
  • Register a bwrap marker in [tool.pytest.ini_options] (pyproject.toml:101-105). Its description says the test needs a working bubblewrap and is skipped where bwrap is not installed.
  • Add one pytest_collection_modifyitems hook in tests/conftest.py, beside the existing session hooks (:726-763). When HostSandbox().is_available() is false, it adds a skip to every item marked bwrap, with a reason that names bubblewrap. It constructs HostSandbox once per collection, not per item.
  • Mark the 16 live tests listed above with @pytest.mark.bwrap. test_host_sandbox_build_args_structure (:108), test_host_sandbox_consumes_custom_policy (:146) and test_host_sandbox_fails_closed_when_bwrap_missing (:90) are not marked: they never execute bwrap.
  • Make test_host_sandbox_handles_namespace_refusal hermetic. Pass HostSandbox an executable stub file under tmp_path as bwrap_binary, so is_available() is true and the patched subprocess.Popen returns the mocked refusal through the mock branch at sandbox/host.py:226. The test then runs everywhere, CI included.
  • Add one offline invariant to tests/test_architectural_invariants.py, next to the existing ci.yml and Dockerfile check (test_devcontainer_image_path_filter_covers_dockerfile_sources, :428-460, helpers at :397-425). It checks two things:
    • no run: step in any job of .github/workflows/*.yml calls apt-get, sudo or sysctl;
    • .devcontainer/Dockerfile installs bubblewrap.
  • Add changelog.d/832.md and docs/agent/tasks/task-832-<slug>.md in the delivering PR.

Scope

Key Questions

  • Where do the confinement tests run once CI skips them? Answered: in the devcontainer. The pre-push hook runs uv run devops ci there, and bubblewrap is in the image. GitHub CI stops checking confinement. When chore(github): required CI checks bind merges into release and main, and ADR 0004 records the verification policy #842 (v0.2.27) makes Tests & Coverage a required check, that check still won't cover confinement. The owner's issue asks for this split, and fix(review): criteria commands run in the reviewed project's environment with a measured python timeout #847 already assumes it.
  • Should the tests skip only when bwrap is absent, or also when bwrap is present but can't create namespaces? Answered: only when it is absent. A refusal means a host that has the sandbox but can't use it, and reviews on that host would hit the same failure. Failing makes that visible. If a future runner image ships bwrap with the AppArmor limit still on, CI fails loudly and a person decides then.
  • Should the four verdict and confidence tests (test_executable_criteria.py:225,254,283, test_verdict_writers.py:116) get a stub sandbox so they keep running in CI? Answered: no. They test criteria end to end through the real sandbox, and the pre-push gate runs them. A fake sandbox would win back only about 10 statements of review_environment.py coverage in CI (measured).
  • Should the job run inside the devcontainer image instead? Answered: no. That image is built only for PRs into main (ci.yml:101-103). Running bwrap in a job container on the runner would likely need extra container privileges or the same kernel setting, which brings back what this item removes. refactor(ci): github ci runs the gate through devops ci from one check table #843 owns the CI job structure.
  • Where does the skip logic live: a registered marker plus one conftest.py hook, or a skipif decorator per file? Answered: a registered bwrap marker and one hook in tests/conftest.py. The marker gives uv run pytest -m bwrap and a single reason string; a per-file skipif (the stash's design) gives neither. fix(test): the test network guard refuses loopback connects to services the test did not start #837, which also edited conftest.py, shipped in v0.2.24 (d3b2b64, e6ce3db), so there is nothing to rebase on; its loopback guard is now prevent_external_network_calls at tests/conftest.py:98-99.
  • Does dropping python-is-python3 change anything? Answered: no. The runner image already ships it, and the only tests that run python (not python3) inside the sandbox are the 7 marked tests in test_executable_criteria.py and test_verdict_writers.py:116, which skip in CI. test_host_sandbox_fails_closed_when_bwrap_missing (:90) names python -c but never executes it.
  • Does CI coverage stay at or above 90%? Answered: yes, at about 90.3% (measured above). The margin shrinks from about 0.43 to about 0.31 points.
  • Does the invariant cover every workflow, or only ci.yml? Answered: every file in .github/workflows/*.yml (ci.yml, cleanup-devcontainer.yml, codeql.yml, release.yml, update-prs.yml). None of them uses apt-get, sudo or sysctl today, so the invariant passes at landing and stops any workflow from starting. The composite action .github/actions/setup-toolchain/action.yml has only uv sync and mkdir run steps (:46, :50) and is out of the invariant's glob; refactor(ci): github ci runs the gate through devops ci from one check table #843's allowlist covers the composite action.

Acceptance Criteria

  • No workflow changes the runner. grep -rnE 'apt-get|sudo|sysctl' .github/workflows prints nothing, and the new invariant test in tests/test_architectural_invariants.py passes.
  • The invariant test fails if a sudo apt-get install step is added back to ci.yml, and fails if bubblewrap is removed from the Dockerfile. Verified by the builder making each edit locally, watching uv run pytest tests/test_architectural_invariants.py -k <new test name> fail, and reverting it. The PR notes the result. The test takes under 1 s, checked with --durations=0.
  • bwrap is a registered marker: uv run pytest --markers lists it with a description that names bubblewrap, and uv run pytest -m bwrap --collect-only -q collects exactly 16 tests.
  • Where bwrap is missing, the 16 marked tests skip and nothing fails. Verified on the PR's own CI run: the Tests & Coverage log reports 16 skipped and 0 failed, and the skip reason names bubblewrap (-rs).
  • test_host_sandbox_handles_namespace_refusal passes without bwrap. Verified by the same CI run, where it passes and is not among the skipped tests (16 skipped, not 17). Locally, uv run pytest tests/test_host_sandbox.py -k namespace_refusal passes with HostSandbox given an executable stub under tmp_path as bwrap_binary.
  • In the devcontainer, uv run pytest -m bwrap -rs runs 16 tests with 0 skipped, and uv run devops ci passes. Verified by the builder in the devcontainer, with the output in the PR.
  • CI coverage stays at or above fail_under = 90. Verified on the PR's CI run, where about 90.3% is expected.
  • uv run actionlint passes on the edited ci.yml, and the existing tests/test_ci.py workflow tests (:594-628) still pass.
  • src/devops_cli/sandbox/ is unchanged: git diff --stat <base>..HEAD -- src/devops_cli/sandbox/ prints nothing.
  • changelog.d/832.md and docs/agent/tasks/task-832-<slug>.md are in the delivering PR; CHANGELOG.md and docs/ROADMAP.md are not edited (devops pr check-readiness passes).

Out of Scope

Dependencies

Activity

  1. added this to the v0.2.24 milestone on Oct 1, 2026
  2. added
    type/refactor
    type/infra
    scope/github
    priority/p1-high
    on Oct 1, 2026
  3. modified the milestones: v0.2.24, v0.2.25 on Oct 1, 2026
  4. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Descoped from v0.2.24 to v0.2.25 under #740's Cap rule. Admitting the critical fix #837 descopes the lowest-priority item that hasn't started, and this was the only one. #843 (CI parity) builds on it.

  5. changed the title [-]Remove ad-hoc package updates and installs from CI workflow[/-] [+]refactor(ci): ci installs nothing on the runner, and live bubblewrap tests skip where bwrap is missing[/+] on Oct 1, 2026
  6. modified the milestones: v0.2.25, v0.2.26 on Oct 1, 2026
  7. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Moved from v0.2.25 to v0.2.26 to bring v0.2.25 to its cap of 12. #740's cap rule had descoped this item from v0.2.24, so no person placed it in v0.2.25, and it comes last in the trim order: P1, Medium value, highest number. In v0.2.26 it lands before #843, which depends on it.

  8. dan-petty commented on Oct 4, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1156, merged into release/v0.2.26.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  9. added a commit that references this issue on Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/githubtype/infratype/refactor

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions