Repository navigation
Description
Problem or Motivation
Part 4 of 6 of #1335. It needs no other part.
Seven sandbox test files reach sandbox/ through patches and private names. Measured at origin/main 29309f0, with the counting rules of #1335:
| File | Lines | Tests | Patch sites | Seam sites | Private imports |
|---|---|---|---|---|---|
tests/sandbox/test_host_sandbox.py |
755 | 33 | 2 | 0 | 2 |
tests/sandbox/test_sandbox_metrics.py |
1,247 | 57 | 26 | 0 | 12 |
tests/sandbox/test_sandbox_probe.py |
736 | 34 | 15 | 6 | 2 |
tests/core/test_sandbox_policy_properties.py |
367 | 9 | 1 | 1 | 6 |
tests/commands/test_sandbox_lifecycle.py |
1,774 | 62 | 9 | 0 | 0 |
tests/commands/test_sandbox_logs.py |
706 | 33 | 11 | 0 | 1 |
tests/commands/test_sandbox_networking.py |
1,111 | 39 | 6 | 4 | 5 |
| Total | 6,696 | 267 | 70 | 11 | 28 |
The main patch targets:
commands.sandbox.WorkloadSandboxEngine(21 sites) andengine.registry.get_instance,WorkloadSandboxEngine.exec/stop/deploy,engine._spawn_container. The Docker fake (refactor(infra): DockerEngineService is the Docker engine seam, with a shared in-memory engine fake and its contract suite #1316, closed) and the real registry replace them.ai.mcp.server._run_mcp_cmd(3 sites). The process fake covers a call ofuv run devops.sandbox.metrics.parse_cgroup_v2_directory,read_cgroup_v2_metrics,collect_sandbox_metrics,scrape_prometheus_metricsand_read_container_stats_via_engine. A cgroup tree undertmp_pathreplaces them. The filesystem is real in tests.trace_span(2 sites). The OTLP fake (refactor(telemetry): OTLP export goes through one exporter seam, and tests read exported spans and metrics from a shared fake #1319, closed) reads the spans.sandbox.probe.probe_tcp(3 sites). A loopback listener that the test starts replaces it.sandbox.logs.archive_incident,host._communicate_bounded,os.killpg,os.chmod,telemetry.tracer._resolve_telemetry_settings(2 sites),console_module._CONSOLEand_STDERR_CONSOLE, andmodels.is_loopback_or_private_host. The real object, a temporary directory or theconfigfixture replaces each one.- The 11 seam sites are
socket.getaddrinfo(8),socket.socket(2) andhttpx2.Client(1).
The mock detection in sandbox/host.py is already gone, and _run_sandbox_process spawns through the process runner. #2149 (closed) did that. So the old criteria for bwrap are void here.
The 28 private imports name functions of sandbox/models.py, metrics.py, probe.py, host.py, logs.py and commands/sandbox.py. A test must reach each one through a public function.
CliRunner() is built 16 times in the seven files. Four are module-level: test_sandbox_metrics.py:39, test_sandbox_probe.py:37, test_sandbox_networking.py:42 and test_sandbox_logs.py:33. 12 are inside test_sandbox_lifecycle.py (lines 298, 307, 539, 596 and 774 to 922). test_read_int_and_str_file_helpers (test_sandbox_metrics.py:573) is a catch-all.
The span logic in commands/sandbox.py:821 (_resolve_spans_for_traces) is Q19 logic. It calls telemetry.waterfall.resolve_trace_spans. When that returns no spans and last is set or no trace id is given, it falls back to the buffered spans. It has nothing that is specific to the sandbox.
Proposed Solution & Architectural Design
- Replace each patch with the fake or the real object named above. Where a test needs a DNS answer, it takes it from
public_dnsorscripted_resolver. Where a test needs an HTTP answer from a loopback server, it starts the server. - Move the span fallback to
telemetry/waterfall.pyas a public function.commands/sandbox.pycalls it. Test it intests/telemetry/. - Replace each private import by a test of the public behaviour. If a private function holds a rule that no public path reaches, it is dead code. Delete it (TESTING.md, "Coverage").
- Use the
clifixture. Dissolve the catch-all into tests that are named after the behaviour. - Split
test_sandbox_lifecycle.py(1,774 lines),test_sandbox_metrics.pyandtest_sandbox_networking.pyby behaviour. Do this in the same pull request, as the files are edited anyway. Make it a separate commit so the review can see the move. - Leave the 11 seam sites as they are. The code under them reaches DNS and HTTP through
vet_addressesandnew_http_client(sandbox/probe.py:124, 291andsandbox/metrics.py:366). The seams of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 replace the patches. - This part does not wait for refactor(cli): Unify HTTP and DNS seams with shared fakes #1314. It is not proven which item migrates the sandbox callers of the factories. The text of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 does not name the sandbox package in its caller migration.
Out of scope: tests/sandbox/test_sandbox_seccomp.py, test_sandbox_tool_executor.py, test_k8s_ipv6_and_proxy_boundaries.py and tests/telemetry/test_sandbox_traces.py were not in the old list. #1336's ban finds any site that remains in them.
Acceptance criteria
- A test first for the moved span function. Given no spans from
resolve_trace_spansandlastset, it returns the buffered spans and their trace id. Given a trace id with spans, it returns those. Given a trace id with no spans andlastnot set, it returns no spans. - In the seven files, a scan finds no private import and no patch site except the 11 seam sites. The pull request comment gives the counts before (70 patch sites and 28 private imports) and after.
-
commands/sandbox.pyholds no span-resolution logic._resolve_spans_for_tracesis gone. - The seven files hold no module-level
CliRunner()and no test that lists branches in its name. - The number of tests does not fall except for deleted dead code. The pull request comment lists each deleted test and the dead function it covered.
-
uv run devops cipasses. The changed lines are covered at 90 percent.
Target Subsystem
SDLC, Git & PR Governance
Existing Tool Considered
The fakes exist: DockerEngineFake, ProcessFake, FakeCollector (OTLP) and FakeCluster (tests/support/fakes/). No new tool is needed. The cost to build is about 450,000 tokens, because 7 files with 6,700 lines change. It costs about 20,000 tokens a year to keep. The work takes about 3 days.
Strategic alignment: child of #1335. Parent #1307. Related: #2149 (closed, bwrap), #1314 (DNS and HTTP seams, replaces the 11 seam sites), #1336.
Activity
dan-petty commentedon Nov 6, 2026
Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.
testprefix of the title gives the type.(sandbox)scope of the title gives the scope.This is a test-quality refactor with no user-facing defect, but it removes 70 fragile patch sites across 267 tests.Removing internal patches and private imports makes the sandbox test suite more stable and easier to maintain.Seven files with 6,696 lines, 70 patch sites, 28 private imports, plus file splits and a span-logic move.Both work on sandbox tests, but #2149 delivered the process fake and mock-detection removal for host sandbox, while the candidate refactors all seven sandbox test files to edge fakes.test(infra): infrastructure tests run on edge fakes (#4283)