mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-09 12:40:59 +00:00
fix(agent): stabilize post-merge release paths
This commit is contained in:
@@ -30,6 +30,7 @@ from langbot.pkg.agent.runner.binding_resolver import (
|
||||
AgentBindingResolver,
|
||||
AgentBindingResolutionError,
|
||||
)
|
||||
from langbot.pkg.api.http.context import ExecutionContext
|
||||
|
||||
|
||||
class TestQueryToEventEnvelope:
|
||||
@@ -350,9 +351,17 @@ def mock_query():
|
||||
"""Create a mock query for testing."""
|
||||
query = Mock()
|
||||
query.query_id = 123
|
||||
query.query_uuid = None
|
||||
query.workspace_uuid = 'workspace-test'
|
||||
query.bot_uuid = 'bot-uuid-123'
|
||||
query.pipeline_uuid = 'pipeline-uuid-456'
|
||||
query._execution_context = ExecutionContext(
|
||||
instance_uuid='instance-test',
|
||||
workspace_uuid=query.workspace_uuid,
|
||||
placement_generation=1,
|
||||
bot_uuid=query.bot_uuid,
|
||||
pipeline_uuid=query.pipeline_uuid,
|
||||
)
|
||||
query.launcher_type = Mock(value='person')
|
||||
query.launcher_id = 'launcher-123'
|
||||
query.sender_id = 'sender-123'
|
||||
@@ -399,9 +408,17 @@ def mock_query_no_session():
|
||||
"""Create a mock Query without session."""
|
||||
query = Mock()
|
||||
query.query_id = 456
|
||||
query.query_uuid = None
|
||||
query.workspace_uuid = 'workspace-test'
|
||||
query.bot_uuid = 'bot-uuid-456'
|
||||
query.pipeline_uuid = 'pipeline-uuid-789'
|
||||
query._execution_context = ExecutionContext(
|
||||
instance_uuid='instance-test',
|
||||
workspace_uuid=query.workspace_uuid,
|
||||
placement_generation=1,
|
||||
bot_uuid=query.bot_uuid,
|
||||
pipeline_uuid=query.pipeline_uuid,
|
||||
)
|
||||
query.launcher_type = Mock(value='person')
|
||||
query.launcher_id = 'launcher-456'
|
||||
query.sender_id = 'sender-456'
|
||||
|
||||
@@ -1012,8 +1012,22 @@ class TestQueryEntrySessionQueryId:
|
||||
]
|
||||
)
|
||||
ap = FakeApplication(plugin_connector, db_engine)
|
||||
async def build_resource_context(execution_query):
|
||||
from langbot.pkg.provider.tools.loaders.mcp import (
|
||||
_execution_context_from_query,
|
||||
)
|
||||
|
||||
context = _execution_context_from_query(execution_query)
|
||||
assert context.instance_uuid == TEST_CONTEXT.instance_uuid
|
||||
assert context.workspace_uuid == TEST_CONTEXT.workspace_uuid
|
||||
assert context.placement_generation == TEST_CONTEXT.placement_generation
|
||||
assert context.bot_uuid == 'bot_001'
|
||||
return 'Pinned documentation'
|
||||
|
||||
mcp_loader = types.SimpleNamespace(
|
||||
build_resource_context_for_query=AsyncMock(return_value='Pinned documentation')
|
||||
build_resource_context_for_query=AsyncMock(
|
||||
side_effect=build_resource_context
|
||||
)
|
||||
)
|
||||
ap.tool_mgr = types.SimpleNamespace(mcp_tool_loader=mcp_loader)
|
||||
orchestrator = AgentRunOrchestrator(ap, FakeRegistry(descriptor))
|
||||
@@ -1091,6 +1105,14 @@ class TestQueryEntrySessionQueryId:
|
||||
assert 'Pinned documentation' in plugin_connector.contexts[0]['input']['contents'][0]['text']
|
||||
assert event.input.text == 'hello'
|
||||
assert event.input.contents[0].text == 'hello'
|
||||
assert (
|
||||
plugin_connector.contexts[0]['conversation']['workspace_id']
|
||||
== TEST_CONTEXT.workspace_uuid
|
||||
)
|
||||
assert (
|
||||
plugin_connector.contexts[0]['runtime']['metadata']['workspace_id']
|
||||
== TEST_CONTEXT.workspace_uuid
|
||||
)
|
||||
assert 'Pinned documentation' not in str(execution_query.user_message.content)
|
||||
mcp_loader.build_resource_context_for_query.assert_awaited_once_with(execution_query)
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ def make_query(
|
||||
use_llm_model_uuid=None,
|
||||
use_funcs: list | None = None,
|
||||
):
|
||||
return SimpleNamespace(
|
||||
query = SimpleNamespace(
|
||||
query_id=1,
|
||||
bot_uuid='bot_001',
|
||||
launcher_type='person',
|
||||
@@ -85,6 +85,8 @@ def make_query(
|
||||
use_funcs=use_funcs or [],
|
||||
pipeline_uuid='pipeline_001',
|
||||
)
|
||||
query._execution_context = TEST_CONTEXT
|
||||
return query
|
||||
|
||||
|
||||
async def build_resources(app, query, descriptor):
|
||||
|
||||
Reference in New Issue
Block a user