feat(in-transit-transfer): 落地证据流重解析并纳入货代与排程配套改动
外部单号进入异动档自然键,圈档按 T-2 成熟封顶,当前归档可单独重解析。同批带上 Crane 禁整页刷新、ODM 白名单降级、排程抽屉与执行记录日期窗,以及 YAML 库存源下线。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
911afa0f73
commit
4c2a7e2a23
145 files changed
+11695
-4214
No files matched your search
@@ -101,6 +101,80 @@ def _awaiting_outbound_unit(*, callback_id: str):
|
||||
)
|
||||
|
||||
|
||||
def test_outbound_batch_ready_sink_finalizes_schedule_even_if_fact_handler_raises(
|
||||
tmp_path, app, monkeypatch,
|
||||
):
|
||||
"""文件归档单元终态后,事实/证据处理失败仍须收口排程(文件返回= RPA 结束)。
|
||||
|
||||
[断言意图] batch-ready sink 在 finally 中 finalize;不得依赖 handle_outbound_report 成功。
|
||||
"""
|
||||
from app import db
|
||||
from app.models import ScheduleRun, ScheduleTask, FreightRpaOutboundUnitRun
|
||||
from app.services.freight_rpa.reports.dispatch import register_report_handler
|
||||
from app.services.in_transit_transfer.rpa_sinks import _outbound_batch_ready_sink
|
||||
|
||||
drop = tmp_path / "outbound_drop"
|
||||
drop.mkdir()
|
||||
payload_bytes = b"PK\x03\x04fake"
|
||||
(drop / "foo.xlsx").write_bytes(payload_bytes)
|
||||
|
||||
with app.app_context():
|
||||
app.config["FREIGHT_RPA_SHARED_OUTBOUND_DROP_DIR"] = str(drop)
|
||||
task = ScheduleTask(
|
||||
schedule_no="SCH-OUTBOUND-FILE-FINAL",
|
||||
name="Outbound file finalize",
|
||||
schedule_type="platform_job",
|
||||
platform_api_path="freight-rpa-outbound",
|
||||
owner_user_id=1,
|
||||
cron_expr="0 8 * * *",
|
||||
)
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
run = ScheduleRun(
|
||||
run_no="RUN-OUTBOUND-FILE-FINAL",
|
||||
schedule_task_id=task.id,
|
||||
status="running",
|
||||
total_count=1,
|
||||
success_count=0,
|
||||
failed_count=0,
|
||||
skipped_count=0,
|
||||
response_summary_json={"awaiting_outbound_rpa": True},
|
||||
)
|
||||
db.session.add(run)
|
||||
db.session.flush()
|
||||
unit = _awaiting_outbound_unit(callback_id="outbound-file-final-cb")
|
||||
unit.schedule_run_id = run.id
|
||||
db.session.add(unit)
|
||||
db.session.commit()
|
||||
|
||||
monkeypatch.setattr(
|
||||
"app.services.freight_rpa.outbound.report_archive.file_asset_storage.upload_bytes",
|
||||
lambda **_kwargs: None,
|
||||
)
|
||||
|
||||
def _boom(_fact):
|
||||
raise RuntimeError("evidence sync exploded")
|
||||
|
||||
register_report_handler("outbound", _boom)
|
||||
payload = {
|
||||
"schema_version": "freight_rpa.outbound.v1",
|
||||
"callback_id": unit.callback_id,
|
||||
"status": "success",
|
||||
"file_path": r"C:\HxopsRpaTest\data\freight_rpa\outbound\drop\foo.xlsx",
|
||||
"original_filename": "foo.xlsx",
|
||||
"sha256": hashlib.sha256(payload_bytes).hexdigest(),
|
||||
}
|
||||
|
||||
with pytest.raises(RuntimeError, match="evidence sync exploded"):
|
||||
_outbound_batch_ready_sink(**payload)
|
||||
|
||||
db.session.expire_all()
|
||||
refreshed = db.session.get(ScheduleRun, run.id)
|
||||
assert refreshed.status == "success"
|
||||
assert (refreshed.response_summary_json or {}).get("awaiting_outbound_rpa") is False
|
||||
assert db.session.get(FreightRpaOutboundUnitRun, unit.id).status == "success"
|
||||
|
||||
|
||||
def test_ingest_outbound_callback_archives_and_dispatches_fact(tmp_path, app, monkeypatch):
|
||||
"""success 回调按 Windows 绝对路径只认文件名归档,并投递 report_kind=outbound 事实。"""
|
||||
from app import db
|
||||
|
||||
Reference in new issue
Block a user