@@ -605,3 +605,63 @@ def __init__(self):
605605 deployment = await apply (plan , copy_style = "loaded_modules" , dryrun = True )
606606
607607 assert "e" in deployment .envs
608+
609+
610+ @pytest .mark .asyncio
611+ async def test_deploy_task_counts_deployed_triggers (monkeypatch ):
612+ """Triggers ship inside DeployTaskRequest, so deploy_task is the only place they can be counted."""
613+ from flyteidl2 .task import task_definition_pb2
614+
615+ root_dir = pathlib .Path (__file__ ).parents [2 ].resolve ()
616+ monkeypatch .setattr (sys , "path" , [str (root_dir / "src" ), * sys .path ])
617+
618+ env = flyte .TaskEnvironment (name = "test_env" , image = "python:3.10" )
619+
620+ @env .task ()
621+ async def task () -> None :
622+ pass
623+
624+ task = replace (task , triggers = (Mock (), Mock ()))
625+ context = SerializationContext (version = "v1" , root_dir = root_dir )
626+ config = Mock (sync_local_sys_paths = False )
627+
628+ with (
629+ patch ("flyte._deploy.ensure_client" ),
630+ patch ("flyte._deploy.get_init_config" , return_value = config ),
631+ patch ("flyte._deploy.get_client" , return_value = Mock (task_service = Mock (deploy_task = AsyncMock ()))),
632+ patch ("flyte._internal.runtime.convert.convert_upload_default_inputs" , AsyncMock (return_value = [])),
633+ patch (
634+ "flyte._internal.runtime.trigger_serde.to_task_trigger" ,
635+ AsyncMock (return_value = task_definition_pb2 .TaskTrigger (name = "t" )),
636+ ),
637+ patch ("flyte._deploy.count" ) as count_mock ,
638+ ):
639+ await _deploy_task (task , context , dryrun = False )
640+
641+ count_mock .assert_called_once_with ("flyte.operation" , 2 , tags = {"operation" : "deploy_trigger" , "status" : "success" })
642+
643+
644+ @pytest .mark .asyncio
645+ async def test_deploy_task_without_triggers_emits_no_trigger_count (monkeypatch ):
646+ root_dir = pathlib .Path (__file__ ).parents [2 ].resolve ()
647+ monkeypatch .setattr (sys , "path" , [str (root_dir / "src" ), * sys .path ])
648+
649+ env = flyte .TaskEnvironment (name = "test_env" , image = "python:3.10" )
650+
651+ @env .task ()
652+ async def task () -> None :
653+ pass
654+
655+ context = SerializationContext (version = "v1" , root_dir = root_dir )
656+ config = Mock (sync_local_sys_paths = False )
657+
658+ with (
659+ patch ("flyte._deploy.ensure_client" ),
660+ patch ("flyte._deploy.get_init_config" , return_value = config ),
661+ patch ("flyte._deploy.get_client" , return_value = Mock (task_service = Mock (deploy_task = AsyncMock ()))),
662+ patch ("flyte._internal.runtime.convert.convert_upload_default_inputs" , AsyncMock (return_value = [])),
663+ patch ("flyte._deploy.count" ) as count_mock ,
664+ ):
665+ await _deploy_task (task , context , dryrun = False )
666+
667+ count_mock .assert_not_called ()
0 commit comments