fix(shipping-notice): 收料回调路径契约改为 drop 根内文件名

- 修复跨机成功回调全程 400:Worker(Windows)与后端(Linux 挂载根)分属两机根路径不同,后端无法解析 Worker 本机绝对路径
- Worker 只上报文件名(output.name),后端按自身挂载的 drop 根拼接定位;历史载荷携带绝对路径亦按末段文件名兼容解析
- 同步收料 worker 路径契约注释与跨机路径回归测试
This commit is contained in:
hugo committed 2026-10-08 13:14:47 +08:00
1 parent 91a4bd538d
commit 4e97553f42
3 files changed
+40 -4

No files matched your search

@@ -288,3 +288,27 @@ def test_receipt_progress_routes_are_registered(app):
resp = client.post(path, json=payload, headers=headers)
assert resp.status_code == 200, (path, resp.status_code, resp.get_json())
assert resp.get_json()['data']['updated'] is False
def test_read_receipt_callback_file_resolves_drop_root_filename(app, tmp_path):
"""跨机路径契约:Worker 只上报文件名(或历史 Windows 绝对路径),后端按自身 drop 根定位。"""
from app.core.errors import ValidationError
from app.services.shipping_notice.receipt_report_storage import _read_receipt_callback_file
with app.app_context():
drop_root = tmp_path / 'receipt-drop'
drop_root.mkdir()
app.config['FREIGHT_RPA_SHARED_RECEIPT_DROP_DIR'] = str(drop_root)
target = drop_root / 'receipt_RUN_X_SITE_NA_2026.xlsx'
target.write_bytes(b'receipt-bytes')
# [断言意图] 裸文件名(新 Worker 契约)与 Windows 本机绝对路径(历史载荷)都
# 必须解析到后端 drop 根内同一文件;根外文件依旧拒绝(任意本机文件读取护栏不变)。
assert _read_receipt_callback_file('receipt_RUN_X_SITE_NA_2026.xlsx') == b'receipt-bytes'
assert _read_receipt_callback_file(
r'C:\HxopsRpaTest\data\freight_rpa\receipt\drop\receipt_RUN_X_SITE_NA_2026.xlsx'
) == b'receipt-bytes'
outside = tmp_path / 'outside.xlsx'
outside.write_bytes(b'x')
with pytest.raises(ValidationError, match='receipt callback file'):
_read_receipt_callback_file(str(outside))