@@ -10,22 +10,14 @@ use spk_schema::foundation::fixtures::*;
1010use spk_schema:: foundation:: ident_component:: Component ;
1111use spk_schema:: foundation:: { opt_name, option_map} ;
1212use spk_schema:: ident:: { PkgRequest , RangeIdent , Request } ;
13- use spk_schema:: {
14- recipe,
15- ComponentSpecList ,
16- FromYaml ,
17- Inheritance ,
18- Opt ,
19- Package ,
20- Recipe ,
21- SpecRecipe ,
22- } ;
13+ use spk_schema:: { recipe, ComponentSpecList , FromYaml , Package , Recipe , SpecRecipe } ;
2314use spk_solve:: Solution ;
2415use spk_storage:: fixtures:: * ;
2516use spk_storage:: { self as storage, Repository } ;
2617
2718use super :: { BinaryPackageBuilder , BuildSource } ;
2819use crate :: build:: SourcePackageBuilder ;
20+ use crate :: Error ;
2921
3022#[ rstest]
3123fn test_split_manifest_permissions ( ) {
@@ -317,14 +309,14 @@ async fn test_build_var_pinning() {
317309 . unwrap ( ) ;
318310
319311 let spec = rt. tmprepo . read_package ( spec. ident ( ) ) . await . unwrap ( ) ;
320- let top_req = spec. runtime_requirements ( ) . get ( 0 ) . unwrap ( ) ;
312+ let top_req = spec. runtime_requirements ( ) . get ( 0 ) . unwrap ( ) . clone ( ) ;
321313 match top_req {
322- Request :: Var ( r) => assert_eq ! ( & r. value, "topvalue" ) ,
314+ Request :: Var ( r) => assert_eq ! ( r. value. as_pinned ( ) , Some ( "topvalue" ) ) ,
323315 _ => panic ! ( "expected var request" ) ,
324316 }
325- let depreq = spec. runtime_requirements ( ) . get ( 1 ) . unwrap ( ) ;
317+ let depreq = spec. runtime_requirements ( ) . get ( 1 ) . unwrap ( ) . clone ( ) ;
326318 match depreq {
327- Request :: Var ( r) => assert_eq ! ( & r. value, "depvalue" ) ,
319+ Request :: Var ( r) => assert_eq ! ( r. value. as_pinned ( ) , Some ( "depvalue" ) ) ,
328320 _ => panic ! ( "expected var request" ) ,
329321 }
330322}
@@ -519,14 +511,14 @@ async fn test_build_filters_unmodified_files() {
519511
520512#[ rstest]
521513#[ tokio:: test]
522- async fn test_build_package_requirement_propagation ( ) {
514+ async fn test_build_package_downstream_build_requests ( ) {
523515 let rt = spfs_runtime ( ) . await ;
524516 let base_spec = recipe ! (
525517 {
526518 "pkg" : "base/1.0.0" ,
527519 "sources" : [ ] ,
528520 "build" : {
529- "options" : [ { "var" : "inherited/val" , "inheritance" : "Strong " } ] ,
521+ "options" : [ { "var" : "inherited/val" , "inheritance" : "StrongForBuildOnly " } ] ,
530522 "script" : "echo building..." ,
531523 } ,
532524 }
@@ -538,14 +530,14 @@ async fn test_build_package_requirement_propagation() {
538530 "build" : { "options" : [ { "pkg" : "base" } ] , "script" : "echo building..." } ,
539531 }
540532 ) ;
541- rt. tmprepo . publish_recipe ( & base_spec) . await . unwrap ( ) ;
542533 rt. tmprepo . publish_recipe ( & top_spec) . await . unwrap ( ) ;
534+ rt. tmprepo . publish_recipe ( & base_spec) . await . unwrap ( ) ;
543535
544536 SourcePackageBuilder :: from_recipe ( base_spec. clone ( ) )
545537 . build_and_publish ( "." , & * rt. tmprepo )
546538 . await
547539 . unwrap ( ) ;
548- let _base_pkg = BinaryPackageBuilder :: from_recipe ( base_spec)
540+ let ( base_pkg , _ ) = BinaryPackageBuilder :: from_recipe ( base_spec)
549541 . with_repository ( rt. tmprepo . clone ( ) )
550542 . build_and_publish ( option_map ! { } , & * rt. tmprepo )
551543 . await
@@ -555,45 +547,85 @@ async fn test_build_package_requirement_propagation() {
555547 . build_and_publish ( "." , & * rt. tmprepo )
556548 . await
557549 . unwrap ( ) ;
558- let ( top_pkg , _ ) = BinaryPackageBuilder :: from_recipe ( top_spec)
550+ let result = BinaryPackageBuilder :: from_recipe ( top_spec)
559551 . with_repository ( rt. tmprepo . clone ( ) )
560552 . build_and_publish ( option_map ! { } , & * rt. tmprepo )
561- . await
562- . unwrap ( ) ;
553+ . await ;
563554
564- assert_eq ! ( top_pkg. options( ) . len( ) , 2 , "should get option added" ) ;
565- let opt = top_pkg. options ( ) . get ( 1 ) . unwrap ( ) ;
566- match opt {
567- Opt :: Var ( opt) => {
568- assert_eq ! (
569- & * opt. var, "base.inherited" ,
570- "should be inherited as package option"
571- ) ;
572- assert_eq ! (
573- opt. inheritance,
574- Inheritance :: Weak ,
575- "inherited option should have weak inheritance"
555+ match result {
556+ Err ( Error :: MissingDownstreamBuildRequest {
557+ required_by,
558+ request,
559+ ..
560+ } ) => {
561+ assert_eq ! ( & required_by, base_pkg. ident( ) ) ;
562+ assert ! (
563+ matches!( & request, Request :: Var ( v) if v. var. as_str( ) == "base.inherited" && v. value. as_pinned( ) == Some ( "val" ) ) ,
564+ "{request}"
576565 ) ;
577566 }
578- _ => panic ! ( "should be given inherited option" ) ,
567+ Err ( err) => panic ! ( "Expected Error::MissingDownstreamBuildRequest, got {err:?}" ) ,
568+ Ok ( _) => panic ! ( "should error when downstream package does not define inherited opt" ) ,
579569 }
570+ }
580571
581- assert_eq ! (
582- top_pkg. runtime_requirements( ) . len( ) ,
583- 1 ,
584- "should get install requirement"
572+ #[ rstest]
573+ #[ tokio:: test]
574+ async fn test_build_package_downstream_runtime_request ( ) {
575+ let rt = spfs_runtime ( ) . await ;
576+ let base_spec = recipe ! (
577+ {
578+ "pkg" : "base/1.0.0" ,
579+ "sources" : [ ] ,
580+ "build" : {
581+ "options" : [ { "var" : "inherited/val" , "inheritance" : "Strong" } ] ,
582+ "script" : "echo building..." ,
583+ } ,
584+ }
585585 ) ;
586- let req = top_pkg. runtime_requirements ( ) . get ( 0 ) . unwrap ( ) ;
587- match req {
588- Request :: Var ( req) => {
589- assert_eq ! (
590- & * req. var, "base.inherited" ,
591- "should be inherited with package namespace"
586+ let top_spec = recipe ! (
587+ {
588+ "pkg" : "top/1.0.0" ,
589+ "sources" : [ ] ,
590+ "build" : { "options" : [ { "pkg" : "base" } , { "var" : "inherited/val" } ] , "script" : "echo building..." } ,
591+ }
592+ ) ;
593+ rt. tmprepo . publish_recipe ( & top_spec) . await . unwrap ( ) ;
594+ rt. tmprepo . publish_recipe ( & base_spec) . await . unwrap ( ) ;
595+
596+ SourcePackageBuilder :: from_recipe ( base_spec. clone ( ) )
597+ . build_and_publish ( "." , & * rt. tmprepo )
598+ . await
599+ . unwrap ( ) ;
600+ let ( base_pkg, _) = BinaryPackageBuilder :: from_recipe ( base_spec)
601+ . with_repository ( rt. tmprepo . clone ( ) )
602+ . build_and_publish ( & option_map ! { } , & * rt. tmprepo )
603+ . await
604+ . unwrap ( ) ;
605+
606+ SourcePackageBuilder :: from_recipe ( top_spec. clone ( ) )
607+ . build_and_publish ( "." , & * rt. tmprepo )
608+ . await
609+ . unwrap ( ) ;
610+ let result = BinaryPackageBuilder :: from_recipe ( top_spec)
611+ . with_repository ( rt. tmprepo . clone ( ) )
612+ . build_and_publish ( & option_map ! { } , & * rt. tmprepo )
613+ . await ;
614+
615+ match result {
616+ Err ( Error :: MissingDownstreamRuntimeRequest {
617+ required_by,
618+ request,
619+ ..
620+ } ) => {
621+ assert_eq ! ( & required_by, base_pkg. ident( ) ) ;
622+ assert ! (
623+ matches!( & request, Request :: Var ( v) if v. var. as_str( ) == "base.inherited" && v. value. as_pinned( ) == Some ( "val" ) ) ,
624+ "{request}"
592625 ) ;
593- assert ! ( !req. pin, "should not be pinned after build" ) ;
594- assert_eq ! ( req. value, "val" , "should be rendered to build time var" ) ;
595626 }
596- _ => panic ! ( "should be given var request" ) ,
627+ Err ( err) => panic ! ( "Expected Error::MissingDownstreamRuntimeRequest, got {err}" ) ,
628+ Ok ( _) => panic ! ( "should error when downstream package does not define inherited opt" ) ,
597629 }
598630}
599631
0 commit comments