Skip to content

Commit e3a887d

Browse files
committed
chore(dev): update CLAUDE.md with new testing info
1 parent a642b2f commit e3a887d

File tree

1 file changed

+63
-49
lines changed

1 file changed

+63
-49
lines changed

CLAUDE.md

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,62 +21,86 @@ basedpyright
2121

2222
### Testing
2323

24-
**IMPORTANT**: Tests require Balatro to be running in the background. Always start the game before running tests.
24+
**IMPORTANT**: Tests require Balatro to be running in the background. Use `./balatro.sh --status` to check if the game is running.
2525

2626
```bash
2727
# Run all tests (requires Balatro to be running) - stops after first failure
28-
pytest -x
28+
pytest
2929

3030
# Run specific test file - stops after first failure
31-
pytest -x tests/lua/test_api_functions.py
31+
pytest tests/lua/test_api_functions.py
3232

3333
# Run tests with verbose output - stops after first failure
3434
pytest -vx
35+
36+
# Run tests on specific port
37+
pytest --port 12347 tests/lua/endpoints/test_cash_out.py
3538
```
3639

37-
#### Test Prerequisites and Workflow
40+
#### Parallel Testing with Multiple Balatro Instances
41+
42+
The test suite supports running tests in parallel across multiple Balatro instances. This dramatically reduces test execution time by distributing tests across multiple game instances.
43+
44+
**Setup for Parallel Testing:**
45+
46+
1. **Check existing instances and start multiple Balatro instances on different ports**:
3847

39-
1. **Always start Balatro first**:
48+
```bash
49+
# First, check if any instances are already running
50+
./balatro.sh --status
4051

41-
```bash
42-
# Check if game is running
43-
ps aux | grep -E "(Balatro\.app|balatro\.sh)" | grep -v grep
52+
# If you need to kill all existing instances first:
53+
./balatro.sh --kill
54+
```
4455

45-
# Start if not running
46-
./balatro.sh > balatro.log 2>&1 & sleep 10 && echo 'Balatro started and ready'
47-
```
56+
```bash
57+
# Start two instances with a single command
58+
./balatro.sh -p 12346 -p 12347
4859
49-
2. **Monitor game startup**:
60+
# With performance optimizations for faster testing
61+
./balatro.sh --fast -p 12346
5062
51-
```bash
52-
# Check logs for successful mod loading
53-
tail -n 100 balatro.log
63+
# Headless mode for server environments
64+
./balatro.sh --headless -p 12346
5465
55-
# Look for these success indicators:
56-
# - "BalatrobotAPI initialized"
57-
# - "BalatroBot loaded - version X.X.X"
58-
# - "TCP socket created on port 12346"
59-
```
66+
# Fast Headless mode on 4 instances (recommended configuration)
67+
./balatro.sh --headless --fast -p 12346 -p 12347 -p 12348 -p 12349
68+
```
6069

61-
3. **Common startup issues and fixes**:
70+
2. **Run tests in parallel**:
6271

63-
- **Game crashes on mod load**: Review full log for Lua stack traces
64-
- **Steam connection warnings**: Can be ignored - game works without Steam in development
65-
- **JSON metadata errors**: Normal for development files (.vscode, .luarc.json) - can be ignored
72+
```bash
73+
# Two workers (faster than single instance)
74+
pytest -n 4 --port 12346 --port 12347 tests/lua/
6675
67-
4. **Test execution**:
76+
# Four workers (maximum parallelization)
77+
pytest -n 4 --port 12346 --port 12347 --port 12348 --port 12349 tests/lua/
78+
```
6879

69-
- **Test suite**: 102 tests covering API functions and TCP communication
70-
- **Execution time**: ~210 seconds (includes game state transitions)
71-
- **Coverage**: API function calls, socket communication, error handling, edge cases
80+
**Benefits:**
7281

73-
5. **Troubleshooting test failures**:
82+
- **Faster test execution**: ~4x speedup with 4 parallel workers
83+
- **Port isolation**: Each worker uses its dedicated Balatro instance
84+
85+
**Notes:**
86+
87+
- Each Balatro instance must be running on a different port before starting tests
88+
- Tests automatically distribute across available workers
89+
- Monitor logs for each instance: `tail -f logs/balatro_12346.log`
90+
- Logs are automatically created in the `logs/` directory with format `balatro_PORT.log`
91+
92+
#### Test Prerequisites and Workflow
7493

75-
- **Connection timeouts**: Ensure TCP port 12346 is available
76-
- **Game state errors**: Check if game is responsive and not crashed
77-
- **Invalid responses**: Verify mod loaded correctly by checking logs
78-
- **If test/s fail for timeout the reasons is that Balatro crash because there was an error in the Balatro mod (i.e. @balatrobot.lua and @src/lua/ ). The error should be logged in the `balatro.log` file.**
79-
- **Balatro app crashes**: When the Balatro app crashes during testing, **do not run the remaining tests**. The crash usually indicates an issue with the Lua mod code that causes cryptic errors in `balatro.log`. Stop test execution and investigate the crash logs before continuing. Before running the tests again, ALWAYS kill the current Balatro instance running and start it again.
94+
0. **Check existing instances first**:
95+
96+
```bash
97+
# Check if Balatro instances are already running
98+
./balatro.sh --status
99+
100+
# If instances are running on needed ports, you can proceed with testing
101+
# If you need to kill all running instances and start fresh:
102+
./balatro.sh --kill
103+
```
80104

81105
### Documentation
82106

@@ -100,19 +124,14 @@ BalatroBot is a Python framework for developing automated bots to play the card
100124

101125
### 2. Python Framework Layer (`src/balatrobot/`)
102126

103-
**NOTE**: This is the old implementation that is being heavily refactored without backwards compatibility.
104-
It will be drastically simplified in the future. For the moment I'm just focusing on the Lua API (`src/lua/api.lua`).
105-
I keep the old code around for reference.
106-
107-
- **Bot Base Class** (`base.py`): Abstract base class defining the bot interface
108-
- **ActionSchema**: TypedDict defining structured action format with `action` (enum) and `args` (list)
109-
- **Enums** (`enums.py`): Game state enums (Actions, Decks, Stakes, State)
110-
- **Socket Management**: Automatic reconnection, timeout handling, JSON parsing
127+
- **BalatroClient** (`client.py`): TCP client for communicating with game API via JSON messages
128+
- **Type-Safe Models** (`models.py`): Pydantic models matching Lua game state structure (G, GGame, GHand, etc.)
129+
- **Enums** (`enums.py`): Game state enums (Actions, Decks, Stakes, State, ErrorCode)
130+
- **Exception Hierarchy** (`exceptions.py`): Structured error handling with game-specific exceptions
131+
- **API Communication**: JSON request/response protocol with timeout handling and error recovery
111132

112133
## Development Standards
113134

114-
### Python Code Style (from `.cursor/rules/`)
115-
116135
- Use modern Python 3.13+ syntax with built-in collection types
117136
- Type annotations with pipe operator for unions: `str | int | None`
118137
- Use `type` statement for type aliases
@@ -126,8 +145,3 @@ I keep the old code around for reference.
126145
- **MkDocs Documentation**: Comprehensive guides with Material theme
127146
- **Pytest Testing**: TCP socket testing with fixtures
128147
- **Development Tools**: Ruff, basedpyright, modern Python tooling
129-
130-
### Testing Best Practices
131-
132-
- **Always check that Balatro is running before running tests**
133-
- After starting Balatro, check the `balatro.log` to confirm successful startup

0 commit comments

Comments
 (0)