@@ -79,3 +79,115 @@ async def test_prompt_command(local_runtime: LocalSandboxRuntime):
7979 with_prompt_command = await local_runtime .run_in_session (BashAction (command = "echo hello" , action_type = "bash" ))
8080 assert with_prompt_command .output .__contains__ ("ROCK" )
8181 await local_runtime .close_session (CloseBashSessionRequest (session_type = "bash" ))
82+
83+
84+ # ========== Terminal Settings Tests ==========
85+
86+
87+ @pytest .mark .asyncio
88+ async def test_default_terminal_settings (local_runtime : LocalSandboxRuntime ):
89+ """Test that default terminal settings are applied correctly."""
90+ import uuid
91+ session_name = f"term_default_{ uuid .uuid4 ().hex [:8 ]} "
92+ await local_runtime .create_session (
93+ CreateBashSessionRequest (session_type = "bash" , session = session_name , startup_timeout = 5.0 )
94+ )
95+
96+ # Check TERM (default is dumb)
97+ obs = await local_runtime .run_in_session (
98+ BashAction (command = "echo $TERM" , action_type = "bash" , session = session_name , timeout = 10 )
99+ )
100+ assert "dumb" in obs .output
101+
102+ # Check LANG
103+ obs = await local_runtime .run_in_session (
104+ BashAction (command = "echo $LANG" , action_type = "bash" , session = session_name , timeout = 10 )
105+ )
106+ assert "en_US.UTF-8" in obs .output
107+
108+ await local_runtime .close_session (CloseBashSessionRequest (session_type = "bash" , session = session_name ))
109+
110+
111+ @pytest .mark .asyncio
112+ async def test_custom_terminal_settings (local_runtime : LocalSandboxRuntime ):
113+ """Test that custom terminal settings are applied correctly."""
114+ import uuid
115+ session_name = f"term_custom_{ uuid .uuid4 ().hex [:8 ]} "
116+ await local_runtime .create_session (
117+ CreateBashSessionRequest (
118+ session_type = "bash" ,
119+ session = session_name ,
120+ startup_timeout = 5.0 ,
121+ term = "screen" ,
122+ columns = 120 ,
123+ lines = 40 ,
124+ lang = "zh_CN.UTF-8" ,
125+ )
126+ )
127+
128+ # Check TERM
129+ obs = await local_runtime .run_in_session (
130+ BashAction (command = "echo $TERM" , action_type = "bash" , session = session_name , timeout = 10 )
131+ )
132+ assert "screen" in obs .output
133+
134+ # Check LANG
135+ obs = await local_runtime .run_in_session (
136+ BashAction (command = "echo $LANG" , action_type = "bash" , session = session_name , timeout = 10 )
137+ )
138+ assert "zh_CN.UTF-8" in obs .output
139+
140+ await local_runtime .close_session (CloseBashSessionRequest (session_type = "bash" , session = session_name ))
141+
142+
143+ @pytest .mark .asyncio
144+ async def test_terminal_size_stty (local_runtime : LocalSandboxRuntime ):
145+ """Test that terminal size is correctly set via stty size."""
146+ import uuid
147+ session_name = f"term_stty_{ uuid .uuid4 ().hex [:8 ]} "
148+ await local_runtime .create_session (
149+ CreateBashSessionRequest (
150+ session_type = "bash" ,
151+ session = session_name ,
152+ startup_timeout = 5.0 ,
153+ columns = 100 ,
154+ lines = 30 ,
155+ )
156+ )
157+
158+ # stty size outputs "lines columns"
159+ obs = await local_runtime .run_in_session (
160+ BashAction (command = "stty size" , action_type = "bash" , session = session_name , timeout = 10 )
161+ )
162+ assert "30 100" in obs .output
163+
164+ await local_runtime .close_session (CloseBashSessionRequest (session_type = "bash" , session = session_name ))
165+
166+
167+ @pytest .mark .asyncio
168+ async def test_env_overrides_terminal_params (local_runtime : LocalSandboxRuntime ):
169+ """Test that env parameter takes priority over terminal params."""
170+ import uuid
171+ session_name = f"term_override_{ uuid .uuid4 ().hex [:8 ]} "
172+ await local_runtime .create_session (
173+ CreateBashSessionRequest (
174+ session_type = "bash" ,
175+ session = session_name ,
176+ startup_timeout = 5.0 ,
177+ term = "xterm" ,
178+ env = {"TERM" : "vt100" , "LANG" : "C" },
179+ )
180+ )
181+
182+ # env should override term param
183+ obs = await local_runtime .run_in_session (
184+ BashAction (command = "echo $TERM" , action_type = "bash" , session = session_name , timeout = 10 )
185+ )
186+ assert "vt100" in obs .output
187+
188+ obs = await local_runtime .run_in_session (
189+ BashAction (command = "echo $LANG" , action_type = "bash" , session = session_name , timeout = 10 )
190+ )
191+ assert "C" in obs .output
192+
193+ await local_runtime .close_session (CloseBashSessionRequest (session_type = "bash" , session = session_name ))
0 commit comments