85 lines
3.1 KiB
Python
85 lines
3.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from pyro_mcp.runtime import doctor_report, resolve_runtime_paths, runtime_capabilities
|
|
|
|
|
|
def test_resolve_runtime_paths_default_bundle() -> None:
|
|
paths = resolve_runtime_paths()
|
|
assert paths.firecracker_bin.exists()
|
|
assert paths.jailer_bin.exists()
|
|
assert (paths.artifacts_dir / "debian-git" / "vmlinux").exists()
|
|
assert paths.manifest.get("platform") == "linux-x86_64"
|
|
|
|
|
|
def test_resolve_runtime_paths_missing_manifest(
|
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
) -> None:
|
|
empty_root = tmp_path / "bundle"
|
|
empty_root.mkdir(parents=True, exist_ok=True)
|
|
monkeypatch.setenv("PYRO_RUNTIME_BUNDLE_DIR", str(empty_root))
|
|
with pytest.raises(RuntimeError, match="manifest not found"):
|
|
resolve_runtime_paths()
|
|
|
|
|
|
def test_resolve_runtime_paths_checksum_mismatch(
|
|
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
) -> None:
|
|
source = resolve_runtime_paths()
|
|
copied_bundle = tmp_path / "bundle"
|
|
copied_platform = copied_bundle / "linux-x86_64"
|
|
copied_platform.mkdir(parents=True, exist_ok=True)
|
|
(copied_bundle / "NOTICE").write_text(
|
|
source.notice_path.read_text(encoding="utf-8"), encoding="utf-8"
|
|
)
|
|
|
|
manifest = json.loads(source.manifest_path.read_text(encoding="utf-8"))
|
|
(copied_platform / "manifest.json").write_text(
|
|
json.dumps(manifest, indent=2),
|
|
encoding="utf-8",
|
|
)
|
|
firecracker_path = copied_platform / "bin" / "firecracker"
|
|
firecracker_path.parent.mkdir(parents=True, exist_ok=True)
|
|
firecracker_path.write_text("tampered\n", encoding="utf-8")
|
|
(copied_platform / "bin" / "jailer").write_text(
|
|
(source.jailer_bin).read_text(encoding="utf-8"),
|
|
encoding="utf-8",
|
|
)
|
|
for profile in ("debian-base", "debian-git", "debian-build"):
|
|
profile_dir = copied_platform / "profiles" / profile
|
|
profile_dir.mkdir(parents=True, exist_ok=True)
|
|
for filename in ("vmlinux", "rootfs.ext4"):
|
|
source_file = source.artifacts_dir / profile / filename
|
|
(profile_dir / filename).write_text(
|
|
source_file.read_text(encoding="utf-8"), encoding="utf-8"
|
|
)
|
|
|
|
monkeypatch.setenv("PYRO_RUNTIME_BUNDLE_DIR", str(copied_bundle))
|
|
with pytest.raises(RuntimeError, match="checksum mismatch"):
|
|
resolve_runtime_paths()
|
|
|
|
|
|
def test_doctor_report_has_runtime_fields() -> None:
|
|
report = doctor_report()
|
|
assert "runtime_ok" in report
|
|
assert "kvm" in report
|
|
assert "networking" in report
|
|
if report["runtime_ok"]:
|
|
runtime = report.get("runtime")
|
|
assert isinstance(runtime, dict)
|
|
assert "firecracker_bin" in runtime
|
|
networking = report["networking"]
|
|
assert isinstance(networking, dict)
|
|
assert "tun_available" in networking
|
|
|
|
|
|
def test_runtime_capabilities_reports_shim_bundle() -> None:
|
|
paths = resolve_runtime_paths()
|
|
capabilities = runtime_capabilities(paths)
|
|
assert capabilities.supports_vm_boot is False
|
|
assert capabilities.supports_guest_exec is False
|
|
assert capabilities.supports_guest_network is False
|