@@ -354,148 +354,155 @@ impl FileLineTracker {
354354#[ cfg( test) ]
355355mod tests {
356356 use super :: * ;
357- use crate :: agent:: util:: test:: TestDir ;
358- use crate :: util:: test:: TestProvider ;
357+ use crate :: util:: test:: TestBase ;
359358
360359 #[ tokio:: test]
361360 async fn test_create_file ( ) {
362- let test_provider = TestProvider :: new ( ) ;
363- let test_dir = TestDir :: new ( ) ;
361+ let test_base = TestBase :: new ( ) . await ;
364362 let tool = FsWrite :: Create ( FileCreate {
365- path : test_dir . join ( "new.txt" ) . to_string_lossy ( ) . to_string ( ) ,
363+ path : test_base . join ( "new.txt" ) . to_string_lossy ( ) . to_string ( ) ,
366364 content : "hello world" . to_string ( ) ,
367365 } ) ;
368366
369- assert ! ( tool. validate( & test_provider ) . await . is_ok( ) ) ;
370- assert ! ( tool. execute( None , & test_provider ) . await . is_ok( ) ) ;
367+ assert ! ( tool. validate( & test_base ) . await . is_ok( ) ) ;
368+ assert ! ( tool. execute( None , & test_base ) . await . is_ok( ) ) ;
371369
372- let content = tokio:: fs:: read_to_string ( test_dir . join ( "new.txt" ) ) . await . unwrap ( ) ;
370+ let content = tokio:: fs:: read_to_string ( test_base . join ( "new.txt" ) ) . await . unwrap ( ) ;
373371 assert_eq ! ( content, "hello world" ) ;
374372 }
375373
376374 #[ tokio:: test]
377375 async fn test_create_file_with_parent_dirs ( ) {
378- let test_provider = TestProvider :: new ( ) ;
379- let test_dir = TestDir :: new ( ) ;
376+ let test_base = TestBase :: new ( ) . await ;
380377 let tool = FsWrite :: Create ( FileCreate {
381- path : test_dir . join ( "nested/dir/file.txt" ) . to_string_lossy ( ) . to_string ( ) ,
378+ path : test_base . join ( "nested/dir/file.txt" ) . to_string_lossy ( ) . to_string ( ) ,
382379 content : "nested content" . to_string ( ) ,
383380 } ) ;
384381
385- assert ! ( tool. execute( None , & test_provider ) . await . is_ok( ) ) ;
382+ assert ! ( tool. execute( None , & test_base ) . await . is_ok( ) ) ;
386383
387- let content = tokio:: fs:: read_to_string ( test_dir . join ( "nested/dir/file.txt" ) )
384+ let content = tokio:: fs:: read_to_string ( test_base . join ( "nested/dir/file.txt" ) )
388385 . await
389386 . unwrap ( ) ;
390387 assert_eq ! ( content, "nested content" ) ;
391388 }
392389
393390 #[ tokio:: test]
394391 async fn test_str_replace_single_occurrence ( ) {
395- let test_provider = TestProvider :: new ( ) ;
396- let test_dir = TestDir :: new ( ) . with_file_sys ( ( "test.txt" , "hello world" ) , & test_provider) . await ;
392+ let test_base = TestBase :: new ( )
393+ . await
394+ . with_file ( ( "test.txt" , "hello world" ) )
395+ . await ;
397396
398397 let tool = FsWrite :: StrReplace ( StrReplace {
399- path : test_dir . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
398+ path : test_base . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
400399 old_str : "world" . to_string ( ) ,
401400 new_str : "rust" . to_string ( ) ,
402401 replace_all : false ,
403402 } ) ;
404403
405- assert ! ( tool. execute( None , & test_provider ) . await . is_ok( ) ) ;
404+ assert ! ( tool. execute( None , & test_base ) . await . is_ok( ) ) ;
406405
407- let content = tokio:: fs:: read_to_string ( test_dir . join ( "test.txt" ) ) . await . unwrap ( ) ;
406+ let content = tokio:: fs:: read_to_string ( test_base . join ( "test.txt" ) ) . await . unwrap ( ) ;
408407 assert_eq ! ( content, "hello rust" ) ;
409408 }
410409
411410 #[ tokio:: test]
412411 async fn test_str_replace_multiple_occurrences ( ) {
413- let test_provider = TestProvider :: new ( ) ;
414- let test_dir = TestDir :: new ( ) . with_file_sys ( ( "test.txt" , "foo bar foo" ) , & test_provider) . await ;
412+ let test_base = TestBase :: new ( )
413+ . await
414+ . with_file ( ( "test.txt" , "foo bar foo" ) )
415+ . await ;
415416
416417 let tool = FsWrite :: StrReplace ( StrReplace {
417- path : test_dir . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
418+ path : test_base . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
418419 old_str : "foo" . to_string ( ) ,
419420 new_str : "baz" . to_string ( ) ,
420421 replace_all : true ,
421422 } ) ;
422423
423- assert ! ( tool. execute( None , & test_provider ) . await . is_ok( ) ) ;
424+ assert ! ( tool. execute( None , & test_base ) . await . is_ok( ) ) ;
424425
425- let content = tokio:: fs:: read_to_string ( test_dir . join ( "test.txt" ) ) . await . unwrap ( ) ;
426+ let content = tokio:: fs:: read_to_string ( test_base . join ( "test.txt" ) ) . await . unwrap ( ) ;
426427 assert_eq ! ( content, "baz bar baz" ) ;
427428 }
428429
429430 #[ tokio:: test]
430431 async fn test_str_replace_no_match ( ) {
431- let test_provider = TestProvider :: new ( ) ;
432- let test_dir = TestDir :: new ( ) . with_file_sys ( ( "test.txt" , "hello world" ) , & test_provider) . await ;
432+ let test_base = TestBase :: new ( )
433+ . await
434+ . with_file ( ( "test.txt" , "hello world" ) )
435+ . await ;
433436
434437 let tool = FsWrite :: StrReplace ( StrReplace {
435- path : test_dir . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
438+ path : test_base . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
436439 old_str : "missing" . to_string ( ) ,
437440 new_str : "replacement" . to_string ( ) ,
438441 replace_all : false ,
439442 } ) ;
440443
441- assert ! ( tool. execute( None , & test_provider ) . await . is_err( ) ) ;
444+ assert ! ( tool. execute( None , & test_base ) . await . is_err( ) ) ;
442445 }
443446
444447 #[ tokio:: test]
445448 async fn test_insert_at_line ( ) {
446- let test_provider = TestProvider :: new ( ) ;
447- let test_dir = TestDir :: new ( ) . with_file_sys ( ( "test.txt" , "line1\n line2\n line3" ) , & test_provider) . await ;
449+ let test_base = TestBase :: new ( )
450+ . await
451+ . with_file ( ( "test.txt" , "line1\n line2\n line3" ) )
452+ . await ;
448453
449454 let tool = FsWrite :: Insert ( Insert {
450- path : test_dir . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
455+ path : test_base . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
451456 content : "inserted" . to_string ( ) ,
452457 insert_line : Some ( 1 ) ,
453458 } ) ;
454459
455- assert ! ( tool. execute( None , & test_provider ) . await . is_ok( ) ) ;
460+ assert ! ( tool. execute( None , & test_base ) . await . is_ok( ) ) ;
456461
457- let content = tokio:: fs:: read_to_string ( test_dir . join ( "test.txt" ) ) . await . unwrap ( ) ;
462+ let content = tokio:: fs:: read_to_string ( test_base . join ( "test.txt" ) ) . await . unwrap ( ) ;
458463 assert_eq ! ( content, "line1\n inserted\n line2\n line3" ) ;
459464 }
460465
461466 #[ tokio:: test]
462467 async fn test_insert_append ( ) {
463- let test_provider = TestProvider :: new ( ) ;
464- let test_dir = TestDir :: new ( ) . with_file_sys ( ( "test.txt" , "existing" ) , & test_provider) . await ;
468+ let test_base = TestBase :: new ( )
469+ . await
470+ . with_file ( ( "test.txt" , "existing" ) )
471+ . await ;
465472
466473 let tool = FsWrite :: Insert ( Insert {
467- path : test_dir . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
474+ path : test_base . join ( "test.txt" ) . to_string_lossy ( ) . to_string ( ) ,
468475 content : "appended" . to_string ( ) ,
469476 insert_line : None ,
470477 } ) ;
471478
472- assert ! ( tool. execute( None , & test_provider ) . await . is_ok( ) ) ;
479+ assert ! ( tool. execute( None , & test_base ) . await . is_ok( ) ) ;
473480
474- let content = tokio:: fs:: read_to_string ( test_dir . join ( "test.txt" ) ) . await . unwrap ( ) ;
481+ let content = tokio:: fs:: read_to_string ( test_base . join ( "test.txt" ) ) . await . unwrap ( ) ;
475482 assert_eq ! ( content, "existing\n appended" ) ;
476483 }
477484
478485 #[ tokio:: test]
479486 async fn test_fs_write_validate_empty_path ( ) {
480- let test_provider = TestProvider :: new ( ) ;
487+ let test_base = TestBase :: new ( ) . await ;
481488 let tool = FsWrite :: Create ( FileCreate {
482489 path : "" . to_string ( ) ,
483490 content : "content" . to_string ( ) ,
484491 } ) ;
485492
486- assert ! ( tool. validate( & test_provider ) . await . is_err( ) ) ;
493+ assert ! ( tool. validate( & test_base ) . await . is_err( ) ) ;
487494 }
488495
489496 #[ tokio:: test]
490497 async fn test_fs_write_validate_nonexistent_file_for_replace ( ) {
491- let test_provider = TestProvider :: new ( ) ;
498+ let test_base = TestBase :: new ( ) . await ;
492499 let tool = FsWrite :: StrReplace ( StrReplace {
493500 path : "/nonexistent/file.txt" . to_string ( ) ,
494501 old_str : "old" . to_string ( ) ,
495502 new_str : "new" . to_string ( ) ,
496503 replace_all : false ,
497504 } ) ;
498505
499- assert ! ( tool. validate( & test_provider ) . await . is_err( ) ) ;
506+ assert ! ( tool. validate( & test_base ) . await . is_err( ) ) ;
500507 }
501508}
0 commit comments