@@ -14,40 +14,39 @@ def clean_db_path(request):
1414 shutil .rmtree (db_path )
1515
1616def test_replay_safety (clean_db_path ):
17- print ("\n --- Test 1: Replay Safety (50k inserts) ---" )
18-
19- with Mnemos .open (clean_db_path , dimension = 2 ) as db :
17+ print ("\n --- Test 1: Replay Safety (5000 inserts) ---" )
18+
19+ # Use strict sync so every write is fsynced — guarantees full replay on reopen.
20+ with Mnemos .open (clean_db_path , dimension = 2 , sync = "strict" ) as db :
2021 start_time = time .time ()
2122 for i in range (5000 ):
2223 db .remember (f"Entry { i } " , embedding = [0.5 , 0.5 ])
23-
24+
2425 print (f"Inserted 5,000 memories in { time .time () - start_time :.2f} s" )
2526 assert len (db ) == 5000
2627
27- # Simulate closing / crash then reopen
28+ # Simulate closing then reopen — strict policy guarantees no data loss.
2829 print ("Reopening..." )
29- with Mnemos .open (clean_db_path , dimension = 2 ) as db2 :
30- # With Async sync policy a few trailing entries may not be flushed
31- # before the context manager drops the handle — allow up to 20 missing.
32- assert len (db2 ) >= 4980 , f"Expected ~5000 entries after reopen, got { len (db2 )} "
33-
30+ with Mnemos .open (clean_db_path , dimension = 2 , sync = "strict" ) as db2 :
31+ assert len (db2 ) == 5000 , f"Expected 5000 entries after reopen, got { len (db2 )} "
32+
3433 print ("Test 1 PASS" )
3534
3635def test_compaction_integrity (clean_db_path ):
3736 print ("\n --- Test 3: WAL Compaction Integrity ---" )
38-
39- with Mnemos . open ( clean_db_path , dimension = 2 ) as db :
40- # Insert 100 entries
37+
38+ # Use strict sync so compact sees all 100 entries in the WAL.
39+ with Mnemos . open ( clean_db_path , dimension = 2 , sync = "strict" ) as db :
4140 for _ in range (100 ):
4241 db .remember ("Stress entry" , embedding = [0.1 , 0.9 ])
43-
42+
4443 assert len (db ) == 100
4544
4645 print ("Compacting..." )
4746 db .compact ()
4847
4948 print ("Reopening..." )
50- with Mnemos .open (clean_db_path , dimension = 2 ) as db2 :
51- assert len (db2 ) >= 90 , f"Expected ~ 100 entries after compact + reopen, got { len (db2 )} "
52-
49+ with Mnemos .open (clean_db_path , dimension = 2 , sync = "strict" ) as db2 :
50+ assert len (db2 ) == 100 , f"Expected 100 entries after compact + reopen, got { len (db2 )} "
51+
5352 print ("Test 3 PASS" )
0 commit comments