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
+43 -43
View File
@@ -13,7 +13,7 @@ class TestStepInput:
def test_step_input_requires_content_id(self):
"""StepInput 必须包含 content_id 字段"""
from kb_pipeline.schemas import StepInput
from kb_workflow.pipeline.schemas import StepInput
with pytest.raises(ValidationError) as exc_info:
StepInput(platform="bilibili")
@@ -22,7 +22,7 @@ class TestStepInput:
def test_step_input_requires_platform(self):
"""StepInput 必须包含 platform 字段"""
from kb_pipeline.schemas import StepInput
from kb_workflow.pipeline.schemas import StepInput
with pytest.raises(ValidationError) as exc_info:
StepInput(content_id="BV1test123")
@@ -31,7 +31,7 @@ class TestStepInput:
def test_step_input_validates_platform_literal(self):
"""StepInput platform 必须是 bilibili 或 zhihu"""
from kb_pipeline.schemas import StepInput
from kb_workflow.pipeline.schemas import StepInput
# 有效值
step_bilibili = StepInput(content_id="BV1test", platform="bilibili")
@@ -46,7 +46,7 @@ class TestStepInput:
def test_step_input_content_id_non_empty(self):
"""StepInput content_id 不能为空字符串"""
from kb_pipeline.schemas import StepInput
from kb_workflow.pipeline.schemas import StepInput
with pytest.raises(ValidationError):
StepInput(content_id="", platform="bilibili")
@@ -57,7 +57,7 @@ class TestStepOutput:
def test_step_output_requires_success(self):
"""StepOutput 必须包含 success 字段"""
from kb_pipeline.schemas import StepOutput
from kb_workflow.pipeline.schemas import StepOutput
with pytest.raises(ValidationError) as exc_info:
StepOutput()
@@ -66,7 +66,7 @@ class TestStepOutput:
def test_step_output_default_completed_at(self):
"""StepOutput completed_at 默认为当前时间"""
from kb_pipeline.schemas import StepOutput
from kb_workflow.pipeline.schemas import StepOutput
before = datetime.now()
output = StepOutput(success=True)
@@ -76,7 +76,7 @@ class TestStepOutput:
def test_step_output_optional_error_message(self):
"""StepOutput error_message 是可选的"""
from kb_pipeline.schemas import StepOutput
from kb_workflow.pipeline.schemas import StepOutput
output = StepOutput(success=True)
assert output.error_message is None
@@ -90,31 +90,31 @@ class TestStepStatus:
def test_step_status_has_pending(self):
"""StepStatus 包含 PENDING 状态"""
from kb_pipeline.schemas import StepStatus
from kb_workflow.pipeline.schemas import StepStatus
assert StepStatus.PENDING.value == "pending"
def test_step_status_has_running(self):
"""StepStatus 包含 RUNNING 状态"""
from kb_pipeline.schemas import StepStatus
from kb_workflow.pipeline.schemas import StepStatus
assert StepStatus.RUNNING.value == "running"
def test_step_status_has_completed(self):
"""StepStatus 包含 COMPLETED 状态"""
from kb_pipeline.schemas import StepStatus
from kb_workflow.pipeline.schemas import StepStatus
assert StepStatus.COMPLETED.value == "completed"
def test_step_status_has_failed(self):
"""StepStatus 包含 FAILED 状态"""
from kb_pipeline.schemas import StepStatus
from kb_workflow.pipeline.schemas import StepStatus
assert StepStatus.FAILED.value == "failed"
def test_step_status_has_skipped(self):
"""StepStatus 包含 SKIPPED 状态"""
from kb_pipeline.schemas import StepStatus
from kb_workflow.pipeline.schemas import StepStatus
assert StepStatus.SKIPPED.value == "skipped"
@@ -124,21 +124,21 @@ class TestStepRecord:
def test_step_record_requires_step_name(self):
"""StepRecord 必须包含 step_name"""
from kb_pipeline.schemas import StepRecord, StepStatus
from kb_workflow.pipeline.schemas import StepRecord, StepStatus
with pytest.raises(ValidationError):
StepRecord(status=StepStatus.COMPLETED)
def test_step_record_requires_status(self):
"""StepRecord 必须包含 status"""
from kb_pipeline.schemas import StepRecord
from kb_workflow.pipeline.schemas import StepRecord
with pytest.raises(ValidationError):
StepRecord(step_name="fetch_metadata")
def test_step_record_optional_fields(self):
"""StepRecord 可选字段正确工作"""
from kb_pipeline.schemas import StepRecord, StepStatus
from kb_workflow.pipeline.schemas import StepRecord, StepStatus
record = StepRecord(step_name="fetch_metadata", status=StepStatus.COMPLETED)
assert record.started_at is None
@@ -152,28 +152,28 @@ class TestWorkflowState:
def test_workflow_state_requires_content_id(self):
"""WorkflowState 必须包含 content_id"""
from kb_pipeline.schemas import WorkflowState
from kb_workflow.pipeline.schemas import WorkflowState
with pytest.raises(ValidationError):
WorkflowState(platform="bilibili", source_url="https://test.com")
def test_workflow_state_requires_platform(self):
"""WorkflowState 必须包含 platform"""
from kb_pipeline.schemas import WorkflowState
from kb_workflow.pipeline.schemas import WorkflowState
with pytest.raises(ValidationError):
WorkflowState(content_id="BV1test", source_url="https://test.com")
def test_workflow_state_requires_source_url(self):
"""WorkflowState 必须包含 source_url"""
from kb_pipeline.schemas import WorkflowState
from kb_workflow.pipeline.schemas import WorkflowState
with pytest.raises(ValidationError):
WorkflowState(content_id="BV1test", platform="bilibili")
def test_workflow_state_has_steps_dict(self):
"""WorkflowState 包含 steps 字典"""
from kb_pipeline.schemas import WorkflowState
from kb_workflow.pipeline.schemas import WorkflowState
state = WorkflowState(
content_id="BV1test",
@@ -185,7 +185,7 @@ class TestWorkflowState:
def test_workflow_state_default_schema_version(self):
"""WorkflowState schema_version 默认为 1.0"""
from kb_pipeline.schemas import WorkflowState
from kb_workflow.pipeline.schemas import WorkflowState
state = WorkflowState(
content_id="BV1test",
@@ -196,7 +196,7 @@ class TestWorkflowState:
def test_workflow_state_is_step_completed_method(self):
"""WorkflowState 有 is_step_completed 方法"""
from kb_pipeline.schemas import WorkflowState, StepStatus, StepRecord
from kb_workflow.pipeline.schemas import WorkflowState, StepStatus, StepRecord
state = WorkflowState(
content_id="BV1test",
@@ -220,7 +220,7 @@ class TestWorkflowStateMethods:
def test_mark_step_started(self):
"""mark_step_started 正确设置步骤状态"""
from kb_pipeline.schemas import WorkflowState, StepStatus
from kb_workflow.pipeline.schemas import WorkflowState, StepStatus
state = WorkflowState(
content_id="BV1test",
@@ -236,7 +236,7 @@ class TestWorkflowStateMethods:
def test_mark_step_completed_existing_step(self):
"""mark_step_completed 更新已存在的步骤"""
from kb_pipeline.schemas import WorkflowState, StepStatus
from kb_workflow.pipeline.schemas import WorkflowState, StepStatus
state = WorkflowState(
content_id="BV1test",
@@ -253,7 +253,7 @@ class TestWorkflowStateMethods:
def test_mark_step_completed_new_step(self):
"""mark_step_completed 创建新步骤记录"""
from kb_pipeline.schemas import WorkflowState, StepStatus
from kb_workflow.pipeline.schemas import WorkflowState, StepStatus
state = WorkflowState(
content_id="BV1test",
@@ -269,7 +269,7 @@ class TestWorkflowStateMethods:
def test_mark_step_failed_existing_step(self):
"""mark_step_failed 更新已存在的步骤为失败"""
from kb_pipeline.schemas import WorkflowState, StepStatus
from kb_workflow.pipeline.schemas import WorkflowState, StepStatus
state = WorkflowState(
content_id="BV1test",
@@ -286,7 +286,7 @@ class TestWorkflowStateMethods:
def test_mark_step_failed_new_step(self):
"""mark_step_failed 创建新的失败步骤记录"""
from kb_pipeline.schemas import WorkflowState, StepStatus
from kb_workflow.pipeline.schemas import WorkflowState, StepStatus
state = WorkflowState(
content_id="BV1test",
@@ -306,7 +306,7 @@ class TestStepResult:
def test_step_result_creation(self):
"""StepResult 正确创建"""
from kb_pipeline.schemas import StepResult, StepInput, StepStatus
from kb_workflow.pipeline.schemas import StepResult, StepInput, StepStatus
input_data = StepInput(content_id="BV1test", platform="bilibili")
result = StepResult(step_name="fetch_metadata", input_data=input_data)
@@ -317,7 +317,7 @@ class TestStepResult:
def test_step_result_with_output(self):
"""StepResult 包含输出数据"""
from kb_pipeline.schemas import StepResult, StepInput, StepOutput, StepStatus
from kb_workflow.pipeline.schemas import StepResult, StepInput, StepOutput, StepStatus
input_data = StepInput(content_id="BV1test", platform="bilibili")
output_data = StepOutput(success=True)
@@ -337,7 +337,7 @@ class TestStepDefinition:
def test_step_definition_creation(self):
"""StepDefinition 正确创建"""
from kb_pipeline.schemas import StepDefinition, StepInput, StepOutput
from kb_workflow.pipeline.schemas import StepDefinition, StepInput, StepOutput
definition = StepDefinition(
step_name="fetch_metadata",
@@ -352,7 +352,7 @@ class TestStepDefinition:
def test_step_definition_with_dependencies(self):
"""StepDefinition 包含依赖"""
from kb_pipeline.schemas import StepDefinition, StepInput, StepOutput
from kb_workflow.pipeline.schemas import StepDefinition, StepInput, StepOutput
definition = StepDefinition(
step_name="transcribe_audio",
@@ -371,14 +371,14 @@ class TestSchemaValidation:
def test_validation_error_on_invalid_input(self):
"""无效输入抛出 ValidationError"""
from kb_pipeline.schemas import StepInput
from kb_workflow.pipeline.schemas import StepInput
with pytest.raises(ValidationError):
StepInput(content_id=123, platform="bilibili") # type: ignore
def test_model_validate_from_dict(self):
"""model_validate 从字典正确创建实例"""
from kb_pipeline.schemas import StepInput
from kb_workflow.pipeline.schemas import StepInput
data = {"content_id": "BV1test", "platform": "bilibili"}
step_input = StepInput.model_validate(data)
@@ -391,7 +391,7 @@ class TestJSONSerialization:
def test_step_input_model_dump_json(self):
"""StepInput 支持 model_dump_json"""
from kb_pipeline.schemas import StepInput
from kb_workflow.pipeline.schemas import StepInput
import json
step_input = StepInput(content_id="BV1test", platform="bilibili")
@@ -403,7 +403,7 @@ class TestJSONSerialization:
def test_step_output_model_dump_json(self):
"""StepOutput 支持 model_dump_json"""
from kb_pipeline.schemas import StepOutput
from kb_workflow.pipeline.schemas import StepOutput
import json
output = StepOutput(success=True, error_message=None)
@@ -415,7 +415,7 @@ class TestJSONSerialization:
def test_workflow_state_model_dump_json(self):
"""WorkflowState 支持 model_dump_json"""
from kb_pipeline.schemas import WorkflowState
from kb_workflow.pipeline.schemas import WorkflowState
import json
state = WorkflowState(
@@ -433,7 +433,7 @@ class TestJSONSerialization:
def test_workflow_state_model_validate_from_json(self):
"""WorkflowState 可从 JSON 恢复"""
from kb_pipeline.schemas import WorkflowState
from kb_workflow.pipeline.schemas import WorkflowState
import json
original = WorkflowState(
@@ -450,7 +450,7 @@ class TestJSONSerialization:
def test_workflow_state_with_steps_serialization(self):
"""WorkflowState steps 字典正确序列化/反序列化"""
from kb_pipeline.schemas import WorkflowState, StepRecord, StepStatus
from kb_workflow.pipeline.schemas import WorkflowState, StepRecord, StepStatus
import json
original = WorkflowState(
@@ -484,7 +484,7 @@ class TestParseInput:
def test_parse_input_validates_url_field(self):
"""ParseInput 必须包含 url 字段,且 min_length=1"""
from kb_pipeline.schemas import ParseInput
from kb_workflow.pipeline.schemas import ParseInput
# 缺少 url
with pytest.raises(ValidationError) as exc_info:
@@ -501,14 +501,14 @@ class TestParseInput:
def test_parse_input_content_id_default_empty(self):
"""ParseInput content_id 默认为空字符串"""
from kb_pipeline.schemas import ParseInput
from kb_workflow.pipeline.schemas import ParseInput
input_data = ParseInput(url="https://www.bilibili.com/video/BV1xx")
assert input_data.content_id == ""
def test_parse_input_platform_default_empty(self):
"""ParseInput platform 默认为空字符串"""
from kb_pipeline.schemas import ParseInput
from kb_workflow.pipeline.schemas import ParseInput
input_data = ParseInput(url="https://www.bilibili.com/video/BV1xx")
assert input_data.platform == ""
@@ -519,7 +519,7 @@ class TestParseOutput:
def test_parse_output_inherits_step_output(self):
"""ParseOutput 继承 StepOutput 的 success 和 error_message"""
from kb_pipeline.schemas import ParseOutput, StepOutput
from kb_workflow.pipeline.schemas import ParseOutput, StepOutput
output = ParseOutput(
success=True,
@@ -536,7 +536,7 @@ class TestParseOutput:
def test_parse_output_has_required_fields(self):
"""ParseOutput 包含所有必需字段"""
from kb_pipeline.schemas import ParseOutput
from kb_workflow.pipeline.schemas import ParseOutput
output = ParseOutput(
success=True,
@@ -555,7 +555,7 @@ class TestParseOutput:
def test_parse_output_with_error(self):
"""ParseOutput 可以表示失败状态"""
from kb_pipeline.schemas import ParseOutput
from kb_workflow.pipeline.schemas import ParseOutput
output = ParseOutput(
success=False,