@@ -2892,22 +2892,105 @@ async def fake_db_get(model_class, filters=None, limit=None, order_by=None, sing
28922892 monkeypatch .setattr (real_database_service , "db_get" , fake_db_get )
28932893 monkeypatch .setattr (real_db_models , "DemoTable" , DummyModel , raising = False )
28942894
2895- result = await integration_module .PluginRuntimeManager ._cap_database_get (
2895+ manager = object .__new__ (integration_module .PluginRuntimeManager )
2896+ result = await manager ._cap_database_get (
28962897 "plugin_a" ,
28972898 "database.get" ,
28982899 {
2899- "table " : "DemoTable" ,
2900+ "model_name " : "DemoTable" ,
29002901 "filters" : {"status" : "active" },
29012902 "limit" : 5 ,
29022903 },
29032904 )
29042905
2905- assert result == { "success" : True , "result" : [{"id" : 1 }]}
2906+ assert result == [{"id" : 1 }]
29062907 assert captured ["model_class" ] is DummyModel
29072908 assert captured ["filters" ] == {"status" : "active" }
29082909 assert captured ["limit" ] == 5
29092910 assert captured ["single_result" ] is False
29102911
2912+ @pytest .mark .asyncio
2913+ async def test_cap_database_get_response_is_not_double_wrapped (self , monkeypatch ):
2914+ from src .plugin_runtime import integration as integration_module
2915+ import src .common .database .database_model as real_db_models
2916+ from src .plugin_runtime .host .capability_service import CapabilityService
2917+ from src .plugin_runtime .protocol .envelope import CapabilityRequestPayload , Envelope , MessageType
2918+ from src .services import database_service as real_database_service
2919+
2920+ class AllowAllAuthorization :
2921+ def check_capability (self , plugin_id , capability ):
2922+ return True , ""
2923+
2924+ class DummyModel :
2925+ pass
2926+
2927+ async def fake_db_get (model_class , filters = None , limit = None , order_by = None , single_result = False ):
2928+ return {"id" : 1 , "full_path" : "E:\\ test.png" }
2929+
2930+ monkeypatch .setattr (real_database_service , "db_get" , fake_db_get )
2931+ monkeypatch .setattr (real_db_models , "DemoTable" , DummyModel , raising = False )
2932+
2933+ manager = object .__new__ (integration_module .PluginRuntimeManager )
2934+ service = CapabilityService (AllowAllAuthorization ())
2935+ service .register_capability ("database.get" , manager ._cap_database_get )
2936+
2937+ request = Envelope (
2938+ request_id = 1 ,
2939+ message_type = MessageType .REQUEST ,
2940+ method = "cap.call" ,
2941+ plugin_id = "plugin_a" ,
2942+ payload = CapabilityRequestPayload (
2943+ capability = "database.get" ,
2944+ args = {"model_name" : "DemoTable" , "single_result" : True },
2945+ ).model_dump (),
2946+ )
2947+
2948+ response = await service .handle_capability_request (request )
2949+
2950+ assert response .payload == {
2951+ "success" : True ,
2952+ "result" : {"id" : 1 , "full_path" : "E:\\ test.png" },
2953+ }
2954+
2955+ @pytest .mark .asyncio
2956+ async def test_cap_database_success_handlers_return_raw_results (self , monkeypatch ):
2957+ from src .plugin_runtime import integration as integration_module
2958+ import src .common .database .database_model as real_db_models
2959+ from src .services import database_service as real_database_service
2960+
2961+ class DummyModel :
2962+ pass
2963+
2964+ async def fake_db_get (** kwargs ):
2965+ return [{"id" : 1 }]
2966+
2967+ async def fake_db_save (** kwargs ):
2968+ return {"id" : 2 }
2969+
2970+ async def fake_db_delete (** kwargs ):
2971+ return 3
2972+
2973+ async def fake_db_count (** kwargs ):
2974+ return 4
2975+
2976+ monkeypatch .setattr (real_database_service , "db_get" , fake_db_get )
2977+ monkeypatch .setattr (real_database_service , "db_save" , fake_db_save )
2978+ monkeypatch .setattr (real_database_service , "db_delete" , fake_db_delete )
2979+ monkeypatch .setattr (real_database_service , "db_count" , fake_db_count )
2980+ monkeypatch .setattr (real_db_models , "DemoTable" , DummyModel , raising = False )
2981+
2982+ manager = object .__new__ (integration_module .PluginRuntimeManager )
2983+ base_args = {"model_name" : "DemoTable" }
2984+
2985+ assert await manager ._cap_database_query ("plugin_a" , "database.query" , base_args ) == [{"id" : 1 }]
2986+ assert await manager ._cap_database_save (
2987+ "plugin_a" , "database.save" , {** base_args , "data" : {"name" : "demo" }}
2988+ ) == {"id" : 2 }
2989+ assert await manager ._cap_database_delete (
2990+ "plugin_a" , "database.delete" , {** base_args , "filters" : {"id" : 2 }}
2991+ ) == 3
2992+ assert await manager ._cap_database_count ("plugin_a" , "database.count" , base_args ) == 4
2993+
29112994 @pytest .mark .asyncio
29122995 async def test_component_enable_rejects_ambiguous_short_name (self , monkeypatch ):
29132996 from src .plugin_runtime import integration as integration_module
0 commit comments