"""Exercise RRSI's released selector with synthetic inputs; no model calls."""
import argparse
from pathlib import Path
import sys


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("repo", type=Path, help="path to the pinned google-research/rrsi checkout")
    args = parser.parse_args()
    repo = args.repo.resolve()
    if not (repo / "rrsi" / "selection.py").is_file():
        parser.error("repo must contain rrsi/selection.py")
    sys.path.insert(0, str(repo))
    from rrsi.config import RRSIConfig
    from rrsi.evaluate import EvalResult
    from rrsi.selection import Candidate, select_round

    # Illustrative settings, not the paper's domain hyperparameters.
    cfg = RRSIConfig(beta0=0.10, beta1=4.0, w_s=0.0, w_c=15.0, w_n=0.5)

    def result(name, score, tokens):
        return EvalResult(job=name, k=1, per_task={}, S=score, C=tokens,
                          n_expected=1, missing=0)

    incumbent = result("base", 0.70, 1000)
    specs = [
        ("small-noisy-gain", 0.71, 1000),
        ("expensive-gain", 0.75, 1800),
        ("reusable-gain", 0.73, 1200),
        ("cheaper", 0.70, 800),
        ("below-floor", 0.68, 700),
    ]
    candidates = [
        Candidate(name, [{"component": "prompt", "hypothesis": "synthetic demo"}],
                  ev=result(name, score, tokens))
        for name, score, tokens in specs
    ]
    winner, decisions = select_round(
        candidates, incumbent, S_star=0.72, delta=0.02,
        cfg=cfg, incumbent_counts={},
    )
    print("SYNTHETIC INPUTS: selection only; no benchmark evaluation")
    for decision in decisions:
        verdict = "ADMIT" if decision.admissible else "REJECT"
        print(f"{decision.variant}: {verdict}")
    print("WINNER:", winner.variant if winner else "none")
    return 0


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