Skip to content

test(sandbox): sandbox tests run on edge fakes #3749

Closed

Description

@dan-petty

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) and engine.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 of uv run devops.
  • sandbox.metrics.parse_cgroup_v2_directory, read_cgroup_v2_metrics, collect_sandbox_metrics, scrape_prometheus_metrics and _read_container_stats_via_engine. A cgroup tree under tmp_path replaces 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._CONSOLE and _STDERR_CONSOLE, and models.is_loopback_or_private_host. The real object, a temporary directory or the config fixture replaces each one.
  • The 11 seam sites are socket.getaddrinfo (8), socket.socket (2) and httpx2.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

  1. Replace each patch with the fake or the real object named above. Where a test needs a DNS answer, it takes it from public_dns or scripted_resolver. Where a test needs an HTTP answer from a loopback server, it starts the server.
  2. Move the span fallback to telemetry/waterfall.py as a public function. commands/sandbox.py calls it. Test it in tests/telemetry/.
  3. 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").
  4. Use the cli fixture. Dissolve the catch-all into tests that are named after the behaviour.
  5. Split test_sandbox_lifecycle.py (1,774 lines), test_sandbox_metrics.py and test_sandbox_networking.py by 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.
  6. Leave the 11 seam sites as they are. The code under them reaches DNS and HTTP through vet_addresses and new_http_client (sandbox/probe.py:124, 291 and sandbox/metrics.py:366). The seams of refactor(cli): Unify HTTP and DNS seams with shared fakes #1314 replace the patches.
  7. 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_spans and last set, 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 and last not 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.py holds no span-resolution logic. _resolve_spans_for_traces is 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 ci passes. 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

  1. added
    source/agent
    type/test
    scope/sandbox
    status/new
    value/medium
    effort/high
    on Nov 6, 2026
  2. dan-petty commented on Nov 6, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

  3. added
    priority/p2-medium
    on Nov 6, 2026
  4. added
    status/in-review
    and removed
    status/new
    on Nov 6, 2026
  5. removed
    status/in-review
    on Nov 6, 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

    effort/highpriority/p2-mediumscope/sandboxsource/agenttype/testvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions