Chess AI App is a Python-based chess application supporting user authentication, game management, and AI-powered features. It includes robust automated testing using pytest and supports a passwordless test mode for streamlined integration testing.
- User registration, login, and email verification
- Play, load, and practice chess games (including classic endgames and mate puzzles)
- View player stats and ask a chess expert
- Multiple AI models: GPT-4o, DeepSeek, Gemini, Claude, Llama, Stockfish (with skill levels)
- Automated tests with pytest and pexpect
- Test Mode: Set
CHESS_APP_TEST_MODE=1
to bypass authentication and password prompts for automated testing
--- Main Menu ---
1: Play a New Game
2: Load a Saved Game
3: Load a Practice Position
4: View Player Stats
?: Ask a Chess Expert
q: Quit
python -m src.main
Most tests use passwordless test mode for speed and reliability.
Set the environment variable before running tests:
set CHESS_APP_TEST_MODE=1
pytest
The login integration test (tests/test_login_integration.py
) temporarily disables test mode to verify the full authentication flow:
pytest tests/test_login_integration.py
pytest --ignore=tests/test_login_integration.py
- When
CHESS_APP_TEST_MODE=1
, the app starts directly at the main menu and bypasses authentication and password prompts. - When
CHESS_APP_TEST_MODE=0
, the app runs in normal mode with full authentication.
src/
main.py
auth_ui.py
utils/
input_handler.py
tests/
test_basic.py
test_login_integration.py
test_integration_main_menu.py
...
Integration tests are located in tests/test_integration_main_menu.py
and use pexpect
to interact with the CLI application.
- Set
CHESS_APP_TEST_MODE=1
in your environment before running tests for deterministic behavior. - The player stats test only checks for the presence of the statistics header and return prompt, not specific player names.
- All tests clean up child processes after execution.
- Some flows (e.g., new game) may be skipped; see the test file for details.
- Fork the repo
- Create a feature branch
- Submit a pull request
This project uses GitHub Actions for CI/CD.
On every pull request to master
, the pipeline will:
- Install dependencies
- Set a dummy
OPENAI_API_KEY
for tests that require OpenAI client instantiation - Install Stockfish on Linux runners and set the
STOCKFISH_EXECUTABLE
environment variable - Run all pytest tests in passwordless mode (
CHESS_APP_TEST_MODE=1
) except the login integration test - Run the login integration test in full authentication mode (
CHESS_APP_TEST_MODE=0
)
See .github/workflows/python-app.yml
for details.
- The CI pipeline sets a dummy
OPENAI_API_KEY
for tests that require OpenAI client instantiation. - If your tests do not need to call the real OpenAI API, use
pytest-mock
to mock the OpenAI client. - The Stockfish chess engine is installed on Linux runners and its path is set using the
STOCKFISH_EXECUTABLE
environment variable. - All tests should use
os.environ.get("STOCKFISH_EXECUTABLE", "stockfish")
to locate the Stockfish binary. - If you encounter authentication menu prompts in tests when
CHESS_APP_TEST_MODE=0
, ensure your test code navigates through authentication before expecting the main menu. - For tests that expect the main menu immediately, use
CHESS_APP_TEST_MODE=1
.
- Authentication Menu Timeout:
If a test fails waiting for the main menu but the authentication menu is shown, update your test to handle authentication (login or register) before proceeding to the main menu whenCHESS_APP_TEST_MODE=0
. - Missing Dependencies:
If you seeModuleNotFoundError
, add the missing package torequirements.txt
. - Stockfish Not Found:
Ensure Stockfish is installed and the path is set viaSTOCKFISH_EXECUTABLE
in your workflow and code. - OpenAI API Key Error:
Set a dummyOPENAI_API_KEY
in your CI environment for tests that instantiate the OpenAI client.
MIT
For more details, see the code and tests in the src/
and tests/
directories.