Files
hms-mediaengine/tests/unit/test_portable_paths.py
T
HMS MediaEngine Agent 0922cc1d68 Phase 0: Repository-Initialisierung nach Bauplan v1.2
- Struktur gemäß §8 (Eigentumsgrenzen), PLAN.md als normative Basis
- Pflichtdokumente: STATUS.md, ERRORS.md, TEST_REPORT.md, CHANGELOG.md, ADRs
- ADR-0001 Python 3.13-Pin, ADR-0002 GStreamer 1.28.6-Pin (Windows),
  ADR-0003 IPC TCP+MessagePack v1
- Kernpakete: hms_protocol, hms_domain, hms_parameter, hms_artnet,
  hms_adaptive, hms_capabilities, hms_plugin_sdk
- Renderer-Spike: D3D11-Primärpfad + Dev-GL-Pfad (§36 Nr. 4-5)
- Control Core: FastAPI REST + WebSocket (§36 Nr. 9)
- Beispielplugins: Passthrough + Gaussian Blur (3 Adaptive-Quality-
  Varianten, HLSL/GLSL/GLES)
- Tools: Art-Net-Emulator, Fixture-Generator (Master32/Layer64-CSV),
  Capability-Probe
- JSON-Schemas: IPC, Plugin, Projekt, Cluster
- 121 Unit-/Integrationstests grün, Ruff grün

Gate 0 bleibt offen: Hardwaremessungen nur auf echter Windows-Referenz-
hardware gültig (§29.7, §33).
2026-09-11 00:36:59 +02:00

55 lines
2.1 KiB
Python

"""Unit-Tests portable Pfade (PLAN.md §9, §9.1)."""
from __future__ import annotations
from pathlib import Path
from hms_launcher import AppPaths
def test_paths_are_relative_to_root(tmp_path: Path) -> None:
paths = AppPaths(root=tmp_path)
assert paths.app == tmp_path / "app"
assert paths.runtime == tmp_path / "runtime"
assert paths.gstreamer_bin == tmp_path / "runtime" / "gstreamer" / "bin"
assert paths.gstreamer_plugins == tmp_path / "runtime" / "gstreamer" / "lib" / "gstreamer-1.0"
assert paths.database == tmp_path / "userdata" / "database"
assert paths.cache == tmp_path / "userdata" / "cache"
assert paths.identity == tmp_path / "userdata" / "identity" / "node_id"
# Keine Laufwerksbuchstaben, keine absoluten Fremdpfade
assert not str(paths.app).startswith("C:")
def test_ensure_writable(tmp_path: Path) -> None:
assert AppPaths(root=tmp_path).ensure_writable() is True
assert not (tmp_path / ".write_probe").exists() # Probe wird aufgeräumt
def test_ensure_writable_false_on_write_error(tmp_path: Path, monkeypatch) -> None:
"""Schreibfehler (z. B. schreibgeschütztes Medium) → False.
Der Fehler wird simuliert, weil root in Containern Verzeichnisrechte
umgeht und ein chmod-Test dort falsch grün/rot wäre.
"""
from pathlib import Path as _Path
def _raise_write(self, *args, **kwargs):
raise OSError("read-only file system")
monkeypatch.setattr(_Path, "write_text", _raise_write)
assert AppPaths(root=tmp_path).ensure_writable() is False
def test_portable_environment_sets_gstreamer_vars(tmp_path: Path) -> None:
paths = AppPaths(root=tmp_path)
env = paths.portable_environment()
assert env["GST_PLUGIN_PATH_1_0"].endswith("gstreamer-1.0")
assert env["GST_PLUGIN_SYSTEM_PATH_1_0"] == "" # System-Plugins unterdrückt
def test_portable_environment_prepends_bundled_bin(tmp_path: Path) -> None:
gs_bin = tmp_path / "runtime" / "gstreamer" / "bin"
gs_bin.mkdir(parents=True)
env = AppPaths(root=tmp_path).portable_environment()
assert env["PATH"].startswith(str(gs_bin))