@@ -362,6 +362,42 @@ def cookbook_json(name, version, dependencies = {})
362362 expect ( result ) . to be_nil
363363 end
364364
365+ it "uses cached cookbook data instead of re-fetching during backtracking" do
366+ desired = {
367+ "web" => [ "1.0.0" , "2.0.0" ] ,
368+ "db" => [ "1.0.0" ] ,
369+ }
370+ # web 2.0.0 depends on lib, which depends on missing (doesn't exist) → branch fails
371+ # web 1.0.0 has no deps → backtracks here, db must be re-solved
372+ # db 1.0.0 should be fetched only once (cached from the first branch)
373+ allow ( data_store ) . to receive ( :get )
374+ . with ( org_prefix + [ "cookbooks" , "web" , "2.0.0" ] , request )
375+ . and_return ( cookbook_json ( "web" , "2.0.0" , { "lib" => ">= 1.0.0" } ) )
376+ allow ( data_store ) . to receive ( :get )
377+ . with ( org_prefix + [ "cookbooks" , "web" , "1.0.0" ] , request )
378+ . and_return ( cookbook_json ( "web" , "1.0.0" ) )
379+ expect ( data_store ) . to receive ( :get )
380+ . with ( org_prefix + [ "cookbooks" , "db" , "1.0.0" ] , request )
381+ . once
382+ . and_return ( cookbook_json ( "db" , "1.0.0" ) )
383+ allow ( data_store ) . to receive ( :exists_dir? )
384+ . with ( org_prefix + %w{ cookbooks lib } )
385+ . and_return ( true )
386+ allow ( data_store ) . to receive ( :list )
387+ . with ( org_prefix + %w{ cookbooks lib } )
388+ . and_return ( [ "1.0.0" ] )
389+ allow ( data_store ) . to receive ( :get )
390+ . with ( org_prefix + [ "cookbooks" , "lib" , "1.0.0" ] , request )
391+ . and_return ( cookbook_json ( "lib" , "1.0.0" , { "missing" => ">= 1.0.0" } ) )
392+ allow ( data_store ) . to receive ( :exists_dir? )
393+ . with ( org_prefix + %w{ cookbooks missing } )
394+ . and_return ( false )
395+
396+ result , _cache = endpoint . depsolve ( request , %w{ web db } , desired , { } )
397+ expect ( result [ "web" ] ) . to eq ( [ "1.0.0" ] )
398+ expect ( result [ "db" ] ) . to eq ( [ "1.0.0" ] )
399+ end
400+
365401 it "resolves a deep dependency chain" do
366402 desired = { "app" => [ "1.0.0" ] }
367403 allow ( data_store ) . to receive ( :get )
0 commit comments