Skip to content

Commit e29d4b6

Browse files
committed
fix(tests): use echo marker instead of prompt detection in waiter test
why: Test was unreliable because shell prompts vary by environment what: - Replace prompt detection ($, %, >, #) with echo marker pattern - Remove skip decorator - test now runs reliably - Simplify test logic by using deterministic output
1 parent dc1341c commit e29d4b6

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

tests/examples/_internal/waiter/test_wait_until_ready.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
import contextlib
6-
import re
75
from typing import TYPE_CHECKING
86

97
import pytest
@@ -15,43 +13,30 @@
1513

1614

1715
@pytest.mark.example
18-
@pytest.mark.skip(reason="Test is unreliable in CI environment due to timing issues")
1916
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+
"""
2123
window = session.new_window(window_name="test_shell_ready")
2224
pane = window.active_pane
2325
assert pane is not None
2426

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}'")
3431

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
3833
result = wait_until_pane_ready(
3934
pane,
40-
shell_prompt="$",
41-
timeout=10, # Increased timeout
35+
shell_prompt=marker,
36+
match_type=ContentMatchType.CONTAINS,
37+
timeout=10,
4238
)
4339

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}"
5441

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

Comments
 (0)