fix: [bug] step3 未防御 table source null row + Layer C QE Audit 100% 不合格 - 来自 #18 e2e - Closes #73 #74

Merged
pzhang_zywl merged 1 commits from dev/issue-73-fix-null-row into main 2026-06-02 18:06:07 +08:00
2 changed files with 18 additions and 1 deletions
Showing only changes of commit 93bbfe6029 - Show all commits
@@ -206,7 +206,12 @@ def _normalize_rule(rule: dict) -> dict:
if stype and stype not in valid_types:
src["type"] = "text"
stype = "text"
if stype in ("table", "text"):
if stype == "table":
if not src.get("section"):
src["section"] = default_section
if src.get("row") is None:
src["row"] = 0
elif stype == "text":
if not src.get("section"):
src["section"] = default_section
else:
@@ -512,6 +512,18 @@ class TestNormalizeRule:
normalized = _normalize_rule(rule)
assert "section" not in normalized["sources"][0]
def test_normalize_table_source_null_row(self):
"""Table source with null row gets row=0 (defensive)."""
rule = {
"trigger": {"conditions": [{"signal": "x", "operator": "==", "value": "1"}]},
"sources": [
{"type": "table", "section": "3.1 功能", "row": None},
],
}
normalized = _normalize_rule(rule)
assert normalized["sources"][0]["row"] == 0
def test_normalize_source_invalid_type(self):
"""Invalid source types (LLM hallucinations) are normalized to text."""
rule = {