"""Contract checks for the internal Atlas AI operations dashboard.""" from __future__ import annotations import importlib.util import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[2] SCRIPT = ROOT / "scripts/render/dashboards_render_atlas.py" def load_module(): """Load the dashboard generator without invoking its CLI.""" spec = importlib.util.spec_from_file_location("dashboards_render_atlas_ai", SCRIPT) module = importlib.util.module_from_spec(spec) assert spec and spec.loader sys.modules[spec.name] = module spec.loader.exec_module(module) return module def test_ai_dashboard_is_internal_and_uses_real_quota_and_switchyard_metrics(): mod = load_module() dashboard = mod.build_ai_dashboard() panels = {panel["title"]: panel for panel in dashboard["panels"]} expressions = "\n".join( target.get("expr", "") for panel in dashboard["panels"] for target in panel.get("targets", []) ) assert dashboard["uid"] == "atlas-ai" assert dashboard["folderUid"] == mod.PRIVATE_FOLDER assert dashboard["refresh"] == "1m" assert "Codex Weekly Remaining" in panels assert "Claude 5h Remaining" in panels assert "Claude 7d Remaining" in panels assert "Provider Selections (Range)" in panels assert "Local Classifier Calls" in panels assert "Hermes Workload CPU (Attribution Proxy)" in panels assert "atlas_ai_quota_remaining_percent" in expressions assert "atlas_ai_quota_reset_timestamp_seconds" in expressions assert "switchyard_decisions_total" in expressions assert "switchyard_cached_tokens_total" in expressions assert "switchyard_model_call_latency_ms_bucket" in expressions assert "/status" not in expressions assert all( panel.get("description") or panel["type"] == "text" for panel in dashboard["panels"] ) def test_ai_dashboard_cost_and_instance_panels_do_not_claim_false_attribution(): mod = load_module() dashboard = mod.build_ai_dashboard() panels = {panel["title"]: panel for panel in dashboard["panels"]} cost_text = panels["Cost Semantics"]["options"]["content"] proxy_description = panels["Hermes Workload CPU (Attribution Proxy)"]["description"] assert "does not invent API costs" in cost_text assert "subscription" in cost_text assert "proxy" in proxy_description assert "not tenant-slot token labels" in proxy_description