@@ -331,7 +331,9 @@ class TestTimeoutPassed:
331331 @patch ("unstract.api_deployments.client.requests.request" )
332332 def test_no_default_timeout_set (self , mock_request , client ):
333333 """api_timeout is a server-side parameter, not an HTTP socket timeout.
334- _request_with_retry should NOT inject a default timeout kwarg."""
334+
335+ _request_with_retry should NOT inject a default timeout kwarg.
336+ """
335337 mock_request .return_value = _mock_response (200 )
336338 client ._request_with_retry ("GET" , "https://api.example.com/test" )
337339 _ , kwargs = mock_request .call_args
@@ -476,7 +478,8 @@ def test_422_with_executing_status_sets_pending_true(self, mock_request, client)
476478
477479 @patch ("unstract.api_deployments.client.requests.request" )
478480 def test_422_with_pending_status_sets_pending_true (self , mock_request , client ):
479- """HTTP 422 with PENDING body status — still detected via body check."""
481+ """HTTP 422 with PENDING body status — still detected via body
482+ check."""
480483 mock_request .return_value = _mock_response (
481484 422 , json_data = {"status" : "PENDING" , "error" : "" , "message" : "" }
482485 )
@@ -591,12 +594,20 @@ def test_structure_file_sync_mode_default_timeout(self, mock_post, tmp_path):
591594 assert mock_post .call_count == 1
592595
593596
594- # ── structure_file: 422 + PENDING sets pending=True ──
597+ # ── structure_file: POST 422 does NOT set pending ──
598+ # The POST endpoint returns 200 for successful queuing (PENDING/EXECUTING)
599+ # and 422 only on setup errors. A 422 should never trigger polling.
595600
596601
597- class TestStructureFilePendingOn422 :
602+ class TestStructureFile422DoesNotSetPending :
598603 @patch ("unstract.api_deployments.client.requests.post" )
599- def test_422_pending_sets_pending_true (self , mock_post , tmp_path ):
604+ def test_422_pending_does_not_set_pending (self , mock_post , tmp_path ):
605+ """POST 422 with PENDING status should NOT set pending=True.
606+
607+ The POST endpoint returns 422 only on setup errors, so the
608+ client must not start polling even if execution_status says
609+ PENDING.
610+ """
600611 test_file = tmp_path / "test.pdf"
601612 test_file .write_bytes (b"fake pdf content" )
602613
@@ -618,12 +629,16 @@ def test_422_pending_sets_pending_true(self, mock_post, tmp_path):
618629 },
619630 )
620631 result = c .structure_file ([str (test_file )])
621- assert result ["pending" ] is True
622- assert result ["status_check_api_endpoint" ] == "/api/status/abc"
632+ assert result ["pending" ] is False
623633 assert result ["status_code" ] == 422
624634
625635 @patch ("unstract.api_deployments.client.requests.post" )
626- def test_422_executing_sets_pending_true (self , mock_post , tmp_path ):
636+ def test_422_executing_does_not_set_pending (self , mock_post , tmp_path ):
637+ """POST 422 with EXECUTING status should NOT set pending=True.
638+
639+ Same rationale as above — 422 from POST means a setup error, not
640+ a legitimately queued execution.
641+ """
627642 test_file = tmp_path / "test.pdf"
628643 test_file .write_bytes (b"fake pdf content" )
629644
@@ -645,12 +660,12 @@ def test_422_executing_sets_pending_true(self, mock_post, tmp_path):
645660 },
646661 )
647662 result = c .structure_file ([str (test_file )])
648- assert result ["pending" ] is True
663+ assert result ["pending" ] is False
649664 assert result ["status_code" ] == 422
650665
651666 @patch ("unstract.api_deployments.client.requests.post" )
652- def test_200_pending_still_works (self , mock_post , tmp_path ):
653- """Existing behaviour: 200 + PENDING also sets pending=True."""
667+ def test_200_pending_sets_pending_true (self , mock_post , tmp_path ):
668+ """POST 200 + PENDING correctly sets pending=True for polling ."""
654669 test_file = tmp_path / "test.pdf"
655670 test_file .write_bytes (b"fake pdf content" )
656671
0 commit comments