rewrite: TS monorepo — pi SDK stateless agents, Postgres+pg-boss, SvelteKit themed UI; legacy moved to legacy/

This commit is contained in:
ai-chess
2026-10-18 15:32:39 +03:00
parent e23a07f07b
commit 5be4bd1da4
321 changed files with 37840 additions and 158 deletions
View File
+2
View File
@@ -0,0 +1,2 @@
# tests/conftest.py
# Async tests use pytest-asyncio (asyncio_mode = "auto" in pyproject.toml).
+163
View File
@@ -0,0 +1,163 @@
import asyncio
import pytest
from fastapi.testclient import TestClient
import ai_chess.state as state_mod
from ai_chess.app import build_app
from ai_chess.chess_game import ChessGame
@pytest.fixture
def client(tmp_path, monkeypatch):
# Use a fresh AppState per test
monkeypatch.setattr(state_mod, "GAMES_DIR", tmp_path / "games")
monkeypatch.setattr(state_mod, "CONFIG_DIR", tmp_path / "config")
monkeypatch.setattr(state_mod, "LOGS_DIR", tmp_path / "logs")
s = state_mod.AppState()
s.game = ChessGame(game_id="t1")
monkeypatch.setattr(state_mod, "state", s)
app = build_app(s)
return TestClient(app)
def test_state_endpoint(client):
r = client.get("/api/state")
assert r.status_code == 200
body = r.json()
assert body["game"]["fen"].startswith("rnbqkbnr")
assert body["game"]["side_to_move"] == "white"
def test_settings_get_post(client):
r = client.get("/api/settings")
assert r.status_code == 200
assert r.json()["allow_draw_resign"] is True
r = client.post("/api/settings", json={"allow_illegal_moves": True})
assert r.status_code == 200
assert r.json()["allow_illegal_moves"] is True
def test_mcp_initialize(client):
r = client.post("/mcp/white", json={
"jsonrpc": "2.0", "id": 1, "method": "initialize",
"params": {"protocolVersion": "2025-06-18", "capabilities": {}, "clientInfo": {"name": "test", "version": "0"}},
})
assert r.status_code == 200
body = r.json()
assert body["result"]["serverInfo"]["name"].startswith("ai-chess")
def test_mcp_tools_list_and_call(client):
r = client.post("/mcp/white", json={
"jsonrpc": "2.0", "id": 2, "method": "tools/list", "params": {},
})
names = [t["name"] for t in r.json()["result"]["tools"]]
assert "move" in names and "resign" in names
r = client.post("/mcp/white", json={
"jsonrpc": "2.0", "id": 3, "method": "tools/call",
"params": {"name": "move", "arguments": {"move": "e4", "comment": "го"}},
})
body = r.json()
content = body["result"]["content"][0]["text"]
assert '"ok": true' in content or '"ok":true' in content
assert "e4" in content
def test_mcp_wrong_side_blocked(client):
r = client.post("/mcp/black", json={
"jsonrpc": "2.0", "id": 4, "method": "tools/call",
"params": {"name": "move", "arguments": {"move": "e5"}},
})
text = r.json()["result"]["content"][0]["text"]
assert "not_your_turn" in text
def test_mcp_notification_returns_202_no_body(client):
# JSON-RPC notification (no "id" key) MUST return 202 with empty body —
# otherwise rmcp (codex's MCP client) treats 200+body as an unexpected
# response and closes the transport.
r = client.post("/mcp/white", json={
"jsonrpc": "2.0", "method": "notifications/initialized", "params": {},
})
assert r.status_code == 202
assert r.content == b""
def test_mcp_batch_with_notification(client):
# Batch with one request + one notification — response should contain
# only the request's reply.
r = client.post("/mcp/white", json=[
{"jsonrpc": "2.0", "id": 5, "method": "tools/list", "params": {}},
{"jsonrpc": "2.0", "method": "notifications/initialized", "params": {}},
])
assert r.status_code == 200
body = r.json()
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"] == []
+152
View File
@@ -0,0 +1,152 @@
import pytest
from ai_chess.chess_game import ChessGame, MoveResult
from ai_chess.sides import Side
def test_new_game_state():
g = ChessGame(game_id="g1")
state = g.get_state()
assert state["side_to_move"] == "white"
assert state["history"] == []
assert state["status"]["result"] is None
assert "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR" in state["fen"]
def test_legal_move_white_san():
g = ChessGame(game_id="g1")
r = g.try_move(Side.WHITE, "e4")
assert r.ok is True
assert r.san == "e4"
assert r.uci == "e2e4"
assert g.get_state()["side_to_move"] == "black"
assert g.get_state()["history"][0]["san"] == "e4"
def test_legal_move_uci():
g = ChessGame(game_id="g1")
r = g.try_move(Side.WHITE, "e2e4")
assert r.ok is True
assert r.san == "e4"
def test_not_your_turn():
g = ChessGame(game_id="g1")
r = g.try_move(Side.BLACK, "e5")
assert r.ok is False
assert r.reason == "not_your_turn"
def test_illegal_move_default_rejected():
g = ChessGame(game_id="g1")
r = g.try_move(Side.WHITE, "e2e5") # pawn can't move two from e2 to e5
assert r.ok is False
assert r.reason == "illegal_move"
def test_history_contains_comment():
g = ChessGame(game_id="g1")
g.try_move(Side.WHITE, "e4", comment="готовься")
h = g.get_state()["history"]
assert h[0]["san"] == "e4"
assert h[0]["comment"] == "готовься"
def test_game_over_checkmate_fools_mate():
g = ChessGame(game_id="g1")
moves = [
(Side.WHITE, "f3"),
(Side.BLACK, "e5"),
(Side.WHITE, "g4"),
(Side.BLACK, "Qh4"),
]
for side, mv in moves:
r = g.try_move(side, mv)
assert r.ok, (mv, r)
st = g.get_state()
assert st["status"]["result"] == "0-1"
assert st["status"]["termination"] == "checkmate"
def test_move_after_game_over():
g = ChessGame(game_id="g1")
for side, mv in [(Side.WHITE, "f3"), (Side.BLACK, "e5"),
(Side.WHITE, "g4"), (Side.BLACK, "Qh4")]:
g.try_move(side, mv)
r = g.try_move(Side.WHITE, "a3")
assert r.ok is False
assert r.reason == "game_over"
def test_resign():
g = ChessGame(game_id="g1")
g.try_move(Side.WHITE, "e4")
out = g.resign(Side.BLACK, comment="сдаюсь")
assert out["ok"] is True
assert out["result"] == "1-0"
assert g.get_state()["status"]["result"] == "1-0"
assert g.get_state()["status"]["termination"] == "resignation"
def test_offer_then_accept_draw():
g = ChessGame(game_id="g1")
g.try_move(Side.WHITE, "e4")
out = g.offer_draw(Side.BLACK, comment="ничья?")
assert out["ok"] is True
assert g.get_state()["status"]["pending_draw_offer_by"] == "black"
out2 = g.accept_draw(Side.WHITE)
assert out2["ok"] is True
assert g.get_state()["status"]["result"] == "1/2-1/2"
assert g.get_state()["status"]["termination"] == "agreement"
def test_offer_then_decline_draw():
g = ChessGame(game_id="g1")
g.try_move(Side.WHITE, "e4")
g.offer_draw(Side.BLACK)
out = g.decline_draw(Side.WHITE)
assert out["ok"] is True
assert g.get_state()["status"]["pending_draw_offer_by"] is None
assert g.get_state()["status"]["result"] is None
def test_offer_mutual_short_circuit_accepts():
g = ChessGame(game_id="g1")
g.try_move(Side.WHITE, "e4")
g.offer_draw(Side.BLACK)
out = g.offer_draw(Side.WHITE) # белый тоже предлагает — авто-accept
assert out["ok"] is True
assert g.get_state()["status"]["result"] == "1/2-1/2"
def test_move_retracts_draw_offer():
g = ChessGame(game_id="g1")
g.try_move(Side.WHITE, "e4")
g.offer_draw(Side.BLACK)
g.try_move(Side.BLACK, "e5")
assert g.get_state()["status"]["pending_draw_offer_by"] is None
def test_allow_illegal_move():
g = ChessGame(game_id="g1")
r = g.try_move(Side.WHITE, "e2e7", allow_illegal=True)
assert r.ok is True
assert r.illegal is True
assert r.san is None
fen = g.get_state()["fen"]
# pawn moved 5 squares forward — that's an illegal raw push
assert "P" in fen.split(" ")[0].split("/")[1] # rank 7 has white pawn now
def test_pgn_export_contains_comments():
g = ChessGame(game_id="g1", agents={
"white": {"agent": "claude", "model": "opus"},
"black": {"agent": "codex", "model": "gpt-5.5"},
})
g.try_move(Side.WHITE, "e4", comment="первый ход")
g.try_move(Side.BLACK, "c5", comment="сицилианка")
pgn = g.to_pgn()
assert "claude/opus" in pgn
assert "codex/gpt-5.5" in pgn
assert "первый ход" in pgn
assert "сицилианка" in pgn
+83
View File
@@ -0,0 +1,83 @@
import asyncio
import pytest
import ai_chess.coordinator as coord_mod
from ai_chess.chess_game import ChessGame
from ai_chess.coordinator import Coordinator
from ai_chess.sides import Side
from ai_chess.state import AppState, AgentBinding
@pytest.fixture(autouse=True)
def _isolated_games_dir(tmp_path, monkeypatch):
"""Redirect save_game writes into a tmp directory so tests don't pollute games/."""
monkeypatch.setattr(coord_mod, "GAMES_DIR", tmp_path / "games")
class FakeTmux:
def __init__(self):
self.calls: list[tuple] = []
async def submit(self, pane: int, text: str):
self.calls.append(("submit", pane, text))
async def send_keys(self, pane: int, keys):
self.calls.append(("send_keys", pane, list(keys)))
@pytest.mark.asyncio
async def test_first_prompt_white_on_start():
state = AppState()
state.game = ChessGame(game_id="t1")
state.bindings[Side.WHITE] = AgentBinding(Side.WHITE, "claude", "opus", "max")
state.bindings[Side.BLACK] = AgentBinding(Side.BLACK, "codex", "gpt-5.5", "xhigh")
fake = FakeTmux()
coord = Coordinator(state, tmux=fake, pane_for={"white": 0, "black": 1})
await coord.dispatch_first_prompt()
assert any(call[0] == "submit" and call[1] == 0 for call in fake.calls)
text = next(c[2] for c in fake.calls if c[0] == "submit" and c[1] == 0)
assert "белыми" in text
@pytest.mark.asyncio
async def test_on_move_sends_to_opponent():
state = AppState()
state.game = ChessGame(game_id="t1")
state.bindings[Side.WHITE] = AgentBinding(Side.WHITE, "claude", "opus", "max")
state.bindings[Side.BLACK] = AgentBinding(Side.BLACK, "codex", "gpt-5.5", "xhigh")
fake = FakeTmux()
coord = Coordinator(state, tmux=fake, pane_for={"white": 0, "black": 1})
await coord.run_subscriber_step_once({
"type": "move",
"side": "white",
"san": "e4",
"comment": "готовься",
"fen": state.game.board.fen(),
"ascii": str(state.game.board),
})
assert any(c[0] == "submit" and c[1] == 1 for c in fake.calls)
text = next(c[2] for c in fake.calls if c[0] == "submit" and c[1] == 1)
assert "e4" in text
assert "готовься" in text
@pytest.mark.asyncio
async def test_game_over_sends_summary_to_both():
state = AppState()
state.game = ChessGame(game_id="t1")
state.bindings[Side.WHITE] = AgentBinding(Side.WHITE, "claude", "opus", "max")
state.bindings[Side.BLACK] = AgentBinding(Side.BLACK, "codex", "gpt-5.5", "xhigh")
fake = FakeTmux()
coord = Coordinator(state, tmux=fake, pane_for={"white": 0, "black": 1})
state.game.try_move(Side.WHITE, "f3")
state.game.try_move(Side.BLACK, "e5")
state.game.try_move(Side.WHITE, "g4")
state.game.try_move(Side.BLACK, "Qh4")
await coord.run_subscriber_step_once({
"type": "game_over",
"result": "0-1",
"termination": "checkmate",
})
panes = sorted({c[1] for c in fake.calls if c[0] == "submit"})
assert panes == [0, 1]
+91
View File
@@ -0,0 +1,91 @@
import pytest
from ai_chess.chess_game import ChessGame
from ai_chess.mcp_server import build_tools_for_side
from ai_chess.settings import Settings
from ai_chess.sides import Side
from ai_chess.state import AppState
def fresh_state() -> AppState:
s = AppState()
s.game = ChessGame(game_id="t1")
return s
@pytest.mark.asyncio
async def test_get_board():
s = fresh_state()
tools = build_tools_for_side(Side.WHITE, s)
res = await tools["get_board"]({})
assert "ascii" in res and "fen" in res
assert res["side_to_move"] == "white"
@pytest.mark.asyncio
async def test_move_legal():
s = fresh_state()
tools = build_tools_for_side(Side.WHITE, s)
res = await tools["move"]({"move": "e4", "comment": "го"})
assert res["ok"] is True
assert res["san"] == "e4"
@pytest.mark.asyncio
async def test_move_not_your_turn():
s = fresh_state()
tools = build_tools_for_side(Side.BLACK, s)
res = await tools["move"]({"move": "e5"})
assert res["ok"] is False
assert res["reason"] == "not_your_turn"
@pytest.mark.asyncio
async def test_move_illegal_default_off():
s = fresh_state()
tools = build_tools_for_side(Side.WHITE, s)
res = await tools["move"]({"move": "e2e7"})
assert res["ok"] is False
assert res["reason"] == "illegal_move"
@pytest.mark.asyncio
async def test_move_illegal_allowed_when_flag_on():
s = fresh_state()
s.settings = Settings(allow_illegal_moves=True)
tools = build_tools_for_side(Side.WHITE, s)
res = await tools["move"]({"move": "e2e7"})
assert res["ok"] is True
assert res["illegal"] is True
@pytest.mark.asyncio
async def test_resign_disabled():
s = fresh_state()
s.settings = Settings(allow_draw_resign=False)
tools = build_tools_for_side(Side.WHITE, s)
res = await tools["resign"]({})
assert res["ok"] is False
assert res["reason"] == "resign_disabled"
@pytest.mark.asyncio
async def test_resign_ok_then_game_over():
s = fresh_state()
tools = build_tools_for_side(Side.WHITE, s)
res = await tools["resign"]({"comment": "сдаюсь"})
assert res["ok"] is True
assert s.game.result == "0-1"
@pytest.mark.asyncio
async def test_draw_offer_and_accept():
s = fresh_state()
s.game.try_move(Side.WHITE, "e4")
tools_b = build_tools_for_side(Side.BLACK, s)
r1 = await tools_b["offer_draw"]({"comment": "ничья?"})
assert r1["ok"] is True
tools_w = build_tools_for_side(Side.WHITE, s)
r2 = await tools_w["accept_draw"]({})
assert r2["ok"] is True
assert s.game.result == "1/2-1/2"
+48
View File
@@ -0,0 +1,48 @@
import json
from pathlib import Path
from ai_chess.chess_game import ChessGame
from ai_chess.persistence import save_game, list_games, load_game
from ai_chess.sides import Side
def make_game() -> ChessGame:
g = ChessGame(game_id="01HZZZTEST", agents={
"white": {"agent": "claude", "model": "opus", "effort": "max"},
"black": {"agent": "codex", "model": "gpt-5.5", "effort": "xhigh"},
})
g.try_move(Side.WHITE, "e4", comment="го")
g.try_move(Side.BLACK, "c5", comment="да")
g.resign(Side.BLACK)
return g
def test_save_creates_files(tmp_path: Path):
g = make_game()
save_game(tmp_path, g)
assert (tmp_path / "01HZZZTEST.pgn").exists()
assert (tmp_path / "01HZZZTEST.json").exists()
meta = json.loads((tmp_path / "01HZZZTEST.json").read_text())
assert meta["id"] == "01HZZZTEST"
assert meta["result"] == "1-0"
assert meta["termination"] == "resignation"
assert meta["agents"]["white"]["agent"] == "claude"
def test_list_games_sorted_newest_first(tmp_path: Path):
g1 = make_game()
g1.game_id = "AAA1"
save_game(tmp_path, g1)
g2 = make_game()
g2.game_id = "ZZZ9"
save_game(tmp_path, g2)
games = list_games(tmp_path)
assert [g["id"] for g in games] == ["ZZZ9", "AAA1"]
def test_load_game_returns_meta_and_pgn(tmp_path: Path):
g = make_game()
save_game(tmp_path, g)
loaded = load_game(tmp_path, "01HZZZTEST")
assert loaded["meta"]["id"] == "01HZZZTEST"
assert "[White " in loaded["pgn"]
+43
View File
@@ -0,0 +1,43 @@
from ai_chess.prompts import build_system_prompt, build_first_prompt, build_turn_prompt, WATCHDOG_NUDGE
from ai_chess.sides import Side
def test_system_prompt_mentions_opponent_and_toxicity():
sp = build_system_prompt(side=Side.WHITE, opponent_name="codex", opponent_model="gpt-5.5")
assert "codex" in sp
assert "gpt-5.5" in sp
assert "грубо" in sp or "трэш" in sp or "троллить" in sp
assert "русск" in sp.lower()
assert "move(" in sp
assert "resign" in sp
assert "offer_draw" in sp
def test_first_prompt_white():
p = build_first_prompt(side=Side.WHITE, fen="startfen", ascii_board="...board...", opponent_san=None, opponent_comment=None)
assert "белыми" in p.lower() or "белые" in p.lower()
assert "startfen" in p
assert "...board..." in p
def test_first_prompt_black_includes_white_move():
p = build_first_prompt(side=Side.BLACK, fen="f", ascii_board="b", opponent_san="e4", opponent_comment="готовься")
assert "чёрн" in p.lower() or "черн" in p.lower()
assert "e4" in p
assert "готовься" in p
def test_turn_prompt_includes_san_and_comment():
p = build_turn_prompt(opponent_san="Nf3", opponent_comment="трясись", fen="f", ascii_board="b", pending_draw_from_opponent=False)
assert "Nf3" in p
assert "трясись" in p
def test_turn_prompt_with_draw_offer():
p = build_turn_prompt(opponent_san="e5", opponent_comment=None, fen="f", ascii_board="b", pending_draw_from_opponent=True)
assert "ничь" in p.lower()
assert "accept_draw" in p
def test_watchdog_nudge_constant():
assert "move" in WATCHDOG_NUDGE
+49
View File
@@ -0,0 +1,49 @@
import json
from pathlib import Path
import pytest
from ai_chess.settings import Settings, load_settings, save_settings, DEFAULTS
def test_defaults():
s = Settings()
assert s.allow_draw_resign is True
assert s.allow_illegal_moves is False
assert s.theme_mode == "by_side"
assert s.watchdog_seconds == 180
assert s.watchdog_max_nudges == 3
assert s.stockfish_depth == 15
def test_load_creates_file_if_missing(tmp_path: Path):
cfg = tmp_path / "settings.json"
s = load_settings(cfg)
assert cfg.exists()
assert s == Settings()
assert json.loads(cfg.read_text()) == DEFAULTS
def test_load_round_trip(tmp_path: Path):
cfg = tmp_path / "settings.json"
cfg.write_text(json.dumps({"allow_illegal_moves": True, "stockfish_depth": 22}))
s = load_settings(cfg)
assert s.allow_illegal_moves is True
assert s.stockfish_depth == 22
assert s.allow_draw_resign is True # default preserved
def test_save_partial(tmp_path: Path):
cfg = tmp_path / "settings.json"
s = load_settings(cfg)
s2 = save_settings(cfg, s, {"allow_illegal_moves": True})
assert s2.allow_illegal_moves is True
assert s2.allow_draw_resign is True
assert json.loads(cfg.read_text())["allow_illegal_moves"] is True
def test_save_rejects_unknown(tmp_path: Path):
cfg = tmp_path / "settings.json"
s = load_settings(cfg)
with pytest.raises(ValueError):
save_settings(cfg, s, {"nonsense": 1})
+16
View File
@@ -0,0 +1,16 @@
from ai_chess.sides import Side
def test_opposite():
assert Side.WHITE.opposite() is Side.BLACK
assert Side.BLACK.opposite() is Side.WHITE
def test_from_str():
assert Side.from_str("white") is Side.WHITE
assert Side.from_str("black") is Side.BLACK
def test_str_value():
assert Side.WHITE.value == "white"
assert Side.BLACK.value == "black"
+35
View File
@@ -0,0 +1,35 @@
import shutil
import pytest
from ai_chess.stockfish_engine import StockfishEngine
pytestmark = pytest.mark.skipif(
shutil.which("stockfish") is None,
reason="stockfish not installed",
)
@pytest.mark.asyncio
async def test_startpos_eval():
eng = StockfishEngine()
await eng.start()
try:
r = await eng.analyze("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1", depth=6)
assert r["best_uci"] is not None
assert r["cp"] is not None or r["mate"] is not None
finally:
await eng.stop()
@pytest.mark.asyncio
async def test_mate_eval():
eng = StockfishEngine()
await eng.start()
try:
# Mate in 1: white to move, Qh5#-style position
r = await eng.analyze("4k3/8/8/8/8/8/4Q3/4K3 w - - 0 1", depth=10)
assert (r["mate"] is not None and r["mate"] > 0) or (r["cp"] is not None and r["cp"] > 500)
finally:
await eng.stop()
+54
View File
@@ -0,0 +1,54 @@
import asyncio
import os
import tempfile
import pytest
from ai_chess.tmux import TmuxSession
@pytest.mark.asyncio
async def test_create_kill_session():
s = TmuxSession("aichess-test-create")
try:
await s.kill() # idempotent
await s.create_window_with_cmd("cat > /tmp/aichess-test.out")
assert await s.exists()
finally:
await s.kill()
assert not await s.exists()
@pytest.mark.asyncio
async def test_paste_multiline():
out = tempfile.NamedTemporaryFile(mode="w", suffix=".out", delete=False)
out.close()
s = TmuxSession("aichess-test-paste")
try:
await s.kill()
await s.create_window_with_cmd(f"cat > {out.name}")
await asyncio.sleep(0.2)
await s.paste_text(pane=0, text='многострочный\nтест с "кавычками" и $vars\nthird')
await s.send_keys(pane=0, keys=["C-d"])
await asyncio.sleep(0.2)
with open(out.name) as f:
data = f.read()
assert "многострочный" in data
assert 'тест с "кавычками" и $vars' in data
assert "third" in data
finally:
await s.kill()
os.unlink(out.name)
@pytest.mark.asyncio
async def test_capture_pane():
s = TmuxSession("aichess-test-capture")
try:
await s.kill()
await s.create_window_with_cmd("printf 'hello world\\n'; sleep 5")
await asyncio.sleep(0.4)
text = await s.capture_pane(pane=0)
assert "hello world" in text
finally:
await s.kill()