@@ -587,7 +587,7 @@ async def test_import_index_with_overwrite_fallback_to_create(
587587 async def test_import_pipeline_with_overwrite_true (
588588 self , pipeline_service : PipelineService , index_pipeline : Pipeline , mock_api : AsyncMock
589589 ) -> None :
590- """Test importing a pipeline with overwrite=True creates a new version via POST endpoint ."""
590+ """Test importing a pipeline with overwrite=True patches latest draft version."""
591591 config = PipelineConfig (
592592 name = "test_pipeline_overwrite" ,
593593 inputs = PipelineInputs (query = ["retriever.query" ]),
@@ -600,39 +600,93 @@ async def test_import_pipeline_with_overwrite_true(
600600 validation_response = Mock (spec = Response )
601601 validation_response .status_code = HTTPStatus .NO_CONTENT .value
602602
603- # Mock successful "create new version" response
603+ # Mock successful versions response, latest version is a draft
604+ versions_response = Mock (status_code = HTTPStatus .OK .value )
605+ versions_response .json .return_value = {
606+ "data" : [{"version_id" : "42abcd" , "is_draft" : True }],
607+ }
608+
609+ # Mock successful overwrite (PATCH) response
604610 overwrite_response = Mock (spec = Response )
605- overwrite_response .status_code = HTTPStatus .CREATED .value
611+ overwrite_response .status_code = HTTPStatus .OK .value
612+
613+ mock_api .post .return_value = validation_response
614+ mock_api .get .return_value = versions_response
615+ mock_api .patch .return_value = overwrite_response
616+
617+ await pipeline_service .import_async (index_pipeline , config )
618+
619+ # validation + GET versions + PATCH draft version
620+ assert mock_api .post .call_count == 1
621+ assert mock_api .get .call_count == 1
622+ assert mock_api .patch .call_count == 1
623+
624+ # Check validation call
625+ validation_call = mock_api .post .call_args_list [0 ]
626+ assert validation_call .kwargs ["endpoint" ] == "pipeline_validations"
627+ assert "query_yaml" in validation_call .kwargs ["json" ]
628+ # When overwrite=True, name should be excluded from validation payload
629+ assert "name" not in validation_call .kwargs ["json" ]
630+
631+ # Check PATCH call
632+ overwrite_call = mock_api .patch .call_args_list [0 ]
633+ assert overwrite_call .kwargs ["endpoint" ] == "pipelines/test_pipeline_overwrite/versions/42abcd"
634+ assert "config_yaml" in overwrite_call .kwargs ["json" ]
635+
636+ @pytest .mark .asyncio
637+ async def test_import_pipeline_with_overwrite_true_creates_new_version_when_not_draft (
638+ self , pipeline_service : PipelineService , index_pipeline : Pipeline , mock_api : AsyncMock
639+ ) -> None :
640+ """Test importing a pipeline with overwrite=True creates a new version when latest version is not draft."""
641+ config = PipelineConfig (
642+ name = "test_pipeline_overwrite" ,
643+ inputs = PipelineInputs (query = ["retriever.query" ]),
644+ outputs = PipelineOutputs (documents = "meta_ranker.documents" ),
645+ strict_validation = False ,
646+ overwrite = True ,
647+ )
648+
649+ # Mock successful validation response
650+ validation_response = Mock (spec = Response )
651+ validation_response .status_code = HTTPStatus .NO_CONTENT .value
652+
653+ # Mock versions response, latest version is NOT a draft
654+ versions_response = Mock (status_code = HTTPStatus .OK .value )
655+ versions_response .json .return_value = {
656+ "data" : [{"version_id" : "42abcd" , "is_draft" : False }],
657+ }
658+
659+ # Mock successful "create new version" response
660+ new_version_response = Mock (spec = Response )
661+ new_version_response .status_code = HTTPStatus .CREATED .value
606662
607663 # First POST is validation, second POST is "create new version"
608- mock_api .post .side_effect = [validation_response , overwrite_response ]
664+ mock_api .post .side_effect = [validation_response , new_version_response ]
665+ mock_api .get .return_value = versions_response
609666
610667 await pipeline_service .import_async (index_pipeline , config )
611668
612- # Should call validation endpoint first, then create-version endpoint
669+ # validation + GET versions + POST versions (new version)
613670 assert mock_api .post .call_count == 2
614- # No GET/PATCH/PUT calls in the overwrite path anymore
615- assert mock_api .get .call_count == 0
671+ assert mock_api .get .call_count == 1
616672 assert mock_api .patch .call_count == 0
617- assert mock_api .put .call_count == 0
618673
619674 # Check validation call
620675 validation_call = mock_api .post .call_args_list [0 ]
621676 assert validation_call .kwargs ["endpoint" ] == "pipeline_validations"
622677 assert "query_yaml" in validation_call .kwargs ["json" ]
623- # When overwrite=True, name should be excluded from validation payload
624678 assert "name" not in validation_call .kwargs ["json" ]
625679
626- # Check create-version call
627- overwrite_call = mock_api .post .call_args_list [1 ]
628- assert overwrite_call .kwargs ["endpoint" ] == "pipelines/test_pipeline_overwrite/versions"
629- assert "config_yaml" in overwrite_call .kwargs ["json" ]
680+ # Check create-version POST call
681+ create_version_call = mock_api .post .call_args_list [1 ]
682+ assert create_version_call .kwargs ["endpoint" ] == "pipelines/test_pipeline_overwrite/versions"
683+ assert "config_yaml" in create_version_call .kwargs ["json" ]
630684
631685 @pytest .mark .asyncio
632686 async def test_import_pipeline_with_overwrite_fallback_to_create (
633687 self , pipeline_service : PipelineService , index_pipeline : Pipeline , mock_api : AsyncMock
634688 ) -> None :
635- """Test importing a pipeline with overwrite=True that falls back to create when version creation fails ."""
689+ """Test importing a pipeline with overwrite=True that falls back to create when resource doesn't exist ."""
636690
637691 config = PipelineConfig (
638692 name = "test_pipeline_fallback" ,
@@ -646,41 +700,35 @@ async def test_import_pipeline_with_overwrite_fallback_to_create(
646700 validation_response = Mock (spec = Response )
647701 validation_response .status_code = HTTPStatus .NO_CONTENT .value
648702
649- # Mock non-201 response for POST /pipelines/{name}/versions (version creation fails )
650- version_fail_response = Mock (spec = Response )
651- version_fail_response .status_code = HTTPStatus .BAD_REQUEST .value
703+ # Mock 404 response for GET (resource not found )
704+ not_found_response = Mock (spec = Response )
705+ not_found_response .status_code = HTTPStatus .NOT_FOUND .value
652706
653- # Mock successful creation response for POST /pipelines
707+ # Mock successful creation response
654708 create_response = Mock (spec = Response )
655709 create_response .status_code = HTTPStatus .CREATED .value
656710
657- # POST calls: validation, create-version (fails), create-pipeline (fallback)
658- mock_api .post . side_effect = [ validation_response , version_fail_response , create_response ]
711+ mock_api . post . side_effect = [ validation_response , create_response ]
712+ mock_api .get . return_value = not_found_response
659713
660714 await pipeline_service .import_async (index_pipeline , config )
661715
662- # Should call validation endpoint, then POST to create new version (fails),
663- # then POST to create the pipeline
664- assert mock_api .post .call_count == 3
665- # No GET anymore; overwrite logic doesn't fetch versions
666- assert mock_api .get .call_count == 0
667- assert mock_api .patch .call_count == 0
668- assert mock_api .put .call_count == 0
716+ # validation + GET (404) + POST create
717+ assert mock_api .post .call_count == 2
718+ assert mock_api .get .call_count == 1
669719
670720 # Check validation call
671721 validation_call = mock_api .post .call_args_list [0 ]
672722 assert validation_call .kwargs ["endpoint" ] == "pipeline_validations"
673723 assert "query_yaml" in validation_call .kwargs ["json" ]
674- # When overwrite=True, name should be excluded from validation payload
675724 assert "name" not in validation_call .kwargs ["json" ]
676725
677- # Check attempted version creation call
678- version_call = mock_api .post .call_args_list [1 ]
679- assert version_call .kwargs ["endpoint" ] == "pipelines/test_pipeline_fallback/versions"
680- assert "config_yaml" in version_call .kwargs ["json" ]
726+ # Check GET versions attempt
727+ get_call = mock_api .get .call_args_list [0 ]
728+ assert get_call .kwargs ["endpoint" ] == "pipelines/test_pipeline_fallback/versions"
681729
682- # Check fallback create-pipeline call
683- create_call = mock_api .post .call_args_list [2 ]
730+ # Check fallback POST call
731+ create_call = mock_api .post .call_args_list [1 ]
684732 assert create_call .kwargs ["endpoint" ] == "pipelines"
685733 assert create_call .kwargs ["json" ]["name" ] == "test_pipeline_fallback"
686734 assert "query_yaml" in create_call .kwargs ["json" ]
0 commit comments