1919 os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))), 'src' ))
2020
2121from vfb_connectomics_import .images .io import (
22- PRODUCTS , TERMINAL , Ledger , OutputSet , partial_path )
22+ PRODUCTS , SWEEP_AFTER_SWAP , TERMINAL , Ledger , OutputSet , partial_path )
2323
2424ALL = ('swc' , 'obj' , 'nrrd' )
2525
2626
2727# --------------------------------------------------------------------------- helpers
28- def plant (folder , thumbnail = True , volumes = ALL ):
28+ #: What VFB actually serves per neuron, confirmed live 2026-08-26. Only the first three
29+ #: are written by this loader; the rest belong to other jobs.
30+ SERVED = ('volume.swc' , 'volume.nrrd' , 'volume_man.obj' ,
31+ 'volume.obj' , 'volume.wlz' , 'thumbnail.png' , 'thumbnailT.png' )
32+
33+
34+ def plant (folder , thumbnail = True , volumes = ALL , extras = True ):
2935 """An existing v626-era image, as the loader will find on almost every neuron."""
3036 os .makedirs (folder , exist_ok = True )
3137 for k in volumes :
3238 with open (os .path .join (folder , PRODUCTS [k ]), 'w' ) as fh :
3339 fh .write (f'OLD v626 { k } ' )
40+ if extras :
41+ for n in ('volume.obj' , 'volume.wlz' ):
42+ with open (os .path .join (folder , n ), 'w' ) as fh :
43+ fh .write ('OLD ' + n )
3444 if thumbnail :
35- with open (os .path .join (folder , 'thumbnail.png' ), 'w' ) as fh :
36- fh .write ('OLD THUMB' )
45+ for n in ('thumbnail.png' , 'thumbnailT.png' ):
46+ with open (os .path .join (folder , n ), 'w' ) as fh :
47+ fh .write ('OLD THUMB' )
3748
3849
3950def names (folder ):
@@ -66,16 +77,27 @@ def test_partial_suffix_precedes_the_extension():
6677
6778
6879# ------------------------------------------------------------------------ the swap is safe
69- def test_swap_replaces_content_and_clears_thumbnail ():
80+ def test_swap_replaces_three_products_and_deletes_only_volume_obj ():
81+ """The agreed contract (2026-08-26): replace swc / nrrd / volume_man.obj, additionally
82+ delete volume.obj, and LEAVE volume.wlz and the thumbnails. Those go briefly out of
83+ sync with the new alignment, which is accepted -- other jobs refresh them, and
84+ deleting products nothing here regenerates would be worse."""
7085 with tempfile .TemporaryDirectory () as d :
7186 plant (d )
7287 out = OutputSet (d , ALL )
7388 assert read (d , 'swc' ) == 'OLD v626 swc'
7489 wrote , removed = out .swap (build (out , ALL ))
7590 assert wrote == sorted (PRODUCTS [k ] for k in ALL )
76- assert removed == ['thumbnail.png ' ], 'a stale thumbnail depicts the old alignment'
91+ assert removed == ['volume.obj ' ], removed
7792 assert read (d , 'swc' ) == 'NEW swc'
78- assert 'thumbnail.png' not in names (d )
93+ for n in ('volume.wlz' , 'thumbnail.png' , 'thumbnailT.png' ):
94+ assert n in names (d ), n + ' must NOT be swept'
95+
96+
97+ def test_sweep_list_is_exactly_volume_obj ():
98+ """Pinned because an earlier version globbed volume*/thumbnail* and removed five files
99+ per neuron, including volume.wlz, which nothing in this repo regenerates."""
100+ assert SWEEP_AFTER_SWAP == ('volume.obj' ,)
79101
80102
81103def test_swap_never_leaves_a_served_file_missing ():
@@ -99,8 +121,8 @@ def test_swap_sweeps_a_product_dropped_from_products():
99121 plant (d , thumbnail = False )
100122 out = OutputSet (d , ('swc' , 'nrrd' ))
101123 _ , removed = out .swap (build (out , ('swc' , 'nrrd' )))
102- assert removed == ['volume_man.obj' ]
103- assert names (d ) == [ 'volume.nrrd' , 'volume.swc' ]
124+ assert removed == ['volume.obj' , ' volume_man.obj' ], removed
125+ assert 'volume.wlz' in names (d ), 'still not ours to delete'
104126
105127
106128# ------------------------------------------------------------- existing-image bookkeeping
@@ -138,8 +160,8 @@ def test_remove_all_clears_volumes_and_thumbnails():
138160 with tempfile .TemporaryDirectory () as d :
139161 plant (d )
140162 removed = OutputSet (d , ALL ).remove_all ()
141- assert removed == [ 'thumbnail.png' , 'volume.nrrd' , 'volume.swc' , 'volume_man.obj' ]
142- assert names (d ) == []
163+ assert sorted ( removed ) == sorted ( SERVED ), removed
164+ assert names (d ) == [], 'a spurious image must not be left half-served'
143165
144166
145167# --------------------------------------------------------------------- the deletion policy
0 commit comments