|
1 | 1 | from typing import Any |
2 | 2 | from unittest.mock import patch |
3 | 3 |
|
| 4 | +import pytest |
| 5 | +from fastapi import HTTPException |
4 | 6 | from fastapi.testclient import TestClient |
5 | 7 |
|
6 | | -from cas_reference_product.app import create_app |
| 8 | +from cas_reference_product.app import _raise_workflow_backend_failure, create_app |
7 | 9 | from cas_reference_product.config import Settings |
8 | 10 | from cas_reference_product.workflow import WorkflowAgentServiceError |
9 | 11 |
|
@@ -69,3 +71,23 @@ def test_workflow_api_sanitizes_external_service_failures(envelope: "Any") -> No |
69 | 71 | assert response.status_code == 502 |
70 | 72 | assert response.json() == {"detail": "Workflow backend request failed"} |
71 | 73 | assert "sensitive" not in response.text |
| 74 | + |
| 75 | + |
| 76 | +def test_workflow_backend_failure_preserves_exception_chain() -> None: |
| 77 | + with pytest.raises(HTTPException) as caught: |
| 78 | + try: |
| 79 | + raise RuntimeError("sensitive provider detail") |
| 80 | + except RuntimeError as provider_error: |
| 81 | + try: |
| 82 | + raise WorkflowAgentServiceError("Foundry workflow invocation failed") from ( |
| 83 | + provider_error |
| 84 | + ) |
| 85 | + except WorkflowAgentServiceError as workflow_error: |
| 86 | + _raise_workflow_backend_failure(workflow_error) |
| 87 | + |
| 88 | + assert caught.value.status_code == 502 |
| 89 | + assert caught.value.detail == "Workflow backend request failed" |
| 90 | + assert isinstance(caught.value.__cause__, WorkflowAgentServiceError) |
| 91 | + assert str(caught.value.__cause__) == "Foundry workflow invocation failed" |
| 92 | + assert isinstance(caught.value.__cause__.__cause__, RuntimeError) |
| 93 | + assert str(caught.value.__cause__.__cause__) == "sensitive provider detail" |
0 commit comments