Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
tests(refactor[plugin_system]) Use Pane.display_message wrapper
why: Six tests in the plugin-system suite were querying tmux for
session/window names via the same `session.cmd("display-message",
"-p", "'#S'")` escape hatch that production just migrated away
from in `cli/load.py:_reattach`. Keeping the tests on the typed
wrapper that production now uses keeps the call shape consistent
across the codebase and removes the last `cmd("display-message",
...)` site from the repo.

what:
- `tests/cli/test_cli.py::test_reattach_plugins`: replace the
  `cmd()` call with `active_pane.display_message("'#S'",
  get_text=True)` so the post-reattach assertion uses the typed
  wrapper.
- `tests/workspace/test_builder.py`: migrate four
  `test_plugin_system_*` checks (`before_workspace_builder`,
  `on_window_create`, `after_window_finished`, and the
  multi-window variant covering both `before_script` and
  `after_window_finished`) onto `active_pane.display_message()`.
  The multi-window variant hoists the active_pane lookup once and
  reuses it for both the `'#S'` and `'#W'` queries.
- Each call site adds a narrowing assert on `active_pane`
  (libtmux types it as `Pane | None`) so mypy can prove the call
  is well-typed. Mirrors the production assert added in
  `_reattach()`.

No behavior change: tmux's `display-message` defaults to the
session's active pane when no `-t` is passed, so the underlying
tmux invocations are byte-for-byte identical to the prior
`session.cmd(...)` calls.
  • Loading branch information
tony committed May 10, 2026
commit 46b52f1673025ec660851417d2505767047bb4b1
6 changes: 4 additions & 2 deletions tests/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ def test_reattach_plugins(
_reattach(builder)

assert builder.session is not None
proc = builder.session.cmd("display-message", "-p", "'#S'")
active_pane = builder.session.active_pane
assert active_pane is not None
lines = active_pane.display_message("'#S'", get_text=True)

assert proc.stdout[0] == "'plugin_test_r'"
assert lines[0] == "'plugin_test_r'"
29 changes: 19 additions & 10 deletions tests/workspace/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,8 +824,10 @@ def test_plugin_system_before_workspace_builder(

builder.build(session=session)

proc = session.cmd("display-message", "-p", "'#S'")
assert proc.stdout[0] == "'plugin_test_bwb'"
active_pane = session.active_pane
assert active_pane is not None
lines = active_pane.display_message("'#S'", get_text=True)
assert lines[0] == "'plugin_test_bwb'"


def test_plugin_system_on_window_create(
Expand All @@ -847,8 +849,10 @@ def test_plugin_system_on_window_create(

builder.build(session=session)

proc = session.cmd("display-message", "-p", "'#W'")
assert proc.stdout[0] == "'plugin_test_owc'"
active_pane = session.active_pane
assert active_pane is not None
lines = active_pane.display_message("'#W'", get_text=True)
assert lines[0] == "'plugin_test_owc'"


def test_plugin_system_after_window_finished(
Expand All @@ -870,8 +874,10 @@ def test_plugin_system_after_window_finished(

builder.build(session=session)

proc = session.cmd("display-message", "-p", "'#W'")
assert proc.stdout[0] == "'plugin_test_awf'"
active_pane = session.active_pane
assert active_pane is not None
lines = active_pane.display_message("'#W'", get_text=True)
assert lines[0] == "'plugin_test_awf'"


def test_plugin_system_on_window_create_multiple_windows(
Expand Down Expand Up @@ -946,15 +952,18 @@ def test_plugin_system_multiple_plugins(

builder.build(session=session)

active_pane = session.active_pane
assert active_pane is not None

# Drop through to the before_script plugin hook
proc = session.cmd("display-message", "-p", "'#S'")
assert proc.stdout[0] == "'plugin_test_bwb'"
lines = active_pane.display_message("'#S'", get_text=True)
assert lines[0] == "'plugin_test_bwb'"

# Drop through to the after_window_finished. This won't succeed
# unless on_window_create succeeds because of how the test plugin
# override methods are currently written
proc = session.cmd("display-message", "-p", "'#W'")
assert proc.stdout[0] == "'mp_test_awf'"
lines = active_pane.display_message("'#W'", get_text=True)
assert lines[0] == "'mp_test_awf'"


def test_load_configs_same_session(
Expand Down