fix: step3 _normalize_rule 为空 sources 的 rule 添加最小 text source - Closes #64
CI / test (pull_request) Successful in 11s

防御性处理 LLM 输出中 sources 为空数组的情况,避免 Layer A schema 失败。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-06-02 17:25:12 +08:00
parent c091b6c256
commit a24408521c
2 changed files with 33 additions and 15 deletions
@@ -526,3 +526,15 @@ class TestNormalizeRule:
assert normalized["sources"][0]["type"] == "text"
assert normalized["sources"][1]["type"] == "text"
assert normalized["sources"][0]["section"] == "3.1 功能"
def test_normalize_empty_sources(self):
"""Rules with empty sources get a minimal text source (defensive)."""
rule = {
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
"path": "3.1 策略 > decision_speed",
"sources": [],
}
normalized = _normalize_rule(rule)
assert len(normalized["sources"]) == 1
assert normalized["sources"][0]["type"] == "text"
assert normalized["sources"][0]["section"] == "3.1 策略"