mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-09 23:36:02 +00:00
refactor(agent-runner): simplify event-first entry path
This commit is contained in:
@@ -1,31 +1,15 @@
|
||||
"""Tests for Pipeline adapter params and prompt packaging."""
|
||||
"""Tests for Query entry adapter params packaging."""
|
||||
from __future__ import annotations
|
||||
|
||||
from langbot.pkg.agent.runner.pipeline_adapter import PipelineAdapter
|
||||
|
||||
|
||||
class FakeMessage:
|
||||
"""Fake prompt/history message."""
|
||||
def __init__(self, content='Hello'):
|
||||
self.content = content
|
||||
self.role = 'user'
|
||||
|
||||
def model_dump(self, mode='json'):
|
||||
return {'role': self.role, 'content': self.content}
|
||||
|
||||
|
||||
class FakePrompt:
|
||||
"""Fake prompt container."""
|
||||
def __init__(self, messages=None):
|
||||
self.messages = messages or []
|
||||
from langbot.pkg.agent.runner.query_entry_adapter import QueryEntryAdapter
|
||||
|
||||
|
||||
class TestBuildParams:
|
||||
"""Tests for PipelineAdapter.build_params filtering."""
|
||||
"""Tests for QueryEntryAdapter.build_params filtering."""
|
||||
|
||||
def test_params_empty_when_no_variables(self):
|
||||
query = type('Query', (), {'variables': None})()
|
||||
assert PipelineAdapter.build_params(query) == {}
|
||||
assert QueryEntryAdapter.build_params(query) == {}
|
||||
|
||||
def test_params_filters_underscore_prefix(self):
|
||||
query = type('Query', (), {
|
||||
@@ -37,7 +21,7 @@ class TestBuildParams:
|
||||
},
|
||||
})()
|
||||
|
||||
params = PipelineAdapter.build_params(query)
|
||||
params = QueryEntryAdapter.build_params(query)
|
||||
assert '_internal_var' not in params
|
||||
assert '_pipeline_bound_plugins' not in params
|
||||
assert '_monitoring_bot_name' not in params
|
||||
@@ -61,7 +45,7 @@ class TestBuildParams:
|
||||
},
|
||||
})()
|
||||
|
||||
params = PipelineAdapter.build_params(query)
|
||||
params = QueryEntryAdapter.build_params(query)
|
||||
assert 'api_key' not in params
|
||||
assert 'API_KEY' not in params
|
||||
assert 'token' not in params
|
||||
@@ -89,7 +73,7 @@ class TestBuildParams:
|
||||
},
|
||||
})()
|
||||
|
||||
params = PipelineAdapter.build_params(query)
|
||||
params = QueryEntryAdapter.build_params(query)
|
||||
assert params['launcher_type'] == 'telegram'
|
||||
assert params['launcher_id'] == 'group_123'
|
||||
assert params['sender_id'] == 'user_001'
|
||||
@@ -116,7 +100,7 @@ class TestBuildParams:
|
||||
},
|
||||
})()
|
||||
|
||||
params = PipelineAdapter.build_params(query)
|
||||
params = QueryEntryAdapter.build_params(query)
|
||||
assert 'string_value' in params
|
||||
assert 'int_value' in params
|
||||
assert 'float_value' in params
|
||||
@@ -139,41 +123,40 @@ class TestBuildParams:
|
||||
},
|
||||
})()
|
||||
|
||||
params = PipelineAdapter.build_params(query)
|
||||
params = QueryEntryAdapter.build_params(query)
|
||||
assert 'nested_list_with_bad' not in params
|
||||
assert 'nested_dict_with_bad' not in params
|
||||
assert 'good_nested_list' in params
|
||||
assert 'good_nested_dict' in params
|
||||
|
||||
def test_is_json_serializable_primitives_and_collections(self):
|
||||
assert PipelineAdapter.is_json_serializable(None) is True
|
||||
assert PipelineAdapter.is_json_serializable('string') is True
|
||||
assert PipelineAdapter.is_json_serializable(42) is True
|
||||
assert PipelineAdapter.is_json_serializable(['a', 'b']) is True
|
||||
assert PipelineAdapter.is_json_serializable({'key': 'value'}) is True
|
||||
assert PipelineAdapter.is_json_serializable((1, 2, 3)) is True
|
||||
assert QueryEntryAdapter.is_json_serializable(None) is True
|
||||
assert QueryEntryAdapter.is_json_serializable('string') is True
|
||||
assert QueryEntryAdapter.is_json_serializable(42) is True
|
||||
assert QueryEntryAdapter.is_json_serializable(['a', 'b']) is True
|
||||
assert QueryEntryAdapter.is_json_serializable({'key': 'value'}) is True
|
||||
assert QueryEntryAdapter.is_json_serializable((1, 2, 3)) is True
|
||||
|
||||
def test_is_json_serializable_rejects_sets_and_objects(self):
|
||||
class CustomObject:
|
||||
pass
|
||||
|
||||
assert PipelineAdapter.is_json_serializable(CustomObject()) is False
|
||||
assert PipelineAdapter.is_json_serializable({1, 2, 3}) is False
|
||||
assert PipelineAdapter.is_json_serializable([1, {2, 3}]) is False
|
||||
assert PipelineAdapter.is_json_serializable({'key': {1, 2}}) is False
|
||||
assert QueryEntryAdapter.is_json_serializable(CustomObject()) is False
|
||||
assert QueryEntryAdapter.is_json_serializable({1, 2, 3}) is False
|
||||
assert QueryEntryAdapter.is_json_serializable([1, {2, 3}]) is False
|
||||
assert QueryEntryAdapter.is_json_serializable({'key': {1, 2}}) is False
|
||||
|
||||
|
||||
class TestBuildPrompt:
|
||||
"""Tests for PipelineAdapter.build_prompt."""
|
||||
class TestBuildAdapterContext:
|
||||
"""Tests for QueryEntryAdapter.build_adapter_context."""
|
||||
|
||||
def test_prompt_empty_when_missing(self):
|
||||
query = type('Query', (), {})()
|
||||
assert PipelineAdapter.build_prompt(query) == []
|
||||
|
||||
def test_prompt_serializes_messages(self):
|
||||
def test_adapter_context_does_not_push_prompt(self):
|
||||
query = type('Query', (), {
|
||||
'prompt': FakePrompt([FakeMessage('Effective prompt')]),
|
||||
'variables': {},
|
||||
'query_id': 123,
|
||||
'prompt': object(),
|
||||
})()
|
||||
|
||||
prompt = PipelineAdapter.build_prompt(query)
|
||||
assert prompt == [{'role': 'user', 'content': 'Effective prompt'}]
|
||||
context = QueryEntryAdapter.build_adapter_context(query, binding=None)
|
||||
|
||||
assert context == {'params': {}, 'query_id': 123}
|
||||
|
||||
Reference in New Issue
Block a user