fix(pipeline): handle empty longtext response chain (#2197)

This commit is contained in:
huanghuoguoguo
2026-05-16 11:35:20 +08:00
committed by GitHub
parent 27fdccce16
commit 245e798b79
2 changed files with 43 additions and 0 deletions

View File

@@ -76,6 +76,10 @@ class LongTextProcessStage(stage.PipelineStage):
self.ap.logger.debug('Long message processing strategy is not set, skip long message processing.')
return entities.StageProcessResult(result_type=entities.ResultType.CONTINUE, new_query=query)
if not query.resp_message_chain:
self.ap.logger.debug('Response message chain is empty, skip long message processing.')
return entities.StageProcessResult(result_type=entities.ResultType.CONTINUE, new_query=query)
# 检查是否包含非 Plain 组件
contains_non_plain = False

View File

@@ -0,0 +1,39 @@
"""
LongTextProcessStage unit tests
"""
from importlib import import_module
from unittest.mock import AsyncMock
import pytest
def get_modules():
"""Lazy import to ensure proper initialization order"""
longtext = import_module('langbot.pkg.pipeline.longtext.longtext')
entities = import_module('langbot.pkg.pipeline.entities')
return longtext, entities
@pytest.mark.asyncio
async def test_empty_response_message_chain_continues_without_processing(mock_app, sample_query):
"""Empty response chains should be a no-op for long text processing."""
longtext, entities = get_modules()
sample_query.resp_message_chain = []
sample_query.pipeline_config = {
'output': {
'long-text-processing': {
'threshold': 1,
},
},
}
stage = longtext.LongTextProcessStage(mock_app)
stage.strategy_impl = AsyncMock()
result = await stage.process(sample_query, 'LongTextProcessStage')
assert result.result_type == entities.ResultType.CONTINUE
assert result.new_query == sample_query
stage.strategy_impl.process.assert_not_called()