feat(shipping-notice): 增强发货通知候选管理功能,支持候选选择、重复检测与业务摘要修订

This commit is contained in:
hugo committed 2026-07-15 11:57:04 +08:00
1 parent 70f684b94a
commit b595e157e9
83 files changed
+5857 -200

No files matched your search

+134 -1
View File
@@ -121,7 +121,14 @@ def test_shipping_notice_tool_flow(app, client):
"task_id": task_id,
"structured": {
"customer_name": "ACME",
"lines": [{"sku": "A001", "reservation_id": "R-1", "qty": 10, "uom": "EA"}],
"lines": [{
"sku": "A001",
"reservation_id": "R-1",
"qty": 10,
"uom": "EA",
"source_type": "AWS Dublin",
"hub_code": "DUB",
}],
"confidence": 0.95,
},
},
@@ -1297,6 +1304,132 @@ def test_parse_notice_blocks_when_reservation_id_missing(app, client, monkeypatc
assert task.match_status is None
@pytest.mark.auto_rpa
def test_parse_notice_blocks_invalid_nonempty_reservation_id(app, client, monkeypatch):
"""非空内部 hex ID 仍应被后端硬闸门阻断,并在 step_payload 留存解析问题。"""
import app.services.shipping_notice.task_workflow as task_workflow
monkeypatch.setattr(task_workflow, "start_task_orchestrator", lambda task_no: True)
headers = _tool_headers(app)
create_res = client.post(
"/api/shipping-notice/tools/create_task",
headers=headers,
json={"source_type": "manual"},
)
task_id = create_res.get_json()["task_id"]
parse_res = client.post(
"/api/shipping-notice/tools/parse_notice",
headers=headers,
json={
"task_id": task_id,
"raw_text": "Commodity group ID External reservation ID 1f1a682dfdc446a393415dee93eb36ce 3000092917",
"structured": {
"lines": [
{
"sku": "TEMP-S000218929/D4-A08AR12000002",
"reservation_id": "1f1a682dfdc446a393415dee93eb36ce",
"qty": 10,
"uom": "EA",
}
],
"confidence": 0.95,
},
},
)
data = parse_res.get_json()
assert data["status"] == "needs_human"
assert data["checkpoint"] == "rsv_req"
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
assert task is not None
assert "reservation_id" not in task.lines_json[0]
validation = (task.step_payload_json or {})["parse_validation"]
assert validation["status"] == "needs_review"
assert validation["issues"][0]["reason"] == "invalid_format"
@pytest.mark.auto_rpa
def test_human_edit_revalidates_reservation_and_blocks_stale_confirm(app, client, monkeypatch):
"""人工修订应重算硬契约;非法值不能确认,改成合法字母型业务 ID 后清除阻断。"""
import app.services.shipping_notice.decision_workflow as decision_workflow
monkeypatch.setattr(decision_workflow, "start_task_orchestrator", lambda task_no: True)
headers = _tool_headers(app)
task_id = client.post(
"/api/shipping-notice/tools/create_task",
headers=headers,
json={"source_type": "manual"},
).get_json()["task_id"]
client.post(
"/api/shipping-notice/tools/parse_notice",
headers=headers,
json={
"task_id": task_id,
"structured": {
"lines": [{"sku": "A001", "reservation_id": "1000140351", "qty": 2, "uom": "EA"}],
"confidence": 0.4,
},
},
)
invalid_edit = client.post(
"/api/shipping-notice/tools/update_notice_line",
headers=headers,
json={"task_id": task_id, "line_index": 0, "patch": {"reservation_id": "f" * 32}},
)
assert invalid_edit.get_json()["status"] == "ok"
blocked = client.post(
"/api/shipping-notice/tools/submit_decision",
headers=headers,
json={"task_id": task_id, "decision": "confirm_parse"},
).get_json()
assert blocked["status"] == "needs_human"
assert blocked["data"]["parse_validation"]["issues"][0]["reason"] == "invalid_format"
valid_edit = client.post(
"/api/shipping-notice/tools/update_notice_line",
headers=headers,
json={"task_id": task_id, "line_index": 0, "patch": {"reservation_id": "AWS-311"}},
)
assert valid_edit.get_json()["status"] == "ok"
with app.app_context():
task = ShippingTask.query.filter_by(task_no=task_id).first()
validation = (task.step_payload_json or {})["parse_validation"]
assert validation["status"] == "ready"
assert validation["issues"] == []
@pytest.mark.auto_rpa
def test_parse_notice_blocks_valid_reservation_when_column_evidence_conflicts(app, client):
"""两个值格式都合法时,原文列证据冲突仍必须进入 parse_review,不能靠高置信度自动通过。"""
headers = _tool_headers(app)
task_id = client.post(
"/api/shipping-notice/tools/create_task",
headers=headers,
json={"source_type": "manual"},
).get_json()["task_id"]
raw_text = "AWS Sku\tReservation ID\tQty\nA001\t3000092917\t2"
result = client.post(
"/api/shipping-notice/tools/parse_notice",
headers=headers,
json={
"task_id": task_id,
"raw_text": raw_text,
"structured": {
"lines": [{"sku": "A001", "reservation_id": "3000092918", "qty": 2, "uom": "EA"}],
"confidence": 0.95,
},
},
).get_json()
assert result["status"] == "needs_human"
assert result["checkpoint"] == "parse_review"
assert result["data"]["parse_validation"]["issues"][0]["reason"] == "source_conflict"
@pytest.mark.auto_rpa
def test_parse_notice_low_confidence_does_not_write_parse_review_chat_card(app, client):
headers = _tool_headers(app)