strix/tests/test_docker_client_devices.py
Ahmed Allam 200a501f15
Some checks failed
CI / python (push) Has been cancelled
CI / tui (push) Has been cancelled
CI / viewer (push) Has been cancelled
CI / package (push) Has been cancelled
CI / workflows (push) Has been cancelled
CI / ci-passed (push) Has been cancelled
feat(runtime): pass host devices from STRIX_DOCKER_SANDBOX_DEVICES through to the sandbox container
2026-10-25 01:59:21 +03:00

32 lines
1.2 KiB
Python

"""``STRIX_DOCKER_SANDBOX_DEVICES`` passes host devices through to the sandbox container."""
from __future__ import annotations
from typing import TYPE_CHECKING
from strix.runtime import docker_client
if TYPE_CHECKING:
import pytest
def test_unset_adds_no_devices(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv(docker_client._SANDBOX_DEVICES_ENV, raising=False)
kwargs: dict[str, object] = {}
docker_client._apply_sandbox_devices(kwargs)
assert kwargs == {}
def test_devices_are_mapped_to_the_same_path_rwm(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv(docker_client._SANDBOX_DEVICES_ENV, " /dev/net/tun, /dev/kvm ,,")
kwargs: dict[str, object] = {}
docker_client._apply_sandbox_devices(kwargs)
assert kwargs["devices"] == ["/dev/net/tun:/dev/net/tun:rwm", "/dev/kvm:/dev/kvm:rwm"]
def test_existing_devices_are_kept_and_not_duplicated(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv(docker_client._SANDBOX_DEVICES_ENV, "/dev/fuse,/dev/net/tun")
kwargs: dict[str, object] = {"devices": ["/dev/fuse"]}
docker_client._apply_sandbox_devices(kwargs)
assert kwargs["devices"] == ["/dev/fuse", "/dev/net/tun:/dev/net/tun:rwm"]