@@ -1330,7 +1330,7 @@ async fn test_read_file_lines_normal() {
13301330 . read_file_lines ( & file_path, 1 , Some ( 2 ) )
13311331 . await
13321332 . unwrap ( ) ;
1333- assert_eq ! ( result, vec! [ "line2" , "line3" ] ) ;
1333+ assert_eq ! ( result, "line2\n line3 \n " ) ; // No trailing newline
13341334}
13351335
13361336#[ tokio:: test]
@@ -1342,7 +1342,7 @@ async fn test_read_file_lines_empty_file() {
13421342 . read_file_lines ( & file_path, 0 , Some ( 5 ) )
13431343 . await
13441344 . unwrap ( ) ;
1345- assert_eq ! ( result, Vec :: < String > :: new ( ) ) ;
1345+ assert_eq ! ( result, "" ) ;
13461346}
13471347
13481348#[ tokio:: test]
@@ -1354,7 +1354,7 @@ async fn test_read_file_lines_offset_beyond_file() {
13541354 . read_file_lines ( & file_path, 5 , Some ( 3 ) )
13551355 . await
13561356 . unwrap ( ) ;
1357- assert_eq ! ( result, Vec :: < String > :: new ( ) ) ;
1357+ assert_eq ! ( result, "" ) ;
13581358}
13591359
13601360#[ tokio:: test]
@@ -1368,7 +1368,7 @@ async fn test_read_file_lines_no_limit() {
13681368 . await ;
13691369
13701370 let result = service. read_file_lines ( & file_path, 2 , None ) . await . unwrap ( ) ;
1371- assert_eq ! ( result, vec! [ "line3" , "line4" ] ) ;
1371+ assert_eq ! ( result, "line3\n line4" ) ; // No trailing newline
13721372}
13731373
13741374#[ tokio:: test]
@@ -1381,29 +1381,65 @@ async fn test_read_file_lines_limit_zero() {
13811381 . read_file_lines ( & file_path, 1 , Some ( 0 ) )
13821382 . await
13831383 . unwrap ( ) ;
1384- assert_eq ! ( result, Vec :: < String > :: new ( ) ) ;
1384+ assert_eq ! ( result, "" ) ;
13851385}
13861386
13871387#[ tokio:: test]
1388- async fn test_read_file_lines_invalid_path ( ) {
1388+ async fn test_read_file_lines_exact_file_length ( ) {
13891389 let ( temp_dir, service, _allowed_dirs) = setup_service ( vec ! [ "dir1" . to_string( ) ] ) ;
1390- let invalid_path = temp_dir. join ( "dir2/test.txt" ) ; // Outside allowed_dirs
1390+ let file_path =
1391+ create_test_file ( & temp_dir, "dir1/test.txt" , vec ! [ "line1" , "line2" , "line3" ] ) . await ;
13911392
1392- let result = service. read_file_lines ( & invalid_path, 0 , Some ( 3 ) ) . await ;
1393- assert ! ( result. is_err( ) , "Expected error for invalid path" ) ;
1393+ let result = service
1394+ . read_file_lines ( & file_path, 0 , Some ( 3 ) )
1395+ . await
1396+ . unwrap ( ) ;
1397+ assert_eq ! ( result, "line1\n line2\n line3" ) ; // No trailing newline
13941398}
13951399
13961400#[ tokio:: test]
1397- async fn test_read_file_lines_exact_file_length ( ) {
1401+ async fn test_read_file_lines_no_newline_at_end ( ) {
1402+ let ( temp_dir, service, _allowed_dirs) = setup_service ( vec ! [ "dir1" . to_string( ) ] ) ;
1403+ let file_path = create_temp_file (
1404+ & temp_dir. join ( "dir1" ) ,
1405+ "test.txt" ,
1406+ "line1\n line2\n line3" , // No newline at end
1407+ ) ;
1408+
1409+ let result = service
1410+ . read_file_lines ( & file_path, 1 , Some ( 2 ) )
1411+ . await
1412+ . unwrap ( ) ;
1413+ assert_eq ! ( result, "line2\n line3" ) ; // No trailing newline
1414+ }
1415+
1416+ #[ tokio:: test]
1417+ async fn test_read_file_lines_windows_line_endings ( ) {
13981418 let ( temp_dir, service, _allowed_dirs) = setup_service ( vec ! [ "dir1" . to_string( ) ] ) ;
13991419 let file_path =
14001420 create_test_file ( & temp_dir, "dir1/test.txt" , vec ! [ "line1" , "line2" , "line3" ] ) . await ;
14011421
1422+ // Override to use \r\n explicitly
1423+ let file_path = create_temp_file (
1424+ & temp_dir. join ( "dir1" ) ,
1425+ "test.txt" ,
1426+ "line1\r \n line2\r \n line3" ,
1427+ ) ;
1428+
14021429 let result = service
1403- . read_file_lines ( & file_path, 0 , Some ( 3 ) )
1430+ . read_file_lines ( & file_path, 1 , Some ( 2 ) )
14041431 . await
14051432 . unwrap ( ) ;
1406- assert_eq ! ( result, vec![ "line1" , "line2" , "line3" ] ) ;
1433+ assert_eq ! ( result, "line2\r \n line3" ) ; // No trailing newline
1434+ }
1435+
1436+ #[ tokio:: test]
1437+ async fn test_read_file_lines_invalid_path ( ) {
1438+ let ( temp_dir, service, _allowed_dirs) = setup_service ( vec ! [ "dir1" . to_string( ) ] ) ;
1439+ let invalid_path = temp_dir. join ( "dir2/test.txt" ) ; // Outside allowed_dirs
1440+
1441+ let result = service. read_file_lines ( & invalid_path, 0 , Some ( 3 ) ) . await ;
1442+ assert ! ( result. is_err( ) , "Expected error for invalid path" ) ;
14071443}
14081444
14091445#[ test]
0 commit comments