import importlib.util import pathlib def load_module(): path = pathlib.Path(__file__).resolve().parents[1] / "dashboards_render_atlas.py" spec = importlib.util.spec_from_file_location("scripts.dashboards_render_atlas", path) module = importlib.util.module_from_spec(spec) assert spec.loader is not None spec.loader.exec_module(module) return module def flatten_panels(panels): flat = [] for panel in panels: flat.append(panel) flat.extend(panel.get("panels", [])) return flat def test_table_panel_options_and_filterable(): mod = load_module() panel = mod.table_panel( 1, "test", "metric", {"h": 1, "w": 1, "x": 0, "y": 0}, unit="percent", transformations=[{"id": "labelsToFields", "options": {}}], instant=True, options={"showColumnFilters": False}, filterable=False, footer={"show": False, "fields": "", "calcs": []}, format="table", ) assert panel["fieldConfig"]["defaults"]["unit"] == "percent" assert panel["fieldConfig"]["defaults"]["custom"]["filterable"] is False assert panel["options"]["showHeader"] is True assert panel["targets"][0]["format"] == "table" def test_node_filter_and_expr_helpers(): mod = load_module() expr = mod.node_filter("titan-.*") assert "label_replace" in expr cpu_expr = mod.node_cpu_expr("titan-.*") mem_expr = mod.node_mem_expr("titan-.*") assert "node_cpu_seconds_total" in cpu_expr assert "node_memory_MemAvailable_bytes" in mem_expr def test_overview_availability_panel_uses_recorded_365d_rollup(): mod = load_module() dashboard = mod.build_overview() panel = next(panel for panel in flatten_panels(dashboard["panels"]) if panel["id"] == 27) assert panel["title"] == "Atlas Availability (365d)" assert panel["targets"][0]["expr"] == 'last_over_time(atlas:availability:ratio_365d{scope="atlas"}[24h])' assert panel["targets"][0]["instant"] is True assert "precomputed" in panel["description"] assert "last successful rollup for up to 24h" in panel["description"] def test_overview_uses_readable_quality_power_and_gitops_panels(): mod = load_module() dashboard = mod.build_overview() panels_by_title = {panel["title"]: panel for panel in flatten_panels(dashboard["panels"])} assert "Platform Test Success Rate" not in panels_by_title assert panels_by_title["Gate Checks Passing by Suite"]["type"] == "bargauge" assert panels_by_title["Gate Checks Passing by Suite"]["options"]["displayMode"] == "basic" assert panels_by_title["UPS History (Power Draw)"]["fieldConfig"]["defaults"]["custom"]["drawStyle"] == "bars" assert panels_by_title["Ariadne Run Volume"]["fieldConfig"]["defaults"]["custom"]["drawStyle"] == "bars" assert panels_by_title["Flux Source"]["type"] == "stat" assert panels_by_title["GitOps Health"]["type"] == "bargauge" assert panels_by_title["GitOps Health"]["gridPos"]["h"] == 4 def test_render_configmap_writes(tmp_path): mod = load_module() mod.DASHBOARD_DIR = tmp_path / "dash" mod.ROOT = tmp_path uid = "atlas-test" info = {"configmap": tmp_path / "cm.yaml"} data = {"title": "Atlas Test"} mod.write_json(uid, data) mod.render_configmap(uid, info) json_path = mod.DASHBOARD_DIR / f"{uid}.json" assert json_path.exists() content = (tmp_path / "cm.yaml").read_text() assert "kind: ConfigMap" in content assert f"{uid}.json" in content def test_testing_suite_variable_uses_canonical_values_only(): mod = load_module() variable = mod.testing_suite_variable() canonical_matcher = "|".join(mod.PLATFORM_TEST_SUITE_NAMES) legacy_names = {"bstein-home", "data-prepper", "titan-iac", "pegasus-health"} assert variable["allValue"] == canonical_matcher assert not any(alias in variable["query"] for alias in legacy_names) assert not any(alias in variable["allValue"] for alias in legacy_names) assert [option["value"] for option in variable["options"]] == mod.PLATFORM_TEST_SUITE_NAMES def test_jobs_dashboard_separates_current_gate_health_from_reliability(): mod = load_module() dashboard = mod.build_jobs_dashboard() panels_by_title = {panel["title"]: panel for panel in flatten_panels(dashboard["panels"])} assert "Current Gate Health by Suite" in panels_by_title assert "Run Reliability by Suite (24h)" in panels_by_title assert "Run Reliability by Suite (7d rolling)" in panels_by_title assert "Daily Run Volume (Selected Scope)" in panels_by_title assert "Coverage History by Suite" in panels_by_title assert "Files <=500 LOC History by Suite" in panels_by_title assert "Run Reliability History by Suite" not in panels_by_title assert "Coverage & LOC Compliance History" not in panels_by_title assert "Run Status Mix (30d)" not in panels_by_title assert "Failures by Suite (24h)" not in panels_by_title assert "Success Rate by Suite (24h)" not in panels_by_title current_gate_expr = panels_by_title["Current Gate Health by Suite"]["targets"][0]["expr"] assert 'check)' in current_gate_expr assert 'result=~"ok|passed|success|not_applicable|skipped|na|n/a"' in current_gate_expr reliability_panel = panels_by_title["Run Reliability by Suite (24h)"] reliability_expr = reliability_panel["targets"][0]["expr"] assert "platform_quality_gate_runs_total" in reliability_expr assert "> 0" in reliability_expr assert "- 1" in reliability_expr assert reliability_panel["fieldConfig"]["defaults"]["mappings"] == [ {"type": "value", "options": {"-1": {"text": "no runs"}}} ] rolling_panel = panels_by_title["Run Reliability by Suite (7d rolling)"] assert rolling_panel["type"] == "state-timeline" assert "[7d]" in rolling_panel["targets"][0]["expr"] coverage_panel = panels_by_title["Coverage History by Suite"] loc_panel = panels_by_title["Files <=500 LOC History by Suite"] assert coverage_panel["type"] == "state-timeline" assert loc_panel["type"] == "state-timeline" assert coverage_panel["targets"][0]["expr"] != loc_panel["targets"][0]["expr"] run_volume_panel = panels_by_title["Daily Run Volume (Selected Scope)"] assert run_volume_panel["fieldConfig"]["defaults"]["custom"]["drawStyle"] == "bars" assert "[$__interval]" not in run_volume_panel["targets"][0]["expr"] def test_jobs_dashboard_bar_gauges_use_solid_threshold_colors(): mod = load_module() dashboard = mod.build_jobs_dashboard() panels = flatten_panels(dashboard["panels"]) bar_gauges = [panel for panel in panels if panel["type"] == "bargauge"] assert bar_gauges assert all(panel["options"]["displayMode"] == "basic" for panel in bar_gauges) assert all( panel["fieldConfig"]["defaults"]["color"]["mode"] == "thresholds" for panel in bar_gauges ) reliability_panel = next( panel for panel in panels if panel["title"] == "Run Reliability by Suite (24h)" ) threshold_steps = reliability_panel["fieldConfig"]["defaults"]["thresholds"]["steps"] assert {"color": "dark-yellow", "value": 93} in threshold_steps assert {"color": "dark-blue", "value": 100} in threshold_steps def test_jobs_dashboard_collapses_heavy_drilldowns_for_light_first_paint(): mod = load_module() dashboard = mod.build_jobs_dashboard() panels = dashboard["panels"] rows = [panel for panel in panels if panel["type"] == "row"] visible_query_panels = [panel for panel in panels if panel["type"] != "row"] nested_panels_by_title = { child["title"]: child for row in rows for child in row.get("panels", []) } assert len(panels) == 16 assert len(visible_query_panels) == 10 assert sum(len(panel.get("targets", [])) for panel in visible_query_panels) == 10 assert all( panel["title"] != "Coverage Gap to 95% by Suite" for panel in visible_query_panels ) assert [row["title"] for row in rows] == [ "Reliability And Run History", "Check Failure Rates By Suite", "Check Healthy Rates By Suite", "Test Drilldowns And Problem Tests", "Telemetry Completeness And Branches", "SonarQube Project Health", ] assert all(row["collapsed"] for row in rows) assert "Coverage Failure Rate" in nested_panels_by_title assert "Supply Chain Healthy Rate" in nested_panels_by_title assert "Selected Test Pass Rate History" in nested_panels_by_title assert "Coverage Metrics Present by Suite" in nested_panels_by_title assert "SonarQube API Up" in nested_panels_by_title failure_rate_panel = nested_panels_by_title["Coverage Failure Rate"] assert failure_rate_panel["type"] == "state-timeline" assert failure_rate_panel["fieldConfig"]["defaults"]["unit"] == "percent" assert failure_rate_panel["fieldConfig"]["defaults"]["max"] == 100 assert failure_rate_panel["fieldConfig"]["defaults"]["thresholds"]["steps"][0]["color"] == "dark-blue" assert "increase(" not in failure_rate_panel["targets"][0]["expr"] assert "0 *" in failure_rate_panel["targets"][0]["expr"] pass_rate_panel = nested_panels_by_title["Selected Test Pass Rate History"] assert pass_rate_panel["type"] == "state-timeline" assert "platform_quality:test_case_pass_rate:percent_1h" in pass_rate_panel["targets"][0]["expr"] assert "platform_quality_gate_test_case_result" not in pass_rate_panel["targets"][0]["expr"] pass_fail_panel = nested_panels_by_title["Selected Test Pass/Fail History"] assert pass_fail_panel["fieldConfig"]["defaults"]["custom"]["drawStyle"] == "bars" assert all( "platform_quality:test_case_status:count_1h" in target["expr"] for target in pass_fail_panel["targets"] ) problematic_panel = nested_panels_by_title["Problematic Tests Over Time (Top failures)"] assert problematic_panel["type"] == "state-timeline" assert problematic_panel["gridPos"]["w"] == 24 assert 'test!=""' in problematic_panel["targets"][0]["expr"] assert "vector(0)" not in problematic_panel["targets"][0]["expr"] sonar_mix_panel = nested_panels_by_title["Sonar Gate Status Mix (Selected)"] sonar_health_panel = nested_panels_by_title["Sonar Gate Health by Project"] assert sonar_mix_panel["gridPos"]["w"] == 4 assert sonar_health_panel["gridPos"]["w"] == 8 assert sonar_health_panel["type"] == "state-timeline" assert "100 * max by (project_key)" in sonar_health_panel["targets"][0]["expr"] branch_panel = nested_panels_by_title["Primary Branch Clean by Suite (30d)"] assert branch_panel["fieldConfig"]["defaults"]["unit"] == "percent" assert "unless on(suite)" in branch_panel["targets"][0]["expr"] assert "> bool 0" in branch_panel["targets"][0]["expr"]