docs: 为全部代码补充中文注释并加入 AGENTS 注释规范

This commit is contained in:
cat-shark
2026-08-13 22:09:55 +08:00
parent 906553d2d0
commit 439b63c81b
7 changed files with 150 additions and 0 deletions
+16
View File
@@ -1,3 +1,9 @@
"""wov_sdk.models 的单元测试。
测试覆盖所有数据模型的 JSON 往返序列化、字段校验和 manifest 文件加载,
确保协议模型的稳定性。
"""
import json
import pytest
@@ -15,6 +21,7 @@ from wov_sdk.models import (
def valid_manifest() -> NodeManifest:
"""构造一个覆盖全部字段的合法 NodeManifest,供测试复用。"""
return NodeManifest(
id="echo",
name="Echo",
@@ -33,6 +40,7 @@ def valid_manifest() -> NodeManifest:
def test_manifest_round_trip() -> None:
"""验证 manifest 经过 to_dict/from_dict 后保持原值。"""
manifest = valid_manifest()
restored = NodeManifest.from_dict(manifest.to_dict())
assert restored == manifest
@@ -53,6 +61,7 @@ def test_manifest_round_trip() -> None:
],
)
def test_manifest_validation(field: str, value: object) -> None:
"""验证必填字段为空或数值越界时抛出 ValueError。"""
manifest = valid_manifest()
setattr(manifest, field, value)
with pytest.raises(ValueError):
@@ -60,6 +69,7 @@ def test_manifest_validation(field: str, value: object) -> None:
def test_manifest_load(tmp_path) -> None:
"""验证 NodeManifest.load 能从 JSON 文件读取并校验。"""
path = tmp_path / "node.manifest.json"
path.write_text(json.dumps(valid_manifest().to_dict()), encoding="utf-8")
loaded = NodeManifest.load(str(path))
@@ -67,6 +77,7 @@ def test_manifest_load(tmp_path) -> None:
def test_invoke_request_round_trip() -> None:
"""验证 InvokeRequest 的 JSON 往返序列化。"""
request = InvokeRequest(
run_id="run_1",
node_instance_id="ni_1",
@@ -79,12 +90,14 @@ def test_invoke_request_round_trip() -> None:
def test_invoke_response_round_trip() -> None:
"""验证 InvokeResponse 的 JSON 往返序列化。"""
response = InvokeResponse(status="completed", outputs={"text": "hello"})
restored = InvokeResponse.from_dict(response.to_dict())
assert restored == response
def test_health_and_progress_serialization() -> None:
"""验证健康检查和进度事件模型的字典输出。"""
health = HealthResponse(status="ok", node_id="echo", version="1.0.0")
assert health.to_dict() == {
"status": "ok",
@@ -102,6 +115,7 @@ def test_health_and_progress_serialization() -> None:
def test_workflow_node_and_edge_round_trip() -> None:
"""验证工作流节点与边的 JSON 往返序列化。"""
node = WorkflowNode(
id="asr",
node_type="faster-whisper",
@@ -117,6 +131,7 @@ def test_workflow_node_and_edge_round_trip() -> None:
def test_workflow_definition_round_trip_and_validation() -> None:
"""验证完整 DAG 定义可往返序列化并通过校验。"""
definition = WorkflowDefinition(
name="demo",
version=1,
@@ -134,6 +149,7 @@ def test_workflow_definition_round_trip_and_validation() -> None:
def test_workflow_definition_invalid() -> None:
"""验证非法 DAG(空名、版本为 0、重复节点、未知边)被拒绝。"""
with pytest.raises(ValueError):
WorkflowDefinition(name="", version=1).validate()