instrument sandbox docker runtime
This commit is contained in:
parent
4cdf6e45de
commit
8d3a080d45
6 changed files with 411 additions and 73 deletions
|
|
@ -10,6 +10,7 @@ from docker.types import Mount
|
|||
|
||||
from adapter.config.model import SandboxConfig
|
||||
from adapter.docker.runtime import DockerSandboxRuntime
|
||||
from adapter.observability.noop import NoopMetrics, NoopTracer
|
||||
from domain.error import SandboxError, SandboxStartError
|
||||
from domain.sandbox import SandboxSession, SandboxStatus
|
||||
|
||||
|
|
@ -116,6 +117,18 @@ def build_config(tmp_path: Path) -> SandboxConfig:
|
|||
)
|
||||
|
||||
|
||||
def build_runtime(
|
||||
config: SandboxConfig,
|
||||
containers: FakeContainers,
|
||||
) -> DockerSandboxRuntime:
|
||||
return DockerSandboxRuntime(
|
||||
config,
|
||||
FakeDockerClient(containers),
|
||||
NoopMetrics(),
|
||||
NoopTracer(),
|
||||
)
|
||||
|
||||
|
||||
def test_runtime_create_applies_mount_policy_and_labels_with_canonical_chat_id(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
|
|
@ -123,7 +136,7 @@ def test_runtime_create_applies_mount_policy_and_labels_with_canonical_chat_id(
|
|||
(tmp_path / 'dependencies').mkdir()
|
||||
(tmp_path / 'lambda-tools').mkdir()
|
||||
containers = FakeContainers()
|
||||
runtime = DockerSandboxRuntime(config, FakeDockerClient(containers))
|
||||
runtime = build_runtime(config, containers)
|
||||
created_at = datetime(2026, 4, 2, 12, 0, tzinfo=UTC)
|
||||
expires_at = created_at + timedelta(minutes=5)
|
||||
|
||||
|
|
@ -181,7 +194,7 @@ def test_runtime_create_raises_start_error_when_container_id_is_missing(
|
|||
(tmp_path / 'dependencies').mkdir()
|
||||
(tmp_path / 'lambda-tools').mkdir()
|
||||
containers = FakeContainers(run_result=FakeContainer(''))
|
||||
runtime = DockerSandboxRuntime(config, FakeDockerClient(containers))
|
||||
runtime = build_runtime(config, containers)
|
||||
|
||||
with pytest.raises(SandboxStartError) as excinfo:
|
||||
runtime.create(
|
||||
|
|
@ -199,7 +212,7 @@ def test_runtime_stop_ignores_missing_container(tmp_path: Path) -> None:
|
|||
config = build_config(tmp_path)
|
||||
containers = FakeContainers()
|
||||
containers.get_result = NotFound('missing')
|
||||
runtime = DockerSandboxRuntime(config, FakeDockerClient(containers))
|
||||
runtime = build_runtime(config, containers)
|
||||
|
||||
runtime.stop('container-123')
|
||||
|
||||
|
|
@ -210,7 +223,7 @@ def test_runtime_stop_wraps_docker_errors(tmp_path: Path) -> None:
|
|||
config = build_config(tmp_path)
|
||||
containers = FakeContainers()
|
||||
containers.get_result = DockerException('boom')
|
||||
runtime = DockerSandboxRuntime(config, FakeDockerClient(containers))
|
||||
runtime = build_runtime(config, containers)
|
||||
|
||||
with pytest.raises(SandboxError) as excinfo:
|
||||
runtime.stop('container-123')
|
||||
|
|
@ -243,7 +256,7 @@ def test_runtime_list_active_sessions_reads_valid_labeled_containers(
|
|||
created_at='2026-04-02T12:01:00Z',
|
||||
),
|
||||
]
|
||||
runtime = DockerSandboxRuntime(config, FakeDockerClient(containers))
|
||||
runtime = build_runtime(config, containers)
|
||||
|
||||
sessions = runtime.list_active_sessions()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue