@@ -900,3 +900,69 @@ def test_set_hook_flag_combinations(
900900 session .unset_hook (hook_name )
901901 if test_case .flag_kwargs .get ("global_" ):
902902 server .cmd ("set-hook" , "-gu" , hook_name )
903+
904+
905+ # =============================================================================
906+ # Hook Scope Tests
907+ # =============================================================================
908+
909+
910+ class HookScopeTestCase (t .NamedTuple ):
911+ """Test case for hook scope handling."""
912+
913+ test_id : str
914+ scope : str # "session", "window", "pane"
915+ scope_flag : str # tmux flag for show-hooks
916+ min_version : str = "3.2"
917+
918+
919+ HOOK_SCOPE_TEST_CASES : list [HookScopeTestCase ] = [
920+ HookScopeTestCase ("session_scope" , "session" , "" ),
921+ HookScopeTestCase ("window_scope" , "window" , "-w" , "3.2" ),
922+ HookScopeTestCase ("pane_scope" , "pane" , "-p" , "3.2" ),
923+ ]
924+
925+
926+ @pytest .mark .parametrize (
927+ "test_case" ,
928+ [pytest .param (tc , id = tc .test_id ) for tc in HOOK_SCOPE_TEST_CASES ],
929+ )
930+ def test_hook_scope_handling (
931+ server : Server ,
932+ test_case : HookScopeTestCase ,
933+ ) -> None :
934+ """Test hooks at different scopes (session, window, pane)."""
935+ if not has_gte_version (test_case .min_version ):
936+ pytest .skip (f"Requires tmux { test_case .min_version } +" )
937+
938+ session = server .new_session (session_name = "test_scope" )
939+ window = session .active_window
940+ assert window is not None
941+ pane = window .active_pane
942+ assert pane is not None
943+
944+ hook_name = "session-renamed"
945+ hook_cmd = f"display-message '{ test_case .scope } scope test'"
946+
947+ # Set hook at the appropriate scope
948+ if test_case .scope == "session" :
949+ session .set_hook (f"{ hook_name } [0]" , hook_cmd )
950+ result = session ._show_hook (f"{ hook_name } [0]" )
951+ elif test_case .scope == "window" :
952+ window .set_hook (f"{ hook_name } [0]" , hook_cmd )
953+ result = window ._show_hook (f"{ hook_name } [0]" )
954+ else : # pane
955+ pane .set_hook (f"{ hook_name } [0]" , hook_cmd )
956+ result = pane ._show_hook (f"{ hook_name } [0]" )
957+
958+ assert result is not None
959+ assert len (result ) > 0
960+ assert "display-message" in result [0 ]
961+
962+ # Cleanup
963+ if test_case .scope == "session" :
964+ session .unset_hook (hook_name )
965+ elif test_case .scope == "window" :
966+ window .unset_hook (hook_name )
967+ else :
968+ pane .unset_hook (hook_name )
0 commit comments