mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-22 12:26:08 +00:00
feat(lark): add functions for current input definitions and visible form content handling
feat(qqofficial): update fallback text handling for non-streaming scenarios feat(difysvapi): enhance form content processing for interactive fields and actions test: add unit tests for Lark and QQ Official adapter functionalities
This commit is contained in:
@@ -1,12 +1,97 @@
|
||||
"""Tests for Lark adapter helper behavior."""
|
||||
|
||||
from langbot.pkg.platform.sources.lark import (
|
||||
LarkAdapter,
|
||||
_lark_clean_form_content,
|
||||
_lark_completed_input_lines,
|
||||
_lark_current_input_defs,
|
||||
_lark_extract_action_form_inputs,
|
||||
_lark_should_update_stream_element,
|
||||
_lark_visible_form_content,
|
||||
)
|
||||
|
||||
|
||||
def test_lark_current_input_defs_only_returns_active_stage():
|
||||
input_defs = [
|
||||
{'output_variable_name': 'us_input', 'type': 'paragraph'},
|
||||
{'output_variable_name': 'xiala', 'type': 'select'},
|
||||
]
|
||||
|
||||
assert _lark_current_input_defs(
|
||||
{
|
||||
'_current_input_field': 'xiala',
|
||||
'input_defs': input_defs,
|
||||
}
|
||||
) == [input_defs[1]]
|
||||
assert (
|
||||
_lark_current_input_defs(
|
||||
{
|
||||
'_action_select_only': True,
|
||||
'input_defs': input_defs,
|
||||
}
|
||||
)
|
||||
== []
|
||||
)
|
||||
|
||||
|
||||
def test_lark_form_field_elements_only_render_active_stage():
|
||||
adapter = LarkAdapter.model_construct()
|
||||
form_data = {
|
||||
'_current_input_field': 'xiala',
|
||||
'input_defs': [
|
||||
{'output_variable_name': 'us_input', 'type': 'paragraph'},
|
||||
{
|
||||
'output_variable_name': 'xiala',
|
||||
'type': 'select',
|
||||
'option_source': {'type': 'constant', 'value': ['1', '2']},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
elements, input_name_map, file_help_lines = adapter._build_lark_form_field_elements(form_data)
|
||||
|
||||
assert len(elements) == 1
|
||||
assert elements[0]['tag'] == 'select_static'
|
||||
assert elements[0]['label']['content'] == 'xiala'
|
||||
assert list(input_name_map.values()) == ['xiala']
|
||||
assert file_help_lines == []
|
||||
|
||||
|
||||
def test_lark_form_stage_skips_closed_streaming_element_update():
|
||||
assert not _lark_should_update_stream_element(
|
||||
resume_from=False,
|
||||
form_data={'_current_input_field': 'xiala'},
|
||||
msg_seq=1,
|
||||
is_final=True,
|
||||
)
|
||||
assert _lark_should_update_stream_element(
|
||||
resume_from=False,
|
||||
form_data=None,
|
||||
msg_seq=1,
|
||||
is_final=True,
|
||||
)
|
||||
|
||||
|
||||
def test_lark_final_action_stage_interleaves_prompts_and_completed_values():
|
||||
form_content = _lark_visible_form_content(
|
||||
{
|
||||
'_action_select_only': True,
|
||||
'raw_form_content': ('11\nQuestion\n{{#$output.us_input#}}\nChoose an answer\n{{#$output.xiala#}}\n'),
|
||||
'all_input_defs': [
|
||||
{'output_variable_name': 'us_input', 'type': 'paragraph'},
|
||||
{'output_variable_name': 'xiala', 'type': 'select'},
|
||||
],
|
||||
'inputs': {'us_input': 'hello', 'xiala': '2'},
|
||||
}
|
||||
)
|
||||
|
||||
assert '{{#$output.' not in form_content
|
||||
assert form_content.startswith('11\nQuestion')
|
||||
assert form_content.index('Question') < form_content.index('us_input')
|
||||
assert form_content.index('us_input') < form_content.index('Choose an answer')
|
||||
assert form_content.index('Choose an answer') < form_content.index('xiala')
|
||||
|
||||
|
||||
def test_lark_completed_input_lines_include_text_select_and_files():
|
||||
lines = _lark_completed_input_lines(
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user