ci(metis): emit per-test case metrics for dashboard history

This commit is contained in:
codex 2026-04-20 09:05:45 -03:00
parent 8a67ab7272
commit 4395f8012c

View File

@ -58,6 +58,34 @@ def _load_junit(path: str) -> dict[str, int]:
return totals
def _load_junit_cases(path: str) -> list[tuple[str, str]]:
tree = ET.parse(path)
root = tree.getroot()
if root.tag == "testsuite":
suites = [root]
elif root.tag == "testsuites":
suites = list(root.findall("testsuite"))
else:
suites = []
cases: list[tuple[str, str]] = []
for suite in suites:
for test_case in suite.findall("testcase"):
case_name = (test_case.attrib.get("name") or "").strip()
class_name = (test_case.attrib.get("classname") or "").strip()
if not case_name:
continue
test_name = f"{class_name}::{case_name}" if class_name else case_name
status = "passed"
if test_case.find("failure") is not None or test_case.find("error") is not None:
status = "failed"
elif test_case.find("skipped") is not None:
status = "skipped"
cases.append((test_name, status))
return cases
def _load_exit_code(path: str) -> int | None:
if not path or not os.path.exists(path):
return None
@ -191,6 +219,7 @@ def main() -> int:
coverage = _load_coverage(coverage_path)
totals = _load_junit(junit_path)
test_cases = _load_junit_cases(junit_path)
test_exit_code = _load_exit_code(test_exit_code_path)
docs_exit_code = _load_exit_code(docs_exit_code_path)
source_lines_over_500 = _count_source_files_over_limit(repo_root, max_lines=500)
@ -255,9 +284,19 @@ def main() -> int:
"# TYPE platform_quality_gate_source_lines_over_500_total gauge",
f'platform_quality_gate_source_lines_over_500_total{{suite="{suite}"}} {source_lines_over_500}',
"# TYPE metis_quality_gate_checks_total gauge",
"# TYPE platform_quality_gate_test_case_result gauge",
"# TYPE metis_quality_gate_build_info gauge",
f"metis_quality_gate_build_info{_label_str(labels)} 1",
]
if test_cases:
payload_lines.extend(
f'platform_quality_gate_test_case_result{{suite="{suite}",test="{_escape_label(test_name)}",status="{_escape_label(test_status)}"}} 1'
for test_name, test_status in test_cases
)
else:
payload_lines.append(
f'platform_quality_gate_test_case_result{{suite="{suite}",test="__no_test_cases__",status="skipped"}} 1'
)
payload_lines.extend(
f'metis_quality_gate_checks_total{{suite="{suite}",check="{check_name}",result="{check_status}"}} 1'
for check_name, check_status in checks.items()