@@ -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 ( ) {
@@ -232,7 +224,7 @@ async fn test_build_package_pinning() {
232224 . unwrap ( ) ;
233225
234226 let spec = rt. tmprepo . read_package ( spec. ident ( ) ) . await . unwrap ( ) ;
235- let req = spec. runtime_requirements ( ) . get ( 0 ) . unwrap ( ) ;
227+ let req = spec. runtime_requirements ( ) . first ( ) . unwrap ( ) . clone ( ) ;
236228 match req {
237229 Request :: Pkg ( req) => {
238230 assert_eq ! ( & req. pkg. to_string( ) , "dep/~1.0" ) ;
@@ -314,12 +306,12 @@ async fn test_build_var_pinning() {
314306 . unwrap ( ) ;
315307
316308 let spec = rt. tmprepo . read_package ( spec. ident ( ) ) . await . unwrap ( ) ;
317- let top_req = spec. runtime_requirements ( ) . get ( 0 ) . unwrap ( ) ;
309+ let top_req = spec. runtime_requirements ( ) . get ( 0 ) . unwrap ( ) . clone ( ) ;
318310 match top_req {
319311 Request :: Var ( r) => assert_eq ! ( & r. value, "topvalue" ) ,
320312 _ => panic ! ( "expected var request" ) ,
321313 }
322- let depreq = spec. runtime_requirements ( ) . get ( 1 ) . unwrap ( ) ;
314+ let depreq = spec. runtime_requirements ( ) . get ( 1 ) . unwrap ( ) . clone ( ) ;
323315 match depreq {
324316 Request :: Var ( r) => assert_eq ! ( & r. value, "depvalue" ) ,
325317 _ => panic ! ( "expected var request" ) ,
@@ -509,14 +501,14 @@ async fn test_build_filters_unmodified_files() {
509501
510502#[ rstest]
511503#[ tokio:: test]
512- async fn test_build_package_requirement_propagation ( ) {
504+ async fn test_build_package_downstream_build_requests ( ) {
513505 let rt = spfs_runtime ( ) . await ;
514506 let base_spec = recipe ! (
515507 {
516508 "pkg" : "base/1.0.0" ,
517509 "sources" : [ ] ,
518510 "build" : {
519- "options" : [ { "var" : "inherited/val" , "inheritance" : "Strong " } ] ,
511+ "options" : [ { "var" : "inherited/val" , "inheritance" : "StrongForBuildOnly " } ] ,
520512 "script" : "echo building..." ,
521513 } ,
522514 }
@@ -528,14 +520,14 @@ async fn test_build_package_requirement_propagation() {
528520 "build" : { "options" : [ { "pkg" : "base" } ] , "script" : "echo building..." } ,
529521 }
530522 ) ;
531- rt. tmprepo . publish_recipe ( & base_spec) . await . unwrap ( ) ;
532523 rt. tmprepo . publish_recipe ( & top_spec) . await . unwrap ( ) ;
524+ rt. tmprepo . publish_recipe ( & base_spec) . await . unwrap ( ) ;
533525
534526 SourcePackageBuilder :: from_recipe ( base_spec. clone ( ) )
535527 . build_and_publish ( "." , & * rt. tmprepo )
536528 . await
537529 . unwrap ( ) ;
538- let _base_pkg = BinaryPackageBuilder :: from_recipe ( base_spec)
530+ let ( base_pkg , _ ) = BinaryPackageBuilder :: from_recipe ( base_spec)
539531 . with_repository ( rt. tmprepo . clone ( ) )
540532 . build_and_publish ( & * rt. tmprepo )
541533 . await
@@ -545,45 +537,85 @@ async fn test_build_package_requirement_propagation() {
545537 . build_and_publish ( "." , & * rt. tmprepo )
546538 . await
547539 . unwrap ( ) ;
548- let ( top_pkg , _ ) = BinaryPackageBuilder :: from_recipe ( top_spec)
540+ let result = BinaryPackageBuilder :: from_recipe ( top_spec)
549541 . with_repository ( rt. tmprepo . clone ( ) )
550542 . build_and_publish ( & * rt. tmprepo )
551- . await
552- . unwrap ( ) ;
543+ . await ;
553544
554- assert_eq ! ( top_pkg. options( ) . len( ) , 2 , "should get option added" ) ;
555- let opt = top_pkg. options ( ) . get ( 1 ) . unwrap ( ) ;
556- match opt {
557- Opt :: Var ( opt) => {
558- assert_eq ! (
559- & * opt. var, "base.inherited" ,
560- "should be inherited as package option"
561- ) ;
562- assert_eq ! (
563- opt. inheritance,
564- Inheritance :: Weak ,
565- "inherited option should have weak inheritance"
545+ match result {
546+ Err ( Error :: MissingDownstreamBuildRequest {
547+ required_by,
548+ request,
549+ ..
550+ } ) => {
551+ assert_eq ! ( & required_by, base_pkg. ident( ) ) ;
552+ assert ! (
553+ matches!( & request, Request :: Var ( v) if v. var. as_str( ) == "base.inherited" && v. value == "val" ) ,
554+ "{request}"
566555 ) ;
567556 }
568- _ => panic ! ( "should be given inherited option" ) ,
557+ Err ( err) => panic ! ( "Expected Error::MissingDownstreamBuildRequest, got {err:?}" ) ,
558+ Ok ( _) => panic ! ( "should error when downstream package does not define inherited opt" ) ,
569559 }
560+ }
570561
571- assert_eq ! (
572- top_pkg. runtime_requirements( ) . len( ) ,
573- 1 ,
574- "should get install requirement"
562+ #[ rstest]
563+ #[ tokio:: test]
564+ async fn test_build_package_downstream_runtime_request ( ) {
565+ let rt = spfs_runtime ( ) . await ;
566+ let base_spec = recipe ! (
567+ {
568+ "pkg" : "base/1.0.0" ,
569+ "sources" : [ ] ,
570+ "build" : {
571+ "options" : [ { "var" : "inherited/val" , "inheritance" : "Strong" } ] ,
572+ "script" : "echo building..." ,
573+ } ,
574+ }
575575 ) ;
576- let req = top_pkg. runtime_requirements ( ) . get ( 0 ) . unwrap ( ) ;
577- match req {
578- Request :: Var ( req) => {
579- assert_eq ! (
580- & * req. var, "base.inherited" ,
581- "should be inherited with package namespace"
576+ let top_spec = recipe ! (
577+ {
578+ "pkg" : "top/1.0.0" ,
579+ "sources" : [ ] ,
580+ "build" : { "options" : [ { "pkg" : "base" } , { "var" : "inherited/val" } ] , "script" : "echo building..." } ,
581+ }
582+ ) ;
583+ rt. tmprepo . publish_recipe ( & top_spec) . await . unwrap ( ) ;
584+ rt. tmprepo . publish_recipe ( & base_spec) . await . unwrap ( ) ;
585+
586+ SourcePackageBuilder :: from_recipe ( base_spec. clone ( ) )
587+ . build_and_publish ( "." , & * rt. tmprepo )
588+ . await
589+ . unwrap ( ) ;
590+ let ( base_pkg, _) = BinaryPackageBuilder :: from_recipe ( base_spec)
591+ . with_repository ( rt. tmprepo . clone ( ) )
592+ . build_and_publish ( & * rt. tmprepo )
593+ . await
594+ . unwrap ( ) ;
595+
596+ SourcePackageBuilder :: from_recipe ( top_spec. clone ( ) )
597+ . build_and_publish ( "." , & * rt. tmprepo )
598+ . await
599+ . unwrap ( ) ;
600+ let result = BinaryPackageBuilder :: from_recipe ( top_spec)
601+ . with_repository ( rt. tmprepo . clone ( ) )
602+ . build_and_publish ( & * rt. tmprepo )
603+ . await ;
604+
605+ match result {
606+ Err ( Error :: MissingDownstreamRuntimeRequest {
607+ required_by,
608+ request,
609+ ..
610+ } ) => {
611+ assert_eq ! ( & required_by, base_pkg. ident( ) ) ;
612+ assert ! (
613+ matches!( & request, Request :: Var ( v) if v. var. as_str( ) == "base.inherited" && v. value == "val" ) ,
614+ "{request}"
582615 ) ;
583- assert ! ( !req. pin, "should not be pinned after build" ) ;
584- assert_eq ! ( req. value, "val" , "should be rendered to build time var" ) ;
585616 }
586- _ => panic ! ( "should be given var request" ) ,
617+ Err ( err) => panic ! ( "Expected Error::MissingDownstreamRuntimeRequest, got {err}" ) ,
618+ Ok ( _) => panic ! ( "should error when downstream package does not define inherited opt" ) ,
587619 }
588620}
589621
0 commit comments