Skip to content

Commit 5770fdb

Browse files
committed
mcp(test[server]): cover _format_handles_section empty-visibility branch
``_format_handles_section`` has two output branches: with hints (``"... prefer (e.g. ...)."``) and without (``"... prefer."``). The no-hints branch fires when ``visible_tool_names`` is non-None but no hint tool is in it. With every current hint tool tagged ``TAG_READONLY`` this branch is unreachable by the existing tool set — even ``LIBTMUX_SAFETY=readonly`` keeps ``snapshot_pane`` / ``wait_for_text`` / ``search_panes`` visible. Codecov flagged it as uncovered, and the upcoming Phase 5 (``LIBTMUX_TOOLSETS``) makes it reachable: a user setting ``LIBTMUX_TOOLSETS=server,session`` would hide every pane tool, leaving ``visible_tool_names`` disjoint from every ``_HANDLE_HINTS`` key. Pin the branch's output now so a regression that emits broken syntax (trailing ", ).", duplicate periods, etc.) fails loudly. Pure addition; no source changes. Pulls the empty-set branch from 0% to 100% coverage.
1 parent de39b7a commit 5770fdb

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

tests/test_server.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,42 @@ def test_handle_hints_keys_are_registered_tools() -> None:
311311
)
312312

313313

314+
def test_format_handles_section_empty_visible_set_emits_no_examples() -> None:
315+
"""``_format_handles_section`` renders a bare Tools handle when no hint matches.
316+
317+
With every current hint tool tagged ``TAG_READONLY`` this branch is
318+
unreachable by the existing tool set — even ``LIBTMUX_SAFETY=readonly``
319+
keeps ``snapshot_pane`` / ``wait_for_text`` / ``search_panes`` visible.
320+
But a future hint tagged mutating/destructive-only would land here under
321+
a readonly safety tier, and so would a future ``LIBTMUX_TOOLSETS`` filter
322+
that hides every pane tool. Pin the branch behavior now so a regression
323+
that emits broken syntax (e.g. trailing ", )." from a half-formatted
324+
hint list, or duplicate periods) fails loudly.
325+
"""
326+
from libtmux_mcp.server import _format_handles_section
327+
328+
result = _format_handles_section(set())
329+
330+
# No hint phrases emitted — no "e.g." preamble, no individual hint
331+
# tool names mentioned in the Tools-line.
332+
assert "e.g." not in result
333+
for tool_name, _ in _VISIBILITY_FILTER_CASES:
334+
assert tool_name not in result, (
335+
f"hint tool name {tool_name!r} leaked into card with empty visible set"
336+
)
337+
338+
# Tools-line still present and well-formed (ends with a single period,
339+
# no dangling comma or open paren).
340+
expected_tools_line = (
341+
"- Tools — call list_tools; per-tool descriptions tell you which to prefer."
342+
)
343+
assert expected_tools_line in result
344+
345+
# The other two handles are unaffected — they don't depend on visibility.
346+
assert "- Resources (tmux://)" in result
347+
assert "- Prompts — packaged workflows" in result
348+
349+
314350
def test_registered_tools_accept_socket_name() -> None:
315351
"""All registered tools (except list_servers) accept ``socket_name``.
316352

0 commit comments

Comments
 (0)