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

@@ -29,12 +29,20 @@ from app.services.shipping_notice.audit_service import append_shipping_audit_eve
def _read_receipt_callback_file(file_path: str) -> bytes:
"""只读取收料专用 drop 根内的 xlsx,拒绝 callback 任意本机文件读取。"""
"""只读取收料专用 drop 根内的 xlsx,拒绝 callback 任意本机文件读取。
路径契约为「drop 根内文件名」:Worker(Windows RPA 主机)与后端(Linux 容器)分属
两机,各自看到的根路径不同(C:\\HxopsRpaTest\\... vs /mnt/hxops-rpa-*-data/...),
Worker 只上报文件名,后端用自身挂载的 drop 根拼接定位;携带本机绝对路径的历史
载荷亦按末段文件名解析(2026-10-08 修复跨机成功回调全程 400 的事故)。
"""
configured_root = str(current_app.config.get('FREIGHT_RPA_SHARED_RECEIPT_DROP_DIR') or '').strip()
if not configured_root:
raise ValidationError('receipt callback file root is unavailable', code='SHIPPING.RECEIPT_CALLBACK_FILE_INVALID')
root = Path(configured_root).resolve()
path = Path(file_path).resolve()
# 容忍历史载荷携带 Windows 绝对路径:先归一分隔符再取末段文件名(防遍历,单一分段)。
name = Path(str(file_path).replace('\\', '/')).name
path = (root / name).resolve()
try:
path.relative_to(root)
except ValueError as exc: