@@ -349,18 +349,20 @@ mod cas {
349349 }
350350
351351 #[ test]
352- fn returns_false_when_already_present ( ) {
352+ fn writes_unconditionally_when_present ( ) {
353353 let sandbox = create_empty_sandbox ( ) ;
354354 let store = create_store ( & sandbox) ;
355355
356356 let data = b"already there" ;
357357 let hash = ContentHash :: hash_bytes ( data) . unwrap ( ) ;
358358
359- // First write commits to disk.
359+ // `write` is an unconditional primitive — the existence check lives
360+ // in the `store_*` callers — so it commits and reports true every
361+ // time, leaving no temp behind.
360362 assert ! ( store. write( & hash, data) . unwrap( ) ) ;
361-
362- // Second write short-circuits — the existence check makes it a no-op.
363- assert ! ( !store . write ( & hash , data ) . unwrap ( ) ) ;
363+ assert ! ( store . write ( & hash , data ) . unwrap ( ) ) ;
364+ assert ! ( store . contains_object ( & hash ) ) ;
365+ assert_eq ! ( count_temp_files ( & store ) , 0 ) ;
364366 }
365367 }
366368
@@ -384,7 +386,7 @@ mod cas {
384386 }
385387
386388 #[ test]
387- fn returns_false_when_already_present ( ) {
389+ fn writes_unconditionally_when_present ( ) {
388390 let sandbox = create_empty_sandbox ( ) ;
389391 let store = create_store ( & sandbox) ;
390392
@@ -393,17 +395,18 @@ mod cas {
393395 std:: fs:: write ( & source, data) . unwrap ( ) ;
394396 let hash = ContentHash :: hash_bytes ( data) . unwrap ( ) ;
395397
398+ // Unconditional primitive: `store_file` does the existence check, so
399+ // write_file itself reflinks and commits on every call.
396400 assert ! ( store. write_file( & hash, & source) . unwrap( ) ) ;
397-
398- // Second call short-circuits on the existence check; the source
399- // is never touched again.
400- assert ! ( !store. write_file( & hash, & source) . unwrap( ) ) ;
401+ assert ! ( store. write_file( & hash, & source) . unwrap( ) ) ;
402+ assert_eq ! ( store. read( & hash) . unwrap( ) , data) ;
401403 }
402404
403405 #[ test]
404- fn warm_cache_creates_no_temp_file ( ) {
405- // Like `store_file`, an object already in the store must short
406- // circuit before any temp file is staged.
406+ fn leaves_no_temp_file_behind ( ) {
407+ // The warm-cache short-circuit now lives in `store_file`; the
408+ // write_file primitive always stages a temp but renames it into the
409+ // store, never leaving one behind.
407410 let sandbox = create_empty_sandbox ( ) ;
408411 let store = create_store ( & sandbox) ;
409412
@@ -412,15 +415,11 @@ mod cas {
412415 std:: fs:: write ( & source, data) . unwrap ( ) ;
413416 let hash = ContentHash :: hash_bytes ( data) . unwrap ( ) ;
414417
415- assert ! ( store. write_file( & hash, & source) . unwrap( ) ) ;
416-
417- std:: fs:: remove_dir_all ( & store. temp_dir ) . unwrap ( ) ;
418+ store. write_file ( & hash, & source) . unwrap ( ) ;
419+ store. write_file ( & hash, & source) . unwrap ( ) ;
418420
419- assert ! ( !store. write_file( & hash, & source) . unwrap( ) ) ;
420- assert ! (
421- !store. temp_dir. exists( ) ,
422- "warm-cache write_file must not create a temp file"
423- ) ;
421+ assert ! ( store. contains_object( & hash) ) ;
422+ assert_eq ! ( count_temp_files( & store) , 0 ) ;
424423 }
425424 }
426425
0 commit comments