@@ -51,3 +51,115 @@ def test_lifecycle_info_logging_schema(
5151 )
5252
5353 window .kill ()
54+
55+
56+ def test_server_new_session_info_logging (
57+ server : Server ,
58+ caplog : pytest .LogCaptureFixture ,
59+ ) -> None :
60+ """Test that server.new_session() produces INFO record with str-typed extra."""
61+ with caplog .at_level (logging .INFO , logger = "libtmux.server" ):
62+ new_session = server .new_session (session_name = "log_test_session" )
63+
64+ records = [
65+ r
66+ for r in caplog .records
67+ if hasattr (r , "tmux_subcommand" )
68+ and r .levelno == logging .INFO
69+ and getattr (r , "tmux_subcommand" , None ) == "new-session"
70+ ]
71+ assert len (records ) >= 1 , "expected INFO record for session creation"
72+
73+ rec = t .cast (t .Any , records [0 ])
74+ assert isinstance (rec .tmux_subcommand , str )
75+ assert isinstance (rec .tmux_session , str )
76+
77+ new_session .kill ()
78+
79+
80+ def test_window_rename_info_logging (
81+ session : Session ,
82+ caplog : pytest .LogCaptureFixture ,
83+ ) -> None :
84+ """Test that window.rename_window() produces INFO record with str-typed extra."""
85+ window = session .active_window
86+ assert window is not None
87+ with caplog .at_level (logging .INFO , logger = "libtmux.window" ):
88+ window .rename_window ("log_renamed" )
89+
90+ records = [
91+ r
92+ for r in caplog .records
93+ if hasattr (r , "tmux_subcommand" )
94+ and r .levelno == logging .INFO
95+ and getattr (r , "tmux_subcommand" , None ) == "rename-window"
96+ ]
97+ assert len (records ) >= 1 , "expected INFO record for window rename"
98+
99+ rec = t .cast (t .Any , records [0 ])
100+ assert isinstance (rec .tmux_subcommand , str )
101+ for key in ("tmux_window" , "tmux_target" ):
102+ val = getattr (rec , key , None )
103+ if val is not None :
104+ assert isinstance (val , str ), (
105+ f"extra key { key !r} should be str, got { type (val ).__name__ } "
106+ )
107+
108+
109+ def test_pane_split_info_logging (
110+ session : Session ,
111+ caplog : pytest .LogCaptureFixture ,
112+ ) -> None :
113+ """Test that pane.split() produces INFO record with str-typed extra."""
114+ window = session .active_window
115+ assert window is not None
116+ pane = window .active_pane
117+ assert pane is not None
118+ with caplog .at_level (logging .INFO , logger = "libtmux.pane" ):
119+ new_pane = pane .split ()
120+
121+ records = [
122+ r
123+ for r in caplog .records
124+ if hasattr (r , "tmux_subcommand" )
125+ and r .levelno == logging .INFO
126+ and getattr (r , "tmux_subcommand" , None ) == "split-window"
127+ ]
128+ assert len (records ) >= 1 , "expected INFO record for pane split"
129+
130+ rec = t .cast (t .Any , records [0 ])
131+ assert isinstance (rec .tmux_subcommand , str )
132+ assert isinstance (rec .tmux_pane , str )
133+ for key in ("tmux_session" , "tmux_window" ):
134+ val = getattr (rec , key , None )
135+ if val is not None :
136+ assert isinstance (val , str ), (
137+ f"extra key { key !r} should be str, got { type (val ).__name__ } "
138+ )
139+
140+ new_pane .kill ()
141+
142+
143+ def test_options_warning_logging_schema (
144+ caplog : pytest .LogCaptureFixture ,
145+ ) -> None :
146+ """Test that options parse warnings produce records with tmux_option_key."""
147+ from libtmux ._internal .sparse_array import SparseArray
148+ from libtmux .options import explode_complex
149+
150+ # A terminal-features value without ":" triggers a split failure and WARNING
151+ bad_features : SparseArray [str | int | bool | None ] = SparseArray ()
152+ bad_features [0 ] = 42 # int, not str — causes .split() to fail
153+
154+ with caplog .at_level (logging .WARNING , logger = "libtmux.options" ):
155+ explode_complex ({"terminal-features" : bad_features }) # type: ignore[dict-item]
156+
157+ records = [
158+ r
159+ for r in caplog .records
160+ if hasattr (r , "tmux_option_key" ) and r .levelno == logging .WARNING
161+ ]
162+ assert len (records ) >= 1 , "expected WARNING record for option parse failure"
163+
164+ rec = t .cast (t .Any , records [0 ])
165+ assert isinstance (rec .tmux_option_key , str )
0 commit comments