feat(in-transit-transfer): 落地证据流重解析并纳入货代与排程配套改动

外部单号进入异动档自然键,圈档按 T-2 成熟封顶,当前归档可单独重解析。同批带上 Crane 禁整页刷新、ODM 白名单降级、排程抽屉与执行记录日期窗,以及 YAML 库存源下线。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-10-22 00:48:37 +08:00
1 parent 911afa0f73
commit 4c2a7e2a23
145 files changed
+11695 -4214

No files matched your search

+77
View File
@@ -187,6 +187,83 @@ def test_batch_inventory_callback_preserves_each_source_v2_identity(monkeypatch,
}
def test_batch_open_browser_failure_records_remaining_sources_as_profile_failed(monkeypatch, tmp_path):
"""批级 launch_persistent_context 失败须为组内全部源记 rpa_profile_failed 并批末回调。
[断言意图] 与 inbound/outbound「剩余单元补 failed」同契约:浏览器未开时不得
静默丢源;须进 results + ONHAND_BATCH_READY,error_code=rpa_profile_failed。
"""
worker = _load_freight_rpa_worker()
trigger_dir = tmp_path / "triggers"
drop_dir = tmp_path / "drop"
processed_dir = trigger_dir / "processed"
trigger_dir.mkdir()
drop_dir.mkdir()
trigger_path = trigger_dir / "inventory_export_batch_open_fail.json"
sources = [
{
"source_code": code,
"connector_type": "dbs",
"warehouse_id": wh,
"expected_warehouse_id": wh,
"rpa_profile_code": "DBS_AR",
"entry_url": "https://s360.dbschenker.com/",
"task_no": "SN-OPEN-FAIL",
"callback_id": f"PSR-OPEN-FAIL-{wh}:C1",
"source_run_no": f"PSR-OPEN-FAIL-{wh}",
"attempt_no": 1,
"lease_token": f"lease-{wh}",
"candidate_set_id": 12,
"execution_id": 88,
"gate_id": 901,
}
for code, wh in (("DSV360_AWSDU", "AWSDU"), ("DSV360_AWSRTM", "AWSRTM"))
]
trigger_path.write_text(json.dumps({
"action": "inventory_export_batch",
"schema_version": "freight_rpa.onhand.v1",
"callback_id": "BATCH-OPEN-FAIL:batch:C1",
"batch_run_no": "BATCH-OPEN-FAIL",
"task_no": "SN-OPEN-FAIL",
"inventory_sources": sources,
}), encoding="utf-8")
callbacks: list[tuple[str, dict]] = []
def _boom(*_args, **_kwargs):
raise RuntimeError("BrowserType.launch_persistent_context: Target page, context or browser has been closed")
monkeypatch.setattr(worker, "_open_browser", _boom)
monkeypatch.setattr(worker, "_post_callback", lambda path, body: callbacks.append((path, body)))
monkeypatch.setattr(worker, "_close_batch_browser_resources", lambda *_a, **_k: None)
worker._handle_onhand_batch_trigger(trigger_path, drop_dir, processed_dir)
completed = next(body for path, body in callbacks if path.endswith("/onhand-batch-ready"))
assert completed["failed_count"] == 2
assert completed["success_count"] == 0
assert len(completed["results"]) == 2
assert {row["source_code"] for row in completed["results"]} == {"DSV360_AWSDU", "DSV360_AWSRTM"}
assert all(row["error_code"] == "rpa_profile_failed" for row in completed["results"])
assert all(row["status"] == "failed" for row in completed["results"])
assert (processed_dir / trigger_path.name).is_file()
def test_onhand_batch_profile_failure_skips_already_recorded_sources_contract():
"""组级补 failed 必须按 recorded_keys 跳过已入 results 的源(禁止二次追加)。
[断言意图] onhand 与 inbound/outbound 同契约:批级失败只收口「剩余」源;
源码须含 recorded_keys / remaining / rpa_profile_failed 门禁。
"""
text = (
_repo_root() / "scripts" / "freight_rpa" / "onhand" / "onhand_rpa_worker.py"
).read_text(encoding="utf-8")
assert "recorded_keys" in text
assert "remaining" in text
assert "rpa_profile_failed" in text
assert "open/group failed" in text
assert "尚未写入 results" in text or "not in recorded_keys" in text
def test_batch_crane_trigger_allows_dynamic_warehouse_identity(monkeypatch, tmp_path):
"""Crane 动态 Warehouse 在导出前未知时,v2 trigger 不应被身份校验拒绝。"""
worker = _load_freight_rpa_worker()