Skip to content

refactor(docker): DockerEngineService is the Docker engine seam, with an in-memory engine fake and its contract suite - #2534

Merged
dan-petty merged 6 commits into
mainfrom
refactor/1316-docker-engine-seam
Oct 28, 2026
Merged

dan-petty merged 6 commits into
mainfrom
refactor/1316-docker-engine-seam

Conversation

@dan-petty

@dan-petty dan-petty commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

DockerEngineService is the one way to the Docker engine, but its tests reached past it: the docker_engine fixture set the private _client of a service and patched get_instance, and tests/test_docker_engine.py built 48 MagicMock objects and patched docker.DockerClient 14 times. No shared fake of the engine existed, and nothing held a double to what the docker SDK does over a real engine.

The fake mirrors the SDK in one place where the service is wrong: docker-py's logs takes no demux, so container_log_stream fails on every real engine. That defect is #2520; this change does not change the method.

Closes #1316

Change: openspec/changes/archive/2026-10-28-1316-docker-engine-seam/

@dan-petty

Copy link
Copy Markdown
Owner Author

Test evidence:

  • Before the recording, each scenario ran straight against a local Docker Engine 29.9.2 and over the fake, and the two gave the same result.
  • The record was made three times; each record passed the suite. One recorded run showed the stdout and stderr lines of one log in the other order, so the scenario compares those lines as a sorted list.
  • uv run pytest tests/docker tests/test_docker_engine.py: 112 passed. No contract case takes more than 0.2 s.
  • The users of the docker_engine factory (test_docker.py, test_sandbox_*, test_workload_sandbox.py, test_ui_dashboard.py, test_devcontainer.py, test_subsystem_containment_and_redaction.py) and test_docker_engine.py: 663 passed.
  • After the rebase onto origin/main: the Docker tests, test_docker.py, test_sandbox_lifecycle.py and test_ui_dashboard.py passed (355).
  • Full uv run devops ci before the last fixes: every gate passed except security (bandit B108 on a /tmp fallback and an exec workdir of /tmp) and uv-check (list[...] inside classes with a list method). Both are fixed. security, uv-check, typecheck, lint, format, deps, docs and devops openspec check pass again. The test gate took 7 m 12 s on a loaded host; perf(ci): the startup-import tests start 56 interpreters and take 204 s of the suite's 2,423 s #2369, perf(ci): each test shard collects only its own test files #2371 and perf(ci): measure coverage and branch cost #2373 cover the suite's time.
  • grep -c MagicMock tests/test_docker_engine.py gives 0; grep -c '_client\|get_instance' tests/test_docker_engine.py gives 0.
  • The record holds no private IPv4 address, internal host name, home or workspace path, password or secret (grep).

Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).

…factory, with an in-memory engine fake and its contract suite

DockerEngineService builds the docker SDK client with a ClientFactory,
docker.DockerClient unless DockerEngineService.install gives it
another. The endpoint check and the mapping of a failure to
DockerDaemonUnavailableError stay on the service's path.
devops_cli/docker/sdk.py names the SDK calls that devops-cli makes as
Protocols.

DockerEngineFake is an in-memory engine behind those calls, with the
docker_daemon fixture. The contract suite runs eight scenarios over the
fake and over a real docker.DockerClient that reads the Engine API's
answers, recorded from Docker Engine 29.9.2 and replayed on a Unix
socket that the test binds.
…fake

tests/test_docker_engine.py builds no MagicMock client and reaches no
private name of the service. The docker_engine factory installs a
test's own client through DockerEngineService.install and no longer
patches get_instance.
…tderr, and the replay socket stays under the test's own directory

The engine reads stdout and stderr from two pipes, so a scenario
compares the lines of one log as a sorted list. The replay server and
the recorder bind their socket under the temporary directory that
pytest keeps short, and end a connection whose client stops reading a
stream. The exec scenario runs in `/`. The SDK Protocols name the
built-in `list` where a method of the same name would hide it.
…ed engine, and the support plugins load on a base without the seam

A contract case runs DockerEngineService with its default factory
against the recorded engine, and reads the same daemon facts as over
the fake. The Protocols are one-line stubs, as in k8s/api.py. The
scenarios import the Protocol only for typing, so the fail-to-pass
replay loads the support plugins on a base without the module.
@dan-petty
dan-petty force-pushed the refactor/1316-docker-engine-seam branch from 1db3289 to b928d8a Compare October 28, 2026 20:55
@dan-petty
dan-petty marked this pull request as ready for review October 28, 2026 21:01
@dan-petty
dan-petty merged commit 1244cbf into main Oct 28, 2026
18 of 20 checks passed
@dan-petty
dan-petty deleted the refactor/1316-docker-engine-seam branch October 28, 2026 21:01
dan-petty pushed a commit that referenced this pull request Oct 28, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.11.3](v0.11.2...v0.11.3)
(2026-10-28)


### Bug Fixes

* **roadmap:** refine wraps no link in the model's code, and wraps each
reference and link that GitHub makes from its text
([#2540](#2540))
([2d38f8d](2d38f8d)),
closes [#2525](#2525)


### Code Refactoring

* **docker:** DockerEngineService is the Docker engine seam, with an
in-memory engine fake and its contract suite
([#2534](#2534))
([1244cbf](1244cbf)),
closes [#1316](#1316)
* **security:** one keyring seam owns the keyring and the Secret
Service, with a shared fake and its contract suite
([#2532](#2532))
([866d2cb](866d2cb)),
closes [#1318](#1318)
* **telemetry:** OTLP export goes through one exporter seam, and tests
read exported spans and metrics from a shared fake
([#2541](#2541))
([8da35e6](8da35e6)),
closes [#1319](#1319)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: dan-petty-release[bot] <346998822+dan-petty-release[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(infra): DockerEngineService is the Docker engine seam, with a shared in-memory engine fake and its contract suite

1 participant