feat(sp35): regression locks on parse-999/277ca/ta1 envelope guards
The 999, 277CA, and TA1 parsers already enforce envelope correctness at the parser level (parse_999.py line 290 raises 'No AK9 segment found'; parse_277ca.py line 298 raises 'Expected ST*277 or ST*277CA'; parse_ta1.py line 111 raises 'Expected TA1, got <other>'). These tests lock the HTTP surface contract: a wrong-kind file POSTed to those endpoints must come back as 400, never as 200 or 500. Tests added: - test_api_999.py: rejects_837_input, rejects_835_input - test_api_277ca.py: rejects_835_input, rejects_837_input - test_api_ta1.py: rejects_837_input, rejects_835_input If a future PR relaxes any of those parser-level guards, the corresponding regression lock fires immediately.
This commit is contained in:
@@ -167,3 +167,48 @@ class TestInboxPayerRejectedLane:
|
||||
# The rejected lane (999 envelope) must be empty — we haven't
|
||||
# uploaded a 999, so this claim isn't there.
|
||||
assert "c1" not in [c["id"] for c in lanes["rejected"]]
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# SP35: parse-277ca envelope regression lock
|
||||
# --------------------------------------------------------------------------- #
|
||||
#
|
||||
# The 277CA parser already raises CycloneParseError("Expected ST*277 or
|
||||
# ST*277CA, got ST*<other>") when fed a file with the wrong ST envelope
|
||||
# (parse_277ca.py line 298). This regression lock confirms the HTTP
|
||||
# surface converts that error into a 400 (never 200, never 500).
|
||||
|
||||
|
||||
def test_parse_277ca_endpoint_rejects_835_input(client: TestClient):
|
||||
"""Posting an 835 file to /api/parse-277ca must surface 400, not 200."""
|
||||
wrong_kind = Path(__file__).parent / "fixtures" / "co_medicaid_835.txt"
|
||||
text = wrong_kind.read_text()
|
||||
assert "ST*835" in text # sanity check on the fixture
|
||||
|
||||
resp = client.post(
|
||||
"/api/parse-277ca",
|
||||
files={"file": ("co_medicaid_835.txt", text, "text/plain")},
|
||||
headers={"Accept": "application/json"},
|
||||
)
|
||||
assert resp.status_code == 400, resp.text
|
||||
body = resp.json()
|
||||
assert "error" in body
|
||||
# The parser-level message must survive (mentions "ST" and the
|
||||
# expected vs actual set id).
|
||||
detail = body.get("detail", "")
|
||||
assert "ST" in detail and ("277" in detail or body["error"] == "Parse error"), body
|
||||
|
||||
|
||||
def test_parse_277ca_endpoint_rejects_837_input(client: TestClient):
|
||||
"""Posting an 837P file to /api/parse-277ca must surface 400, not 200."""
|
||||
wrong_kind = Path(__file__).parent / "fixtures" / "co_medicaid_837p.txt"
|
||||
text = wrong_kind.read_text()
|
||||
assert "ST*837" in text # sanity check
|
||||
|
||||
resp = client.post(
|
||||
"/api/parse-277ca",
|
||||
files={"file": ("co_medicaid_837p.txt", text, "text/plain")},
|
||||
headers={"Accept": "application/json"},
|
||||
)
|
||||
assert resp.status_code == 400, resp.text
|
||||
assert "error" in resp.json()
|
||||
|
||||
Reference in New Issue
Block a user