Skip to content

Commit 1294594

Browse files
committed
test(tools): Use a named buffer sentinel for paste_text isolation test
why: CI on tmux 3.2a failed the paste_text buffer-isolation test — `show-buffer` without `-b` returned an empty stdout after paste_text completed. The behavior of tmux's "default" (unnamed) buffer varies across releases: some versions treat it as "the most recently written buffer" (so a named buffer that was created and deleted during paste_text can leave the default pointing at nothing on older tmux). The original test assumed the sentinel set via `set-buffer <value>` would always be the default after paste_text finished — that assumption doesn't hold portably. what: - Write the sentinel into an explicit named buffer with `set-buffer -b mcp_test_user_buffer <value>` and read it back with `show-buffer -b mcp_test_user_buffer`. Named-buffer targeting has been stable in tmux since 1.5 and works identically across every release in the CI matrix. - Clean up the sentinel named buffer at the end of the test so it doesn't linger across parallel test workers. - Add `import contextlib` at module top (stdlib, namespace style per AGENTS.md). The core claim — that paste_text does not disturb user buffer state — remains tested, now in a portable form. The separate check for "no mcp_paste_* leakage" in list-buffers is unchanged.
1 parent 252f6c1 commit 1294594

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

tests/test_pane_tools.py

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

33
from __future__ import annotations
44

5+
import contextlib
56
import typing as t
67

78
import pytest
@@ -978,27 +979,39 @@ def test_paste_text(mcp_server: Server, mcp_pane: Pane) -> None:
978979
def test_paste_text_does_not_clobber_unnamed_buffer(
979980
mcp_server: Server, mcp_pane: Pane
980981
) -> None:
981-
"""paste_text must not overwrite the user's unnamed tmux paste buffer.
982+
"""paste_text must not disturb a user-owned tmux paste buffer.
982983
983984
Regression guard for the pre-fix behavior: load-buffer without -b
984985
writes into tmux's default unnamed buffer, clobbering whatever the
985-
user had there. The fix uses a unique named buffer per call.
986+
user had there. The fix uses a unique named buffer per call so the
987+
operation is isolated from any buffer the user has set up.
988+
989+
Uses an explicit named buffer as the sentinel because
990+
`show-buffer` semantics for the default (unnamed) buffer vary
991+
across tmux versions — targeting a named buffer is portable all
992+
the way back to tmux 1.5.
986993
"""
987-
sentinel = "USER_UNNAMED_BUFFER_SENTINEL_777"
988-
mcp_server.cmd("set-buffer", sentinel)
994+
sentinel_name = "mcp_test_user_buffer"
995+
sentinel_value = "USER_BUFFER_SENTINEL_777"
996+
mcp_server.cmd("set-buffer", "-b", sentinel_name, sentinel_value)
989997

990998
paste_text(
991999
text="echo BUFFER_ISOLATION_test",
9921000
pane_id=mcp_pane.pane_id,
9931001
socket_name=mcp_server.socket_name,
9941002
)
9951003

996-
# The user's unnamed buffer should still contain the sentinel.
997-
result = mcp_server.cmd("show-buffer")
998-
assert result.stdout and sentinel in "\n".join(result.stdout), (
999-
"paste_text clobbered the user's unnamed paste buffer"
1004+
# The user's named buffer must still hold the sentinel unchanged.
1005+
result = mcp_server.cmd("show-buffer", "-b", sentinel_name)
1006+
assert result.stdout and sentinel_value in "\n".join(result.stdout), (
1007+
f"paste_text disturbed the user's named buffer {sentinel_name!r}; "
1008+
f"show-buffer returned {result.stdout!r}"
10001009
)
10011010

1011+
# Clean up the sentinel.
1012+
with contextlib.suppress(Exception):
1013+
mcp_server.cmd("delete-buffer", "-b", sentinel_name)
1014+
10021015
# And no mcp_paste_* named buffer should linger on the server.
10031016
listing = mcp_server.cmd("list-buffers", "-F", "#{buffer_name}")
10041017
buffer_names = "\n".join(listing.stdout or [])

0 commit comments

Comments
 (0)