refactor(server): split oversized backend services
This commit is contained in:
@@ -16,6 +16,7 @@ from app.schemas.user_agent import UserAgentCitation, UserAgentRequest, UserAgen
|
||||
from app.services.agent_assets import AgentAssetService
|
||||
from app.services.ontology import SemanticOntologyService
|
||||
from app.services.user_agent import UserAgentService
|
||||
from app.services.user_agent_documents import UserAgentDocumentService
|
||||
|
||||
|
||||
def build_session_factory() -> sessionmaker[Session]:
|
||||
@@ -1096,6 +1097,42 @@ def test_user_agent_returns_submitted_draft_payload_for_review_next_step() -> No
|
||||
assert "当前节点为 直属领导审批" in response.answer
|
||||
|
||||
|
||||
def test_user_agent_document_service_normalizes_ocr_fields_and_scene() -> None:
|
||||
document_service = UserAgentDocumentService()
|
||||
|
||||
fields = document_service.extract_document_fields(
|
||||
{
|
||||
"filename": "北京南站火车票.png",
|
||||
"document_type": "train_ticket",
|
||||
"scene_code": "travel",
|
||||
"summary": "电子发票 2026-03-04 广州南至北京南 二等座 票价 ¥560.00 中国铁路",
|
||||
"text": "电子发票 2026-03-04 广州南至北京南 二等座 票价 ¥560.00 中国铁路",
|
||||
"document_fields": [
|
||||
{"key": "amount", "label": "票价", "value": "¥560.00"},
|
||||
{"key": "date", "label": "业务发生时间", "value": "2026-03-04"},
|
||||
{"key": "merchant_name", "label": "商户", "value": "中国铁路"},
|
||||
],
|
||||
}
|
||||
)
|
||||
classified = document_service.classify_document(
|
||||
{"filename": "客户餐饮发票.jpg", "summary": "餐饮发票 客户招待 金额 320 元"},
|
||||
expense_type_code="entertainment",
|
||||
has_customer=True,
|
||||
)
|
||||
|
||||
assert fields["金额"] == "560.00元"
|
||||
assert fields["列车出发时间"] == "2026-03-04"
|
||||
assert "商户/酒店" not in fields
|
||||
assert document_service.extract_amount_text_from_value("滴滴出行 支付金额 1 元,实付 13.4 元,订单号 12345678") == "13.40元"
|
||||
assert classified["document_type"] == "meal_receipt"
|
||||
assert classified["expense_type"] == "entertainment"
|
||||
assert document_service.infer_expense_type_from_documents(
|
||||
[{"filename": "客户餐饮发票.jpg", "summary": "餐饮发票 客户招待 金额 320 元"}],
|
||||
expense_type_code="entertainment",
|
||||
has_customer=True,
|
||||
) == "业务招待费"
|
||||
|
||||
|
||||
def test_user_agent_builds_review_payload_for_multi_document_expense_flow() -> None:
|
||||
session_factory = build_session_factory()
|
||||
with session_factory() as db:
|
||||
|
||||
Reference in New Issue
Block a user