chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑
This commit is contained in:
1 parent
5ef8329bd8
commit
4ec4e57005
183 files changed
+14653
-3936
No files matched your search
@@ -0,0 +1,61 @@
|
||||
"""
|
||||
tests/test_worker_shipping.py
|
||||
|
||||
用途:验证 Shipping Worker 在 Windows spawn 模式下使用启动它的虚拟环境解释器。
|
||||
依赖:worker_shipping、pytest monkeypatch。
|
||||
逻辑:避免 multiprocessing 子进程回退到系统 Python,导致 OCR 等可选依赖从错误环境加载。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
import worker_shipping
|
||||
from app.jobs.types import JobType
|
||||
from app.services.shipping_notice import queue_service
|
||||
|
||||
|
||||
pytestmark = pytest.mark.pure_unit
|
||||
|
||||
|
||||
def test_configure_shipping_worker_process_executable_uses_current_interpreter(monkeypatch):
|
||||
"""子进程解释器必须与 Worker 主进程一致,防止环境混用。"""
|
||||
recorded: list[str] = []
|
||||
monkeypatch.setattr(worker_shipping.mp, 'set_executable', recorded.append)
|
||||
|
||||
worker_shipping.configure_shipping_worker_process_executable()
|
||||
|
||||
# 关键断言:Windows spawn 子进程不能回退到 PATH 上的系统 Python。
|
||||
assert recorded == [sys.executable]
|
||||
|
||||
|
||||
def test_assert_shipping_worker_capabilities_rejects_missing_xfa_ocr(monkeypatch):
|
||||
"""关键断言:shipping Worker 在领取 Job 前必须拒绝缺少 XFA OCR 的运行环境。"""
|
||||
monkeypatch.setattr(worker_shipping, 'is_ocr_engine_available', lambda: False)
|
||||
|
||||
with pytest.raises(RuntimeError, match='XFA OCR dependency is unavailable'):
|
||||
worker_shipping.assert_shipping_worker_capabilities()
|
||||
|
||||
|
||||
def test_assert_shipping_worker_capabilities_accepts_complete_xfa_ocr(monkeypatch):
|
||||
"""关键断言:完整 OCR 环境允许 shipping Worker 启动并消费队列。"""
|
||||
monkeypatch.setattr(worker_shipping, 'is_ocr_engine_available', lambda: True)
|
||||
|
||||
worker_shipping.assert_shipping_worker_capabilities()
|
||||
|
||||
|
||||
def test_shipping_worker_claims_unified_pdf_automark_jobs(monkeypatch):
|
||||
"""统一自动标注必须进入 shipping worker 的领取白名单,不能永久 queued。"""
|
||||
received: dict[str, object] = {}
|
||||
|
||||
def claim_next_job(**kwargs):
|
||||
received.update(kwargs)
|
||||
return None
|
||||
|
||||
monkeypatch.setattr('app.jobs.queue.claim_next_job', claim_next_job)
|
||||
|
||||
queue_service.claim_next_shipping_notice_job()
|
||||
|
||||
assert JobType.SHIPPING_PDF_AUTOMARK in received['job_types']
|
||||
Reference in new issue
Block a user