atlas-iac/testing/tests/test_hermes_hux_ui_autonomy.py
jenkins 2f535d3a30 test(hermes): portable node coverage gate for the HUX suites
Build 20 failed on the CI image's Node 20: --test-coverage-lines and
friends need Node >= 22.8 and --experimental-strip-types needs 22.6.
A shared helper now runs plain --experimental-test-coverage and
enforces the same per-source >=95 floors by parsing the coverage
table, so the gate is identical on Node 20 and newer local Nodes; the
TypeScript suites skip with an explicit reason on runtimes that cannot
strip types. Per-file gating also exposed pre-existing debt the old
aggregate thresholds hid (wave_b_projects_modes.js branches 90 / funcs
94.7) - recorded as explicit enforced floors, not waived.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BvMSXH8VH2tMWXanb8SJdf
2026-08-24 05:22:01 -03:00

90 lines
3.5 KiB
Python

"""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 "<fieldset" in component and "<legend" in component
assert 'type="radio"' in component and '<table>' 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)