| 1 | #!/usr/bin/env python3
|
| 2 | """Evaluate benchmark rows against a Git Baseline Book and target file."""
|
| 3 |
|
| 4 | from __future__ import annotations
|
| 5 |
|
| 6 | import argparse
|
| 7 | import json
|
| 8 | import sys
|
| 9 | from pathlib import Path
|
| 10 |
|
| 11 | ROOT = Path(__file__).resolve().parents[1]
|
| 12 | sys.path.insert(0, str(ROOT / "scripts"))
|
| 13 |
|
| 14 | from oakbench.baseline_book import load_baseline_book, load_targets # noqa: E402
|
| 15 | from oakbench.scorecard import evaluate_targets, load_jsonl # noqa: E402
|
| 16 |
|
| 17 |
|
| 18 | def parse_args() -> argparse.Namespace:
|
| 19 | parser = argparse.ArgumentParser(description=__doc__)
|
| 20 | parser.add_argument("jsonl", nargs="+", type=Path, help="candidate row JSONL")
|
| 21 | parser.add_argument("--baseline-book", required=True, type=Path)
|
| 22 | parser.add_argument("--targets", type=Path, default=ROOT / "config" / "targets.json")
|
| 23 | parser.add_argument("--bootstrap-samples", type=int, default=2000)
|
| 24 | parser.add_argument("--confidence", type=float, default=0.95)
|
| 25 | parser.add_argument("--json", action="store_true")
|
| 26 | parser.add_argument("--mode", choices=("claim", "diagnostic"), default="claim",
|
| 27 | help="claim requires versioned comparable evidence; diagnostic is never public evidence")
|
| 28 | return parser.parse_args()
|
| 29 |
|
| 30 |
|
| 31 | def main() -> int:
|
| 32 | args = parse_args()
|
| 33 | rows = load_jsonl(args.jsonl)
|
| 34 | targets = load_targets(args.targets)
|
| 35 | baseline = load_baseline_book(args.baseline_book)
|
| 36 | results = evaluate_targets(
|
| 37 | rows,
|
| 38 | targets,
|
| 39 | baseline,
|
| 40 | bootstrap_samples=args.bootstrap_samples,
|
| 41 | confidence=args.confidence,
|
| 42 | mode=args.mode,
|
| 43 | )
|
| 44 | if args.json:
|
| 45 | print(json.dumps(results, sort_keys=True))
|
| 46 | else:
|
| 47 | print(f"Scorecard mode: {args.mode}. " + ("Diagnostic verdicts are not public evidence." if args.mode == "diagnostic" else "Claim evidence eligibility enforced."))
|
| 48 | print("| Target | Verdict | Ratio | Goal | n | Notes |")
|
| 49 | print("| --- | --- | ---: | ---: | ---: | --- |")
|
| 50 | for row in results:
|
| 51 | ratio = row.get("ratio")
|
| 52 | ratio_text = "" if ratio is None else f"{ratio:.3f}"
|
| 53 | notes = "; ".join(str(item) for item in row.get("messages", []))
|
| 54 | print(
|
| 55 | f"| `{row['target_id']}` | {row['verdict']} | {ratio_text} | "
|
| 56 | f"{row['goal_value']:.3f} | {row['n']} | {notes} |"
|
| 57 | )
|
| 58 | return 1 if any(row["verdict"] in {"RED", "INVALID"} or
|
| 59 | (args.mode == "claim" and not row["claim_eligible"]) for row in results) else 0
|
| 60 |
|
| 61 |
|
| 62 | if __name__ == "__main__":
|
| 63 | raise SystemExit(main())
|