2222class TestWorkerFunctions :
2323 """Test suite for worker.py functions."""
2424
25+ @pytest .fixture
26+ def mock_plugin_dirs (self , tmp_path ):
27+ """ensure that the plugins directory exists"""
28+ plugin_dirs = tmp_path / "plugins"
29+ tmp = Path (plugin_dirs )
30+ tmp .mkdir (parents = True , exist_ok = True )
31+ return [str (plugin_dirs .resolve ())]
32+
2533 def test_get_environment_info (self ):
2634 """Test getting environment information."""
2735 info = get_environment_info ()
@@ -48,7 +56,7 @@ def test_get_proper_config_found(self, mock_load_config):
4856 mock_config .plugins = [mock_plugin ]
4957 mock_load_config .return_value = mock_config
5058
51- result = get_proper_config ("test_plugin" , "plugins" )
59+ result = get_proper_config ("test_plugin" )
5260
5361 assert result is not None
5462 assert result .name == "test_plugin"
@@ -63,7 +71,7 @@ def test_get_proper_config_not_found(self, mock_load_config):
6371 mock_config .plugins = [mock_plugin ]
6472 mock_load_config .return_value = mock_config
6573
66- result = get_proper_config ("test_plugin" , "plugins" )
74+ result = get_proper_config ("test_plugin" )
6775
6876 assert result is None
6977
@@ -74,7 +82,7 @@ def test_get_proper_config_no_plugins(self, mock_load_config):
7482 mock_config .plugins = None
7583 mock_load_config .return_value = mock_config
7684
77- result = get_proper_config ("test_plugin" , "plugins" )
85+ result = get_proper_config ("test_plugin" )
7886
7987 assert result is None
8088
@@ -95,7 +103,7 @@ async def test_process_task_info(self):
95103 @patch ("cpex.framework.isolated.worker.get_proper_config" )
96104 @patch ("cpex.framework.isolated.worker.importlib.import_module" )
97105 @patch ("cpex.framework.isolated.worker.PluginExecutor" )
98- async def test_process_task_load_and_run_hook_success (self , mock_executor_class , mock_import , mock_get_config ):
106+ async def test_process_task_load_and_run_hook_success (self , mock_executor_class , mock_import , mock_get_config , mock_plugin_dirs ):
99107 """Test processing load_and_run_hook task successfully."""
100108 # Setup mock config
101109 mock_config = MagicMock ()
@@ -127,7 +135,7 @@ async def test_process_task_load_and_run_hook_success(self, mock_executor_class,
127135 task_data = {
128136 "task_type" : "load_and_run_hook" ,
129137 "config" : json .dumps (config_dict ),
130- "script_path " : "plugins" ,
138+ "plugin_dirs " : mock_plugin_dirs ,
131139 "class_name" : "test_plugin.TestPlugin" ,
132140 "hook_type" : "tool_pre_invoke" ,
133141 "payload" : {"name" : "test_tool" , "args" : {}},
@@ -150,7 +158,6 @@ async def test_process_task_load_and_run_hook_no_config(self, mock_get_config):
150158 task_data = {
151159 "task_type" : "load_and_run_hook" ,
152160 "config" : json .dumps (config_dict ),
153- "script_path" : "plugins" ,
154161 "class_name" : "test_plugin.TestPlugin" ,
155162 "hook_type" : "tool_pre_invoke" ,
156163 "payload" : {},
@@ -164,7 +171,7 @@ async def test_process_task_load_and_run_hook_no_config(self, mock_get_config):
164171 @pytest .mark .asyncio
165172 @patch ("cpex.framework.isolated.worker.get_proper_config" )
166173 @patch ("cpex.framework.isolated.worker.importlib.import_module" )
167- async def test_process_task_load_and_run_hook_import_error (self , mock_import , mock_get_config ):
174+ async def test_process_task_load_and_run_hook_import_error (self , mock_import , mock_get_config , mock_plugin_dirs ):
168175 """Test processing load_and_run_hook task with import error."""
169176 mock_config = MagicMock ()
170177 mock_get_config .return_value = mock_config
@@ -175,8 +182,8 @@ async def test_process_task_load_and_run_hook_import_error(self, mock_import, mo
175182 task_data = {
176183 "task_type" : "load_and_run_hook" ,
177184 "config" : json .dumps (config_dict ),
178- "script_path" : "plugins" ,
179185 "class_name" : "test_plugin.TestPlugin" ,
186+ "plugin_dirs" : mock_plugin_dirs ,
180187 "hook_type" : "tool_pre_invoke" ,
181188 "payload" : {},
182189 "context" : {"state" : {}, "global_context" : {}, "metadata" : {}},
@@ -189,7 +196,7 @@ async def test_process_task_load_and_run_hook_import_error(self, mock_import, mo
189196 @patch ("cpex.framework.isolated.worker.get_proper_config" )
190197 @patch ("cpex.framework.isolated.worker.importlib.import_module" )
191198 @patch ("cpex.framework.isolated.worker.PluginExecutor" )
192- async def test_process_task_with_different_hook_types (self , mock_executor_class , mock_import , mock_get_config ):
199+ async def test_process_task_with_different_hook_types (self , mock_executor_class , mock_import , mock_get_config , mock_plugin_dirs ):
193200 """Test processing tasks with different hook types."""
194201 # Setup mocks
195202 mock_config = MagicMock ()
@@ -222,7 +229,7 @@ async def test_process_task_with_different_hook_types(self, mock_executor_class,
222229 task_data = {
223230 "task_type" : "load_and_run_hook" ,
224231 "config" : json .dumps (config_dict ),
225- "script_path " : "plugins" ,
232+ "plugin_dirs " : mock_plugin_dirs ,
226233 "class_name" : "test_plugin.TestPlugin" ,
227234 "hook_type" : hook_type ,
228235 "payload" : {},
@@ -244,7 +251,7 @@ async def test_process_task_unknown_task_type(self):
244251 @patch ("cpex.framework.isolated.worker.get_proper_config" )
245252 @patch ("cpex.framework.isolated.worker.importlib.import_module" )
246253 @patch ("cpex.framework.isolated.worker.PluginExecutor" )
247- async def test_process_task_with_metadata (self , mock_executor_class , mock_import , mock_get_config ):
254+ async def test_process_task_with_metadata (self , mock_executor_class , mock_import , mock_get_config , mock_plugin_dirs ):
248255 """Test processing task with metadata in context."""
249256 mock_config = MagicMock ()
250257 mock_get_config .return_value = mock_config
@@ -273,8 +280,8 @@ async def test_process_task_with_metadata(self, mock_executor_class, mock_import
273280 task_data = {
274281 "task_type" : "load_and_run_hook" ,
275282 "config" : json .dumps (config_dict ),
276- "script_path" : "plugins" ,
277283 "class_name" : "test_plugin.TestPlugin" ,
284+ "plugin_dirs" : mock_plugin_dirs ,
278285 "hook_type" : "tool_pre_invoke" ,
279286 "payload" : {"name" : "test_tool" },
280287 "context" : {
@@ -402,7 +409,6 @@ async def test_main_with_load_and_run_hook_task(self, mock_process_task, mock_pr
402409 task_data = {
403410 "task_type" : "load_and_run_hook" ,
404411 "config" : json .dumps (config_dict ),
405- "script_path" : "plugins" ,
406412 "class_name" : "test_plugin.TestPlugin" ,
407413 "hook_type" : "tool_pre_invoke" ,
408414 "payload" : {"name" : "test_tool" },
0 commit comments