fix(protocol): בחירת פרוטוקול ועדת-ערר לפי protocol_scope + document_id (#223)
analyze_protocol בחר את מסמך-הפרוטוקול הראשון (doc_type='protocol') והתעלם מ-protocol_scope. בתיק עם כמה פרוטוקולים — נספח ועדה-מקומית + דיון ועדת-הערר — הוא ניתח את הלא-נכון (התגלה ב-1043-02-26: ניתח "נספח 18 השתלשלות פרוטוקולים" במקום "פרוטוקול דיון 23.6.26"). - _find_protocol מעדיף פרוטוקול ועדת-ערר (scope שאינו 'lower'); פרוטוקול 'lower' (ועדה מקומית/מחוזית) לא נכנס להשוואה — הוא רקע לבלוק ו בלבד. - כמה פרוטוקולי-ערר → האחרון (created_at) גובר; document_id מכוון במפורש. - analyze_protocol (service + drafting tool + MCP tool) מקבל document_id/ target_document_id אופציונלי. - _protocol_scope: קורא metadata.protocol_scope (ריק=appeal, כמו ה-UI). - 5 בדיקות חדשות: דילוג-lower, all-lower→None, most-recent, targeting, unknown-id. טווח: Fix1 (קוד). ניקוי 1043 (תיוג נספח 18 כ-lower + מחיקת 11 רשומות שגויות + הרצה מכוונת ל-23.6.26) דורש טעינה-מחדש של ה-MCP — אחרי מיזוג. פרוצדורת ניתוח-מסמך-נוסף הכללית — המשך ב-#223. Invariants: G1 (נרמול-במקור — קריאת scope מ-metadata, לא ניחוש-בקריאה) · G2 (אותו נתיב ניתוח, בורר מדויק) · §6 (no_protocol מחזיר סטטוס מפורש, לא בליעה). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -49,6 +49,65 @@ def test_find_protocol_none():
|
||||
assert pa._find_protocol(docs) is None
|
||||
|
||||
|
||||
def test_find_protocol_skips_lower_scope():
|
||||
# A local/district-committee protocol (scope='lower') must NOT be picked for
|
||||
# the hearing-vs-pleadings comparison; the ועדת-ערר one wins (#223).
|
||||
docs = [
|
||||
{"id": "lower", "doc_type": "protocol", "title": "נספח 18 — פרוטוקולי ועדה מקומית",
|
||||
"metadata": {"protocol_scope": "lower"}, "created_at": "2026-01-01"},
|
||||
{"id": "appeal", "doc_type": "protocol", "title": "פרוטוקול דיון 23.6.26",
|
||||
"metadata": {}, "created_at": "2026-06-23"},
|
||||
]
|
||||
assert pa._find_protocol(docs)["id"] == "appeal"
|
||||
|
||||
|
||||
def test_find_protocol_all_lower_returns_none():
|
||||
# If every protocol is lower-scoped there is no ערר-hearing to compare.
|
||||
docs = [
|
||||
{"id": "1", "doc_type": "protocol", "title": "פרוטוקול מקומי",
|
||||
"metadata": {"protocol_scope": "lower"}},
|
||||
]
|
||||
assert pa._find_protocol(docs) is None
|
||||
|
||||
|
||||
def test_find_protocol_prefers_most_recent_appeal():
|
||||
docs = [
|
||||
{"id": "old", "doc_type": "protocol", "title": "פרוטוקול א",
|
||||
"metadata": {}, "created_at": "2026-03-01"},
|
||||
{"id": "new", "doc_type": "protocol", "title": "פרוטוקול ב",
|
||||
"metadata": {}, "created_at": "2026-06-23"},
|
||||
]
|
||||
assert pa._find_protocol(docs)["id"] == "new"
|
||||
|
||||
|
||||
def test_find_protocol_explicit_document_id_overrides():
|
||||
# Explicit target wins even over scope/recency heuristics — including the
|
||||
# ability to point at a lower-scoped doc if the caller insists.
|
||||
docs = [
|
||||
{"id": "aaaaaaaa-0000-0000-0000-000000000001", "doc_type": "protocol",
|
||||
"title": "פרוטוקול ערר", "metadata": {}, "created_at": "2026-06-23"},
|
||||
{"id": "aaaaaaaa-0000-0000-0000-000000000002", "doc_type": "protocol",
|
||||
"title": "פרוטוקול מקומי", "metadata": {"protocol_scope": "lower"},
|
||||
"created_at": "2026-01-01"},
|
||||
]
|
||||
from uuid import UUID
|
||||
picked = pa._find_protocol(
|
||||
docs, document_id=UUID("aaaaaaaa-0000-0000-0000-000000000002"),
|
||||
)
|
||||
assert picked["id"] == "aaaaaaaa-0000-0000-0000-000000000002"
|
||||
|
||||
|
||||
def test_find_protocol_unknown_document_id_returns_none():
|
||||
from uuid import UUID
|
||||
docs = [
|
||||
{"id": "aaaaaaaa-0000-0000-0000-000000000001", "doc_type": "protocol",
|
||||
"title": "פרוטוקול", "metadata": {}},
|
||||
]
|
||||
assert pa._find_protocol(
|
||||
docs, document_id=UUID("bbbbbbbb-0000-0000-0000-000000000009"),
|
||||
) is None
|
||||
|
||||
|
||||
# ── _normalize_change — anti-hallucination gate (INV-AH) ───────────────────
|
||||
|
||||
_AID = "11111111-1111-1111-1111-111111111111"
|
||||
|
||||
Reference in New Issue
Block a user