Skip to content

Commit 44306dd

Browse files
committed
docs: update contributing.md with new instructions for running tests in parallel
1 parent e3a887d commit 44306dd

File tree

2 files changed

+117
-50
lines changed

2 files changed

+117
-50
lines changed

docs/contributing.md

Lines changed: 116 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
Welcome to BalatroBot! We're excited that you're interested in contributing to this Python framework and Lua mod for creating automated bots to play Balatro.
44

5-
BalatroBot uses a unique dual-architecture approach with a Python framework that communicates with a Lua mod running inside Balatro via TCP sockets. This allows for real-time bot automation and game state analysis.
5+
BalatroBot uses a dual-architecture approach with a Python framework that communicates with a Lua mod running inside Balatro via TCP sockets. This allows for real-time bot automation and game state analysis.
66

77
## Project Status & Priorities
88

99
We track all development work using the [BalatroBot GitHub Project](https://github.com/users/S1M0N38/projects/7). This is the best place to see current priorities, ongoing work, and opportunities for contribution.
1010

11-
**Current Focus**: We're heavily refactoring the Python framework while focusing development efforts on the Lua API (`src/lua/api.lua`). The existing Python code serves as reference but will be drastically simplified in future versions.
12-
1311
## Getting Started
1412

1513
### Prerequisites
@@ -20,10 +18,8 @@ Before contributing, ensure you have:
2018
- **SMODS (Steamodded)**: Version 1.0.0-beta-0711a or newer
2119
- **Python**: 3.13+ (managed via uv)
2220
- **uv**: Python package manager ([Installation Guide](https://docs.astral.sh/uv/))
23-
24-
### Recommended Tools
25-
26-
- **[DebugPlus](https://github.com/WilsontheWolf/DebugPlus)**: Essential for Lua API development and debugging
21+
- **OS**: macOS, Linux. Windows is not currently supported
22+
- **[DebugPlus](https://github.com/WilsontheWolf/DebugPlus) (optional)**: useful for Lua API development and debugging
2723

2824
### Development Environment Setup
2925

@@ -40,30 +36,20 @@ Before contributing, ensure you have:
4036
uv sync --all-extras
4137
```
4238

43-
3. **Set Up Balatro with Mods**
44-
45-
**macOS** (currently supported):
39+
3. **Stars Balatro with Mods**
4640

4741
```bash
48-
./balatro.sh > balatro.log 2>&1 & sleep 10 && echo 'Balatro started and ready'
42+
./balatro.sh -p 12346
4943
```
5044

51-
- **Linux**: We need a robust cross-platform script! Feel free to [open an issue](https://github.com/S1M0N38/balatrobot/issues/new) and contribute a Linux-compatible version.
52-
53-
- **Windows**: Development on Windows is not currently supported.
54-
55-
!!! Tip
56-
57-
Right now I'm using this [`balatro.sh`](https://gist.github.com/S1M0N38/4653c532bf048474100df3a270822bb4) script to start balatro with mods.
58-
59-
4. **Verify Game Setup**
45+
4. **Verify Balatro is Running**
6046

6147
```bash
6248
# Check if Balatro is running
63-
ps aux | grep -E "(Balatro\.app|balatro\.sh)" | grep -v grep
49+
./balatro.sh --status
6450
6551
# Monitor startup logs
66-
tail -n 100 balatro.log
52+
tail -n 100 logs/balatro_12346.log
6753
```
6854

6955
Look for these success indicators:
@@ -72,7 +58,6 @@ Before contributing, ensure you have:
7258
- "BalatroBot loaded - version X.X.X"
7359
- "TCP socket created on port 12346"
7460

75-
7661
## How to Contribute
7762

7863
### Types of Contributions Welcome
@@ -95,8 +80,6 @@ Before contributing, ensure you have:
9580
9681
```bash
9782
git checkout -b feature/your-feature-name
98-
# or
99-
git checkout -b fix/issue-description
10083
```
10184
10285
3. **Make Changes**
@@ -110,7 +93,7 @@ Before contributing, ensure you have:
11093
- **Important**: Enable "Allow edits from maintainers" when creating your PR
11194
- Link to related issues
11295
- Provide clear description of changes
113-
- Include testing instructions
96+
- Include test for new functionality
11497
11598
### Commit Messages
11699
@@ -143,27 +126,123 @@ basedpyright
143126
### Testing Requirements
144127
145128
!!! warning
146-
All tests require Balatro to be running in the background.
129+
130+
All tests require Balatro to be running in the background. Use `./balatro.sh --status` to check if the game is running.
131+
132+
#### Single Instance Testing
147133
148134
```bash
149-
# Start Balatro first
150-
./balatro.sh > balatro.log 2>&1 & sleep 10
135+
# Start Balatro with default port (12346)
136+
./balatro.sh -p 12346
151137
152-
# Run all tests (stops on first failure)
153-
pytest -x
138+
# Run all tests
139+
pytest
154140
155141
# Run specific test file
156-
pytest -x tests/lua/test_api_functions.py
142+
pytest tests/lua/test_api_functions.py
157143
158-
# Run with verbose output
144+
# Run with verbose output and stop on first failure
159145
pytest -vx
146+
147+
# Run tests on specific port
148+
pytest --port 12347 tests/lua/endpoints/test_cash_out.py
149+
```
150+
151+
#### Parallel Testing with Multiple Balatro Instances
152+
153+
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.
154+
155+
**Setup for Parallel Testing:**
156+
157+
1. **Check existing instances and start multiple Balatro instances on different ports**:
158+
159+
```bash
160+
# First, check if any instances are already running
161+
./balatro.sh --status
162+
163+
# If you need to kill all existing instances first:
164+
./balatro.sh --kill
165+
```
166+
167+
```bash
168+
# Start two instances with a single command
169+
./balatro.sh -p 12346 -p 12347
170+
171+
# With performance optimizations for faster testing
172+
./balatro.sh --fast -p 12346
173+
174+
# Headless mode for server environments
175+
./balatro.sh --headless -p 12346
176+
177+
# Fast Headless mode on 4 instances (recommended configuration)
178+
./balatro.sh --headless --fast -p 12346 -p 12347 -p 12348 -p 12349
179+
```
180+
181+
2. **Run tests in parallel**:
182+
183+
```bash
184+
# Two workers (faster than single instance)
185+
pytest -n 2 --port 12346 --port 12347
186+
187+
# Four workers (recommended configuration)
188+
pytest -n 4 --port 12346 --port 12347 --port 12348 --port 12349
189+
```
190+
191+
**Benefits:**
192+
193+
- **Faster test execution**: ~4x speedup with 4 parallel workers
194+
- **Port isolation**: Each worker uses its dedicated Balatro instance
195+
196+
**Notes:**
197+
198+
- Each Balatro instance must be running on a different port before starting tests
199+
- Tests automatically distribute across available workers
200+
- Monitor logs for each instance: `tail -f logs/balatro_12346.log`
201+
- Logs are automatically created in the `logs/` directory with format `balatro_PORT.log`
202+
203+
**balatro.sh Command Options:**
204+
205+
```bash
206+
# Usage examples
207+
./balatro.sh -p 12347 # Start single instance on port 12347
208+
./balatro.sh -p 12346 -p 12347 # Start two instances on ports 12346 and 12347
209+
./balatro.sh --headless --fast -p 12346 # Start with headless and fast mode
210+
./balatro.sh --kill # Kill all running Balatro instances
211+
./balatro.sh --status # Show running instances
160212
```
161213
162-
**Test Suite Overview**:
214+
**balatro.sh Modes:**
215+
216+
- **`--headless`**: Enable headless mode (sets `BALATROBOT_HEADLESS=1`)
217+
218+
- Minimizes and hides game window
219+
- Completely disables Love2D graphics operations
220+
- Minimal CPU/GPU usage for pure game logic execution
221+
- Ideal for server environments and cloud-based bot training
163222
164-
- 102 tests covering API functions and TCP communication
165-
- ~210 seconds execution time
166-
- Tests game state transitions, socket communication, error handling
223+
- **`--fast`**: Enable fast mode (sets `BALATROBOT_FAST=1`)
224+
225+
- Unlimited FPS, 10x game speed, 6x faster animations
226+
- Disabled shadows, bloom, CRT effects, VSync
227+
- Complete audio muting
228+
- Optimized for maximum execution speed during bot training
229+
230+
**Test Prerequisites and Workflow:**
231+
232+
```bash
233+
# 1. Check if Balatro instances are already running
234+
./balatro.sh --status
235+
236+
# 2. If instances are running on needed ports, you can proceed with testing
237+
# If you need to kill all running instances and start fresh:
238+
./balatro.sh --kill
239+
240+
# 3. Start the required instances
241+
./balatro.sh --headless --fast -p 12346 -p 12347 -p 12348 -p 12349
242+
243+
# 4. Run parallel tests
244+
pytest -n 4 --port 12346 --port 12347 --port 12348 --port 12349 tests/lua/
245+
```
167246
168247
**Troubleshooting Test Failures**:
169248
@@ -266,14 +345,4 @@ This configuration system enables BalatroBot to run efficiently in diverse envir
266345
- **GitHub Issues**: Primary communication for bugs, features, and project coordination
267346
- **Discord**: Join us at the [Balatro Discord](https://discord.com/channels/1116389027176787968/1391371948629426316) for real-time discussions
268347

269-
270-
---
271-
272-
## Questions?
273-
274-
- Check the [GitHub Project](https://github.com/users/S1M0N38/projects/7) for current priorities
275-
- [Open an issue](https://github.com/S1M0N38/balatrobot/issues/new) for bugs or questions
276-
- Join the [Discord discussion](https://discord.com/channels/1116389027176787968/1391371948629426316)
277-
278348
Happy contributing!
279-

docs/index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ BalatroBot is a Python framework designed to help developers create automated bo
4444

4545
---
4646

47-
Documentation in [llms.txt](https://llmstxt.org/) formats, easily digestible by LLMs.
48-
49-
[:octicons-arrow-right-24: llms.txt](llms.txt)
47+
Documentation in [llms.txt](https://llmstxt.org/) formats. Just paste the following link (or it's content) into the LLM chat.
5048

5149
[:octicons-arrow-right-24: llms-full.txt](llms-full.txt)
5250

0 commit comments

Comments
 (0)