feat: add portfolio graph enrichment
This commit is contained in:
@@ -24,6 +24,37 @@ async def test_neo4j_rejects_unapproved_relationship() -> None:
|
||||
await RelationshipService(FailingGraph()).neighbors(1, "DELETE_ALL")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_portfolio_graph_context_uses_fixed_query_and_filters_noise() -> None:
|
||||
class Graph:
|
||||
async def execute_query(self, query: str, **parameters: object) -> list[object]:
|
||||
assert "HOLDS" in query and "EXPOSED_TO_INDUSTRY" in query
|
||||
assert parameters == {"customer_id": 7, "limit": 20}
|
||||
return [
|
||||
{"industry_name": "科技", "product_count": 2},
|
||||
{"industry_name": "单产品行业", "product_count": 1},
|
||||
]
|
||||
|
||||
result = await RelationshipService(Graph()).portfolio_industry_context(7)
|
||||
assert result == {
|
||||
"degraded": False,
|
||||
"overlaps": [
|
||||
{"industry_name": "科技", "product_count": 2},
|
||||
{"industry_name": "单产品行业", "product_count": 1},
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_portfolio_graph_context_failure_is_degraded() -> None:
|
||||
from app.service.portfolio_analysis_service import PortfolioAnalysisService
|
||||
|
||||
service = PortfolioAnalysisService(graph_service=RelationshipService(FailingGraph()))
|
||||
result = await service._graph_context(7)
|
||||
assert result["degraded"] is True
|
||||
assert str(result["reason"]).startswith("neo4j_unavailable")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_model_router_excludes_unhealthy_endpoint() -> None:
|
||||
from app.model.configuration import ModelEndpointConfig
|
||||
|
||||
Reference in New Issue
Block a user