Skip to content

Commit e989bb4

Browse files
committed
fix: remove worker dependency on plugins/config.yaml
Signed-off-by: habeck <habeck@us.ibm.com>
1 parent 77dae5c commit e989bb4

2 files changed

Lines changed: 3 additions & 83 deletions

File tree

cpex/framework/isolated/worker.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from cpex.framework.loader.config import ConfigLoader
2626
from cpex.framework.loader.plugin import ALLOWED_PLUGIN_DIRS
2727
from cpex.framework.manager import PluginExecutor
28-
from cpex.framework.models import PluginContext
28+
from cpex.framework.models import PluginConfig, PluginContext
2929
from cpex.framework.utils import parse_class_name
3030

3131
logger = logging.getLogger(__name__)
@@ -71,25 +71,6 @@ def get_environment_info():
7171
"installed_packages": [str(d) for d in importlib.metadata.entry_points()][:10], # First 10 packages
7272
}
7373

74-
75-
def get_proper_config(name):
76-
"""
77-
Load a config which has all it's proper decorations
78-
"""
79-
plugin_config_file = os.environ.get("PLUGINS_CONFIG_FILE", "plugins/config.yaml")
80-
plugin_loader_config = ConfigLoader.load_config(Path(plugin_config_file).resolve(), use_jinja=False)
81-
plugins: list[dict] = []
82-
config = None
83-
if plugin_loader_config.plugins:
84-
for plug in plugin_loader_config.plugins:
85-
plugins.append(plug.model_dump())
86-
if plug.name == name:
87-
# config = plug.model_dump()
88-
config = plug
89-
return config
90-
return None
91-
92-
9374
async def process_task(task_data, tp: TaskProcessor):
9475
"""Process the task received from parent."""
9576
task_type = task_data.get("task_type")
@@ -120,7 +101,7 @@ async def process_task(task_data, tp: TaskProcessor):
120101

121102
if tp.config_hash != tp.compute_hash(json_config):
122103
# pull the resolved plugin path and only add the module path if it has the same root
123-
config = get_proper_config(config_raw.get("name"))
104+
config: PluginConfig = PluginConfig(**config_raw)
124105
hook_type = task_data.get(HOOK_TYPE)
125106
cls_name: str = task_data.get("class_name")
126107
mod_name, n_cls_name = parse_class_name(cls_name)

tests/unit/cpex/framework/isolated/test_worker.py

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import pytest
1818

19-
from cpex.framework.isolated.worker import TaskProcessor, get_environment_info, get_proper_config, main, process_task
19+
from cpex.framework.isolated.worker import TaskProcessor, get_environment_info, main, process_task
2020

2121

2222
class TestWorkerFunctions:
@@ -49,47 +49,6 @@ def test_get_environment_info(self):
4949
assert isinstance(info["installed_packages"], list)
5050
assert len(info["installed_packages"]) <= 10 # Limited to first 10
5151

52-
@patch("cpex.framework.isolated.worker.ConfigLoader.load_config")
53-
def test_get_proper_config_found(self, mock_load_config):
54-
"""Test getting proper config when plugin is found."""
55-
# Create mock plugin config
56-
mock_plugin = MagicMock()
57-
mock_plugin.name = "test_plugin"
58-
mock_plugin.model_dump.return_value = {"name": "test_plugin", "kind": "isolated_venv", "config": {}}
59-
60-
mock_config = MagicMock()
61-
mock_config.plugins = [mock_plugin]
62-
mock_load_config.return_value = mock_config
63-
64-
result = get_proper_config("test_plugin")
65-
66-
assert result is not None
67-
assert result.name == "test_plugin"
68-
69-
@patch("cpex.framework.isolated.worker.ConfigLoader.load_config")
70-
def test_get_proper_config_not_found(self, mock_load_config):
71-
"""Test getting proper config when plugin is not found."""
72-
mock_plugin = MagicMock()
73-
mock_plugin.name = "other_plugin"
74-
75-
mock_config = MagicMock()
76-
mock_config.plugins = [mock_plugin]
77-
mock_load_config.return_value = mock_config
78-
79-
result = get_proper_config("test_plugin")
80-
81-
assert result is None
82-
83-
@patch("cpex.framework.isolated.worker.ConfigLoader.load_config")
84-
def test_get_proper_config_no_plugins(self, mock_load_config):
85-
"""Test getting proper config when no plugins exist."""
86-
mock_config = MagicMock()
87-
mock_config.plugins = None
88-
mock_load_config.return_value = mock_config
89-
90-
result = get_proper_config("test_plugin")
91-
92-
assert result is None
9352

9453
@pytest.mark.asyncio
9554
async def test_process_task_info(self):
@@ -154,26 +113,6 @@ async def test_process_task_load_and_run_hook_success(self, mock_executor_class,
154113
mock_executor.execute_plugin.assert_called_once()
155114
self.cleanup_mock_plugin_dirs()
156115

157-
@pytest.mark.asyncio
158-
@patch("cpex.framework.isolated.worker.get_proper_config")
159-
async def test_process_task_load_and_run_hook_no_config(self, mock_get_config):
160-
"""Test processing load_and_run_hook task when config not found."""
161-
mock_get_config.return_value = None
162-
163-
config_dict = {"name": "test_plugin", "kind": "isolated_venv"}
164-
task_data = {
165-
"task_type": "load_and_run_hook",
166-
"config": json.dumps(config_dict),
167-
"class_name": "test_plugin.TestPlugin",
168-
"hook_type": "tool_pre_invoke",
169-
"payload": {},
170-
"context": {"state": {}, "global_context": {}, "metadata": {}},
171-
}
172-
tp = TaskProcessor()
173-
# Should raise an error or return None
174-
with pytest.raises((AttributeError, TypeError)):
175-
await process_task(task_data, tp)
176-
177116
@pytest.mark.asyncio
178117
@patch("cpex.framework.isolated.worker.get_proper_config")
179118
@patch("cpex.framework.isolated.worker.importlib.import_module")

0 commit comments

Comments
 (0)