mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-21 07:55:18 +08:00
fix(telemetry): avoid global plugin enumeration in workspace snapshots and support model adapters
This commit is contained in:
@@ -183,6 +183,7 @@ class TestBuildHeartbeatPayload:
|
||||
assert by_workspace['workspace-b']['execution_generation'] == 9
|
||||
assert by_workspace['workspace-b']['adapters'] == ['WorkspaceBAdapter']
|
||||
assert 'workspace_resources' not in by_workspace['workspace-a']
|
||||
ap.plugin_connector.list_plugins.assert_not_awaited()
|
||||
ap.persistence_mgr.execute_async.assert_not_awaited()
|
||||
ap.workspace_service.list_active_execution_bindings.assert_awaited_once()
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel
|
||||
|
||||
from langbot.pkg.telemetry.platform import observe_adapter
|
||||
|
||||
|
||||
class ModelAdapter(BaseModel):
|
||||
def get_supported_apis(self):
|
||||
return ['send_message']
|
||||
|
||||
async def send_message(self):
|
||||
return {'message_id': 'ok'}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_model_adapter_instrumentation_is_instance_local():
|
||||
first, second = ModelAdapter(), ModelAdapter()
|
||||
ap = SimpleNamespace(telemetry=None)
|
||||
observe_adapter(ap, None, first)
|
||||
wrapped = first.send_message
|
||||
observe_adapter(ap, None, first)
|
||||
assert first.send_message is wrapped
|
||||
assert not getattr(second, '_execution_observed', False)
|
||||
assert await first.send_message() == {'message_id': 'ok'}
|
||||
assert await second.send_message() == {'message_id': 'ok'}
|
||||
Reference in New Issue
Block a user