Repository navigation
Labels
effort/highEffort High: much work, in one pull requestpriority/p2-mediumPriority P2: standard workscope/infraDocker container images, DevContainers, and infrastructure toolingtype/refactorType refactor: a new structure, same behaviorvalue/highValue High: the delivery of the item matters much
Description
Problem
- The engine service is the seam, but tests reach past it.
DockerEngineService[code: src/devops_cli/docker/engine.py:197] is a process singleton (get_instance:214,reset_instance:221,get_engine:539). Itsclient()(:248) validatesDOCKER_HOST(:228-246) and builds the SDK client withdocker.from_env(:257). Thedocker_enginefixture binds a client by setting the private_clientand patchingget_instance[code: tests/conftest.py:738-739]; its 7 users pass the clients they build (with docker_engine(mock_client):, tests/test_docker.py:44). - One bypass skips the egress check. The dashboard builds its own client with
docker.from_env()and no timeout [code: src/devops_cli/ui/data_providers.py:217-221], so a networkDOCKER_HOSTis used without the validation the engine applies. - No shared fake exists. tests/test_docker_engine.py alone builds 31
MagicMockobjects [measured: grep at 5c45b1e]. - docker and podman CLI calls are processes, faked by the process fake of refactor(cli): one process runner owns execution, process groups and dry-run #775, not by this item.
Acceptance criteria
Seam
-
DockerEngineServiceis the seam that supplies the docker SDK client, after validatingDOCKER_HOSTas today. A Protocol indocker/names the SDK calls devops-cli makes: ping and daemon info; container list, get, create, start, stop, remove, exec, logs, log stream, stats and wait; image list; network get, create and list; volume list; disk usage; build-cache prune. - A public hook installs a client for a test. The
docker_enginefixture uses it instead of setting_clientand patchingget_instance; its users keep passing their own clients until their package items switch them to the fake. - The bypass at ui/data_providers.py:217 is left to test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334.
Fake and fixture
-
tests/support/fakes/docker_engine.pyis an in-memory engine: daemon info; containers with states, exit codes, logs and stats; images; networks; volumes; build cache. It raisesdocker.errors.NotFoundanddocker.errors.APIErrorwhere the daemon would, can answer as an unreachable daemon, and records each call. - A fixture installs it through the hook, resets the service at teardown and returns it, registered once from the root conftest.
Contract suite
- One suite in
tests/docker/runs each Protocol call against the fake and against the real docker SDK client, the real side reading recorded Engine API responses from a server the test owns on a unix socket undertmp_path. Cases: the result of each call, a missing container (NotFoundon both sides) and an unreachable daemon (the same error from the service on both sides). - (person-run) The recorded responses are captured once from a local Docker-compatible daemon, scrubbed to
example.comhosts, and committed undertests/fixtures/docker_engine/with the commands that captured them.
Migration
- tests/test_docker_engine.py (path before test(cli): every test file sits in the directory mirroring the package it tests or in tests/invariants/, and the root conftest holds only the hermetic floor #1313's move) uses the fake or the contract suite, builds no
MagicMockclient and reaches no private name of the service. - If test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 introduced its interim
unreachable(...)marker, every marker that names the Docker daemon, in a test whose code reaches it through the service, gives way to the fixture, in the fake's unreachable state where the test relies on the refusal. A marker on the dashboard's bypass goes with test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334. - Tests run offline; each new test runs under 1 s.
- If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its ceilings drop by the sites this PR removes (the
docker_enginefixture's patch ofget_instance[code: tests/conftest.py:739] among them). -
uv run devops cipasses.
Key questions
- Fake the SDK client or the service? (proposed) The SDK client. The service's projections into typed models (
project_container_stats:98,project_container_state:135,build_cache_report:176) then run for real in every test, and the dashboard needs daemon info, volumes and networks, which the service does not wrap. - What about the docker and podman binaries? Decided 2026-10-07: they are process edges, faked by the process fake (refactor(cli): one process runner owns execution, process groups and dry-run #775) (Q23).
- A live daemon for the real side? Decided 2026-10-07: never; recorded responses (Q26).
- Fixture name? (proposed)
docker_daemon. Thedocker_enginefactory goes once its last user has moved to the fake.
Strategic alignment
- Depends on: test(cli): tests find the repository root and fixtures from any depth, import no other test module and build test data with shared builders, and devops test maps a change to its mirror directory #1312. Blocks: test(ci): devops ci, test, devcontainer, workspace, install-tools, uv, branches and pipeline are tested over edge fakes, with no lazy patch targets or PYTEST_CURRENT_TEST checks #1325, test(cli): the infra commands are thin adapters tested over edge fakes, with no internal patches or private imports #1327, test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334, test(infra): infrastructure tests run on edge fakes #1335. Related: refactor(cli): one process runner owns execution, process groups and dry-run #775 (docker and podman through the process seam), test(cli): the hermetic floor fails a test that reaches an edge without a fake and resets all process-wide state after every test #1310 (default deny, interim markers and state resets).
- Parent: test(cli): tests double only process edges and mirror the source tree #1307 (phase D).
Proposed design
Problem statement
The Docker engine service is the seam between devops-cli and the Docker SDK. Tests reach past it by setting a private attribute and patching a singleton method. No shared in-memory fake exists for the SDK client. One dashboard code path bypasses the service and skips the DOCKER_HOST validation. This makes tests brittle and duplicates mock setup across 31 MagicMock objects.
Acceptance criteria
- Criterion 1: A Protocol in src/devops_cli/docker/ names every SDK call devops-cli makes: ping, daemon info, container list, get, create, start, stop, remove, exec, logs, log stream, stats, wait, image list, network get, create, list, volume list, disk usage, and build-cache prune.
Verification: The Protocol file exists under src/devops_cli/docker/ and lists each named method. A static check or type checker confirms the service satisfies the Protocol. - Criterion 2: A public hook on DockerEngineService installs a client for a test. The docker_engine fixture in tests/conftest.py uses the hook instead of setting _client and patching get_instance.
Verification: grep for '_client' and 'get_instance' in tests/conftest.py lines 738-739 returns no hits. The fixture calls the public hook method. - Criterion 3: The bypass at src/devops_cli/ui/data_providers.py:217 is unchanged and left to test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334.
Verification: src/devops_cli/ui/data_providers.py line 217 still calls docker.from_env(). The diff for this PR does not touch that file. - Criterion 4: tests/support/fakes/docker_engine.py is an in-memory engine with daemon info, containers with states, exit codes, logs and stats, images, networks, volumes, and build cache. It raises docker.errors.NotFound and docker.errors.APIError where the daemon would, can answer as an unreachable daemon, and records each call.
Verification: The file exists. A test imports the fake, calls each Protocol method, and asserts the recorded call log and the raised exception types. - Criterion 5: A fixture named docker_daemon installs the fake through the hook, resets the service at teardown, and returns the fake. It is registered once from the root conftest.
Verification: uv run pytest --fixtures shows docker_daemon registered from tests/conftest.py. A test that uses it gets a fresh fake on each call. - Criterion 6: One contract suite in tests/docker/ runs each Protocol call against the fake and against the real Docker SDK client. The real side reads recorded Engine API responses from a server on a unix socket under tmp_path. Cases cover the result of each call, a missing container (NotFound on both sides), and an unreachable daemon.
Verification: uv run pytest tests/docker/ passes. The suite parameterizes over fake and real client. The real side binds a unix socket under tmp_path and serves recorded responses. - Criterion 7: Recorded responses are captured once from a local Docker-compatible daemon, scrubbed to example.com hosts, and committed under tests/fixtures/docker_engine/ with the commands that captured them.
Verification: Files exist under tests/fixtures/docker_engine/. A README or header in each file states the capture command. No host other than example.com appears in the fixtures. - Criterion 8: tests/test_docker_engine.py uses the fake or the contract suite, builds no MagicMock client, and reaches no private name of the service.
Verification: grep -c 'MagicMock' tests/test_docker_engine.py returns 0. grep -c '_client|get_instance' tests/test_docker_engine.py returns 0. - Criterion 9: Every unreachable marker that names the Docker daemon, in a test whose code reaches it through the service, is replaced by the fixture in the fake's unreachable state. A marker on the dashboard bypass goes with test(telemetry): telemetry, server, ui, output and docs tests run on edge fakes, and the dashboard suite splits by behaviour #1334.
Verification: grep -rn 'unreachable' tests/ shows no marker naming the Docker daemon in tests that reach the daemon through DockerEngineService. - Criterion 10: All new tests run offline and each runs under 1 second.
Verification: uv run pytest tests/docker/ --timeout=1 -p no:cacheprovider passes with no network access (run in a network-isolated sandbox). - Criterion 11: If test(cli): ratchets hold internal patches, private imports and test accommodations in src at today's counts and name each site that would raise one #1309 has landed, its ceilings drop by the sites this PR removes, including the docker_engine fixture's patch of get_instance.
Verification: The ceiling configuration file reflects the reduced count. The removed patch site is no longer listed. - Criterion 12: uv run devops ci passes.
Verification: uv run devops ci exits with code 0.
Key questions
- Fake the SDK client or the service?: The SDK client. The service's projections into typed models then run for real in every test, and the dashboard needs daemon info, volumes, and networks, which the service does not wrap. (proposed)
- What about the docker and podman binaries?: Decided 2026-10-07: they are process edges, faked by the process fake (refactor(cli): one process runner owns execution, process groups and dry-run #775). (proposed)
- A live daemon for the real side?: Decided 2026-10-07: never. Use recorded responses. (proposed)
- Fixture name?: docker_daemon. The docker_engine factory goes once its last user has moved to the fake. (proposed)
Fit
Fits in one pull request.
Suspected block
None.
Dependencies
None.
Metadata
Metadata
Assignees
Labels
effort/highEffort High: much work, in one pull requestpriority/p2-mediumPriority P2: standard workscope/infraDocker container images, DevContainers, and infrastructure toolingtype/refactorType refactor: a new structure, same behaviorvalue/highValue High: the delivery of the item matters much
Type
Projects
- StatusShow more project fieldsReady
- StatusShow more project fieldsNew
Activity
dan-petty commentedon Oct 8, 2026
Linked: #1116 and #1108. #1116 adds prune calls this Protocol lacks; #1108 (v0.2.31) deletes the dashboard bypass (
ui/data_providers.py:217-221) this item leaves to #1334. Found by the 2026-10-08 backlog review.dan-petty-bot commentedon Oct 8, 2026
Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.
It improves testability and removes a validation bypass but does not fix a user-facing defect or add a feature, so it is important but not urgent.It makes the Docker engine testable without a live daemon and closes a validation gap, benefiting all future Docker-related work, but it does not change user-visible behaviour.It requires defining a Protocol, a public install hook, a full in-memory fake covering containers/images/networks/volumes/build-cache, a contract suite against a real SDK client, and migrating 31 existing MagicMocks.dan-petty commentedon Oct 26, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.
This change improves testability and maintainability but does not address an urgent issue or bug.Improving testability and reducing coupling makes the codebase more robust and easier to work with.Implementing a new fake engine, contract suite, and migrating existing tests requires significant effort.Both items are about creating seams with fakes and contract suites; however, the candidate focuses on Docker while #1315 addresses Kubernetes services.dan-petty commentedon Oct 28, 2026
Status set to Ready at 69636b6 (see proposed design in issue body).
chore(main): release 0.11.3 (#2539)