mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-06 20:15:17 +02:00
refactor(agents): move skills/, plugins/, plugin_loader to app/agents/shared (slice 7)
- skills/ (builtin SKILL.md assets) has zero Python importers; it is read by filesystem path only. Moved the dir and restored skills_backends._default_builtin_root() to the clean parent.parent / "skills" / "builtin" form (undoing the transient path from 5c). - plugin_loader.py -> shared (frozen chat_deepagent uses it -> re-export shim). - plugins/ package -> shared (year_substituter rewired to shared.plugin_loader; docstring entry-point example updated to the shared dotted path). No shim needed (only a test imported it). Plugin discovery is via importlib entry points (group "surfsense.plugins"), not dotted-path import, and nothing is registered in pyproject, so the move does not affect runtime discovery.
This commit is contained in:
parent
aab95b9130
commit
13a96851ef
14 changed files with 182 additions and 167 deletions
|
|
@ -6,13 +6,13 @@ from unittest.mock import MagicMock, patch
|
|||
|
||||
from langchain.agents.middleware import AgentMiddleware
|
||||
|
||||
from app.agents.new_chat.plugin_loader import (
|
||||
from app.agents.shared.plugin_loader import (
|
||||
PLUGIN_ENTRY_POINT_GROUP,
|
||||
PluginContext,
|
||||
load_allowed_plugin_names_from_env,
|
||||
load_plugin_middlewares,
|
||||
)
|
||||
from app.agents.new_chat.plugins.year_substituter import (
|
||||
from app.agents.shared.plugins.year_substituter import (
|
||||
_YearSubstituterMiddleware,
|
||||
make_middleware as year_substituter_factory,
|
||||
)
|
||||
|
|
@ -66,7 +66,7 @@ class TestPluginLoaderBasics:
|
|||
|
||||
ep = _FakeEntryPoint("dangerous_plugin", factory)
|
||||
with patch(
|
||||
"app.agents.new_chat.plugin_loader.entry_points",
|
||||
"app.agents.shared.plugin_loader.entry_points",
|
||||
return_value=[ep],
|
||||
):
|
||||
result = load_plugin_middlewares(
|
||||
|
|
@ -78,7 +78,7 @@ class TestPluginLoaderBasics:
|
|||
def test_loads_allowlisted_plugin(self) -> None:
|
||||
ep = _FakeEntryPoint("year_substituter", year_substituter_factory)
|
||||
with patch(
|
||||
"app.agents.new_chat.plugin_loader.entry_points",
|
||||
"app.agents.shared.plugin_loader.entry_points",
|
||||
return_value=[ep],
|
||||
):
|
||||
result = load_plugin_middlewares(
|
||||
|
|
@ -95,7 +95,7 @@ class TestPluginLoaderIsolation:
|
|||
|
||||
ep = _FakeEntryPoint("buggy", crashing_factory)
|
||||
with patch(
|
||||
"app.agents.new_chat.plugin_loader.entry_points",
|
||||
"app.agents.shared.plugin_loader.entry_points",
|
||||
return_value=[ep],
|
||||
):
|
||||
result = load_plugin_middlewares(_ctx(), allowed_plugin_names={"buggy"})
|
||||
|
|
@ -107,7 +107,7 @@ class TestPluginLoaderIsolation:
|
|||
|
||||
ep = _FakeEntryPoint("liar", bad_factory)
|
||||
with patch(
|
||||
"app.agents.new_chat.plugin_loader.entry_points",
|
||||
"app.agents.shared.plugin_loader.entry_points",
|
||||
return_value=[ep],
|
||||
):
|
||||
result = load_plugin_middlewares(_ctx(), allowed_plugin_names={"liar"})
|
||||
|
|
@ -121,7 +121,7 @@ class TestPluginLoaderIsolation:
|
|||
raise ImportError("cannot import")
|
||||
|
||||
with patch(
|
||||
"app.agents.new_chat.plugin_loader.entry_points",
|
||||
"app.agents.shared.plugin_loader.entry_points",
|
||||
return_value=[_BrokenEP()],
|
||||
):
|
||||
result = load_plugin_middlewares(_ctx(), allowed_plugin_names={"broken"})
|
||||
|
|
@ -137,7 +137,7 @@ class TestPluginLoaderIsolation:
|
|||
_FakeEntryPoint("crashing", crashing_factory),
|
||||
_FakeEntryPoint("ok", year_substituter_factory),
|
||||
]
|
||||
with patch("app.agents.new_chat.plugin_loader.entry_points", return_value=eps):
|
||||
with patch("app.agents.shared.plugin_loader.entry_points", return_value=eps):
|
||||
result = load_plugin_middlewares(
|
||||
_ctx(), allowed_plugin_names={"crashing", "ok"}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue