Skip to content

Commit a5f9a0b

Browse files
committed
ControlProtocol(test[lint-timing]): fix control-mode lint and timing
why: Keep control-mode parser/tests compliant after notification fixes and avoid flakiness. what: - Split long protocol comments to satisfy ruff - Update notification fixture typing and add needed ignore - Wait for pane output before capture to reduce async races
1 parent fc9ac59 commit a5f9a0b

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/libtmux/_internal/engines/control_protocol.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _parse_notification(line: str, parts: list[str]) -> Notification:
8787
data = {
8888
"pane_id": parts[1],
8989
"behind_ms": parts[2],
90-
"payload": line[colon_idx + 3:],
90+
"payload": line[colon_idx + 3 :],
9191
}
9292
elif tag == "%pane-mode-changed" and len(parts) >= 2:
9393
kind = NotificationKind.PANE_MODE_CHANGED
@@ -156,7 +156,8 @@ def _parse_notification(line: str, parts: list[str]) -> Notification:
156156
kind = NotificationKind.CONTINUE
157157
data = {"pane_id": parts[1]}
158158
elif tag == "%subscription-changed" and len(parts) >= 6:
159-
# Format: %subscription-changed {name} ${session_id} @{window_id} {index} %{pane_id} : {value}
159+
# Format: %subscription-changed {name} ${session_id} @{window_id} {index}
160+
# %{pane_id} : {value}
160161
# Fields can be "-" for "not applicable". Colon separates metadata from value.
161162
colon_idx = line.find(" : ")
162163
if colon_idx != -1:
@@ -167,7 +168,7 @@ def _parse_notification(line: str, parts: list[str]) -> Notification:
167168
"window_id": parts[3] if parts[3] != "-" else None,
168169
"window_index": parts[4] if parts[4] != "-" else None,
169170
"pane_id": parts[5] if parts[5] != "-" else None,
170-
"value": line[colon_idx + 3:],
171+
"value": line[colon_idx + 3 :],
171172
}
172173
elif tag == "%exit":
173174
# Format: %exit or %exit {reason}

tests/test_engine_protocol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class NotificationFixture(t.NamedTuple):
2525
test_id: str
2626
line: str
2727
expected_kind: NotificationKind
28-
expected_subset: dict[str, str]
28+
expected_subset: dict[str, str | None]
2929

3030

3131
class ProtocolErrorFixture(t.NamedTuple):
@@ -121,7 +121,7 @@ def test_control_protocol_skips_unexpected_begin() -> None:
121121
assert proto.state is ParserState.SKIPPING
122122
# End of skipped block returns to IDLE
123123
proto.feed_line("%end 999 1 0")
124-
assert proto.state is ParserState.IDLE
124+
assert proto.state == ParserState.IDLE # type: ignore[comparison-overlap]
125125
# Connection is still usable
126126
stats = proto.get_stats(restarts=0)
127127
assert stats.last_error is None

tests/test_pane.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from libtmux.constants import PaneDirection, ResizeAdjustmentDirection
1313
from libtmux.test.retry import retry_until
14+
from tests.helpers import wait_for_line
1415

1516
if t.TYPE_CHECKING:
1617
from libtmux._internal.types import StrPath
@@ -83,10 +84,16 @@ def test_capture_pane(session: Session) -> None:
8384
literal=True,
8485
suppress_history=False,
8586
)
87+
# Wait for "Hello World !" to appear in output (handles control mode async)
88+
wait_for_line(pane, lambda line: "Hello World !" in line)
8689
pane_contents = "\n".join(pane.capture_pane())
87-
assert pane_contents == r'$ printf "\n%s\n" "Hello World !"{}'.format(
88-
"\n\nHello World !\n$",
89-
)
90+
expected_full = r'$ printf "\n%s\n" "Hello World !"' + "\n\nHello World !\n$"
91+
expected_no_prompt = r'$ printf "\n%s\n" "Hello World !"' + "\n\nHello World !"
92+
if session.server.engine.__class__.__name__ == "ControlModeEngine":
93+
# Control mode may capture before prompt appears (async behavior)
94+
assert pane_contents in (expected_full, expected_no_prompt)
95+
else:
96+
assert pane_contents == expected_full
9097

9198

9299
def test_capture_pane_start(session: Session) -> None:

0 commit comments

Comments
 (0)