@@ -155,18 +155,20 @@ fn sync_depot(
155155 // Baseline: hotspot metadata + manifest + hero render, in whichever
156156 // schema this depot ships (`*_core` or the bare names). Manifest is
157157 // fetched here so the variant lookup below has something to consult.
158- for name in entry. baseline_files ( ) {
158+ let mut fetched = entry. baseline_files ( ) ;
159+ for name in & fetched {
159160 fetch_to_cache ( client, & entry. asset_path , & dir, entry, name) ?;
160161 }
161162
162163 // Dedicated buttons render — only present on devices whose manifest
163164 // points `device_buttons_image` at a distinct side view. Fetch it only
164165 // when the registry lists it so front-only devices don't 404; failure
165166 // is non-fatal (the GUI falls back to the hero render).
166- if let Some ( side) = entry. preferred_file ( & BUTTONS_RENDER_FILES )
167- && let Err ( e) = fetch_to_cache ( client, & entry. asset_path , & dir, entry, side)
168- {
169- warn ! ( depot, error = %e, "buttons render fetch failed" ) ;
167+ if let Some ( side) = entry. preferred_file ( & BUTTONS_RENDER_FILES ) {
168+ match fetch_to_cache ( client, & entry. asset_path , & dir, entry, side) {
169+ Ok ( ( ) ) => fetched. push ( side) ,
170+ Err ( e) => warn ! ( depot, error = %e, "buttons render fetch failed" ) ,
171+ }
170172 }
171173
172174 // Optional second pass: download the manifest-mapped resources — the
@@ -189,16 +191,7 @@ fn sync_depot(
189191 else {
190192 continue ;
191193 } ;
192- if matches ! (
193- variant. as_str( ) ,
194- "front_core.png"
195- | "front.png"
196- | "side_core.png"
197- | "side.png"
198- | "core_metadata.json"
199- | "metadata_full.json"
200- | "metadata.json"
201- ) {
194+ if fetched. contains ( & variant. as_str ( ) ) {
202195 continue ;
203196 }
204197 if let Err ( e) = fetch_to_cache ( client, & entry. asset_path , & dir, entry, & variant) {
@@ -322,6 +315,101 @@ mod tests {
322315 use openlogi_assets:: AssetSource ;
323316 use openlogi_core:: config:: AssetSourcePreference ;
324317
318+ #[ test]
319+ fn g512_sync_fetches_metadata_not_in_the_baseline ( ) {
320+ use std:: io:: { Read , Write } ;
321+ use std:: net:: { TcpListener , TcpStream } ;
322+
323+ let root = tempfile:: tempdir ( ) . expect ( "asset root" ) ;
324+ let dir = root. path ( ) . join ( "g513" ) ;
325+ std:: fs:: create_dir ( & dir) . unwrap ( ) ;
326+ let metadata = br#"{"images":[]}"# ;
327+ let mut entry = openlogi_assets:: DeviceEntry {
328+ model_id : "c33c" . into ( ) ,
329+ model_ids : Vec :: new ( ) ,
330+ display_name : "G513" . into ( ) ,
331+ kind : "keyboard" . into ( ) ,
332+ asset_path : "assets/g513/" . into ( ) ,
333+ files : Vec :: new ( ) ,
334+ } ;
335+ for ( name, bytes) in [
336+ ( "manifest.json" , br#"{"devices":[{"modelId":"g512_ext6","resources":[{"key":"image_metadata","src":"metadata.json"}]}]}"# . as_slice ( ) ) ,
337+ ( "metadata_full.json" , br#"{"images":[]}"# . as_slice ( ) ) ,
338+ ( "metadata.json" , metadata. as_slice ( ) ) ,
339+ ] {
340+ entry. files . push ( openlogi_assets:: FileEntry {
341+ name : name. into ( ) ,
342+ sha256 : openlogi_assets:: http:: sha256_hex ( bytes) ,
343+ bytes : bytes. len ( ) as u64 ,
344+ } ) ;
345+ if name != "metadata.json" {
346+ std:: fs:: write ( dir. join ( name) , bytes) . unwrap ( ) ;
347+ }
348+ }
349+ let listener = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
350+ let address = listener. local_addr ( ) . unwrap ( ) ;
351+ let server = std:: thread:: spawn ( move || {
352+ let ( mut stream, _) = listener. accept ( ) . unwrap ( ) ;
353+ let mut request = Vec :: new ( ) ;
354+ let mut byte = [ 0 ] ;
355+ while stream. read ( & mut byte) . unwrap ( ) != 0 {
356+ request. push ( byte[ 0 ] ) ;
357+ if request. ends_with ( b"\r \n \r \n " ) {
358+ break ;
359+ }
360+ }
361+ if !request. is_empty ( ) {
362+ write ! (
363+ stream,
364+ "HTTP/1.1 200 OK\r \n Content-Length: {}\r \n Connection: close\r \n \r \n " ,
365+ metadata. len( )
366+ )
367+ . unwrap ( ) ;
368+ stream. write_all ( metadata) . unwrap ( ) ;
369+ }
370+ request
371+ } ) ;
372+ let client = openlogi_assets:: http:: AssetClient :: new ( & format ! ( "http://{address}" ) ) ;
373+ super :: sync_depot ( & client, root. path ( ) , "g513" , & entry, 6 ) . unwrap ( ) ;
374+ // Release the server even when a regression skips the HTTP request.
375+ drop ( TcpStream :: connect ( address) ) ;
376+ let request = server. join ( ) . unwrap ( ) ;
377+ assert ! ( request. starts_with( b"GET /assets/g513/metadata.json " ) ) ;
378+ assert_eq ! ( std:: fs:: read( dir. join( "metadata.json" ) ) . unwrap( ) , metadata) ;
379+ }
380+
381+ #[ test]
382+ fn g512_photo_and_metadata_are_selected_for_download ( ) {
383+ let root = tempfile:: tempdir ( ) . expect ( "asset root" ) ;
384+ let manifest = root. path ( ) . join ( "manifest.json" ) ;
385+ std:: fs:: write (
386+ & manifest,
387+ r#"{"devices":[{"modelId":"g512_ext6","resources":[{"key":"device_image","src":"front_ext6.png"},{"key":"image_metadata","src":"metadata.json"}]}]}"# ,
388+ )
389+ . unwrap ( ) ;
390+ let entry = openlogi_assets:: DeviceEntry {
391+ model_id : "c33c" . into ( ) ,
392+ model_ids : Vec :: new ( ) ,
393+ display_name : "G513" . into ( ) ,
394+ kind : "keyboard" . into ( ) ,
395+ asset_path : "assets/g513/" . into ( ) ,
396+ files : Vec :: new ( ) ,
397+ } ;
398+ for ( key, expected) in [
399+ ( "device_image" , "front_ext6.png" ) ,
400+ ( "image_metadata" , "metadata.json" ) ,
401+ ] {
402+ assert_eq ! (
403+ super :: pick_variant_filename( & manifest, & entry, "g513" , 6 , key) . as_deref( ) ,
404+ Some ( expected)
405+ ) ;
406+ assert_eq ! (
407+ super :: pick_variant_filename( & manifest, & entry, "g513" , 5 , key) ,
408+ None
409+ ) ;
410+ }
411+ }
412+
325413 #[ test]
326414 fn automatic_preference_races_the_built_in_sources ( ) {
327415 assert_eq ! (
0 commit comments