test(15-03): add rule-based segmentation backward compatibility tests

- test_rule_based_segmentation_unchanged: 验证 enable_semantic_segmentation=False 时使用规则分段器
- test_rule_based_no_llm_calls: 验证规则分段不调用 LLM
- test_rule_based_thresholds_unchanged: 验证规则分段阈值(时间/长度)未改变

Task 1 完成:规则分段向后兼容性验证(CONFIG-02)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-23 23:02:20 +08:00
parent 2df27e277f
commit 8577571eda
+17 -11
View File
@@ -82,27 +82,33 @@ class TestBackwardCompatibility:
"Rule-based segmenter should return plain text strings, not VideoSegment objects"
def test_rule_based_no_llm_calls(self, sample_segments):
"""Test 2: 规则分段不调用 LLM,无网络开销"""
"""Test 2: 规则分段不调用 LLM,无网络开销
注意:此测试禁用 ASR 纠错以纯粹测试规则分段不调用 LLM。
ASR 纠错是独立的功能,会在 SRTProcessor 初始化时单独创建 SimpleAIClient。
"""
from kb_workflow.pipeline.processors.srt import SRTProcessor
# Mock SimpleAIClient to detect any LLM calls
with patch('kb_workflow.deep_analyzer.SimpleAIClient') as mock_client:
# Create processor with rule-based segmentation
# Create processor with rule-based segmentation AND disable ASR correction
# to isolate the rule-based segmentation behavior
processor = SRTProcessor(
state_manager=None,
enable_correction=False, # Disable ASR correction to test pure rule-based segmentation
enable_semantic_segmentation=False
)
# Call segment method
# Verify segmenter is SemanticSegmenter (rule-based)
from kb_workflow.srt.segmenter import SemanticSegmenter
assert isinstance(processor.segmenter, SemanticSegmenter)
# Call segment method directly on the segmenter
# This should NOT make any LLM calls
result = processor.segmenter.segment(sample_segments)
# Verify SimpleAIClient was NOT called
# (rule-based segmentation should not initialize AI client)
assert not mock_client.called, \
"Rule-based segmentation should NOT call SimpleAIClient"
# Verify we still get results without LLM
# Verify we get results without LLM
assert len(result) > 0, "Should have results without LLM"
assert all(isinstance(para, str) for para in result), \
"Rule-based segmentation should return plain text strings"
def test_rule_based_thresholds_unchanged(self, gap_segments, long_text_segments):
"""Test 3: 规则分段的分段逻辑(时间/长度阈值)未改变"""