@@ -111,6 +111,7 @@ impl Index {
111111 let current_version = args. current_version ;
112112 let product_name = args. product_name ;
113113 let ignore_rollout = args. ignore_rollout ;
114+ let is_auto_update = args. is_auto_update ;
114115 let threshold_override = args. threshold_override ;
115116
116117 if !self . supported . iter ( ) . any ( |support| {
@@ -143,7 +144,9 @@ impl Index {
143144 . filter ( |version| {
144145 version. update_conditions . is_empty ( )
145146 || version. update_conditions . iter ( ) . all ( |cond| match cond {
146- UpdateCondition :: AllowedProductNames ( product_names) => product_names. contains ( product_name) ,
147+ UpdateCondition :: AllowedAutoUpdateProductNames ( product_names) => {
148+ !is_auto_update || product_names. contains ( product_name)
149+ } ,
147150 } )
148151 } )
149152 . collect :: < Vec < & RemoteVersion > > ( ) ;
@@ -252,6 +255,7 @@ pub struct FindNextVersionArgs<'a> {
252255 pub file_type : Option < & ' a FileType > ,
253256 pub current_version : & ' a str ,
254257 pub product_name : & ' a ProductName ,
258+ pub is_auto_update : bool ,
255259 pub ignore_rollout : bool ,
256260 pub threshold_override : Option < u8 > ,
257261}
@@ -286,7 +290,7 @@ pub(crate) struct RemoteVersion {
286290#[ derive( Debug , Clone , PartialEq , Eq , Deserialize , Serialize ) ]
287291#[ serde( rename_all = "camelCase" ) ]
288292pub enum UpdateCondition {
289- AllowedProductNames ( Vec < ProductName > ) ,
293+ AllowedAutoUpdateProductNames ( Vec < ProductName > ) ,
290294}
291295
292296#[ derive( Debug , Clone , PartialEq , Eq , EnumString , Display ) ]
@@ -429,6 +433,7 @@ pub async fn check_for_updates(
429433 variant : & Variant ,
430434 file_type : Option < & FileType > ,
431435 ignore_rollout : bool ,
436+ is_auto_update : bool ,
432437) -> Result < Option < UpdatePackage > , Error > {
433438 const CURRENT_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
434439 let product_name = ProductName :: default ( ) ;
@@ -439,6 +444,7 @@ pub async fn check_for_updates(
439444 current_version : CURRENT_VERSION ,
440445 product_name : & product_name,
441446 ignore_rollout,
447+ is_auto_update,
442448 threshold_override : None ,
443449 } )
444450}
@@ -528,6 +534,7 @@ mod tests {
528534 & Variant :: Full ,
529535 Some ( FileType :: Dmg ) . as_ref ( ) ,
530536 false ,
537+ false ,
531538 )
532539 . await
533540 . unwrap ( ) ;
@@ -707,6 +714,7 @@ mod tests {
707714 current_version : "1.2.1" ,
708715 product_name : & product_name,
709716 ignore_rollout : true ,
717+ is_auto_update : false ,
710718 threshold_override : None ,
711719 } )
712720 . unwrap ( ) ;
@@ -723,6 +731,7 @@ mod tests {
723731 current_version : "1.2.0" ,
724732 product_name : & ProductName :: Unknown ( "qv2" . to_string ( ) ) ,
725733 ignore_rollout : true ,
734+ is_auto_update : false ,
726735 threshold_override : None ,
727736 } )
728737 . unwrap ( )
@@ -740,6 +749,7 @@ mod tests {
740749 current_version : "1.2.1" ,
741750 product_name : & ProductName :: AmazonQ ,
742751 ignore_rollout : true ,
752+ is_auto_update : false ,
743753 threshold_override : None ,
744754 } ) ;
745755 assert ! ( next. is_err( ) ) ;
@@ -755,6 +765,7 @@ mod tests {
755765 current_version : "1.0.5" ,
756766 product_name : & ProductName :: Unknown ( "qv2" . to_string ( ) ) ,
757767 ignore_rollout : true ,
768+ is_auto_update : false ,
758769 threshold_override : None ,
759770 } )
760771 . unwrap ( )
@@ -763,7 +774,7 @@ mod tests {
763774 }
764775
765776 #[ test]
766- fn index_test_allowed_product_names_update ( ) {
777+ fn index_test_allowed_autoupdate_product_names_update ( ) {
767778 let mut index = load_test_index ( ) ;
768779
769780 let next = index
@@ -774,16 +785,34 @@ mod tests {
774785 current_version : "1.0.5" ,
775786 product_name : & ProductName :: AmazonQ ,
776787 ignore_rollout : true ,
788+ is_auto_update : false ,
789+ threshold_override : None ,
790+ } )
791+ . unwrap ( )
792+ . expect ( "should have update package" ) ;
793+ assert_eq ! (
794+ next. version. to_string( ) . as_str( ) ,
795+ "1.2.1" ,
796+ "amazon q during manual update should update into 1.2.1"
797+ ) ;
798+ let next = index
799+ . find_next_version ( FindNextVersionArgs {
800+ target_triple : & TargetTriple :: X86_64UnknownLinuxGnu ,
801+ variant : & Variant :: Full ,
802+ file_type : None ,
803+ current_version : "1.0.5" ,
804+ product_name : & ProductName :: AmazonQ ,
805+ ignore_rollout : true ,
806+ is_auto_update : true ,
777807 threshold_override : None ,
778808 } )
779809 . unwrap ( )
780810 . expect ( "should have update package" ) ;
781811 assert_eq ! (
782812 next. version. to_string( ) . as_str( ) ,
783813 "1.2.0" ,
784- "amazon q should update into 1.2.0"
814+ "amazon q during auto update should update into 1.2.0"
785815 ) ;
786-
787816 let next = index
788817 . find_next_version ( FindNextVersionArgs {
789818 target_triple : & TargetTriple :: X86_64UnknownLinuxGnu ,
@@ -792,19 +821,22 @@ mod tests {
792821 current_version : "1.0.5" ,
793822 product_name : & ProductName :: Unknown ( "qv2" . to_string ( ) ) ,
794823 ignore_rollout : true ,
824+ is_auto_update : true ,
795825 threshold_override : None ,
796826 } )
797827 . unwrap ( )
798828 . expect ( "should have update package" ) ;
799829 assert_eq ! (
800830 next. version. to_string( ) . as_str( ) ,
801831 "1.2.1" ,
802- "qv2 should update into 1.2.1"
832+ "qv2 during auto update should update into 1.2.1"
803833 ) ;
804834
805835 // Push a newer update that allows Amazon Q
806836 let mut last = index. versions . last ( ) . cloned ( ) . unwrap ( ) ;
807- last. update_conditions = vec ! [ UpdateCondition :: AllowedProductNames ( vec![ ProductName :: AmazonQ ] ) ] ;
837+ last. update_conditions = vec ! [ UpdateCondition :: AllowedAutoUpdateProductNames ( vec![
838+ ProductName :: AmazonQ ,
839+ ] ) ] ;
808840 last. version = Version :: from_str ( "2.0.0" ) . unwrap ( ) ;
809841 index. versions . push ( last) ;
810842
@@ -816,6 +848,7 @@ mod tests {
816848 current_version : "1.0.5" ,
817849 product_name : & ProductName :: AmazonQ ,
818850 ignore_rollout : true ,
851+ is_auto_update : true ,
819852 threshold_override : None ,
820853 } )
821854 . unwrap ( )
@@ -824,11 +857,11 @@ mod tests {
824857 }
825858
826859 #[ test]
827- fn index_test_empty_allowed_product_names_does_not_update ( ) {
860+ fn index_test_empty_allowed_autoupdate_product_names_does_not_update ( ) {
828861 let mut index = load_test_index ( ) ;
829862
830863 let mut last = index. versions . last ( ) . cloned ( ) . unwrap ( ) ;
831- last. update_conditions = vec ! [ UpdateCondition :: AllowedProductNames ( vec![ ] ) ] ;
864+ last. update_conditions = vec ! [ UpdateCondition :: AllowedAutoUpdateProductNames ( vec![ ] ) ] ;
832865 last. version = Version :: from_str ( "2.0.0" ) . unwrap ( ) ;
833866 index. versions . push ( last) ;
834867
@@ -840,6 +873,7 @@ mod tests {
840873 current_version : "1.0.5" ,
841874 product_name : & ProductName :: Unknown ( "qv2" . to_string ( ) ) ,
842875 ignore_rollout : true ,
876+ is_auto_update : true ,
843877 threshold_override : None ,
844878 } )
845879 . unwrap ( )
0 commit comments