@@ -835,6 +835,230 @@ async def mock_retrieve(agent_id, **kwargs):
835835
836836 mock_async_client .agents .list .assert_called_once ()
837837
838+ @pytest .mark .asyncio
839+ async def test_create_from_npm (self , mock_async_client : AsyncMock , agent_view : MockAgentView ) -> None :
840+ """Test create_from_npm factory method."""
841+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
842+
843+ client = AsyncAgentOps (mock_async_client )
844+ agent = await client .create_from_npm (
845+ name = "test-agent" ,
846+ package_name = "@runloop/example-agent" ,
847+ )
848+
849+ assert isinstance (agent , AsyncAgent )
850+ assert agent .id == "agent_123"
851+ mock_async_client .agents .create .assert_awaited_once_with (
852+ source = {
853+ "type" : "npm" ,
854+ "npm" : {
855+ "package_name" : "@runloop/example-agent" ,
856+ },
857+ },
858+ name = "test-agent" ,
859+ )
860+
861+ @pytest .mark .asyncio
862+ async def test_create_from_npm_with_all_options (
863+ self , mock_async_client : AsyncMock , agent_view : MockAgentView
864+ ) -> None :
865+ """Test create_from_npm factory method with all optional parameters."""
866+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
867+
868+ client = AsyncAgentOps (mock_async_client )
869+ agent = await client .create_from_npm (
870+ name = "test-agent" ,
871+ package_name = "@runloop/example-agent" ,
872+ npm_version = "1.2.3" ,
873+ registry_url = "https://registry.example.com" ,
874+ agent_setup = ["npm install" , "npm run setup" ],
875+ extra_headers = {"X-Custom" : "header" },
876+ )
877+
878+ assert isinstance (agent , AsyncAgent )
879+ assert agent .id == "agent_123"
880+ mock_async_client .agents .create .assert_awaited_once_with (
881+ source = {
882+ "type" : "npm" ,
883+ "npm" : {
884+ "package_name" : "@runloop/example-agent" ,
885+ "npm_version" : "1.2.3" ,
886+ "registry_url" : "https://registry.example.com" ,
887+ "agent_setup" : ["npm install" , "npm run setup" ],
888+ },
889+ },
890+ name = "test-agent" ,
891+ extra_headers = {"X-Custom" : "header" },
892+ )
893+
894+ @pytest .mark .asyncio
895+ async def test_create_from_npm_raises_when_source_provided (self , mock_async_client : AsyncMock ) -> None :
896+ """Test create_from_npm raises ValueError when source is provided in params."""
897+ client = AsyncAgentOps (mock_async_client )
898+
899+ with pytest .raises (ValueError , match = "Cannot specify 'source' when using create_from_npm" ):
900+ await client .create_from_npm (
901+ name = "test-agent" ,
902+ package_name = "@runloop/example-agent" ,
903+ source = {"type" : "git" , "git" : {"repository" : "https://github.com/example/repo" }},
904+ )
905+
906+ @pytest .mark .asyncio
907+ async def test_create_from_pip (self , mock_async_client : AsyncMock , agent_view : MockAgentView ) -> None :
908+ """Test create_from_pip factory method."""
909+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
910+
911+ client = AsyncAgentOps (mock_async_client )
912+ agent = await client .create_from_pip (
913+ name = "test-agent" ,
914+ package_name = "runloop-example-agent" ,
915+ )
916+
917+ assert isinstance (agent , AsyncAgent )
918+ assert agent .id == "agent_123"
919+ mock_async_client .agents .create .assert_awaited_once_with (
920+ source = {
921+ "type" : "pip" ,
922+ "pip" : {
923+ "package_name" : "runloop-example-agent" ,
924+ },
925+ },
926+ name = "test-agent" ,
927+ )
928+
929+ @pytest .mark .asyncio
930+ async def test_create_from_pip_with_all_options (
931+ self , mock_async_client : AsyncMock , agent_view : MockAgentView
932+ ) -> None :
933+ """Test create_from_pip factory method with all optional parameters."""
934+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
935+
936+ client = AsyncAgentOps (mock_async_client )
937+ agent = await client .create_from_pip (
938+ name = "test-agent" ,
939+ package_name = "runloop-example-agent" ,
940+ pip_version = "1.2.3" ,
941+ registry_url = "https://pypi.example.com" ,
942+ agent_setup = ["pip install extra-deps" ],
943+ )
944+
945+ assert isinstance (agent , AsyncAgent )
946+ assert agent .id == "agent_123"
947+ mock_async_client .agents .create .assert_awaited_once_with (
948+ source = {
949+ "type" : "pip" ,
950+ "pip" : {
951+ "package_name" : "runloop-example-agent" ,
952+ "pip_version" : "1.2.3" ,
953+ "registry_url" : "https://pypi.example.com" ,
954+ "agent_setup" : ["pip install extra-deps" ],
955+ },
956+ },
957+ name = "test-agent" ,
958+ )
959+
960+ @pytest .mark .asyncio
961+ async def test_create_from_git (self , mock_async_client : AsyncMock , agent_view : MockAgentView ) -> None :
962+ """Test create_from_git factory method."""
963+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
964+
965+ client = AsyncAgentOps (mock_async_client )
966+ agent = await client .create_from_git (
967+ name = "test-agent" ,
968+ repository = "https://github.com/example/agent-repo" ,
969+ )
970+
971+ assert isinstance (agent , AsyncAgent )
972+ assert agent .id == "agent_123"
973+ mock_async_client .agents .create .assert_awaited_once_with (
974+ source = {
975+ "type" : "git" ,
976+ "git" : {
977+ "repository" : "https://github.com/example/agent-repo" ,
978+ },
979+ },
980+ name = "test-agent" ,
981+ )
982+
983+ @pytest .mark .asyncio
984+ async def test_create_from_git_with_all_options (
985+ self , mock_async_client : AsyncMock , agent_view : MockAgentView
986+ ) -> None :
987+ """Test create_from_git factory method with all optional parameters."""
988+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
989+
990+ client = AsyncAgentOps (mock_async_client )
991+ agent = await client .create_from_git (
992+ name = "test-agent" ,
993+ repository = "https://github.com/example/agent-repo" ,
994+ ref = "develop" ,
995+ agent_setup = ["npm install" , "npm run build" ],
996+ )
997+
998+ assert isinstance (agent , AsyncAgent )
999+ assert agent .id == "agent_123"
1000+ mock_async_client .agents .create .assert_awaited_once_with (
1001+ source = {
1002+ "type" : "git" ,
1003+ "git" : {
1004+ "repository" : "https://github.com/example/agent-repo" ,
1005+ "ref" : "develop" ,
1006+ "agent_setup" : ["npm install" , "npm run build" ],
1007+ },
1008+ },
1009+ name = "test-agent" ,
1010+ )
1011+
1012+ @pytest .mark .asyncio
1013+ async def test_create_from_object (self , mock_async_client : AsyncMock , agent_view : MockAgentView ) -> None :
1014+ """Test create_from_object factory method."""
1015+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
1016+
1017+ client = AsyncAgentOps (mock_async_client )
1018+ agent = await client .create_from_object (
1019+ name = "test-agent" ,
1020+ object_id = "obj_123" ,
1021+ )
1022+
1023+ assert isinstance (agent , AsyncAgent )
1024+ assert agent .id == "agent_123"
1025+ mock_async_client .agents .create .assert_awaited_once_with (
1026+ source = {
1027+ "type" : "object" ,
1028+ "object" : {
1029+ "object_id" : "obj_123" ,
1030+ },
1031+ },
1032+ name = "test-agent" ,
1033+ )
1034+
1035+ @pytest .mark .asyncio
1036+ async def test_create_from_object_with_agent_setup (
1037+ self , mock_async_client : AsyncMock , agent_view : MockAgentView
1038+ ) -> None :
1039+ """Test create_from_object factory method with agent_setup."""
1040+ mock_async_client .agents .create = AsyncMock (return_value = agent_view )
1041+
1042+ client = AsyncAgentOps (mock_async_client )
1043+ agent = await client .create_from_object (
1044+ name = "test-agent" ,
1045+ object_id = "obj_123" ,
1046+ agent_setup = ["chmod +x setup.sh" , "./setup.sh" ],
1047+ )
1048+
1049+ assert isinstance (agent , AsyncAgent )
1050+ assert agent .id == "agent_123"
1051+ mock_async_client .agents .create .assert_awaited_once_with (
1052+ source = {
1053+ "type" : "object" ,
1054+ "object" : {
1055+ "object_id" : "obj_123" ,
1056+ "agent_setup" : ["chmod +x setup.sh" , "./setup.sh" ],
1057+ },
1058+ },
1059+ name = "test-agent" ,
1060+ )
1061+
8381062
8391063class TestAsyncRunloopSDK :
8401064 """Tests for AsyncRunloopSDK class."""
0 commit comments