fix(halacha): rate-limit refusal ≠ empty answer — לא checkpoint chunk בכשל (#144)
תיקון-ליבה (b): כש-claude CLI מחזיר exit=0 עם הודעת-מגבלה/שגיאה כ-result, query זיהה אותה כהצלחה → _extract_chunk קיבל []/non-list וסימן chunk כ-done-ריק; resume דילג עליו לתמיד → תת-חילוץ קבוע (3→1→0). עכשיו is_error/_looks_like_limit_notice הופכים אותה לכשל-חולף → retry → raise → chunk נשאר un-checkpointed → resume משחזר (כך force-delete כבר לא הרסני-לצמיתות). + churn-detect במתזמר (Δdone<0 / Δhal<-2 → אזהרה+churn_ok ב-JSON). + scripts/reconcile_under_extracted_halacha.py — שחזור completed-עם-0-הלכות-ו≥3 מקטעי-נימוק (dry-run הראה 15 מועמדים); נתיב-הזמנה קנוני (G2), שמרני (לא remand). הערה: אטומיות-מלאה (staging_run_id) נדחתה — PR #257 מיתן את ה-trigger, ו-(b)+resume מונעים אובדן-קבוע (force-delete מתאושש דרך resume). בדיקות: test_claude_session_limit_notice. כל 354 עוברות. guards נקיים. Invariants: G1, INV-G3/X16 (checkpoint=הושלם-באמת), INV-G4 (churn לא-שקט), G12. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
40
mcp-server/tests/test_claude_session_limit_notice.py
Normal file
40
mcp-server/tests/test_claude_session_limit_notice.py
Normal file
@@ -0,0 +1,40 @@
|
||||
"""Regression test for #144 — a usage/rate-limit refusal returned with exit 0
|
||||
must NOT be treated as a real (empty) answer.
|
||||
|
||||
``_looks_like_limit_notice`` recognises a prose refusal in the CLI's exit-0
|
||||
``result`` so ``query`` raises instead of returning it — keeping the halacha
|
||||
extractor from checkpointing the chunk as done-with-0-halachot (silent
|
||||
under-extraction). A genuine JSON result (array/object) is never mis-flagged.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from legal_mcp.services import claude_session as cs
|
||||
|
||||
|
||||
def test_detects_usage_limit_prose():
|
||||
assert cs._looks_like_limit_notice(
|
||||
{"result": "Claude usage limit reached. Try again later."})
|
||||
assert cs._looks_like_limit_notice(
|
||||
{"result": "You've hit the rate limit for this model."})
|
||||
|
||||
|
||||
def test_json_array_result_is_not_a_notice():
|
||||
# A real halacha extraction — must pass through as a valid answer.
|
||||
assert not cs._looks_like_limit_notice(
|
||||
{"result": '[{"rule_statement": "the usage limit of a permit ..."}]'})
|
||||
|
||||
|
||||
def test_json_object_result_is_not_a_notice():
|
||||
assert not cs._looks_like_limit_notice(
|
||||
{"result": '{"summary": "rate limit doctrine"}'})
|
||||
|
||||
|
||||
def test_plain_answer_without_markers_is_not_a_notice():
|
||||
assert not cs._looks_like_limit_notice({"result": "אין הלכות בקטע זה."})
|
||||
|
||||
|
||||
def test_missing_or_nonstring_result():
|
||||
assert not cs._looks_like_limit_notice({})
|
||||
assert not cs._looks_like_limit_notice({"result": None})
|
||||
assert not cs._looks_like_limit_notice({"result": 42})
|
||||
Reference in New Issue
Block a user