"""Shipped patch and DOM contracts for the hands-free conversation instrument.""" from __future__ import annotations import os from pathlib import Path import re import shutil import subprocess import sys from hux_node_gate import require_node ROOT = Path(__file__).resolve().parents[2] FIXTURE = ROOT / "testing/fixtures/hermes-webui-0.52.181" AGENT_FIXTURE = ROOT / "testing/fixtures/hermes-agent" PATCHER = ROOT / "dockerfiles/hermes-webui-atlas-patch.py" VOICE_JS = ROOT / "dockerfiles/hermes-webui-atlas-voice.js" VOICE_CSS = ROOT / "dockerfiles/hermes-webui-atlas-voice.css" DOM_PROBE = ROOT / "testing/probes/hermes_voice_instrument_probe.js" MEDIARECORDER_FIXTURE = ( ROOT / "testing/fixtures/mediarecorder/chromium-webm-opus.json" ) def _patched_fixture(tmp_path: Path) -> Path: target = tmp_path / "hermes-webui" agent_target = tmp_path / "hermes-agent" shutil.copytree(FIXTURE, target) shutil.copytree(AGENT_FIXTURE, agent_target) env = os.environ.copy() env["HERMES_WEBUI_PATCH_ROOT"] = str(target) env["HERMES_AGENT_PATCH_ROOT"] = str(agent_target) subprocess.run( [sys.executable, str(PATCHER)], cwd=ROOT, env=env, check=True, capture_output=True, text=True, ) return target def test_real_upstream_fixture_receives_visual_instrument_contract(tmp_path: Path): """Apply the production patcher to exact fragments from pinned WebUI 0.52.181.""" target = _patched_fixture(tmp_path) index = (target / "static/index.html").read_text(encoding="utf-8") assert index.count('id="voiceInstrumentStyles"') == 1 assert ( 'href="static/atlas-voice.css?v=__WEBUI_VERSION__"' in index ) assert 'role="status"' in index assert 'aria-live="polite"' in index assert 'aria-atomic="true"' in index for layer in ( "voice-instrument-halo", "voice-instrument-ripple", "voice-instrument-orbit", "voice-instrument-core", "voice-instrument-symbol", ): assert layer in index assert '