feat(freight-rpa): 增加出站报表配置与回调支持,重构相关服务
- 将 RPA 管理 API 扩展至出站报表配置,新增出站相关的回调接口。 - 重构 freight_rpa_report_config_service,支持入站与出站报表配置的管理。 - 更新 ORM 模型,增加出站报表相关的持久化模型。 - 统一命名规范,确保在手、入站与出站的概念一致性。
This commit is contained in:
1 parent
39fe3c05f2
commit
911afa0f73
152 files changed
+9861
-2984
No files matched your search
@@ -0,0 +1,16 @@
|
||||
"""
|
||||
tests/services/freight_rpa/test_outbound_trigger_contract.py
|
||||
|
||||
用途:出站 RPA trigger_io 与 Worker 心跳能力串的契约常量回归。
|
||||
依赖:freight_rpa.outbound.trigger_io、worker_heartbeat.OUTBOUND_EXPORT_CAPABILITY。
|
||||
逻辑:Task 7 接口清单的单一真相,防止 schema/action/能力名漂移。
|
||||
"""
|
||||
from app.services.freight_rpa.outbound import trigger_io
|
||||
from app.services.freight_rpa.common.worker_heartbeat import OUTBOUND_EXPORT_CAPABILITY
|
||||
|
||||
|
||||
def test_outbound_trigger_constants():
|
||||
"""出站 trigger schema/action 与 Worker outbound_export 能力须与设计 spec 一致。"""
|
||||
assert trigger_io.SCHEMA == "freight_rpa.outbound.v1"
|
||||
assert trigger_io.ACTION_OUTBOUND_EXPORT_BATCH == "outbound_export_batch"
|
||||
assert OUTBOUND_EXPORT_CAPABILITY == "outbound_export"
|
||||
@@ -179,18 +179,18 @@ def test_empty_callback_dispatches_failure_fact(app, db_session):
|
||||
"schema_version": "freight_rpa.inbound.v1",
|
||||
"callback_id": unit.callback_id,
|
||||
"status": "empty",
|
||||
"error_code": "no_receipt_data",
|
||||
"error_message": "no_receipt_data",
|
||||
"error_code": "no_inbound_data",
|
||||
"error_message": "no_inbound_data",
|
||||
}
|
||||
)
|
||||
assert result["status"] == "empty"
|
||||
assert len(seen) == 1
|
||||
fact = seen[0]
|
||||
# [断言意图] empty 是合法业务结果 → ok=False + error_code=no_receipt_data 的事实。
|
||||
# [断言意图] empty 是合法业务结果 → ok=False + error_code=no_inbound_data 的事实。
|
||||
assert fact.report_kind == "inbound"
|
||||
assert fact.source_code == "DSV"
|
||||
assert fact.ok is False
|
||||
assert fact.file_id is None
|
||||
assert fact.sha256 is None
|
||||
assert fact.error_code == "no_receipt_data"
|
||||
assert fact.error_message == "no_receipt_data"
|
||||
assert fact.error_code == "no_inbound_data"
|
||||
assert fact.error_message == "no_inbound_data"
|
||||
@@ -202,13 +202,13 @@ def test_assert_inventory_rpa_worker_ready_includes_reason_details(app, tmp_path
|
||||
assert (exc_info.value.details or {}).get("detail_message")
|
||||
|
||||
|
||||
def test_assert_receipt_rpa_worker_ready_includes_reason_details(app, tmp_path, monkeypatch):
|
||||
def test_assert_inbound_rpa_worker_ready_includes_reason_details(app, tmp_path, monkeypatch):
|
||||
"""收料 fail-fast 应附带 reasons,且与库存同口径要求共享哨兵。"""
|
||||
from app.core.errors import ServiceUnavailableError
|
||||
from app.services.freight_rpa.common import worker_heartbeat as heartbeat_module
|
||||
from app.services.freight_rpa.common.worker_heartbeat import (
|
||||
RPA_WORKER_OFFLINE_MESSAGE,
|
||||
assert_receipt_rpa_worker_ready,
|
||||
assert_inbound_rpa_worker_ready,
|
||||
reset_rpa_worker_heartbeat_state_for_tests,
|
||||
)
|
||||
|
||||
@@ -224,7 +224,7 @@ def test_assert_receipt_rpa_worker_ready_includes_reason_details(app, tmp_path,
|
||||
|
||||
with app.app_context():
|
||||
with pytest.raises(ServiceUnavailableError) as exc_info:
|
||||
assert_receipt_rpa_worker_ready()
|
||||
assert_inbound_rpa_worker_ready()
|
||||
# [断言意图] 与库存同构的用户可见文案与 reasons;缺哨兵与无心跳同时暴露,
|
||||
# 对应部署侧必须由 ps1 注入 FREIGHT_RPA_SHARED_SCOPE_ID 写哨兵。
|
||||
assert exc_info.value.message == RPA_WORKER_OFFLINE_MESSAGE
|
||||
@@ -502,7 +502,7 @@ def test_assert_freight_upload_rpa_ready_includes_reasons(app, tmp_path):
|
||||
def test_receipt_worker_status_requires_sentinel_like_inventory(app, tmp_path):
|
||||
"""收料 ready 与库存同口径:要求共享哨兵;仅有库存 Worker 不能冒充收料在线。"""
|
||||
from app.services.freight_rpa.common.worker_heartbeat import (
|
||||
check_receipt_rpa_worker_ready,
|
||||
check_inbound_rpa_worker_ready,
|
||||
reset_rpa_worker_heartbeat_state_for_tests,
|
||||
serialize_rpa_worker_status,
|
||||
)
|
||||
@@ -528,7 +528,7 @@ def test_receipt_worker_status_requires_sentinel_like_inventory(app, tmp_path):
|
||||
trigger_dir=str(inventory_trigger),
|
||||
shared_scope_id="hxops-rpa-test-data",
|
||||
))
|
||||
receipt_offline = check_receipt_rpa_worker_ready()
|
||||
receipt_offline = check_inbound_rpa_worker_ready()
|
||||
assert receipt_offline.ready is False
|
||||
assert receipt_offline.workers == []
|
||||
|
||||
@@ -539,11 +539,11 @@ def test_receipt_worker_status_requires_sentinel_like_inventory(app, tmp_path):
|
||||
shared_scope_id="hxops-rpa-test-data",
|
||||
capabilities=[INBOUND_EXPORT_CAPABILITY],
|
||||
))
|
||||
without_sentinel = check_receipt_rpa_worker_ready()
|
||||
without_sentinel = check_inbound_rpa_worker_ready()
|
||||
assert without_sentinel.ready is False
|
||||
|
||||
_write_shared_sentinel(receipt_trigger, scope_id="hxops-rpa-test-data")
|
||||
receipt_ready = check_receipt_rpa_worker_ready()
|
||||
receipt_ready = check_inbound_rpa_worker_ready()
|
||||
assert receipt_ready.ready is True
|
||||
assert [w["worker_id"] for w in receipt_ready.workers] == ["HOST-receipt"]
|
||||
|
||||
@@ -557,7 +557,7 @@ def test_receipt_worker_status_requires_sentinel_like_inventory(app, tmp_path):
|
||||
def test_receipt_worker_recognized_by_trigger_dir_without_receipt_suffix(app, tmp_path):
|
||||
"""未注入 *-receipt 身份时,仍可用收料 trigger_dir 识别在线收料 Worker。"""
|
||||
from app.services.freight_rpa.common.worker_heartbeat import (
|
||||
check_receipt_rpa_worker_ready,
|
||||
check_inbound_rpa_worker_ready,
|
||||
reset_rpa_worker_heartbeat_state_for_tests,
|
||||
)
|
||||
|
||||
@@ -579,6 +579,6 @@ def test_receipt_worker_recognized_by_trigger_dir_without_receipt_suffix(app, tm
|
||||
shared_scope_id="",
|
||||
capabilities=[INBOUND_EXPORT_CAPABILITY],
|
||||
))
|
||||
result = check_receipt_rpa_worker_ready()
|
||||
result = check_inbound_rpa_worker_ready()
|
||||
assert result.ready is True
|
||||
assert [w["worker_id"] for w in result.workers] == ["Hugo-30820"]
|
||||
Reference in new issue
Block a user