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).
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
"""Integrationstests Art-Net-Receiver über echten Loopback-UDP-Socket (§16.1).
|
||||
|
||||
Kein Mock: echter Datagramm-Versand auf 127.0.0.1. Async-Tests laufen
|
||||
über asyncio.run(), damit keine pytest-asyncio-Versionsbindung entsteht.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
from hms_artnet import ArtNetReceiver, build_dmx, build_poll, parse_poll_reply
|
||||
|
||||
|
||||
def test_receiver_emits_updates_and_telemetry() -> None:
|
||||
asyncio.run(_recv_updates_impl())
|
||||
|
||||
|
||||
async def _recv_updates_impl() -> None:
|
||||
receiver = ArtNetReceiver(universes={0}, bind_host="127.0.0.1", port=0)
|
||||
await receiver.start()
|
||||
sock = receiver._transport.get_extra_info("socket")
|
||||
actual_port = sock.getsockname()[1]
|
||||
|
||||
received: list = []
|
||||
receiver.on_dmx(received.append)
|
||||
|
||||
receiver._transport.sendto(
|
||||
build_dmx(0, b"\x11\x22\x33\x44"), ("127.0.0.1", actual_port)
|
||||
)
|
||||
await asyncio.sleep(0.2)
|
||||
|
||||
assert len(received) >= 1
|
||||
assert received[-1].universe == 0
|
||||
assert received[-1].data == b"\x11\x22\x33\x44"
|
||||
tel = receiver.telemetry()
|
||||
assert tel[0].packets >= 1
|
||||
assert tel[0].last_sender_ip == "127.0.0.1"
|
||||
|
||||
# nicht abonniertes Universe ignorieren
|
||||
n_before = tel[0].packets
|
||||
receiver._transport.sendto(
|
||||
build_dmx(9, b"\x00\x00"), ("127.0.0.1", actual_port)
|
||||
)
|
||||
await asyncio.sleep(0.15)
|
||||
assert receiver.telemetry()[0].packets == n_before
|
||||
|
||||
await receiver.stop()
|
||||
|
||||
|
||||
def test_receiver_answers_poll_as_media_server() -> None:
|
||||
asyncio.run(_poll_reply_impl())
|
||||
|
||||
|
||||
async def _poll_reply_impl() -> None:
|
||||
receiver = ArtNetReceiver(
|
||||
universes={0},
|
||||
bind_host="127.0.0.1",
|
||||
port=0,
|
||||
short_name="HMS Test",
|
||||
long_name="HMS MediaEngine Test Node",
|
||||
)
|
||||
await receiver.start()
|
||||
sock = receiver._transport.get_extra_info("socket")
|
||||
actual_port = sock.getsockname()[1]
|
||||
|
||||
reply_ready = asyncio.Event()
|
||||
replies: list = []
|
||||
|
||||
class _Client(asyncio.DatagramProtocol):
|
||||
def datagram_received(self, data, addr) -> None:
|
||||
replies.append(data)
|
||||
reply_ready.set()
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
client_transport, _ = await loop.create_datagram_endpoint(
|
||||
_Client, local_addr=("127.0.0.1", 0)
|
||||
)
|
||||
client_transport.sendto(build_poll(), ("127.0.0.1", actual_port))
|
||||
await asyncio.wait_for(reply_ready.wait(), timeout=2.0)
|
||||
|
||||
info = parse_poll_reply(replies[0])
|
||||
assert info is not None
|
||||
assert info.style == 0x02 # StMedia (§3.4)
|
||||
assert info.short_name == "HMS Test"
|
||||
|
||||
client_transport.close()
|
||||
await receiver.stop()
|
||||
|
||||
|
||||
def test_receiver_allowlist_blocks_foreign_sender() -> None:
|
||||
asyncio.run(_allowlist_impl())
|
||||
|
||||
|
||||
async def _allowlist_impl() -> None:
|
||||
receiver = ArtNetReceiver(
|
||||
universes={0},
|
||||
bind_host="127.0.0.1",
|
||||
port=0,
|
||||
sender_allowlist={"192.168.50.10"}, # nur dieser Sender erlaubt
|
||||
)
|
||||
await receiver.start()
|
||||
sock = receiver._transport.get_extra_info("socket")
|
||||
actual_port = sock.getsockname()[1]
|
||||
|
||||
received: list = []
|
||||
receiver.on_dmx(received.append)
|
||||
|
||||
receiver._transport.sendto(
|
||||
build_dmx(0, b"\x00\x00"), ("127.0.0.1", actual_port)
|
||||
)
|
||||
await asyncio.sleep(0.2)
|
||||
assert received == [] # Absender 127.0.0.1 steht nicht in der Allowlist
|
||||
await receiver.stop()
|
||||
@@ -0,0 +1,121 @@
|
||||
"""Integrationstests Control Core (PLAN.md §6.1B, §23, §36 Nr. 9).
|
||||
|
||||
FastAPI-REST + WebSocket mit derselben Parameter-Engine, die auch
|
||||
Art-Net bedient (§11: eine autoritative Instanz).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from hms_control_server import create_app
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def client() -> TestClient:
|
||||
return TestClient(create_app())
|
||||
|
||||
|
||||
def _payload(path: str, value: float) -> dict:
|
||||
return {"parameter_path": path, "value": value}
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def path() -> str:
|
||||
return f"composition/{uuid.uuid4()}/layer/{uuid.uuid4()}/opacity"
|
||||
|
||||
|
||||
# ---------- Health/Capabilities ----------
|
||||
|
||||
|
||||
def test_health(client: TestClient) -> None:
|
||||
r = client.get("/api/v1/system/health")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["status"] == "ok"
|
||||
assert r.json()["phase"] == 0
|
||||
|
||||
|
||||
def test_capabilities_reported_without_fake_tier(client: TestClient) -> None:
|
||||
r = client.get("/api/v1/system/capabilities")
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["tier"] is None # ungeprüft (CPU-only-Umgebung), kein Fake
|
||||
|
||||
|
||||
def test_diagnostics_reports_not_connected(client: TestClient) -> None:
|
||||
r = client.get("/api/v1/diagnostics")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["renderer"] == "not_connected" # IPC-Handshake Phase 1
|
||||
|
||||
|
||||
# ---------- Commands (§23.2) ----------
|
||||
|
||||
|
||||
def test_parameter_set_command_ack(client: TestClient, path: str) -> None:
|
||||
r = client.post("/api/v1/commands", json={"payload": _payload(path, 0.75)})
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["status"] == "ack"
|
||||
assert body["effective"] == pytest.approx(0.75)
|
||||
|
||||
|
||||
def test_duplicate_command_id_is_idempotent(client: TestClient, path: str) -> None:
|
||||
cmd = {"command_id": str(uuid.uuid4()), "payload": _payload(path, 0.5)}
|
||||
first = client.post("/api/v1/commands", json=cmd).json()
|
||||
second = client.post("/api/v1/commands", json=cmd).json()
|
||||
assert first["status"] == "ack"
|
||||
assert second.get("duplicate") is True # gleiches Ack, kein Doppel-Apply
|
||||
assert second["result"]["revision"] == first["revision"]
|
||||
|
||||
|
||||
def test_revision_conflict_returns_409(client: TestClient, path: str) -> None:
|
||||
r = client.post(
|
||||
"/api/v1/commands",
|
||||
json={"payload": _payload(path, 0.5), "expected_revision": 999},
|
||||
)
|
||||
assert r.status_code == 409
|
||||
assert r.json()["detail"]["error"] == "REVISION_CONFLICT"
|
||||
|
||||
|
||||
def test_invalid_parameter_path_returns_400(client: TestClient) -> None:
|
||||
r = client.post(
|
||||
"/api/v1/commands",
|
||||
json={"payload": _payload("../evil/path", 1.0)},
|
||||
)
|
||||
assert r.status_code == 400
|
||||
|
||||
|
||||
def test_unknown_command_type_returns_400(client: TestClient) -> None:
|
||||
r = client.post("/api/v1/commands", json={"type": "renderer.draw", "payload": {}})
|
||||
assert r.status_code == 400
|
||||
|
||||
|
||||
def test_parameters_endpoint_reflects_state(client: TestClient, path: str) -> None:
|
||||
client.post("/api/v1/commands", json={"payload": _payload(path, 0.42)})
|
||||
r = client.get("/api/v1/parameters")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["values"][path] == pytest.approx(0.42)
|
||||
assert r.json()["revision"] >= 1
|
||||
|
||||
|
||||
# ---------- WebSocket (§23.3) ----------
|
||||
|
||||
|
||||
def test_websocket_snapshot_on_connect(client: TestClient, path: str) -> None:
|
||||
client.post("/api/v1/commands", json={"payload": _payload(path, 0.33)})
|
||||
with client.websocket_connect("/ws") as ws:
|
||||
snap = ws.receive_json()
|
||||
assert snap["type"] == "snapshot"
|
||||
assert snap["values"][path] == pytest.approx(0.33)
|
||||
|
||||
|
||||
def test_websocket_receives_parameter_updates(client: TestClient, path: str) -> None:
|
||||
with client.websocket_connect("/ws") as ws:
|
||||
ws.receive_json() # Initial-Snapshot
|
||||
client.post("/api/v1/commands", json={"payload": _payload(path, 0.9)})
|
||||
event = ws.receive_json()
|
||||
assert event["type"] == "parameter.update"
|
||||
assert event["parameter_path"] == path
|
||||
assert event["value"] == pytest.approx(0.9)
|
||||
Reference in New Issue
Block a user