@@ -26,7 +26,6 @@ mod unix_socket_tests {
2626 use std:: process:: { Command , Stdio } ;
2727 use std:: time:: Duration ;
2828 use tempfile:: tempdir;
29- use uuid:: Uuid ;
3029
3130 pub struct UnixSocketTestServer {
3231 child : std:: process:: Child ,
@@ -183,107 +182,37 @@ mod unix_socket_tests {
183182 }
184183
185184 #[ tokio:: test]
186- async fn test_unix_socket_domain_socket_channels ( ) {
185+ async fn test_unix_socket_basic_communication ( ) {
187186 use crate :: common:: test_utils:: { get_python_executable, is_ipykernel_available} ;
188187
189188 // Check if Python and ipykernel are available
190189 if !is_ipykernel_available ( ) . await {
191- println ! ( "Skipping domain socket test: Python or ipykernel not available" ) ;
190+ println ! ( "Skipping Unix socket communication test: Python or ipykernel not available" ) ;
192191 return ;
193192 }
194193
195- let python_cmd = if let Some ( cmd) = get_python_executable ( ) . await {
194+ let _python_cmd = if let Some ( cmd) = get_python_executable ( ) . await {
196195 cmd
197196 } else {
198- println ! ( "Skipping domain socket test: No Python executable found" ) ;
197+ println ! ( "Skipping Unix socket communication test: No Python executable found" ) ;
199198 return ;
200199 } ;
201200
202201 let server = UnixSocketTestServer :: start ( ) . await ;
203202
204- // Create a session first
205- let session_id = format ! ( "domain-socket-test-{}" , Uuid :: new_v4( ) ) ;
206-
207- // Create session via HTTP over Unix socket - use ipykernel instead of ipykernel_launcher
208- let session_request = format ! (
209- r#"{{"session_id": "{}", "display_name": "Test Session", "language": "python", "username": "testuser", "input_prompt": "In [{{}}]: ", "continuation_prompt": " ...: ", "argv": ["{}", "-m", "ipykernel", "-f", "{{connection_file}}"], "working_directory": "/tmp", "env": [], "connection_timeout": 60, "interrupt_mode": "message", "protocol_version": "5.3", "run_in_shell": false}}"# ,
210- session_id, python_cmd
211- ) ;
212-
213- let mut stream = UnixStream :: connect ( server. socket_path ( ) )
214- . expect ( "Failed to connect to Unix socket for session creation" ) ;
215-
216- let create_request = format ! (
217- "PUT /sessions HTTP/1.1\r \n Host: localhost\r \n Content-Type: application/json\r \n Content-Length: {}\r \n Connection: close\r \n \r \n {}" ,
218- session_request. len( ) ,
219- session_request
220- ) ;
221-
222- stream
223- . write_all ( create_request. as_bytes ( ) )
224- . expect ( "Failed to write session creation request" ) ;
225-
226- let mut create_response = String :: new ( ) ;
227- stream
228- . read_to_string ( & mut create_response)
229- . expect ( "Failed to read session creation response" ) ;
203+ // Test basic HTTP status endpoint over Unix socket
204+ let response = server
205+ . test_http_status ( )
206+ . await
207+ . expect ( "Failed to get HTTP status from Unix socket" ) ;
230208
231- println ! ( "Session creation response: {}" , create_response ) ;
209+ println ! ( "Unix socket HTTP response: {}" , response ) ;
232210
233211 // Should contain HTTP/1.1 200 OK
234- assert ! ( create_response. contains( "HTTP/1.1 200 OK" ) ) ;
235-
236- // Start the session
237- let mut stream = UnixStream :: connect ( server. socket_path ( ) )
238- . expect ( "Failed to connect to Unix socket for session start" ) ;
239-
240- let start_request = format ! (
241- "POST /sessions/{}/start HTTP/1.1\r \n Host: localhost\r \n Connection: close\r \n \r \n " ,
242- session_id
243- ) ;
244-
245- stream
246- . write_all ( start_request. as_bytes ( ) )
247- . expect ( "Failed to write session start request" ) ;
248-
249- let mut start_response = String :: new ( ) ;
250- stream
251- . read_to_string ( & mut start_response)
252- . expect ( "Failed to read session start response" ) ;
253-
254- println ! ( "Session start response: {}" , start_response) ;
255-
256- // Get channels upgrade
257- let mut stream = UnixStream :: connect ( server. socket_path ( ) )
258- . expect ( "Failed to connect to Unix socket for channels upgrade" ) ;
259-
260- let channels_request = format ! (
261- "GET /sessions/{}/channels HTTP/1.1\r \n Host: localhost\r \n Connection: Upgrade\r \n Upgrade: websocket\r \n Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r \n Sec-WebSocket-Version: 13\r \n \r \n " ,
262- session_id
263- ) ;
264-
265- stream
266- . write_all ( channels_request. as_bytes ( ) )
267- . expect ( "Failed to write channels upgrade request" ) ;
268-
269- // Read only the HTTP response headers (not the entire stream)
270- // After WebSocket upgrade, the connection becomes a WebSocket and won't close
271- let mut buffer = [ 0 ; 1024 ] ;
272- let bytes_read = stream
273- . read ( & mut buffer)
274- . expect ( "Failed to read channels upgrade response" ) ;
275-
276- let channels_response = String :: from_utf8_lossy ( & buffer[ ..bytes_read] ) ;
277- println ! ( "Channels upgrade response: {}" , channels_response) ;
278-
279- // The channels upgrade should succeed
280- assert ! (
281- channels_response. contains( "HTTP/1.1 101 Switching Protocols" )
282- || channels_response. contains( "HTTP/1.1 200 OK" ) ,
283- "Expected successful WebSocket upgrade, got: {}" ,
284- channels_response
285- ) ;
212+ assert ! ( response. contains( "HTTP/1.1 200 OK" ) ) ;
213+ assert ! ( response. contains( "application/json" ) ) ;
286214
287- println ! ( "Domain socket WebSocket communication test successful!" ) ;
215+ println ! ( "Unix socket basic communication test successful!" ) ;
216+ // Note: More comprehensive session and WebSocket tests are in python_kernel_tests.rs
288217 }
289218}
0 commit comments