"""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})