|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | | -import contextlib |
6 | | -import re |
7 | 5 | from typing import TYPE_CHECKING |
8 | 6 |
|
9 | 7 | import pytest |
|
15 | 13 |
|
16 | 14 |
|
17 | 15 | @pytest.mark.example |
18 | | -@pytest.mark.skip(reason="Test is unreliable in CI environment due to timing issues") |
19 | 16 | def test_wait_until_ready(session: Session) -> None: |
20 | | - """Demonstrate waiting for shell prompt.""" |
| 17 | + """Demonstrate waiting for shell readiness using a marker command. |
| 18 | +
|
| 19 | + This test shows how to reliably detect when a shell is ready by sending |
| 20 | + a known command and waiting for its output, rather than trying to detect |
| 21 | + environment-specific shell prompts. |
| 22 | + """ |
21 | 23 | window = session.new_window(window_name="test_shell_ready") |
22 | 24 | pane = window.active_pane |
23 | 25 | assert pane is not None |
24 | 26 |
|
25 | | - # Force shell prompt by sending a few commands and waiting |
26 | | - pane.send_keys("echo 'test command'") |
27 | | - pane.send_keys("ls") |
28 | | - |
29 | | - # For test purposes, look for any common shell prompt characters |
30 | | - # The wait_until_pane_ready function works either with: |
31 | | - # 1. A string to find (will use CONTAINS match_type) |
32 | | - # 2. A predicate function taking lines and returning bool |
33 | | - # (will use PREDICATE match_type) |
| 27 | + # Use a unique marker to prove shell is ready and responsive. |
| 28 | + # This is more reliable than trying to detect shell prompts (which vary) |
| 29 | + marker = "SHELL_READY_MARKER_12345" |
| 30 | + pane.send_keys(f"echo '{marker}'") |
34 | 31 |
|
35 | | - # Using a regex to match common shell prompt characters: $, %, >, # |
36 | | - |
37 | | - # Try with a simple string first |
| 32 | + # Wait for the marker - proves shell executed the command |
38 | 33 | result = wait_until_pane_ready( |
39 | 34 | pane, |
40 | | - shell_prompt="$", |
41 | | - timeout=10, # Increased timeout |
| 35 | + shell_prompt=marker, |
| 36 | + match_type=ContentMatchType.CONTAINS, |
| 37 | + timeout=10, |
42 | 38 | ) |
43 | 39 |
|
44 | | - if not result.success: |
45 | | - # Fall back to regex pattern if the specific character wasn't found |
46 | | - result = wait_until_pane_ready( |
47 | | - pane, |
48 | | - shell_prompt=re.compile(r"[$%>#]"), # Using standard prompt characters |
49 | | - match_type=ContentMatchType.REGEX, |
50 | | - timeout=10, # Increased timeout |
51 | | - ) |
52 | | - |
53 | | - assert result.success |
| 40 | + assert result.success, f"Shell did not become ready: {result.error}" |
54 | 41 |
|
55 | | - # Only kill the window if the test is still running |
56 | | - with contextlib.suppress(Exception): |
57 | | - window.kill() |
| 42 | + window.kill() |
0 commit comments