@@ -791,6 +791,99 @@ def test_pipeline_disable_experiment_config(sagemaker_session_mock):
791791 )
792792
793793
794+ @patch ("sagemaker.workflow.pipeline.EXPERIMENTS_REGIONS" , {"us-east-1" , "us-west-2" })
795+ def test_pipeline_init_with_default_experiment_config_in_supported_region (sagemaker_session_mock ):
796+ """Test that default experiment config is preserved in regions where Experiments is available."""
797+ sagemaker_session_mock .boto_region_name = "us-east-1"
798+
799+ pipeline = Pipeline (
800+ name = "MyPipeline" ,
801+ steps = [CustomStep (name = "MyStep" , input_data = "input" )],
802+ sagemaker_session = sagemaker_session_mock ,
803+ )
804+
805+ # Default experiment config should be preserved
806+ assert pipeline .pipeline_experiment_config is not None
807+ assert (
808+ pipeline .pipeline_experiment_config .experiment_name == ExecutionVariables .PIPELINE_NAME
809+ )
810+ assert (
811+ pipeline .pipeline_experiment_config .trial_name
812+ == ExecutionVariables .PIPELINE_EXECUTION_ID
813+ )
814+
815+
816+ @patch ("sagemaker.workflow.pipeline.EXPERIMENTS_REGIONS" , {"us-east-1" , "us-west-2" })
817+ def test_pipeline_init_with_default_experiment_config_in_unsupported_region (
818+ sagemaker_session_mock ,
819+ ):
820+ """Test that default experiment config is disabled in regions where Experiments is not available."""
821+ sagemaker_session_mock .boto_region_name = "ap-southeast-4" # Not in EXPERIMENTS_REGIONS
822+
823+ pipeline = Pipeline (
824+ name = "MyPipeline" ,
825+ steps = [CustomStep (name = "MyStep" , input_data = "input" )],
826+ sagemaker_session = sagemaker_session_mock ,
827+ )
828+
829+ # Default experiment config should be set to None
830+ assert pipeline .pipeline_experiment_config is None
831+
832+
833+ @patch ("sagemaker.workflow.pipeline.EXPERIMENTS_REGIONS" , {"us-east-1" , "us-west-2" })
834+ def test_pipeline_init_with_explicit_experiment_config_in_unsupported_region (
835+ sagemaker_session_mock ,
836+ ):
837+ """Test that explicitly set experiment config is preserved even in unsupported regions."""
838+ sagemaker_session_mock .boto_region_name = "ap-southeast-4" # Not in EXPERIMENTS_REGIONS
839+
840+ explicit_config = PipelineExperimentConfig ("MyExperiment" , "MyTrial" )
841+ pipeline = Pipeline (
842+ name = "MyPipeline" ,
843+ pipeline_experiment_config = explicit_config ,
844+ steps = [CustomStep (name = "MyStep" , input_data = "input" )],
845+ sagemaker_session = sagemaker_session_mock ,
846+ )
847+
848+ # Explicitly set experiment config should be preserved
849+ assert pipeline .pipeline_experiment_config is not None
850+ assert pipeline .pipeline_experiment_config .experiment_name == "MyExperiment"
851+ assert pipeline .pipeline_experiment_config .trial_name == "MyTrial"
852+
853+
854+ @patch ("sagemaker.workflow.pipeline.EXPERIMENTS_REGIONS" , {"us-east-1" , "us-west-2" })
855+ def test_pipeline_init_with_none_experiment_config_in_supported_region (sagemaker_session_mock ):
856+ """Test that explicitly setting experiment config to None is respected in supported regions."""
857+ sagemaker_session_mock .boto_region_name = "us-east-1"
858+
859+ pipeline = Pipeline (
860+ name = "MyPipeline" ,
861+ pipeline_experiment_config = None ,
862+ steps = [CustomStep (name = "MyStep" , input_data = "input" )],
863+ sagemaker_session = sagemaker_session_mock ,
864+ )
865+
866+ # Explicitly set None should be preserved
867+ assert pipeline .pipeline_experiment_config is None
868+
869+
870+ @patch ("sagemaker.workflow.pipeline.EXPERIMENTS_REGIONS" , {"us-east-1" })
871+ def test_pipeline_definition_without_experiment_config_in_unsupported_region (
872+ sagemaker_session_mock ,
873+ ):
874+ """Test that pipeline definition has no experiment config in unsupported regions."""
875+ sagemaker_session_mock .boto_region_name = "ap-southeast-4" # Not in EXPERIMENTS_REGIONS
876+
877+ pipeline = Pipeline (
878+ name = "MyPipeline" ,
879+ steps = [CustomStep (name = "MyStep" , input_data = "input" )],
880+ sagemaker_session = sagemaker_session_mock ,
881+ )
882+
883+ definition = json .loads (pipeline .definition ())
884+ assert definition ["PipelineExperimentConfig" ] is None
885+
886+
794887def test_pipeline_list_executions (sagemaker_session_mock ):
795888 sagemaker_session_mock .sagemaker_client .list_pipeline_executions .return_value = {
796889 "PipelineExecutionSummaries" : [Mock ()],
0 commit comments