feat: 结果对象 error_code 字段(默认 None 向后兼容)
This commit is contained in:
@@ -53,3 +53,4 @@
|
||||
| 2026-08-09 10:50 | 反馈迭代 | 里程碑3.1 backlog 清理(retro 3 项):① chat_structured 增加 token 超限检测(渲染后估算超限→truncate_cb→重渲染,与 chat 流程一致)TDD RED→GREEN 新增 test_chat_structured_truncation_callback_triggered;② 清理 test_inference_engine.py 未用导入(pytest/json/ChatMessage);③ HttpLLMClient 增加上下文管理器(__enter__/__exit__ 退出时关闭底层 httpx.Client 释放连接)TDD 新增 test_client_context_manager_closes_transport;pytest 全量 119 passed 覆盖 100.00%,fail_under=99 达标;提交见 git log | src/genesis/inference/engine.py, src/genesis/inference/client.py, tests/test_inference_engine.py, tests/test_inference_client.py, _AI_USAGE_LOG.md | deepseek-v4-flash-free |
|
||||
| 2026-08-09 11:20 | 反馈迭代 | Web UI 设计评审(v1.0→v1.1,7 项发现全修):以大赛手册+api-design 为权威基准审查 web-ui-design.md——F1 上传区补「概要设计做成说明书」独立 write_instruction file_type(api-design §2.2 连带扩展)+ 命名统一;F2 §4.1 任务队列 Redis 写死→抽象 TaskQueue(InMemory 默认/Redis/Valkey 可选);F3 新增设置页 §3.6;F4 预览路径改 ContentBlock→chapter_html+docx;F5 生成页新增规则冲突卡片(WS conflict_pending→conflicts/{id}/resolve);F6 新增会话历史页 §3.7;F7 新增 §7 无障碍与设计规范。同步 design.md §8 镜像(上传区/设置/队列/会话/冲突卡片/历史简版//history 命令);产出评审报告 docs/web-ui-design-review-v1.1.md;docs/design.md、docs/api-design.md 连带修订 | docs/web-ui-design.md, docs/web-ui-design-review-v1.1.md, docs/api-design.md, docs/design.md, _AI_USAGE_LOG.md | deepseek-v4-flash-free |
|
||||
| 2026-08-09 11:45 | Agent 实现 | LLM 错误码对齐 Task1:异常树 error_code 类属性(LLMError 基类 None + four 子类 four 码,对齐 api-design §7),沿用现有中文 docstring 未改动。TDD RED(AttributeError: type object 'LLMError' has no attribute 'error_code')→ GREEN(聚焦 4 passed,exceptions.py 100%);聚焦单文件运行触发全库 fail-under=99 coverage exit 1 为基线行为(总覆盖 9.95%),与本次改动无关;加入 _AI_USAGE_LOG.md 提交 | src/genesis/inference/exceptions.py, tests/test_inference_errors.py, _AI_USAGE_LOG.md | deepseek-v4-flash-free |
|
||||
| 2026-08-09 13:42 | Agent 实现 | LLM 错误码对齐 Task2:ChatResult/StructuredResult 增加 error_code 字段(默认 None 向后兼容)。TDD RED(AttributeError: 'ChatResult' object has no attribute 'error_code')→ GREEN(聚焦 8 passed,types.py 100%);pytest 全量 123 passed 覆盖 100.00%(799 stmts/188 br),fail_under=99 达标;提交见 git log | src/genesis/inference/types.py, tests/test_inference_types.py, _AI_USAGE_LOG.md | deepseek-v4-flash-free |
|
||||
|
||||
@@ -28,6 +28,7 @@ class ChatResult:
|
||||
duration_ms: int
|
||||
status: Literal["ok", "fallback", "failed"]
|
||||
error: str | None = None
|
||||
error_code: str | None = None # 失败时的 api §7 错误码;成功为 None
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -42,6 +43,7 @@ class StructuredResult:
|
||||
duration_ms: int
|
||||
status: Literal["ok", "fallback", "parse_error", "failed"]
|
||||
error: str | None = None
|
||||
error_code: str | None = None # 失败/parse_error 时的错误码;成功为 None
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -35,6 +35,22 @@ def test_structured_result_status_parse_error():
|
||||
assert r.status == "parse_error" and r.error == "bad json"
|
||||
|
||||
|
||||
def test_chat_result_error_code_default_none():
|
||||
r = ChatResult(
|
||||
text="t", model="m", prompt_version="v1", usage=TokenUsage(),
|
||||
duration_ms=10, status="ok",
|
||||
)
|
||||
assert r.error_code is None
|
||||
|
||||
|
||||
def test_structured_result_error_code_default_none():
|
||||
r = StructuredResult(
|
||||
data={"a": 1}, raw_text='{"a":1}', parse_attempts=1, model="m",
|
||||
prompt_version="v1", usage=TokenUsage(), duration_ms=10, status="ok",
|
||||
)
|
||||
assert r.error_code is None
|
||||
|
||||
|
||||
def test_prompt_fields():
|
||||
p = Prompt(name="writer", version="v2", template="章节 {{chapter}}")
|
||||
assert p.name == "writer" and p.version == "v2"
|
||||
Reference in New Issue
Block a user