refactor(rpa): 重构 scripts/rpa 目录结构与命名

按 common/connectors/inventory/receipt 分层并重命名

- common/: rpa_common, rpa_heartbeat, download_artifact_fallback,
  new_rpa_worker_secret
- connectors/dsv|crane/: 登录网站连接器,库存与收料共用
- inventory/: inventory_rpa_worker, run_inventory_batch_trigger,
  start_inventory_worker, register_inventory_worker_tasks
- receipt/: receipt_rpa_worker, receipt_crane/dbs_export,
  start_receipt_worker

保留裸 import + sys.path 引导;修正懒加载路径;
按范围命名 register_rpa_background_tasks -> register_inventory_worker_tasks;
同步 backend 测试、start_local.ps1、.env 注释、docs 与 README 路径。

(cherry picked from commit f3050164d0)
This commit is contained in:
hugo committed 2026-08-28 17:23:39 +08:00
1 parent 09deada712
commit 12521489c6
40 files changed
+384 -172

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@ import pytest
def _load_navigation():
module_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "crane_navigation.py"
module_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "connectors" / "crane" / "crane_navigation.py"
spec = importlib.util.spec_from_file_location("crane_navigation_test", module_path)
assert spec and spec.loader
module = importlib.util.module_from_spec(spec)
+1 -1
View File
@@ -10,7 +10,7 @@ import pytest
def _load_export():
module_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "crane_report_export.py"
module_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "connectors" / "crane" / "crane_report_export.py"
spec = importlib.util.spec_from_file_location("crane_report_export_test", module_path)
assert spec and spec.loader
module = importlib.util.module_from_spec(spec)
+2 -2
View File
@@ -8,7 +8,7 @@ from unittest.mock import MagicMock
def _load_crane_session():
module_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "crane_session.py"
module_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "connectors" / "crane" / "crane_session.py"
spec = importlib.util.spec_from_file_location("crane_session_test", module_path)
assert spec and spec.loader
module = importlib.util.module_from_spec(spec)
@@ -144,7 +144,7 @@ def test_find_crane_sign_in_button_waits_for_enabled_state(monkeypatch):
def test_ensure_crane_session_skips_login_when_session_active(monkeypatch):
"""batch 内 session 有效时不应重复 goto + login。"""
worker_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "freight_rpa_worker.py"
worker_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "inventory" / "inventory_rpa_worker.py"
spec = importlib.util.spec_from_file_location("freight_rpa_worker_crane_test", worker_path)
assert spec and spec.loader
worker = importlib.util.module_from_spec(spec)
+1 -1
View File
@@ -7,7 +7,7 @@ from pathlib import Path
def _load_module():
path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "dsv_report_parameters.py"
path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / "connectors" / "dsv" / "dsv_report_parameters.py"
spec = importlib.util.spec_from_file_location("dsv_report_parameters_test", path)
assert spec and spec.loader
module = importlib.util.module_from_spec(spec)
@@ -7,7 +7,7 @@ from pathlib import Path
def test_receipt_worker_isolated_from_inventory_worker_and_uses_receipt_contract():
"""收料 Worker 只消费 v1 receipt trigger、专用目录和独立 callback。"""
text = (Path(__file__).resolve().parents[2] / 'scripts' / 'rpa' / 'freight_receipt_rpa_worker.py').read_text(encoding='utf-8')
text = (Path(__file__).resolve().parents[2] / 'scripts' / 'rpa' / 'receipt' / 'receipt_rpa_worker.py').read_text(encoding='utf-8')
assert 'SHIPPING_NOTICE_RPA_SHARED_RECEIPT_TRIGGER_DIR' in text
assert 'SHIPPING_NOTICE_RPA_SHARED_RECEIPT_DROP_DIR' in text
assert 'shipping_receipt_rpa.v1' in text
@@ -19,8 +19,8 @@ def test_receipt_worker_isolated_from_inventory_worker_and_uses_receipt_contract
def test_receipt_crane_driver_forces_inbound_details_match_name():
"""收料 Crane 必须将固定报表名传给轮询匹配,不能落回库存文件名默认值。"""
root = Path(__file__).resolve().parents[2] / 'scripts' / 'rpa'
receipt_driver = (root / 'freight_receipt_crane_export.py').read_text(encoding='utf-8')
crane_driver = (root / 'crane_report_export.py').read_text(encoding='utf-8')
receipt_driver = (root / 'receipt' / 'receipt_crane_export.py').read_text(encoding='utf-8')
crane_driver = (root / 'connectors' / 'crane' / 'crane_report_export.py').read_text(encoding='utf-8')
assert "'scheduled_report_name': 'Inbound Details'" in receipt_driver
assert "source_value = str((source or {}).get('scheduled_report_name') or '').strip()" in crane_driver
@@ -28,7 +28,7 @@ def test_receipt_crane_driver_forces_inbound_details_match_name():
def test_receipt_crane_driver_forces_inbound_details_entry_route():
"""复用 Profile 的门户首页时,收料不能误走库存 On Hand Details 路由。"""
root = Path(__file__).resolve().parents[2] / 'scripts' / 'rpa'
module_path = root / 'freight_receipt_crane_export.py'
module_path = root / 'receipt' / 'receipt_crane_export.py'
sys.path.insert(0, str(root))
spec = importlib.util.spec_from_file_location('freight_receipt_crane_export_test', module_path)
assert spec and spec.loader
+1 -1
View File
@@ -13,7 +13,7 @@ def _load_freight_rpa_heartbeat_module():
rpa_dir = Path(__file__).resolve().parents[2] / "scripts" / "rpa"
if str(rpa_dir) not in sys.path:
sys.path.insert(0, str(rpa_dir))
module_path = rpa_dir / "freight_rpa_heartbeat.py"
module_path = rpa_dir / "common" / "rpa_heartbeat.py"
spec = importlib.util.spec_from_file_location("freight_rpa_heartbeat_test", module_path)
module = importlib.util.module_from_spec(spec)
assert spec.loader is not None
+3 -3
View File
@@ -26,8 +26,8 @@ def _repo_root() -> Path:
def _load_freight_rpa_worker():
module_path = _repo_root() / "scripts" / "rpa" / "freight_rpa_worker.py"
spec = importlib.util.spec_from_file_location("freight_rpa_worker_under_test", module_path)
module_path = _repo_root() / "scripts" / "rpa" / "inventory" / "inventory_rpa_worker.py"
spec = importlib.util.spec_from_file_location("inventory_rpa_worker_under_test", module_path)
assert spec is not None
assert spec.loader is not None
module = importlib.util.module_from_spec(spec)
@@ -1627,7 +1627,7 @@ def test_has_dsv_password_upgrade_prompt_skips_portal_page_scan(monkeypatch):
def test_ensure_dsv_session_retries_entry_after_home_not_ready(monkeypatch):
"""登录后 home-not-ready 且 session 仍在 entry 站点时,应回 entry 重试一次。"""
module_path = _repo_root() / "scripts" / "rpa" / "dsv_report_export.py"
module_path = _repo_root() / "scripts" / "rpa" / "connectors" / "dsv" / "dsv_report_export.py"
spec = importlib.util.spec_from_file_location("dsv_report_export_retry_test", module_path)
assert spec is not None and spec.loader is not None
dsv_report_export = importlib.util.module_from_spec(spec)
@@ -20,8 +20,21 @@ def _load_dsv_auth_login_flow():
return _load_rpa_module("dsv_auth_login_flow")
_RPA_MODULE_PATHS = {
"freight_rpa_worker": "inventory/inventory_rpa_worker.py",
"inventory_rpa_worker": "inventory/inventory_rpa_worker.py",
"dsv_report_export": "connectors/dsv/dsv_report_export.py",
"dsv_auth_login_flow": "connectors/dsv/dsv_auth_login_flow.py",
"dsv_navigation": "connectors/dsv/dsv_navigation.py",
"dsv_auth": "connectors/dsv/dsv_auth.py",
"dsv_session": "connectors/dsv/dsv_session.py",
"dsv_debug": "connectors/dsv/dsv_debug.py",
}
def _load_rpa_module(module_name: str):
module_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / f"{module_name}.py"
rel = _RPA_MODULE_PATHS.get(module_name, f"{module_name}.py")
module_path = Path(__file__).resolve().parents[2] / "scripts" / "rpa" / rel
scripts_dir = str(module_path.parent)
if scripts_dir not in sys.path:
sys.path.insert(0, scripts_dir)