Skip to content

Commit e88921b

Browse files
committed
docs(CLAUDE): Add critical warnings about Server() in doctests
Document the dangerous pattern where creating Server() directly in doctests causes the user's tmux session to be killed: 1. conftest.py:44 overwrites Server with TestServer factory 2. TestServer tracks ALL created servers via on_init callback 3. TestServer finalizer kills ALL tracked servers at test suite end 4. socket_name="default" → kills user's actual tmux session! Added warnings in two sections: - Doctest Integration: Explains the root cause and safe patterns - Writing Tests: Quick reference for test authors This prevents the critical bug where running `uv run pytest` from inside tmux would kill the user's session.
1 parent 245da21 commit e88921b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

CLAUDE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,33 @@ Window(@3 2:my_window, Session($1 ...))
203203

204204
These execute against real tmux during `pytest --doctest-modules`.
205205

206+
**CRITICAL DOCTEST RULE: NEVER create Server objects directly**
207+
208+
**WRONG - Will kill user's tmux session:**
209+
```python
210+
>>> server = Server(socket_name="default") # DANGEROUS!
211+
>>> server = Server(socket_name="testing") # Still dangerous!
212+
```
213+
214+
**CORRECT - Use lowercase fixtures:**
215+
```python
216+
>>> assert server.command_runner is not None # Uses injected fixture
217+
>>> server.new_session("test") # Fixture has unique socket
218+
```
219+
220+
**Why this matters:**
221+
- `conftest.py:44` overwrites `Server` with `TestServer` factory
222+
- `TestServer` tracks ALL created servers via `on_init` callback
223+
- `TestServer` finalizer kills ALL tracked servers at test suite end
224+
- If you use `socket_name="default"` → user's session gets killed!
225+
- If you use any socket name → cleanup may interfere with user
226+
227+
**Safe patterns:**
228+
1. Use lowercase `server` fixture (unique socket like `libtmux_test3k9m7x2q`)
229+
2. Use lowercase `session`, `window`, `pane` fixtures
230+
3. Never instantiate `Server()` directly in doctests
231+
4. Never use `socket_name="default"` anywhere
232+
206233
#### Parallel Test Execution
207234

208235
**Tests are safe for parallel execution** (`pytest -n auto`):
@@ -291,6 +318,8 @@ Tests run against:
291318

292319
**When writing new tests**:
293320
- Use `server` and `session` fixtures - they provide real tmux instances
321+
- **NEVER create `Server()` directly with hardcoded socket names** (use fixtures or `TestServer`)
322+
- **NEVER use `socket_name="default"` or reuse fixture sockets** (will kill user's tmux!)
294323
- Never mock tmux - use `retry_until()` for async operations instead
295324
- Use `temp_session()` / `temp_window()` context managers for temporary objects
296325
- Use `get_test_session_name()` / `get_test_window_name()` for unique names

0 commit comments

Comments
 (0)