@@ -368,41 +368,61 @@ FOSSIL_TEST(c_test_archive_create_null_params) {
368368 ASSUME_ITS_CNULL (archive );
369369}
370370
371+ // ======================================================
371372// Test archive inspection functions
373+ // ======================================================
372374FOSSIL_TEST (c_test_archive_get_stats ) {
373375 const char * archive_path = "test_stats.zip" ;
374- fossil_io_archive_stats_t stats ;
375-
376+ fossil_io_archive_stats_t stats = { 0 }; // always zero-init
377+
376378 // Create archive and add test files
377- fossil_io_archive_t * archive = fossil_io_archive_create (archive_path , FOSSIL_IO_ARCHIVE_ZIP , FOSSIL_IO_COMPRESSION_NORMAL );
379+ fossil_io_archive_t * archive = fossil_io_archive_create (
380+ archive_path ,
381+ FOSSIL_IO_ARCHIVE_ZIP ,
382+ FOSSIL_IO_COMPRESSION_NORMAL
383+ );
378384 ASSUME_NOT_CNULL (archive );
379-
385+
380386 // Create temporary test files
381387 const char * test_file1 = "temp_test_file1.txt" ;
382388 const char * test_file2 = "temp_test_file2.txt" ;
383389 const char * content1 = "Test content 1" ;
384390 const char * content2 = "Test content 2 is longer" ;
385-
386- fossil_fstream_t temp_stream ;
391+
392+ fossil_fstream_t temp_stream = {0 }; // safety init
393+
394+ // Write first test file
387395 ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (& temp_stream , test_file1 , "w" ));
388- fossil_fstream_write (& temp_stream , content1 , strlen (content1 ), 1 );
396+ ASSUME_ITS_EQUAL_SIZE (strlen (content1 ),
397+ fossil_fstream_write (& temp_stream , content1 , strlen (content1 ), 1 ));
389398 fossil_fstream_close (& temp_stream );
390-
399+
400+ // Write second test file
391401 ASSUME_ITS_EQUAL_I32 (0 , fossil_fstream_open (& temp_stream , test_file2 , "w" ));
392- fossil_fstream_write (& temp_stream , content2 , strlen (content2 ), 1 );
402+ ASSUME_ITS_EQUAL_SIZE (strlen (content2 ),
403+ fossil_fstream_write (& temp_stream , content2 , strlen (content2 ), 1 ));
393404 fossil_fstream_close (& temp_stream );
394-
395- // Add files to archive
405+
406+ // Add files to archive (ensure no duplicates)
396407 ASSUME_ITS_TRUE (fossil_io_archive_add_file (archive , test_file1 , "test1.txt" ));
397408 ASSUME_ITS_TRUE (fossil_io_archive_add_file (archive , test_file2 , "test2.txt" ));
398-
399- // Get stats
409+
410+ // Request stats
400411 ASSUME_ITS_TRUE (fossil_io_archive_get_stats (archive , & stats ));
412+
413+ // Validate archive stats
401414 ASSUME_ITS_EQUAL_SIZE (2 , stats .total_entries );
402415 ASSUME_ITS_EQUAL_SIZE (strlen (content1 ) + strlen (content2 ), stats .total_size );
403416 ASSUME_ITS_TRUE (stats .compression_ratio >= 0.0 && stats .compression_ratio <= 1.0 );
404-
417+
418+ // Cleanup — always close archive before removing files on macOS
405419 fossil_io_archive_close (archive );
420+
421+ // Small delay can help with file sync issues on macOS file systems
422+ #ifdef __APPLE__
423+ usleep (10000 ); // 10 ms
424+ #endif
425+
406426 fossil_fstream_remove (test_file1 );
407427 fossil_fstream_remove (test_file2 );
408428 fossil_fstream_remove (archive_path );
0 commit comments