mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-17 18:06:06 +00:00
feat(agent-runner): enforce 4.x host-owned execution
This commit is contained in:
@@ -30,23 +30,9 @@ def mock_circular_import_chain():
|
||||
make_pipeline_handler_import_mocks,
|
||||
get_handler_modules_to_clear,
|
||||
)
|
||||
from langbot_plugin.api.entities.builtin.provider.message import Message
|
||||
|
||||
mocks = make_pipeline_handler_import_mocks()
|
||||
|
||||
# Create a default runner that yields a simple response
|
||||
class DefaultRunner:
|
||||
name = 'local-agent'
|
||||
|
||||
def __init__(self, app, config):
|
||||
self.app = app
|
||||
self.config = config
|
||||
|
||||
async def run(self, query):
|
||||
yield Message(role='assistant', content='fake response')
|
||||
|
||||
mocks['langbot.pkg.provider.runner'].preregistered_runners = [DefaultRunner]
|
||||
|
||||
clear = get_handler_modules_to_clear('chat')
|
||||
|
||||
with isolated_sys_modules(mocks=mocks, clear=clear):
|
||||
@@ -56,22 +42,27 @@ def mock_circular_import_chain():
|
||||
@pytest.fixture
|
||||
def fake_app():
|
||||
"""Create FakeApp instance."""
|
||||
import sys
|
||||
from langbot_plugin.api.entities.builtin.provider.message import Message
|
||||
|
||||
app = FakeApp()
|
||||
|
||||
class FakeAgentRunOrchestrator:
|
||||
runner_class = None
|
||||
|
||||
async def try_claim_steering_from_query(self, query):
|
||||
return False
|
||||
|
||||
async def run_from_query(self, query):
|
||||
runner_cls = sys.modules['langbot.pkg.provider.runner'].preregistered_runners[0]
|
||||
runner = runner_cls(app, {})
|
||||
if self.runner_class is None:
|
||||
yield Message(role='assistant', content='fake response')
|
||||
return
|
||||
|
||||
runner = self.runner_class(app, {})
|
||||
async for result in runner.run(query):
|
||||
yield result
|
||||
|
||||
def resolve_runner_id_for_telemetry(self, query):
|
||||
return 'local-agent'
|
||||
return 'plugin:langbot-team/LocalAgent/default'
|
||||
|
||||
app.agent_run_orchestrator = FakeAgentRunOrchestrator()
|
||||
return app
|
||||
@@ -89,13 +80,11 @@ def mock_event_ctx():
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def set_runner():
|
||||
"""Factory fixture to set a custom runner for tests."""
|
||||
def set_runner(fake_app):
|
||||
"""Configure the orchestrator test double for one test."""
|
||||
|
||||
def _set_runner(runner_class):
|
||||
import sys
|
||||
|
||||
sys.modules['langbot.pkg.provider.runner'].preregistered_runners = [runner_class]
|
||||
fake_app.agent_run_orchestrator.runner_class = runner_class
|
||||
|
||||
return _set_runner
|
||||
|
||||
|
||||
Reference in New Issue
Block a user