@@ -505,9 +505,15 @@ async def test_output_file_rotation():
505505 },
506506 )
507507
508- # Should only have MAX_OUTPUT_FILES files
509- files = list (OUTPUT_DIR .glob ("task_*.log" ))
510- assert len (files ) <= MAX_OUTPUT_FILES
508+ # Should only have MAX_OUTPUT_FILES tasks worth of files
509+ # Each task produces 2 files (.log + .raw.log), glob("task_*.log") matches both
510+ all_files = list (OUTPUT_DIR .glob ("task_*.log" ))
511+ assert len (all_files ) <= MAX_OUTPUT_FILES * 2
512+ # Verify .raw.log files are also cleaned (not just .log)
513+ log_files = [f for f in all_files if f .name .endswith (".log" ) and not f .name .endswith (".raw.log" )]
514+ raw_files = [f for f in all_files if f .name .endswith (".raw.log" )]
515+ assert len (log_files ) <= MAX_OUTPUT_FILES
516+ assert len (raw_files ) <= MAX_OUTPUT_FILES
511517
512518
513519@pytest .mark .asyncio
@@ -538,10 +544,11 @@ async def test_oldest_logs_deleted_first():
538544 if match :
539545 task_ids .append (int (match .group (1 )))
540546
541- # Get remaining files
542- remaining_files = list (OUTPUT_DIR .glob ("task_*.log" ))
547+ # Get remaining files — filter to .log only (exclude .raw.log) for task ID extraction
548+ all_remaining = list (OUTPUT_DIR .glob ("task_*.log" ))
549+ remaining_log_files = [f for f in all_remaining if not f .name .endswith (".raw.log" )]
543550 remaining_ids = []
544- for f in remaining_files :
551+ for f in remaining_log_files :
545552 import re
546553
547554 match = re .search (r"task_(\d+)\.log" , f .name )
@@ -551,6 +558,10 @@ async def test_oldest_logs_deleted_first():
551558 # The first 3 task IDs should be gone (oldest deleted)
552559 for old_id in task_ids [:3 ]:
553560 assert old_id not in remaining_ids , f"Old task { old_id } should have been deleted"
561+ # Verify the .raw.log companion file is also gone
562+ assert not (OUTPUT_DIR / f"task_{ old_id } .raw.log" ).exists (), (
563+ f"Raw log for old task { old_id } should also have been deleted"
564+ )
554565
555566 # The last MAX_OUTPUT_FILES task IDs should still exist
556567 for new_id in task_ids [- MAX_OUTPUT_FILES :]:
0 commit comments