from __future__ import annotations

from pathlib import Path

import yaml


REQUIRED = [
    "request_id",
    "problem",
    "evidence",
    "target_metric",
    "affected_formula",
    "affected_output",
    "expected_side_effect",
    "rollback_plan",
    "test_cases",
]


def main() -> int:
    errors: list[str] = []
    for path in Path("governance/change_requests").glob("*.yaml"):
        data = yaml.safe_load(path.read_text(encoding="utf-8"))
        for key in REQUIRED:
            if key not in data:
                errors.append(f"{path}: missing {key}")
    if errors:
        print("FAIL")
        for err in errors:
            print(err)
        return 1
    print("CHANGE_REQUESTS_OK")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

