#!/bin/sh
# VERDICT: exit 0 only if the AI-news-triage artifact is valid, complete, and
# correctly binned (20 items across 5 bins with required fields and real URLs).
python3 - <<'PY'
import json, sys
p = "/root/.hermes/wizard-outputs/sol/ai-news-triage-2026-11-02.json"
try:
    d = json.load(open(p))
except Exception as e:
    sys.stderr.write("JSON load failed: %s\n" % e)
    sys.exit(1)
assert d.get("kind") == "ai-news-triage"
assert d.get("generated") == "2026-11-02"
assert d.get("summary", {}).get("total_items") == 20, "summary total wrong"
bins = d.get("bins")
assert isinstance(bins, dict) and len(bins) == 5, "bad bin count"
exp_counts = {"frontier-models":4, "policy-regulation":4, "funding":6, "elections-safety":4, "infrastructure-ops":2}
# bin counts must match
assert len(bins) == len(exp_counts) and all(len(bins[k]) == c for k, c in exp_counts.items()), "bin counts wrong: %s" % bins
# every item must carry required fields, belong to its bin, and cite a URL
seen = set()
for cat, its in bins.items():
    for it in its:
        assert set(("title","date","category","source","verdict")) <= set(it.keys()), cat
        assert it["category"] == cat, "category mismatch in %s" % cat
        assert it.get("source","").startswith("http"), "source not http"
        seen.add(it["category"])
assert seen == set(exp_counts.keys()), seen
print("OK: 20 items, bins=%s" % bins)
PY
