#!/usr/bin/env python3
"""CI: Validate cron fleet health. Exit 1 on systemic failures."""

import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from cron_audit_662 import audit_fleet, load_cron_state, load_crontab_backups

def main():
    hermes = load_cron_state()
    crontabs = load_crontab_backups(Path(__file__).parent.parent / "cron" / "vps")
    report = audit_fleet(hermes, crontabs)
    print(f"Cron Audit CI: {report['total_jobs']} jobs — H:{report['summary']['healthy']} T:{report['summary']['transient_errors']} S:{report['summary']['systemic_failures']}")
    if report["systemic_jobs"]:
        for j in report["systemic_jobs"]:
            print(f"  FAIL: {j['name']} — {j['reason']}")
        sys.exit(1)
    print("CI PASSED")
    sys.exit(0)

if __name__ == "__main__":
    main()
