turkic-ocr-code / scripts /r5_loopguard /lg_refusal_tests.py
treoa's picture
Release 1
24aaa76
Raw History Blame Contribute Delete
2.4 kB
"""LOOPGUARD-1 smoke: the held-out sets must be refused, before anything is opened, without the official unseal token.
Runs each entry point once with a held-out set and records its exit code and the last line it printed. Nothing held-out is
read: every refusal happens in om_text.check_unsealed before a held-out path is opened (the official token does not exist).
usage: lg_refusal_tests.py --smoke DIR --out JSON
"""
import argparse
import json
import os
import subprocess
C = "/path/to/TURKIC_OCR_CODE"
S = C + "/scripts/r5_loopguard"
PY, PK = C + "/.venv_vlm/bin/python", C + "/.venv_kraken/bin/python"
ap = argparse.ArgumentParser()
ap.add_argument("--smoke", required=True)
ap.add_argument("--out", required=True)
a = ap.parse_args()
fake = os.path.join(a.smoke, "UNSEAL")
json.dump({"design": "LOOPGUARD-1", "arm": "A2", "roles_allowed": ["A0", "A2", "pipeline", "score"]}, open(fake, "w"))
cases = {
"om_eval_pages_school_test_no_token": [PY, "-I", S + "/om_eval_pages.py", "--model-dir", "/nonexistent", "--name", "refuse", "--arm", "A2",
"--sets", "school_test", "--device", "cpu", "--out-root", a.smoke + "/refuse"],
"om_eval_pages_gen_test_fake_token": [PY, "-I", S + "/om_eval_pages.py", "--model-dir", "/nonexistent", "--name", "refuse", "--arm", "A0",
"--observe", "--sets", "gen_test", "--device", "cpu", "--out-root", a.smoke + "/refuse",
"--sealed-token", fake],
"om_score_gen_test": [PK, "-I", S + "/om_score.py", "--name", "A2", "--sets", "gen_test,school_test", "--out", a.smoke + "/refuse"],
"om_baseline_school_test": [PY, "-I", S + "/om_baseline.py", "--set", "school_test", "--device", "cpu", "--out", a.smoke + "/refuse/b.jsonl"],
"lg_flags_heldout": [PK, "-I", S + "/lg_flags.py", "heldout", "--a0obs", a.smoke + "/refuse", "--out", a.smoke + "/refuse/f.json"],
"om_lg_select_confirm": [PK, "-I", S + "/om_lg_select.py", "confirm", "--root", a.smoke + "/dry"],
}
res = {}
for k, cmd in cases.items():
p = subprocess.run(cmd, capture_output=True, text=True)
txt = (p.stdout + "\n" + p.stderr).strip().splitlines()
res[k] = {"rc": p.returncode, "tail": (txt[-1] if txt else "")[:300]}
print(k, res[k]["rc"], res[k]["tail"][:160], flush=True)
os.remove(fake)
json.dump(res, open(a.out, "w"), indent=1)