2026-08-24 04:12:03 -03:00
|
|
|
"""Executable and static quality gates for isolated HUX-08 research UX."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
2026-08-24 05:22:01 -03:00
|
|
|
from hux_node_gate import run_node_coverage
|
|
|
|
|
|
2026-08-24 04:12:03 -03:00
|
|
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
|
RESEARCH = ROOT / "dockerfiles" / "hermes-webui-hux" / "research"
|
|
|
|
|
|
|
|
|
|
|
2026-08-24 05:22:01 -03:00
|
|
|
|
2026-08-24 04:12:03 -03:00
|
|
|
def test_hux_research_node_suite_and_coverage():
|
2026-08-24 05:22:01 -03:00
|
|
|
run_node_coverage(
|
|
|
|
|
[
|
|
|
|
|
"dockerfiles/hermes-webui-hux/research/model.ts",
|
|
|
|
|
"dockerfiles/hermes-webui-hux/research/security.ts",
|
|
|
|
|
"dockerfiles/hermes-webui-hux/research/endpoints.ts",
|
|
|
|
|
],
|
2026-08-24 04:12:03 -03:00
|
|
|
[
|
|
|
|
|
"testing/tests/test_hermes_hux_ui_research.mjs",
|
|
|
|
|
],
|
2026-08-24 05:22:01 -03:00
|
|
|
{"branches": 95, "functions": 95, "lines": 95},
|
|
|
|
|
strip_types=True,
|
2026-08-24 04:12:03 -03:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_hux_research_matches_shared_contract_and_stays_default_off():
|
|
|
|
|
schema = json.loads(
|
|
|
|
|
(ROOT / "services/hermes/contracts/hux/citation.schema.json").read_text(
|
|
|
|
|
encoding="utf-8"
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
model = (RESEARCH / "model.ts").read_text(encoding="utf-8")
|
|
|
|
|
for definition in ("source", "passage", "citation", "notebook"):
|
|
|
|
|
assert schema["$defs"][definition]["properties"]["schema"]["const"] in model
|
|
|
|
|
for value in schema["$defs"]["source"]["properties"]["kind"]["enum"]:
|
|
|
|
|
assert f'"{value}"' in model
|
|
|
|
|
for value in schema["$defs"]["source"]["properties"]["classification"][
|
|
|
|
|
"enum"
|
|
|
|
|
]:
|
|
|
|
|
assert f'"{value}"' in model
|
|
|
|
|
for value in schema["$defs"]["citation"]["properties"]["support"]["enum"]:
|
|
|
|
|
assert f'"{value}"' in model
|
|
|
|
|
assert "researchEnabled(props.flags)" in (
|
|
|
|
|
RESEARCH / "ResearchWorkspace.tsx"
|
|
|
|
|
).read_text(encoding="utf-8")
|
|
|
|
|
assert "dockerfiles/hermes-webui-hux/research" not in (
|
|
|
|
|
ROOT / "dockerfiles/Dockerfile.hermes-webui"
|
|
|
|
|
).read_text(encoding="utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_hux_research_ui_is_accessible_and_evidence_is_not_executable():
|
|
|
|
|
component = (RESEARCH / "ResearchWorkspace.tsx").read_text(encoding="utf-8")
|
|
|
|
|
endpoints = (RESEARCH / "endpoints.ts").read_text(encoding="utf-8")
|
|
|
|
|
security = (RESEARCH / "security.ts").read_text(encoding="utf-8")
|
|
|
|
|
styles = (RESEARCH / "styles.css").read_text(encoding="utf-8")
|
|
|
|
|
assert "if (!enabled || !page) return null" in component
|
|
|
|
|
assert 'aria-label="Research and citations"' in component
|
|
|
|
|
assert 'aria-expanded={expanded}' in component
|
|
|
|
|
assert 'aria-controls={panelId}' in component
|
|
|
|
|
assert 'aria-live="polite"' in component
|
|
|
|
|
assert "primary source" not in component # classification is data-driven
|
|
|
|
|
assert "Research notes" in component
|
|
|
|
|
assert "Assumptions" in component
|
|
|
|
|
assert "Unresolved questions" in component
|
|
|
|
|
assert 'rel="noopener noreferrer"' in component
|
|
|
|
|
assert "dangerouslySetInnerHTML" not in component
|
|
|
|
|
assert "<iframe" not in component and "<object" not in component
|
|
|
|
|
assert "javascript:" not in component and "data:" not in component
|
|
|
|
|
assert 'parsed.protocol === "https:"' in security
|
|
|
|
|
assert "fetch(" not in endpoints and "axios" not in endpoints
|
|
|
|
|
assert ".hux-research" in styles
|
|
|
|
|
assert "body" not in styles and ":root" not in styles
|
|
|
|
|
assert "prefers-reduced-motion" in styles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_hux_research_sources_are_bounded_and_endpoint_only():
|
|
|
|
|
sources = sorted(RESEARCH.glob("*"))
|
|
|
|
|
assert {path.name for path in sources} == {
|
|
|
|
|
"ResearchWorkspace.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
|
|
|
|
|
endpoints = (RESEARCH / "endpoints.ts").read_text(encoding="utf-8")
|
|
|
|
|
assert "expected_updated_at" in endpoints
|
|
|
|
|
assert '"PATCH"' not in endpoints and '"DELETE"' not in endpoints
|