#!/usr/bin/env python3
"""Verify illustrative grain-drift outputs for EAM-REPLAY-20260823."""

from __future__ import annotations

import csv
import pathlib
import sys


EXPECTED = {
    "order_lines": "17200",
    "rank_changes": "7",
    "sign_flips": "4",
    "missing_dated_cost": "91",
}


def main() -> int:
    path = pathlib.Path(__file__).with_name("grain-drift-EAM-REPLAY-20260823.csv")
    with path.open(newline="", encoding="utf-8") as handle:
        rows = list(csv.DictReader(handle))
    observed = {row["metric"]: row["value"] for row in rows if row["status"] == "published"}
    held = [row for row in rows if row["status"].startswith("held_")]
    if observed != EXPECTED or len(held) != 2:
        print("FAIL: drift outputs or held decisions are incorrect.", file=sys.stderr)
        return 1
    if any(row["value"] for row in held):
        print("FAIL: a held decision exposes a result.", file=sys.stderr)
        return 1
    print("OK: four drift aggregates and two held decisions verified.")
    return 0


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