@@ -628,6 +628,230 @@ async def mock_retrieve(agent_id, **kwargs):
628628
629629 mock_async_client .agents .list .assert_called_once ()
630630
631+ @pytest .mark .asyncio
632+ async def test_create_from_npm (self , mock_async_client : AsyncMock , agent_view : MockAgentView ) -> None :
633+ """Test create_from_npm factory method."""
634+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
635+
636+ client = AsyncAgentOps (mock_async_client )
637+ agent = await client .create_from_npm (
638+ name = "test-agent" ,
639+ package_name = "@runloop/example-agent" ,
640+ )
641+
642+ assert isinstance (agent , AsyncAgent )
643+ assert agent .id == "agent_123"
644+ mock_async_client .agents .create .assert_awaited_once_with (
645+ source = {
646+ "type" : "npm" ,
647+ "npm" : {
648+ "package_name" : "@runloop/example-agent" ,
649+ },
650+ },
651+ name = "test-agent" ,
652+ )
653+
654+ @pytest .mark .asyncio
655+ async def test_create_from_npm_with_all_options (
656+ self , mock_async_client : AsyncMock , agent_view : MockAgentView
657+ ) -> None :
658+ """Test create_from_npm factory method with all optional parameters."""
659+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
660+
661+ client = AsyncAgentOps (mock_async_client )
662+ agent = await client .create_from_npm (
663+ name = "test-agent" ,
664+ package_name = "@runloop/example-agent" ,
665+ npm_version = "1.2.3" ,
666+ registry_url = "https://registry.example.com" ,
667+ agent_setup = ["npm install" , "npm run setup" ],
668+ extra_headers = {"X-Custom" : "header" },
669+ )
670+
671+ assert isinstance (agent , AsyncAgent )
672+ assert agent .id == "agent_123"
673+ mock_async_client .agents .create .assert_awaited_once_with (
674+ source = {
675+ "type" : "npm" ,
676+ "npm" : {
677+ "package_name" : "@runloop/example-agent" ,
678+ "npm_version" : "1.2.3" ,
679+ "registry_url" : "https://registry.example.com" ,
680+ "agent_setup" : ["npm install" , "npm run setup" ],
681+ },
682+ },
683+ name = "test-agent" ,
684+ extra_headers = {"X-Custom" : "header" },
685+ )
686+
687+ @pytest .mark .asyncio
688+ async def test_create_from_npm_raises_when_source_provided (self , mock_async_client : AsyncMock ) -> None :
689+ """Test create_from_npm raises ValueError when source is provided in params."""
690+ client = AsyncAgentOps (mock_async_client )
691+
692+ with pytest .raises (ValueError , match = "Cannot specify 'source' when using create_from_npm" ):
693+ await client .create_from_npm (
694+ name = "test-agent" ,
695+ package_name = "@runloop/example-agent" ,
696+ source = {"type" : "git" , "git" : {"repository" : "https://github.com/example/repo" }},
697+ )
698+
699+ @pytest .mark .asyncio
700+ async def test_create_from_pip (self , mock_async_client : AsyncMock , agent_view : MockAgentView ) -> None :
701+ """Test create_from_pip factory method."""
702+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
703+
704+ client = AsyncAgentOps (mock_async_client )
705+ agent = await client .create_from_pip (
706+ name = "test-agent" ,
707+ package_name = "runloop-example-agent" ,
708+ )
709+
710+ assert isinstance (agent , AsyncAgent )
711+ assert agent .id == "agent_123"
712+ mock_async_client .agents .create .assert_awaited_once_with (
713+ source = {
714+ "type" : "pip" ,
715+ "pip" : {
716+ "package_name" : "runloop-example-agent" ,
717+ },
718+ },
719+ name = "test-agent" ,
720+ )
721+
722+ @pytest .mark .asyncio
723+ async def test_create_from_pip_with_all_options (
724+ self , mock_async_client : AsyncMock , agent_view : MockAgentView
725+ ) -> None :
726+ """Test create_from_pip factory method with all optional parameters."""
727+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
728+
729+ client = AsyncAgentOps (mock_async_client )
730+ agent = await client .create_from_pip (
731+ name = "test-agent" ,
732+ package_name = "runloop-example-agent" ,
733+ pip_version = "1.2.3" ,
734+ registry_url = "https://pypi.example.com" ,
735+ agent_setup = ["pip install extra-deps" ],
736+ )
737+
738+ assert isinstance (agent , AsyncAgent )
739+ assert agent .id == "agent_123"
740+ mock_async_client .agents .create .assert_awaited_once_with (
741+ source = {
742+ "type" : "pip" ,
743+ "pip" : {
744+ "package_name" : "runloop-example-agent" ,
745+ "pip_version" : "1.2.3" ,
746+ "registry_url" : "https://pypi.example.com" ,
747+ "agent_setup" : ["pip install extra-deps" ],
748+ },
749+ },
750+ name = "test-agent" ,
751+ )
752+
753+ @pytest .mark .asyncio
754+ async def test_create_from_git (self , mock_async_client : AsyncMock , agent_view : MockAgentView ) -> None :
755+ """Test create_from_git factory method."""
756+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
757+
758+ client = AsyncAgentOps (mock_async_client )
759+ agent = await client .create_from_git (
760+ name = "test-agent" ,
761+ repository = "https://github.com/example/agent-repo" ,
762+ )
763+
764+ assert isinstance (agent , AsyncAgent )
765+ assert agent .id == "agent_123"
766+ mock_async_client .agents .create .assert_awaited_once_with (
767+ source = {
768+ "type" : "git" ,
769+ "git" : {
770+ "repository" : "https://github.com/example/agent-repo" ,
771+ },
772+ },
773+ name = "test-agent" ,
774+ )
775+
776+ @pytest .mark .asyncio
777+ async def test_create_from_git_with_all_options (
778+ self , mock_async_client : AsyncMock , agent_view : MockAgentView
779+ ) -> None :
780+ """Test create_from_git factory method with all optional parameters."""
781+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
782+
783+ client = AsyncAgentOps (mock_async_client )
784+ agent = await client .create_from_git (
785+ name = "test-agent" ,
786+ repository = "https://github.com/example/agent-repo" ,
787+ ref = "develop" ,
788+ agent_setup = ["npm install" , "npm run build" ],
789+ )
790+
791+ assert isinstance (agent , AsyncAgent )
792+ assert agent .id == "agent_123"
793+ mock_async_client .agents .create .assert_awaited_once_with (
794+ source = {
795+ "type" : "git" ,
796+ "git" : {
797+ "repository" : "https://github.com/example/agent-repo" ,
798+ "ref" : "develop" ,
799+ "agent_setup" : ["npm install" , "npm run build" ],
800+ },
801+ },
802+ name = "test-agent" ,
803+ )
804+
805+ @pytest .mark .asyncio
806+ async def test_create_from_object (self , mock_async_client : AsyncMock , agent_view : MockAgentView ) -> None :
807+ """Test create_from_object factory method."""
808+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
809+
810+ client = AsyncAgentOps (mock_async_client )
811+ agent = await client .create_from_object (
812+ name = "test-agent" ,
813+ object_id = "obj_123" ,
814+ )
815+
816+ assert isinstance (agent , AsyncAgent )
817+ assert agent .id == "agent_123"
818+ mock_async_client .agents .create .assert_awaited_once_with (
819+ source = {
820+ "type" : "object" ,
821+ "object" : {
822+ "object_id" : "obj_123" ,
823+ },
824+ },
825+ name = "test-agent" ,
826+ )
827+
828+ @pytest .mark .asyncio
829+ async def test_create_from_object_with_agent_setup (
830+ self , mock_async_client : AsyncMock , agent_view : MockAgentView
831+ ) -> None :
832+ """Test create_from_object factory method with agent_setup."""
833+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
834+
835+ client = AsyncAgentOps (mock_async_client )
836+ agent = await client .create_from_object (
837+ name = "test-agent" ,
838+ object_id = "obj_123" ,
839+ agent_setup = ["chmod +x setup.sh" , "./setup.sh" ],
840+ )
841+
842+ assert isinstance (agent , AsyncAgent )
843+ assert agent .id == "agent_123"
844+ mock_async_client .agents .create .assert_awaited_once_with (
845+ source = {
846+ "type" : "object" ,
847+ "object" : {
848+ "object_id" : "obj_123" ,
849+ "agent_setup" : ["chmod +x setup.sh" , "./setup.sh" ],
850+ },
851+ },
852+ name = "test-agent" ,
853+ )
854+
631855
632856class TestAsyncRunloopSDK :
633857 """Tests for AsyncRunloopSDK class."""
0 commit comments