Files
hms-mediaengine/tests/unit/test_domain_ids.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

54 lines
1.7 KiB
Python

"""Unit-Tests stabile IDs (PLAN.md §3.6, §6.3)."""
from __future__ import annotations
import uuid
from hms_domain import new_node_id, new_uuid, persistent_node_id
def test_new_uuids_are_unique_and_parseable() -> None:
a, b = new_uuid(), new_uuid()
assert a != b
uuid.UUID(a)
uuid.UUID(b)
def test_node_id_is_uuid_and_random() -> None:
a, b = new_node_id(), new_node_id()
uuid.UUID(a)
assert a != b
def test_persistent_node_id_stable_across_calls(tmp_path) -> None:
identity = tmp_path / "identity" / "node_id"
first = persistent_node_id(identity)
second = persistent_node_id(identity)
assert first == second # IP-/Hostnamenunabhängig: Datei ist Quelle der Wahrheit
assert identity.read_text(encoding="utf-8").strip() == first
def test_persistent_node_id_validated_on_load(tmp_path) -> None:
identity = tmp_path / "identity" / "node_id"
identity.parent.mkdir(parents=True)
identity.write_text("not-a-uuid", encoding="utf-8")
import pytest
with pytest.raises(ValueError):
persistent_node_id(identity)
def test_two_nodes_get_distinct_ids(tmp_path) -> None:
a = persistent_node_id(tmp_path / "a" / "node_id")
b = persistent_node_id(tmp_path / "b" / "node_id")
assert a != b # doppelte node_ids wären ein Fehler (§6.3)
def test_concurrent_creation_yields_single_id(tmp_path) -> None:
"""O_EXCL-Rennbedingung: beide Aufrufer erhalten dieselbe ID."""
identity = tmp_path / "identity" / "node_id"
id_a = persistent_node_id(identity)
# zweite Erzeugung mit bereits existierender Datei → lädt vorhandene ID
id_b = persistent_node_id(identity)
assert id_a == id_b