11from fastapi .testclient import TestClient
22
33from app .core .config import settings
4- from app .core .exception_handlers import _filter_union_branch_errors
4+ from app .core .exception_handlers import _sanitize_validation_errors
55from app .tests .utils .auth import TestAuthContext
66
77
8- class TestFilterUnionBranchErrors :
9- """Unit tests for _filter_union_branch_errors ."""
8+ class TestSanitizeValidationErrors :
9+ """Unit tests for _sanitize_validation_errors ."""
1010
1111 def test_non_union_errors_pass_through (self ) -> None :
1212 errors = [
1313 {"type" : "missing" , "loc" : ("body" , "name" ), "msg" : "Field required" },
1414 ]
15- assert _filter_union_branch_errors (errors ) == errors
15+ assert _sanitize_validation_errors (errors ) == errors
1616
1717 def test_picks_branch_with_fewer_literal_errors (self ) -> None :
1818 errors = [
@@ -37,7 +37,7 @@ def test_picks_branch_with_fewer_literal_errors(self) -> None:
3737 "msg" : "Field required" ,
3838 },
3939 ]
40- result = _filter_union_branch_errors (errors )
40+ result = _sanitize_validation_errors (errors )
4141 assert len (result ) == 2
4242 for err in result :
4343 assert "NativeConfig" not in err ["loc" ]
@@ -56,7 +56,7 @@ def test_tied_branches_keep_both_and_dedup(self) -> None:
5656 "msg" : "Field required" ,
5757 },
5858 ]
59- result = _filter_union_branch_errors (errors )
59+ result = _sanitize_validation_errors (errors )
6060 assert len (result ) == 1
6161 assert result [0 ]["loc" ] == ("body" , "c" , "x" )
6262
@@ -74,7 +74,7 @@ def test_strips_branch_identifiers_from_loc(self) -> None:
7474 "msg" : "Field required" ,
7575 }
7676 ]
77- result = _filter_union_branch_errors (errors )
77+ result = _sanitize_validation_errors (errors )
7878 assert result [0 ]["loc" ] == ("body" , "cfg" , "completion" , "params" )
7979
8080 def test_non_union_preserved_with_union (self ) -> None :
@@ -91,17 +91,17 @@ def test_non_union_preserved_with_union(self) -> None:
9191 "msg" : "Field required" ,
9292 },
9393 ]
94- result = _filter_union_branch_errors (errors )
94+ result = _sanitize_validation_errors (errors )
9595 assert len (result ) == 2
9696 locs = [r ["loc" ] for r in result ]
9797 assert ("body" , "name" ) in locs
9898
9999 def test_empty_list (self ) -> None :
100- assert _filter_union_branch_errors ([]) == []
100+ assert _sanitize_validation_errors ([]) == []
101101
102102 def test_fallback_on_malformed_input (self ) -> None :
103103 malformed = [None , 42 ] # type: ignore[list-item]
104- result = _filter_union_branch_errors (malformed )
104+ result = _sanitize_validation_errors (malformed )
105105 assert result == malformed
106106
107107
0 commit comments