From f3a30256d5b96f6e9e9feb33eb5aa09828666352 Mon Sep 17 00:00:00 2001 From: lhl Date: Sun, 9 Aug 2026 13:58:53 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=B8=85=E7=90=86=20error=5Fcode=20?= =?UTF-8?q?=E6=94=B6=E5=B0=BE=EF=BC=88=E5=88=A0=E5=86=97=E4=BD=99=E6=AD=BB?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A1=8C=E3=80=81=E8=A1=A5=E5=B0=BE=E6=8D=A2?= =?UTF-8?q?=E8=A1=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _AI_USAGE_LOG.md | 1 + src/genesis/inference/engine.py | 2 +- tests/test_inference_engine.py | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/_AI_USAGE_LOG.md b/_AI_USAGE_LOG.md index 18c17ea..b4a6654 100644 --- a/_AI_USAGE_LOG.md +++ b/_AI_USAGE_LOG.md @@ -56,3 +56,4 @@ | 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 | | 2026-08-09 14:02 | Agent 实现 | LLM 错误码对齐 Task3:engine 失败/parse_error 路径透传 error_code(与 error 同源取最后一次异常)。chat() 循环记 last_error_code=exc.error_code,失败返回 error_code=last_error_code;chat_structured() 三路径:JSONDecodeError 分支置 last_error_code="LLM_PARSE_ERROR"(解析耗尽→parse_error)、LLMError 分支 early return 带 error_code=exc.error_code、循环后 parse_error 用 last_error_code。TDD RED(5 failed,error_code=None)→ GREEN(聚焦 22 passed);pytest 全量 128 passed 覆盖 100.00%(803 stmts/188 br),fail_under=99 达标;提交见 git log | src/genesis/inference/engine.py, tests/test_inference_engine.py, _AI_USAGE_LOG.md | deepseek-v4-flash-free | | 2026-08-09 13:51 | Agent 实现 | LLM 错误码对齐 Task4:api-design §7 补 LLM_NETWORK_ERROR 行(对齐异常树 error_code)。在 docs/api-design.md §7 错误码表 LLM_TIMEOUT 行后插入新行 `| LLM_NETWORK_ERROR | 502 | 网络失败/5xx 重试耗尽 | retry / skip / abort | exceptions.LLMNetworkError |`,保留 LLM_NOT_CONFIGURED/LLM_PARSE_ERROR 与 INTERNAL_ERROR 兜底行不动;纯文档改动,全量回归 128 passed 覆盖 100.00%(803 stmts/188 br),fail_under=99 达标 | docs/api-design.md, _AI_USAGE_LOG.md | deepseek-v4-flash-free | +| 2026-08-09 | 测试验证 | 里程碑3.1 LLM错误码对齐收尾改动(最终评审 Minor):① 删除 tests/test_inference_engine.py 中 test_chat_failed_error_code_not_configured 首行未使用变量 client = FakeLLMClient(...)(死代码,未引用,函数自洽性核查通过);② 补齐 src/genesis/inference/engine.py 文件末尾换行符(最后一字节 ) → \n)。覆盖测试 22 passed;pytest 全量 128 passed,覆盖 100.00%(803 stmts/188 br),fail_under=99 达标;提交见 git log | tests/test_inference_engine.py, src/genesis/inference/engine.py, _AI_USAGE_LOG.md | deepseek-v4-flash-free | diff --git a/src/genesis/inference/engine.py b/src/genesis/inference/engine.py index 0f114af..1a9fc8a 100644 --- a/src/genesis/inference/engine.py +++ b/src/genesis/inference/engine.py @@ -189,4 +189,4 @@ class InferenceEngine: usage=TokenUsage(), duration_ms=int((time.monotonic() - start) * 1000), status="parse_error", error=last_error, error_code=last_error_code, - ) \ No newline at end of file + ) diff --git a/tests/test_inference_engine.py b/tests/test_inference_engine.py index adc1c08..8737f92 100644 --- a/tests/test_inference_engine.py +++ b/tests/test_inference_engine.py @@ -103,7 +103,6 @@ def test_chat_failed_error_code_network_last(): def test_chat_failed_error_code_not_configured(): # 备用模型 Key 缺失(最后一次)→ LLM_NOT_CONFIGURED - client = FakeLLMClient([("raise_network", ""), ("raise_timeout", "")]) # 用自定义异常客户端模拟 NotConfigured class NotConfiguredClient: def __init__(self):