refactor(06-02): update CLI and test imports to kb_workflow.pipeline

- Remove sys.path manipulation from kb_workflow.py
- Update CLI imports to use kb_workflow.pipeline prefix
- Update all test file imports and patch paths

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-17 00:17:10 +08:00
parent fdca690bd6
commit c9ca1b538d
20 changed files with 307 additions and 307 deletions
+25 -25
View File
@@ -5,7 +5,7 @@ Tests that ParseProcessor:
- Parses Zhihu answer URLs correctly
- Returns ParseOutput with success=False for unknown URLs
- Records state when state_manager is provided
- Can be imported from kb_pipeline.processors
- Can be imported from kb_workflow.pipeline.processors
"""
import pytest
@@ -18,10 +18,10 @@ class TestParseProcessorBilibili:
@pytest.mark.asyncio
async def test_parse_bilibili_video_url(self):
"""ParseProcessor 正确解析 Bilibili 视频 URL"""
from kb_pipeline.processors.parse import ParseProcessor
from kb_pipeline.schemas import ParseInput
from kb_workflow.pipeline.processors.parse import ParseProcessor
from kb_workflow.pipeline.schemas import ParseInput
with patch("kb_pipeline.processors.base.get_settings") as mock_settings:
with patch("kb_workflow.pipeline.processors.base.get_settings") as mock_settings:
mock_settings.return_value = MagicMock()
processor = ParseProcessor()
@@ -38,10 +38,10 @@ class TestParseProcessorBilibili:
@pytest.mark.asyncio
async def test_parse_bilibili_article_url(self):
"""ParseProcessor 正确解析 Bilibili 专栏 URL"""
from kb_pipeline.processors.parse import ParseProcessor
from kb_pipeline.schemas import ParseInput
from kb_workflow.pipeline.processors.parse import ParseProcessor
from kb_workflow.pipeline.schemas import ParseInput
with patch("kb_pipeline.processors.base.get_settings") as mock_settings:
with patch("kb_workflow.pipeline.processors.base.get_settings") as mock_settings:
mock_settings.return_value = MagicMock()
processor = ParseProcessor()
@@ -61,10 +61,10 @@ class TestParseProcessorZhihu:
@pytest.mark.asyncio
async def test_parse_zhihu_answer_url(self):
"""ParseProcessor 正确解析 Zhihu 回答 URL"""
from kb_pipeline.processors.parse import ParseProcessor
from kb_pipeline.schemas import ParseInput
from kb_workflow.pipeline.processors.parse import ParseProcessor
from kb_workflow.pipeline.schemas import ParseInput
with patch("kb_pipeline.processors.base.get_settings") as mock_settings:
with patch("kb_workflow.pipeline.processors.base.get_settings") as mock_settings:
mock_settings.return_value = MagicMock()
processor = ParseProcessor()
@@ -80,10 +80,10 @@ class TestParseProcessorZhihu:
@pytest.mark.asyncio
async def test_parse_zhihu_zhuanlan_url(self):
"""ParseProcessor 正确解析 Zhihu 专栏 URL"""
from kb_pipeline.processors.parse import ParseProcessor
from kb_pipeline.schemas import ParseInput
from kb_workflow.pipeline.processors.parse import ParseProcessor
from kb_workflow.pipeline.schemas import ParseInput
with patch("kb_pipeline.processors.base.get_settings") as mock_settings:
with patch("kb_workflow.pipeline.processors.base.get_settings") as mock_settings:
mock_settings.return_value = MagicMock()
processor = ParseProcessor()
@@ -103,10 +103,10 @@ class TestParseProcessorUnknown:
@pytest.mark.asyncio
async def test_parse_unknown_url_returns_failure(self):
"""ParseProcessor 对未知 URL 返回 success=False"""
from kb_pipeline.processors.parse import ParseProcessor
from kb_pipeline.schemas import ParseInput
from kb_workflow.pipeline.processors.parse import ParseProcessor
from kb_workflow.pipeline.schemas import ParseInput
with patch("kb_pipeline.processors.base.get_settings") as mock_settings:
with patch("kb_workflow.pipeline.processors.base.get_settings") as mock_settings:
mock_settings.return_value = MagicMock()
processor = ParseProcessor()
@@ -124,14 +124,14 @@ class TestParseProcessorStateRecording:
@pytest.mark.asyncio
async def test_state_recording_on_success(self):
"""ParseProcessor 成功时记录状态"""
from kb_pipeline.processors.parse import ParseProcessor
from kb_pipeline.schemas import ParseInput, WorkflowState
from kb_workflow.pipeline.processors.parse import ParseProcessor
from kb_workflow.pipeline.schemas import ParseInput, WorkflowState
mock_state_manager = MagicMock()
mock_state = MagicMock(spec=WorkflowState)
mock_state_manager.load.return_value = mock_state
with patch("kb_pipeline.processors.base.get_settings") as mock_settings:
with patch("kb_workflow.pipeline.processors.base.get_settings") as mock_settings:
mock_settings.return_value = MagicMock()
processor = ParseProcessor(state_manager=mock_state_manager)
@@ -147,10 +147,10 @@ class TestParseProcessorStateRecording:
@pytest.mark.asyncio
async def test_no_state_recording_without_manager(self):
"""无 state_manager 时不记录状态"""
from kb_pipeline.processors.parse import ParseProcessor
from kb_pipeline.schemas import ParseInput
from kb_workflow.pipeline.processors.parse import ParseProcessor
from kb_workflow.pipeline.schemas import ParseInput
with patch("kb_pipeline.processors.base.get_settings") as mock_settings:
with patch("kb_workflow.pipeline.processors.base.get_settings") as mock_settings:
mock_settings.return_value = MagicMock()
processor = ParseProcessor(state_manager=None)
@@ -167,18 +167,18 @@ class TestParseProcessorModuleExport:
def test_parse_processor_importable_from_processors(self):
"""ParseProcessor 可以从 kb_pipeline.processors 导入"""
from kb_pipeline.processors import ParseProcessor
from kb_workflow.pipeline.processors import ParseProcessor
assert ParseProcessor is not None
def test_base_processor_importable_from_processors(self):
"""BaseProcessor 可以从 kb_pipeline.processors 导入"""
from kb_pipeline.processors import BaseProcessor
from kb_workflow.pipeline.processors import BaseProcessor
assert BaseProcessor is not None
def test_asr_processor_still_importable(self):
"""ASRProcessor 仍然可以从 kb_pipeline.processors 导入"""
from kb_pipeline.processors import ASRProcessor
from kb_workflow.pipeline.processors import ASRProcessor
assert ASRProcessor is not None