feat(in-transit-transfer): 自动调拨联动收料就绪并分层来源错误

- 调度整合:退役 in_transit_receipt_file_job,收料归档收敛 shipping_receipt_rpa_archive,排程注册表统一
- 自动调拨 Job:调拨前确保各来源当日收料文件就绪(缺失自动触发收料 RPA),严格等量匹配后生成 ERP 调拨单
- worker 手动唤醒:排程工作台支持手动唤醒与 runs 透视,heartbeat 协议同步
- 收料缺失幸存 T2:parse_failed 状态落库(迁移 q4c5)
- 来源错误分层与 stale 时钟换源:改挂 inventory_checked_at 库存查得时刻,展示阈值与执行门禁解耦(迁移 t5a6)
- 新增 wecom_sender 企微通知:每非空 Run 汇总一条,通知失败不影响 ERP 结果
- 同步排程工作台/调拨卡片前端、chat/admin 文案四语言、RPA 脚本与测试全家
This commit is contained in:
hugo committed 2026-09-30 00:20:06 +08:00
1 parent 993e581135
commit abf3d48927
144 files changed
+10161 -2132

No files matched your search

+116
View File
@@ -17,6 +17,7 @@ from app.core.errors import ServiceUnavailableError
from app.services.shipping_notice.rpa_worker_heartbeat import (
FREIGHT_UPLOAD_CAPABILITY,
INVENTORY_EXPORT_CAPABILITY,
RECEIPT_EXPORT_CAPABILITY,
RPA_FREIGHT_UPLOAD_NOT_READY_MESSAGE,
RPA_HEARTBEAT_STORAGE_UNAVAILABLE_MESSAGE,
RPA_WORKER_OFFLINE_MESSAGE,
@@ -201,6 +202,36 @@ 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):
"""收料 fail-fast 应附带 reasons,且不要求共享哨兵。"""
from app.core.errors import ServiceUnavailableError
from app.services.shipping_notice import rpa_worker_heartbeat as heartbeat_module
from app.services.shipping_notice.rpa_worker_heartbeat import (
RPA_WORKER_OFFLINE_MESSAGE,
assert_receipt_rpa_worker_ready,
reset_rpa_worker_heartbeat_state_for_tests,
)
monkeypatch.setattr(heartbeat_module, '_redis_client', lambda: None)
reset_rpa_worker_heartbeat_state_for_tests()
trigger_dir = tmp_path / 'receipt_triggers'
trigger_dir.mkdir()
app.config['ENV_NAME'] = 'test'
app.config['FREIGHT_RPA_SHARED_RECEIPT_TRIGGER_DIR'] = str(trigger_dir)
app.config['FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRED'] = True
app.config['FREIGHT_RPA_WORKER_HEARTBEAT_ALLOW_MEMORY_FALLBACK'] = True
app.config['FREIGHT_RPA_WORKER_MOCK'] = 'false'
with app.app_context():
with pytest.raises(ServiceUnavailableError) as exc_info:
assert_receipt_rpa_worker_ready()
# [断言意图] 与库存同构的用户可见文案与 reasons;收料不因缺哨兵失败。
assert exc_info.value.message == RPA_WORKER_OFFLINE_MESSAGE
reasons = (exc_info.value.details or {}).get('reasons', [])
assert 'no_worker_heartbeat' in reasons
assert 'shared_sentinel_missing' not in reasons
def test_check_inventory_rpa_worker_ready_rejects_stale_heartbeat(app, tmp_path, monkeypatch):
"""超过 TTL 的心跳应视为离线。"""
import time as time_module
@@ -465,3 +496,88 @@ def test_assert_freight_upload_rpa_ready_includes_reasons(app, tmp_path):
assert exc_info.value.message == RPA_FREIGHT_UPLOAD_NOT_READY_MESSAGE
reasons = (exc_info.value.details or {}).get("reasons", [])
assert "credential_key_missing" in reasons
def test_receipt_worker_status_requires_sentinel_like_inventory(app, tmp_path):
"""收料 ready 与库存同口径:要求共享哨兵;仅有库存 Worker 不能冒充收料在线。"""
from app.services.shipping_notice.rpa_worker_heartbeat import (
check_receipt_rpa_worker_ready,
reset_rpa_worker_heartbeat_state_for_tests,
serialize_rpa_worker_status,
)
receipt_trigger = tmp_path / "receipt" / "triggers"
receipt_trigger.mkdir(parents=True)
inventory_trigger = tmp_path / "inventory" / "triggers"
inventory_trigger.mkdir(parents=True)
_write_shared_sentinel(inventory_trigger, scope_id="hxops-rpa-test-data")
app.config["ENV_NAME"] = "test"
app.config["FREIGHT_RPA_SHARED_INVENTORY_TRIGGER_DIR"] = str(inventory_trigger)
app.config["FREIGHT_RPA_SHARED_RECEIPT_TRIGGER_DIR"] = str(receipt_trigger)
app.config["FREIGHT_RPA_SHARED_SCOPE_ID"] = "hxops-rpa-test-data"
app.config["FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRED"] = True
app.config["FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRE_REDIS"] = False
app.config["FREIGHT_RPA_WORKER_HEARTBEAT_ALLOW_MEMORY_FALLBACK"] = True
app.config["FREIGHT_RPA_WORKER_MOCK"] = "false"
reset_rpa_worker_heartbeat_state_for_tests()
with app.app_context():
record_rpa_worker_heartbeat(_heartbeat_payload(
worker_id="HOST-inventory",
trigger_dir=str(inventory_trigger),
shared_scope_id="hxops-rpa-test-data",
))
receipt_offline = check_receipt_rpa_worker_ready()
assert receipt_offline.ready is False
assert receipt_offline.workers == []
# 无哨兵时即便有收料心跳也不得 ready。
record_rpa_worker_heartbeat(_heartbeat_payload(
worker_id="HOST-receipt",
trigger_dir=str(receipt_trigger),
shared_scope_id="hxops-rpa-test-data",
capabilities=[RECEIPT_EXPORT_CAPABILITY],
))
without_sentinel = check_receipt_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()
assert receipt_ready.ready is True
assert [w["worker_id"] for w in receipt_ready.workers] == ["HOST-receipt"]
payload = serialize_rpa_worker_status(scope="receipt")
assert payload["scope"] == "receipt"
assert payload["ready"] is True
assert payload["trigger_dir"] == str(receipt_trigger)
assert [w["worker_id"] for w in payload["workers"]] == ["HOST-receipt"]
def test_receipt_worker_recognized_by_trigger_dir_without_receipt_suffix(app, tmp_path):
"""未注入 *-receipt 身份时,仍可用收料 trigger_dir 识别在线收料 Worker。"""
from app.services.shipping_notice.rpa_worker_heartbeat import (
check_receipt_rpa_worker_ready,
reset_rpa_worker_heartbeat_state_for_tests,
)
receipt_trigger = tmp_path / "receipt" / "triggers"
receipt_trigger.mkdir(parents=True)
app.config["ENV_NAME"] = "dev"
app.config["FREIGHT_RPA_SHARED_RECEIPT_TRIGGER_DIR"] = str(receipt_trigger)
app.config["FREIGHT_RPA_SHARED_SCOPE_ID"] = ""
app.config["FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRED"] = True
app.config["FREIGHT_RPA_WORKER_HEARTBEAT_REQUIRE_REDIS"] = False
app.config["FREIGHT_RPA_WORKER_HEARTBEAT_ALLOW_MEMORY_FALLBACK"] = True
app.config["FREIGHT_RPA_WORKER_MOCK"] = "false"
reset_rpa_worker_heartbeat_state_for_tests()
with app.app_context():
record_rpa_worker_heartbeat(_heartbeat_payload(
worker_id="Hugo-30820",
trigger_dir=str(receipt_trigger),
shared_scope_id="",
capabilities=[RECEIPT_EXPORT_CAPABILITY],
))
result = check_receipt_rpa_worker_ready()
assert result.ready is True
assert [w["worker_id"] for w in result.workers] == ["Hugo-30820"]