feat: prompt presets, setup dialog, /games + leaderboard, one-game gate
Backend:
- prompts.py: 5 personality presets (уличный_гопник default, профессор,
поэт, молчун, шут). Each provides voice + label + description.
build_system_prompt accepts `preset` parameter; the MCP-tools section
+ must-call-move rule is shared common tail.
- coordinator: `start_new_game` now accepts `overrides` ({white: {agent,
model, prompt}, black: {...}}) — missing fields filled randomly.
MODEL_OPTIONS published per agent.
- AppState.prompts tracks the preset id per side; persisted into game's
agents dict and PGN.
- AppState.eval_cache cleared on new_game (was per-life-of-process before).
- persistence.save_game now stores full history (with comments) and the
per-position eval cache in the game JSON.
- ChessGame.abort() — manual game termination with result='*' and
Termination='aborted'.
- New endpoints:
• GET /api/options — agents, models per agent, prompt presets.
• GET /api/stats — leaderboard aggregated from games/*.json:
per (agent, model) and per persona, with score = wins + 0.5*draws.
• POST /api/abort-game — force-end current game.
- POST /api/new-game now returns 409 when a game is in progress.
- GET /api/games[/{id}[/pgn]] also 409 while in progress — gallery is
hidden behind the one-game-at-a-time rule.
Frontend:
- New setup dialog: per-side agent / model / persona selects, swap +
random shortcuts, persona description preview, abort button inline
when current game blocks the start.
- 'games & stats' link in the board footer; greyed out while a game is
active.
- /games page reworked: leaderboard (player × model + by persona),
games table with persona labels, replay panel showing eval per ply
with prev/next/first/last + arrow-key nav.
- chess.js loadPgn → load_pgn fix consolidated; replay prefers saved
history (comments + side) over PGN parse when available.
This commit is contained in:
@@ -98,3 +98,66 @@ def test_mcp_batch_with_notification(client):
|
||||
assert isinstance(body, list)
|
||||
assert len(body) == 1
|
||||
assert body[0]["id"] == 5
|
||||
|
||||
|
||||
def test_options_lists_models_and_prompts(client):
|
||||
r = client.get("/api/options")
|
||||
assert r.status_code == 200
|
||||
b = r.json()
|
||||
assert "claude" in b["agents"] and "codex" in b["agents"]
|
||||
assert "opus" in b["models"]["claude"]
|
||||
assert "gpt-5.5" in b["models"]["codex"]
|
||||
prompt_ids = [p["id"] for p in b["prompts"]]
|
||||
assert "уличный_гопник" in prompt_ids
|
||||
assert "профессор" in prompt_ids
|
||||
|
||||
|
||||
def test_new_game_accepts_overrides(client):
|
||||
# Abort the fixture's t1 game first — one game at a time.
|
||||
client.post("/api/abort-game")
|
||||
r = client.post("/api/new-game", json={"overrides": {
|
||||
"white": {"agent": "claude", "model": "sonnet", "prompt": "профессор"},
|
||||
"black": {"agent": "codex", "model": "gpt-5.4", "prompt": "шут"},
|
||||
}})
|
||||
assert r.status_code == 200
|
||||
g = r.json()
|
||||
a = g["agents"]
|
||||
assert a["white"]["agent"] == "claude"
|
||||
assert a["white"]["model"] == "sonnet"
|
||||
assert a["white"]["prompt"] == "профессор"
|
||||
assert a["black"]["agent"] == "codex"
|
||||
assert a["black"]["model"] == "gpt-5.4"
|
||||
assert a["black"]["prompt"] == "шут"
|
||||
|
||||
|
||||
def test_new_game_409_when_current_in_progress(client):
|
||||
# First call: t1 game is active (no result), need to finish it first.
|
||||
r = client.post("/api/new-game")
|
||||
assert r.status_code == 409
|
||||
|
||||
|
||||
def test_abort_game_then_new(client):
|
||||
r = client.post("/api/abort-game")
|
||||
assert r.status_code == 200
|
||||
assert r.json()["ok"] is True
|
||||
r2 = client.post("/api/new-game")
|
||||
assert r2.status_code == 200
|
||||
|
||||
|
||||
def test_games_endpoints_blocked_when_in_progress(client):
|
||||
# t1 is in progress per fixture
|
||||
assert client.get("/api/games").status_code == 409
|
||||
assert client.get("/api/games/anything").status_code == 409
|
||||
assert client.get("/api/games/anything/pgn").status_code == 409
|
||||
# Abort and they become accessible
|
||||
client.post("/api/abort-game")
|
||||
assert client.get("/api/games").status_code == 200
|
||||
|
||||
|
||||
def test_stats_empty_when_no_games(client):
|
||||
r = client.get("/api/stats")
|
||||
assert r.status_code == 200
|
||||
b = r.json()
|
||||
assert b["total_games"] == 0
|
||||
assert b["players"] == []
|
||||
assert b["prompts"] == []
|
||||
|
||||
Reference in New Issue
Block a user