4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Run RCA investigations from markdown alert files in tests/e2e/rca/.
|
|
|
|
Usage:
|
|
python -m tests.e2e.rca.run_rca_test # run all .md files
|
|
python -m tests.e2e.rca.run_rca_test pipeline_error_in_logs # run one (with or without .md)
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import re
|
|
import sys
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
from tools.investigation.capability import run_investigation
|
|
|
|
RCA_DIR = Path(__file__).parent
|
|
|
|
|
|
def _parse_alert_md(path: Path) -> dict[str, Any]:
|
|
"""Extract title, severity, pipeline_name, and raw_alert JSON from a markdown alert file."""
|
|
text = path.read_text()
|
|
|
|
title_match = re.search(r"^#\s+Alert:\s+(.+)$", text, re.MULTILINE)
|
|
title = title_match.group(1).strip() if title_match else path.stem
|
|
|
|
meta_match = re.search(r"```json\s*(\{.*?\})\s*```", text, re.DOTALL)
|
|
meta: dict[str, Any] = json.loads(meta_match.group(1)) if meta_match else {}
|
|
|
|
labels = meta.get("commonLabels", {})
|
|
severity = labels.get("severity", "critical")
|
|
pipeline_name = labels.get("pipeline_name") or labels.get("grafana_folder") or "unknown"
|
|
|
|
return {"title": title, "severity": severity, "pipeline_name": pipeline_name, "raw_alert": meta}
|
|
|
|
|
|
def run_file(path: Path) -> bool:
|
|
print(f"\n RCA TEST {path.stem}")
|
|
|
|
alert = _parse_alert_md(path)
|
|
|
|
state = run_investigation(alert["raw_alert"])
|
|
|
|
passed = bool(state.get("root_cause"))
|
|
category = state.get("root_cause_category") or "—"
|
|
mark = "\033[1;32m●\033[0m" if passed else "\033[1;31m●\033[0m"
|
|
status = "pass" if passed else "fail"
|
|
print(f"\n {mark} {status} {path.stem} {category}")
|
|
return passed
|
|
|
|
|
|
def main() -> None:
|
|
if len(sys.argv) > 1:
|
|
name = sys.argv[1]
|
|
if not name.endswith(".md"):
|
|
name += ".md"
|
|
targets = [RCA_DIR / name]
|
|
else:
|
|
targets = sorted(RCA_DIR.glob("*.md"))
|
|
|
|
if not targets:
|
|
print("No markdown alert files found in tests/rca/")
|
|
sys.exit(1)
|
|
|
|
results = [run_file(p) for p in targets]
|
|
|
|
total, passed = len(results), sum(results)
|
|
mark = "\033[1;32m●\033[0m" if passed == total else "\033[1;31m●\033[0m"
|
|
print(f"\n {mark} {passed}/{total} passed\n")
|
|
if not all(results):
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|