atlas-iac/testing/tests/test_hermes_hux_ui_artifacts.py

70 lines
2.6 KiB
Python
Raw Normal View History

"""Executable and static quality gates for isolated HUX-04 artifacts."""
from __future__ import annotations
from pathlib import Path
from hux_node_gate import run_node_coverage
ROOT = Path(__file__).resolve().parents[2]
ARTIFACTS = ROOT / "dockerfiles" / "hermes-webui-hux" / "artifacts"
def test_hux_artifact_model_node_suite_and_coverage():
run_node_coverage(
[
"dockerfiles/hermes-webui-hux/artifacts/model.ts",
"dockerfiles/hermes-webui-hux/artifacts/security.ts",
"dockerfiles/hermes-webui-hux/artifacts/endpoints.ts",
],
[
"testing/tests/test_hermes_hux_ui_artifacts.mjs",
],
{"branches": 95, "functions": 95, "lines": 95},
strip_types=True,
)
def test_hux_artifact_component_is_flagged_accessible_and_inert():
component = (ARTIFACTS / "ArtifactWorkspace.tsx").read_text(encoding="utf-8")
model = (ARTIFACTS / "model.ts").read_text(encoding="utf-8")
endpoints = (ARTIFACTS / "endpoints.ts").read_text(encoding="utf-8")
styles = (ARTIFACTS / "styles.css").read_text(encoding="utf-8")
assert "if (!enabled || !page) return null" in component
assert "artifactsEnabled(props.flags)" in component
assert all(flag in model for flag in ("FOUNDATION_FLAG", "PROJECTS_FLAG", "ARTIFACTS_FLAG"))
assert 'aria-label="Artifact workspace"' in component
assert 'aria-live="polite"' in component
assert "Immutable version history" in component
assert "Continue editing" in component
assert "Promote version to project" in component
assert "Sources attached" in component and "Citations attached" in component
assert "dangerouslySetInnerHTML" not in component
assert "<iframe" not in component and "<object" not in component
assert "fetch(" not in endpoints and "axios" not in endpoints
assert "expected_current_version" in endpoints
assert '"PATCH"' not in endpoints and '"DELETE"' not in endpoints
assert ".hux-artifacts" in styles
assert "body" not in styles and ":root" not in styles
assert "prefers-reduced-motion" in styles
def test_hux_artifact_sources_respect_size_and_isolated_scope():
sources = sorted(ARTIFACTS.glob("*"))
assert {path.name for path in sources} == {
"ArtifactWorkspace.tsx",
"endpoints.ts",
"index.ts",
"model.ts",
"security.ts",
"styles.css",
"types.ts",
}
for path in sources:
assert len(path.read_text(encoding="utf-8").splitlines()) <= 500
assert "dockerfiles/hermes-webui-hux/artifacts" not in (
ROOT / "dockerfiles" / "Dockerfile.hermes-agent"
).read_text(encoding="utf-8")