Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 93bbfe6029 | |||
| 6b1424b1c4 |
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user