"""Executable and static quality gates for isolated HUX-05 frontend.""" from __future__ import annotations import json from pathlib import Path from hux_node_gate import run_node_coverage ROOT = Path(__file__).resolve().parents[2] AUTONOMY = ROOT / "dockerfiles" / "hermes-webui-hux" / "autonomy" def test_hux_autonomy_model_node_suite_and_coverage(): """Fail-closed policy decisions retain at least 95% executable coverage.""" run_node_coverage( [ "dockerfiles/hermes-webui-hux/autonomy/model.ts", "dockerfiles/hermes-webui-hux/autonomy/security.ts", "dockerfiles/hermes-webui-hux/autonomy/endpoints.ts", ], [ "testing/tests/test_hermes_hux_ui_autonomy.mjs", ], {"functions": 95, "lines": 95}, strip_types=True, ) def test_hux_autonomy_component_is_accessible_flagged_and_inert(): """Static checks preserve accessible controls and callback-only effects.""" component = (AUTONOMY / "AutonomyControls.tsx").read_text(encoding="utf-8") model = (AUTONOMY / "model.ts").read_text(encoding="utf-8") endpoints = (AUTONOMY / "endpoints.ts").read_text(encoding="utf-8") styles = (AUTONOMY / "styles.css").read_text(encoding="utf-8") assert "if (!enabled) return null" in component assert "autonomyControlsEnabled(props.flags)" in component for flag in ("hux.foundation", "hux.activity_timeline", "hux.autonomy"): assert flag in model assert "' in component assert "Stop current run" in component and "Review external side effects" in component assert 'role="status"' in component and 'aria-live="polite"' in component assert "dangerouslySetInnerHTML" not in component assert "fetch(" not in component and "fetch(" not in endpoints assert "hux.v1" in endpoints and "hux.release.v1" in endpoints assert "live_verified" in endpoints and "hux.cancel_receipt.v1" in endpoints assert ".hux-autonomy" in styles assert "body" not in styles and ":root" not in styles assert "focus-visible" in styles and "prefers-reduced-motion" in styles def test_hux_autonomy_matches_permission_contract_and_stays_bounded(): """Canonical values match the source schema and stay out of live images.""" schema = json.loads( (ROOT / "services/hermes/contracts/hux/permission.schema.json").read_text( encoding="utf-8" ) ) model = (AUTONOMY / "model.ts").read_text(encoding="utf-8") types = (AUTONOMY / "types.ts").read_text(encoding="utf-8") for value in schema["$defs"]["capability"]["enum"]: assert f'"{value}"' in model for value in schema["$defs"]["policy"]["properties"]["autonomy"]["enum"]: assert f'"{value}"' in model for value in schema["$defs"]["decision"]["enum"]: assert f'"{value}"' in model for value in schema["$defs"]["approval"]["properties"]["decision"][ "properties" ]["choice"]["enum"]: assert f'"{value}"' in types assert {path.name for path in AUTONOMY.iterdir()} == { "AutonomyControls.tsx", "endpoints.ts", "index.ts", "model.ts", "security.ts", "styles.css", "types.ts", } for path in AUTONOMY.iterdir(): assert len(path.read_text(encoding="utf-8").splitlines()) <= 500 dockerfiles = list((ROOT / "dockerfiles").glob("Dockerfile.hermes*")) assert all("hermes-webui-hux/autonomy" not in path.read_text(encoding="utf-8") for path in dockerfiles)