owenrusk.dev

casebench

test cases straight onto the board.

git clone https://owenrusk.dev/casebench.git

commit 8156dd1c33b189dd92bb6f861aa6b4dd6d1d3469
parent 14af15c526a0e604ea49199b68d70b6186570845
author Owen Rusk <owen@papermothgames.com>
date   2025-06-10 15:09:58 -0500
list: what the bench has put where
casebench/cli.py+9-0
casebench/db.py+12-0
diff --git a/casebench/cli.py b/casebench/cli.py
index 2f82a78..d8eca0f 100644
--- a/casebench/cli.py
+++ b/casebench/cli.py
@@ -43,6 +43,10 @@ def main(argv: list[str] | None = None) -> int:
     unlocker.add_argument("--player", required=True)
     unlocker.set_defaults(run=run_unlock)
 
+    lister = sub.add_parser("list", help="what the bench has put where")
+    lister.add_argument("--player")
+    lister.set_defaults(run=run_list)
+
     args = parser.parse_args(argv)
     dsn = os.environ.get("CASEBENCH_DSN")
     if not dsn:
@@ -101,3 +105,8 @@ def run_unlock(conn: psycopg.Connection, args: argparse.Namespace) -> None:
     if not db.unlock(conn, who, args.case):
         raise Fail(f"{args.case} isn't locked for {args.player}")
     print(f"{args.player}: unlocked {args.case}")
+
+
+def run_list(conn: psycopg.Connection, args: argparse.Namespace) -> None:
+    for handle, case_id, title in db.bench_cases(conn, args.player):
+        print(f"{handle}\t{case_id}\t{title}")
diff --git a/casebench/db.py b/casebench/db.py
index 5c5a6e7..1a4dd8c 100644
--- a/casebench/db.py
+++ b/casebench/db.py
@@ -86,3 +86,15 @@ def unlock(conn: psycopg.Connection, player: str, case_id: str) -> bool:
     ).rowcount
     conn.commit()
     return gone > 0
+
+
+def bench_cases(conn: psycopg.Connection, handle: str | None = None) -> list[tuple[str, str, str]]:
+    query = (
+        "select p.handle, c.case_id, c.title from board_cases c join players p on p.id = c.player_id"
+        " where c.source = 'bench'"
+    )
+    params: tuple[str, ...] = ()
+    if handle is not None:
+        query += " and p.handle = %s"
+        params = (handle,)
+    return conn.execute(query + " order by p.handle, c.placed_at", params).fetchall()