casebench
test cases straight onto the board.
git clone https://owenrusk.dev/casebench.git
commit 92339d27479548c60dda5a2e69bb2a09914949b3 parent c263b32922570596542a29c027b4be03dde977af author Owen Rusk <owen@papermothgames.com> date 2025-03-24 21:07:51 -0500
put: don't overwrite a case the runtime put there tess reuses ids between drafts. a test case with the same id as a real one would have replaced it.
| casebench/cli.py | +3 | -0 |
| casebench/db.py | +7 | -0 |
diff --git a/casebench/cli.py b/casebench/cli.py index 0708045..c50bb1f 100644 --- a/casebench/cli.py +++ b/casebench/cli.py @@ -28,6 +28,9 @@ def main(argv: list[str] | None = None) -> int: if player is None: print(f"casebench: no player {args.player}", file=sys.stderr) return 1 + if db.source(conn, player, case.id) not in (None, "bench"): + print(f"casebench: {args.player} already has {case.id} from the runtime", file=sys.stderr) + return 1 db.put(conn, player, case) print(f"{args.player}: put {case.id}") return 0 diff --git a/casebench/db.py b/casebench/db.py index c995a2e..41591cc 100644 --- a/casebench/db.py +++ b/casebench/db.py @@ -12,6 +12,13 @@ def player_id(conn: psycopg.Connection, handle: str) -> str | None: return row[0] if row else None +def source(conn: psycopg.Connection, player: str, case_id: str) -> str | None: + row = conn.execute( + "select source from board_cases where player_id = %s and case_id = %s", (player, case_id) + ).fetchone() + return row[0] if row else None + + def put(conn: psycopg.Connection, player: str, case: Case) -> None: # putting a case again replaces it. tess changes cases faster than i can pull them. with conn.transaction():