Standalone per-card browser model/security/view modules for HUX-01..10 plus node+pytest suites that read the hux.v1 contract schemas directly. Reconciled drift found on integration: the activity model now accepts all 32 hux.event.v1 kinds (delegation.*, memory.suppressed, memory.retrieval_removed, budget.exhausted, side_effect.*), the autonomy model carries the external_side_effect capability, and the foundation boundary test now asserts the shipped static HUX surface exists on disk and that images never bake activated HUX_FLAGS. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BvMSXH8VH2tMWXanb8SJdf
96 lines
3.9 KiB
Python
96 lines
3.9 KiB
Python
"""Executable and static quality gates for isolated HUX-05 frontend."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
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."""
|
|
|
|
result = subprocess.run(
|
|
[
|
|
"node",
|
|
"--test",
|
|
"--experimental-strip-types",
|
|
"--experimental-test-coverage",
|
|
"--test-coverage-lines=95",
|
|
"--test-coverage-functions=95",
|
|
"--test-coverage-include=dockerfiles/hermes-webui-hux/autonomy/model.ts",
|
|
"--test-coverage-include=dockerfiles/hermes-webui-hux/autonomy/security.ts",
|
|
"--test-coverage-include=dockerfiles/hermes-webui-hux/autonomy/endpoints.ts",
|
|
"testing/tests/test_hermes_hux_ui_autonomy.mjs",
|
|
],
|
|
cwd=ROOT,
|
|
check=False,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=30,
|
|
)
|
|
assert result.returncode == 0, result.stdout + result.stderr
|
|
|
|
|
|
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)
|