#!/usr/bin/env python3
"""Run every Lumen Second-Edition chapter verifier and print a combined summary.
Usage: python3 se_verify_all.py        (requires only numpy)"""
import subprocess, glob, os, sys
here = os.path.dirname(os.path.abspath(__file__))
scripts = sorted(g for g in glob.glob(os.path.join(here, "se_*.py"))
                 if os.path.basename(g) not in ("se_verify_all.py", "se_verify_common.py"))
tp = tn = 0; allok = True
for s in scripts:
    r = subprocess.run([sys.executable, s], capture_output=True, text=True)
    print(r.stdout.rstrip()); print()
    for ln in r.stdout.splitlines():
        if "checks passed" in ln:
            p, n = ln.strip().split()[0].split("/"); tp += int(p); tn += int(n)
            if int(p) != int(n): allok = False
print("=" * 104)
print("  LUMEN SECOND EDITION -- combined: %d / %d checks passed across %d chapters" % (tp, tn, len(scripts)))
print("  %s" % ("ALL CHAPTERS PASS" if allok else "SOME CHECKS FAILED"))
print("=" * 104)
