Skip to content

Commit 2ad0a88

Browse files
author
zhangtao
committed
test: 补充工作流画布拆分覆盖
1 parent 29c8d05 commit 2ad0a88

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""工作流画布拆分/源目标派生测试(纯函数)。"""
2+
3+
from __future__ import annotations
4+
5+
from types import SimpleNamespace
6+
7+
import pytest
8+
9+
from app.core.exceptions import CustomException
10+
from app.modules.task.storage.workflow.service import WorkflowService
11+
12+
13+
def _graph() -> dict:
14+
return {
15+
"nodes": [
16+
{"id": "n1", "type": "storage", "position": {"x": 1, "y": 2}, "data": {"source_id": 1, "source_path": "a"}},
17+
{"id": "n2", "position": {"x": 3, "y": 4}, "data": {"source_id": 2, "source_path": "b"}},
18+
{"id": "n3", "data": {}},
19+
],
20+
"edges": [
21+
{"id": "e1", "source": "n1", "target": "n2", "data": {"enabled": True, "transfer_mode": "stream"}},
22+
{"id": "e2", "source": "n1", "target": "n2", "data": {}},
23+
{"id": "e3", "source": "n1", "target": "missing"},
24+
],
25+
}
26+
27+
28+
def test_split_graph_valid_and_dedup() -> None:
29+
result = WorkflowService._split_graph(_graph())
30+
assert [n.node_key for n in result.nodes] == ["n1", "n2"]
31+
assert result.sources[0].source_id == 1
32+
assert result.targets[0].target_id == 2 and result.targets[0].target_path == "b"
33+
assert len(result.edges) == 1 and result.edges[0].enabled is True
34+
assert len(result.layout["nodes"]) == 3 and len(result.layout["edges"]) == 1
35+
36+
37+
def test_split_graph_invalid_edges() -> None:
38+
with pytest.raises(CustomException):
39+
WorkflowService._split_graph({"nodes": [], "edges": []})
40+
with pytest.raises(CustomException):
41+
WorkflowService._split_graph({"nodes": [], "edges": [{"id": "e", "source": "a", "target": "b"}]})
42+
43+
44+
def test_split_graph_same_source_target() -> None:
45+
graph = {
46+
"nodes": [
47+
{"id": "a", "data": {"source_id": 1}},
48+
{"id": "b", "data": {"source_id": 1}},
49+
],
50+
"edges": [{"id": "e", "source": "a", "target": "b"}],
51+
}
52+
with pytest.raises(CustomException, match="源与目标不能相同"):
53+
WorkflowService._split_graph(graph)
54+
55+
56+
def test_sources_and_targets_from_edges() -> None:
57+
rows = [
58+
SimpleNamespace(source_node_key="a", target_node_key="b"),
59+
SimpleNamespace(source_node_key="missing", target_node_key="c"),
60+
]
61+
node_map = {
62+
"a": SimpleNamespace(source_id=1, source_path="a"),
63+
"b": SimpleNamespace(source_id=2, source_path="b"),
64+
"c": SimpleNamespace(source_id=3, source_path=None),
65+
}
66+
sources = WorkflowService._sources_from(rows, node_map)
67+
targets = WorkflowService._targets_from(rows, node_map)
68+
assert [s.source_id for s in sources] == [1]
69+
assert [(t.target_id, t.target_path) for t in targets] == [(2, "b"), (3, "")]

‎docs/COVERAGE-PLAN.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ D 包含四个独立目标:
3131
- `test_s3_adapter_paths.py`:S3 连接/列表/桶/复制/重命名/URL/关闭,s3_adapter 53%;
3232
- `test_storage_browse_service.py`:路径校验/上传/下载/删除/列表/重命名/目录/分享,browse service 58%;
3333
- `test_transfer_engine_helpers.py`:本地大小/文件树/目录准备/临时清理/目录判断/步骤正交,transfer engine 26%;
34-
- `test_monitor_services.py`:缓存服务 100%、服务器监控 75%。
34+
- `test_monitor_services.py`:缓存服务 100%、服务器监控 75%;
35+
- `test_workflow_graph_service.py`:画布拆分、去重、源目标派生、非法连线,workflow service 39%。
3536

3637
## 外部协议范围(2026-11-05 确认)
3738

0 commit comments

Comments
 (0)