feat(shipping-notice): 新增发货批次和任务管理功能,支持批次创建与任务处理
This commit is contained in:
1 parent
457f0f4e5e
commit
634dee4b81
81 files changed
+9088
-3625
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from app import db
|
||||
from app.models import ShippingInventoryMapping, ShippingTask
|
||||
|
||||
@@ -35,7 +37,7 @@ def test_shipping_notice_tool_flow(app, client):
|
||||
)
|
||||
assert parse_res.status_code == 200
|
||||
parse_body = parse_res.get_json()
|
||||
assert parse_body["status"] in {"ok", "needs_human"}
|
||||
assert parse_body["status"] in {"ok", "needs_human", "running"}
|
||||
assert "【发货通知解析确认】" in parse_body["message"]
|
||||
assert "| 料号 | A001 |" in parse_body["message"]
|
||||
|
||||
@@ -121,14 +123,17 @@ def test_shipping_notice_match_shortage_needs_human(app, client):
|
||||
assert "订单" in data["message"]
|
||||
assert "库存" in data["message"]
|
||||
assert "缺口" in data["message"]
|
||||
assert "confirm" in (data.get("human_options") or [])
|
||||
options = data.get("human_options") or []
|
||||
assert "confirm" not in options
|
||||
assert "reparse_inventory" in options
|
||||
assert "rematch" in options
|
||||
|
||||
confirm_res = client.post(
|
||||
"/api/shipping-notice/tools/submit_decision",
|
||||
headers=headers,
|
||||
json={"task_id": task_id, "decision": "confirm"},
|
||||
)
|
||||
assert confirm_res.get_json()["status"] == "ok"
|
||||
assert confirm_res.get_json()["status"] == "failed"
|
||||
|
||||
|
||||
def test_openapi_spec_public(app, client):
|
||||
@@ -178,7 +183,7 @@ def test_parse_inventory_from_chat_text(app, client):
|
||||
assert parse_inv.status_code == 200
|
||||
data = parse_inv.get_json()
|
||||
assert data["status"] == "needs_human"
|
||||
assert data.get("checkpoint") == "inventory_field_mapping_review"
|
||||
assert data.get("checkpoint") == "align_review"
|
||||
assert data.get("stop_agent_turn") is True
|
||||
assert "match_inventory" in (data.get("forbidden_next_tools") or [])
|
||||
assert "field_alignment" in data["data"]
|
||||
@@ -190,7 +195,7 @@ def test_parse_inventory_from_chat_text(app, client):
|
||||
)
|
||||
confirm_data = confirm_res.get_json()
|
||||
assert confirm_data["status"] == "needs_human"
|
||||
assert confirm_data.get("checkpoint") == "inventory_field_mapping_review"
|
||||
assert confirm_data.get("checkpoint") == "align_review"
|
||||
assert "Reservation ID" in (confirm_data.get("message") or "")
|
||||
|
||||
match_res = client.post(
|
||||
@@ -215,7 +220,9 @@ def test_parse_inventory_empty_needs_human(app, client):
|
||||
json={"task_id": task_id, "raw_inventory_text": " "},
|
||||
)
|
||||
assert res.get_json()["status"] == "needs_human"
|
||||
assert "reparse_inventory" in (res.get_json().get("human_options") or [])
|
||||
body = res.get_json()
|
||||
assert body.get("checkpoint") in {"map_infer", "upload_req"}
|
||||
assert body.get("human_options") is not None or body.get("action_buttons")
|
||||
|
||||
|
||||
def test_match_by_aws_sku_and_reservation_id(app, client):
|
||||
@@ -308,7 +315,7 @@ def test_match_inventory_blocked_before_mapping_confirm(app, client):
|
||||
)
|
||||
blocked = match_res.get_json()
|
||||
assert blocked["status"] == "needs_human"
|
||||
assert blocked.get("checkpoint") == "inventory_field_mapping_review"
|
||||
assert blocked.get("checkpoint") == "align_review"
|
||||
assert blocked.get("stop_agent_turn") is True
|
||||
assert "field_alignment" in blocked["data"]
|
||||
mapping = blocked["data"]["field_alignment"]
|
||||
@@ -352,7 +359,7 @@ def test_match_inventory_requires_reservation_id(app, client):
|
||||
)
|
||||
data = match_res.get_json()
|
||||
assert data["status"] == "needs_human"
|
||||
assert data.get("checkpoint") == "reservation_id_required"
|
||||
assert data.get("checkpoint") == "rsv_req"
|
||||
|
||||
|
||||
def test_correct_inventory_mapping_resets_to_inference(app, client, tmp_path):
|
||||
@@ -393,8 +400,9 @@ def test_correct_inventory_mapping_resets_to_inference(app, client, tmp_path):
|
||||
json={"task_id": task_id, "decision": "correct_inventory_mapping"},
|
||||
)
|
||||
data = correct_res.get_json()
|
||||
assert data["status"] == "ok"
|
||||
assert data.get("checkpoint") == "inventory_mapping_inference"
|
||||
assert data["status"] == "needs_human"
|
||||
assert data.get("checkpoint") == "map_infer"
|
||||
assert data.get("stop_agent_turn") is True
|
||||
assert "schema_preview" in data["data"]
|
||||
assert data["data"]["schema_preview"]["headers"] == ["AWS Sku", "COM ID", "Qty Available"]
|
||||
|
||||
@@ -433,8 +441,12 @@ def test_rpa_inventory_callback(app, client, tmp_path, monkeypatch):
|
||||
assert cb_res.status_code == 200
|
||||
data = cb_res.get_json()
|
||||
assert data["status"] == "needs_human"
|
||||
assert data["data"]["process_status"] == "inventory_ready"
|
||||
assert data.get("checkpoint") in {"map_infer", "align_review"}
|
||||
assert "confirm_inventory_mapping" in (data.get("human_options") or [])
|
||||
with app.app_context():
|
||||
task = ShippingTask.query.filter_by(task_no=task_id).first()
|
||||
assert task is not None
|
||||
assert task.process_status == "inventory_ready"
|
||||
|
||||
|
||||
def test_rpa_upload_callback(app, client, tmp_path):
|
||||
@@ -614,7 +626,7 @@ def test_upload_inventory_file_parses_server_side(app, client, tmp_path):
|
||||
assert upload_res.status_code == 200
|
||||
upload_data = upload_res.get_json()
|
||||
assert upload_data["status"] == "ok"
|
||||
assert upload_data.get("checkpoint") == "inventory_mapping_inference"
|
||||
assert upload_data.get("checkpoint") == "map_infer"
|
||||
preview = upload_data["data"]["schema_preview"]
|
||||
assert preview["headers"] == ["AWS Sku", "COM ID", "Qty Available"]
|
||||
assert preview["suggested_mapping"]["sku"] == "AWS Sku"
|
||||
@@ -632,7 +644,7 @@ def test_upload_inventory_file_parses_server_side(app, client, tmp_path):
|
||||
)
|
||||
apply_data = apply_res.get_json()
|
||||
assert apply_data["status"] == "needs_human"
|
||||
assert apply_data.get("checkpoint") == "inventory_field_mapping_review"
|
||||
assert apply_data.get("checkpoint") == "align_review"
|
||||
assert apply_data["data"]["field_alignment"]["inventory_row_count"] == 1
|
||||
assert apply_data["data"]["field_alignment"]["match_rule"].startswith("LLM:")
|
||||
assert apply_data["data"]["field_alignment"].get("match_rule_source") == "llm"
|
||||
@@ -704,7 +716,7 @@ def test_get_inventory_schema_preview(app, client, tmp_path):
|
||||
headers=headers,
|
||||
json={"task_id": task_id},
|
||||
)
|
||||
assert missing.get_json()["checkpoint"] == "inventory_upload_required"
|
||||
assert missing.get_json()["checkpoint"] == "upload_req"
|
||||
|
||||
|
||||
def test_apply_inventory_mapping_custom_headers(app, client, tmp_path):
|
||||
@@ -751,7 +763,7 @@ def test_apply_inventory_mapping_custom_headers(app, client, tmp_path):
|
||||
)
|
||||
apply_data = apply_res.get_json()
|
||||
assert apply_data["status"] == "needs_human"
|
||||
assert apply_data["data"]["inventory_row_count"] == 1
|
||||
assert apply_data["data"]["field_alignment"]["inventory_row_count"] == 1
|
||||
sample = apply_data["data"]["field_alignment"]["sample_inventory_lines"][0]
|
||||
assert sample["sku"] == "SKU-99"
|
||||
assert sample["available_qty"] == 12
|
||||
@@ -804,6 +816,7 @@ def test_confirm_parse_does_not_skip_inventory_match(app, client):
|
||||
assert task.match_status is None
|
||||
|
||||
|
||||
@pytest.mark.auto_rpa
|
||||
def test_parse_notice_auto_continue_hides_parse_confirmation_hint(app, client):
|
||||
headers = _tool_headers(app)
|
||||
|
||||
@@ -832,6 +845,7 @@ def test_parse_notice_auto_continue_hides_parse_confirmation_hint(app, client):
|
||||
assert parse_data.get("checkpoint") != "parse_review"
|
||||
|
||||
|
||||
@pytest.mark.auto_rpa
|
||||
def test_submit_decision_confirm_during_waiting_inventory_is_not_failed(app, client, tmp_path):
|
||||
headers = _tool_headers(app)
|
||||
trigger = tmp_path / "inventory_triggers"
|
||||
@@ -909,7 +923,7 @@ def test_submit_decision_by_conversation_id(app, client):
|
||||
)
|
||||
dup_data = dup_res.get_json()
|
||||
assert dup_data["task_id"] == task_id
|
||||
assert dup_data.get("checkpoint") == "task_already_exists"
|
||||
assert dup_data.get("checkpoint") == "task_exists"
|
||||
|
||||
|
||||
def test_parse_inventory_rejects_oversized_text(app, client):
|
||||
@@ -930,7 +944,7 @@ def test_parse_inventory_rejects_oversized_text(app, client):
|
||||
)
|
||||
data = res.get_json()
|
||||
assert data["status"] == "needs_human"
|
||||
assert data.get("checkpoint") == "inventory_upload_required"
|
||||
assert data.get("checkpoint") == "upload_req"
|
||||
assert "过大" in data["message"]
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user