feat(freight-rpa): 批次R解耦编排层并切换 onhand/inbound 契约

将 RPA 编排收编至 freight_rpa,回调迁 /api/freight-rpa/*。
共享目录与 Worker 契约一次切换至 onhand/inbound/upload,
并补 outbound 骨架与 tt16 排程 job key 迁移。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
hugoandCursor committed 2026-10-17 23:18:48 +08:00
1 parent bf3154033b
commit ffc0d4a430
147 files changed
+4221 -2678

No files matched your search

@@ -128,7 +128,7 @@ def test_configuration_test_callback_isolated_from_production_inventory(app, tmp
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
started = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -151,9 +151,9 @@ def test_configuration_test_callback_maps_windows_drop_path_to_shared_mount(app,
drop_dir.mkdir()
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
app.config['FREIGHT_RPA_SHARED_INVENTORY_DROP_DIR'] = str(drop_dir)
app.config['FREIGHT_RPA_SHARED_ONHAND_DROP_DIR'] = str(drop_dir)
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
started = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -172,7 +172,7 @@ def test_empty_configuration_export_is_successful_but_marks_data_validation_pend
"""已绑定发布方案的空库存结果是有效连接证据,不能被误写为 RPA 失败。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
field_id = _published_order_field()
@@ -208,7 +208,7 @@ def test_empty_configuration_export_without_published_profile_is_rejected(app):
"""没有受控解析定义时,空结果不能被用作站点可用性的替代证据。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
started = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -225,7 +225,7 @@ def test_configuration_test_automatically_verifies_compatible_bound_profile(app,
"""当前绑定方案的核心栏位仍在时,历史无关列缺失也必须直接成为验证证据。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -245,7 +245,7 @@ def test_verified_current_profile_does_not_auto_enable_ready_source(app, tmp_pat
"""当前解析验证通过且硬门槛齐全时,测试回调仍不得自动启用;启停只走显式开关。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
seeded = _complete_test_run(source, tmp_path)
@@ -268,7 +268,7 @@ def test_verified_current_profile_keeps_source_disabled_without_template(app, tm
"""解析测试通过不绕过发货模板门禁,条件不完整的站点必须保持停用。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
seeded = _complete_test_run(source, tmp_path)
@@ -289,7 +289,7 @@ def test_empty_export_does_not_auto_enable_ready_fixed_source(app, tmp_path):
"""固定仓查询成功但无库存时,只写入验证事实,不得自动启用站点。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
seeded = _complete_test_run(source, tmp_path)
@@ -313,7 +313,7 @@ def test_batch_configuration_test_groups_profiles_and_isolates_site_results(app,
"""同连接站点一次投递,混合成功、空库存及失败后仍独立汇总为部分失败。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
) as write_trigger:
first = _source('BATCH_SOURCE_A', 'BATCH_LOGIN_A')
second = _source('BATCH_SOURCE_B', 'BATCH_LOGIN_B')
@@ -355,7 +355,7 @@ def test_retry_batch_only_retriggers_failed_sites(app, tmp_path):
"""批次重试只新建失败站点运行,成功和空库存结果不会被重复导出。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source('RETRY_SOURCE', 'RETRY_LOGIN')
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -377,7 +377,7 @@ def test_batch_callback_marks_changed_source_stale_and_ignores_unknown_run(app,
"""配置变更后的旧批次回调必须失效,未知运行号不能污染同批次状态。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source('STALE_BATCH_SOURCE', 'STALE_BATCH_LOGIN')
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -405,7 +405,7 @@ def test_latest_active_batch_restores_only_unfinished_validation(app, tmp_path):
"""页面刷新只能恢复仍在执行的批次,已结束批次不会反复占用进度面板。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source('RESTORE_BATCH_SOURCE', 'RESTORE_BATCH_LOGIN')
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -427,7 +427,7 @@ def test_batch_progress_marks_only_claimed_current_run_processing(app, tmp_path)
"""Worker 领取回调只更新本批次当前运行,终态运行不得被重新打开。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source('PROGRESS_BATCH_SOURCE', 'PROGRESS_BATCH_LOGIN')
seed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -460,7 +460,7 @@ def test_latest_configuration_test_recovers_only_current_configuration(app, tmp_
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
first = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -480,9 +480,9 @@ def test_configuration_test_timeout_marks_run_failed(app, tmp_path):
"""RPA 长时间未回调时,读取最近运行应服务端收口为失败而非让前端无限轮询。"""
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
app.config['FREIGHT_RPA_INVENTORY_TIMEOUT_SECONDS'] = 1
app.config['FREIGHT_RPA_ONHAND_TIMEOUT_SECONDS'] = 1
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
started = inventory_configuration_test.start_test_export(source['id'], actor_id=None)
@@ -509,9 +509,9 @@ def test_configuration_test_timeout_marks_run_failed(app, tmp_path):
def test_batch_configuration_test_timeout_scales_with_shared_worker_queue(app, tmp_path):
"""同连接批量站点在 Worker 串行等待时,不得按单站时限提前失败。"""
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
app.config['FREIGHT_RPA_INVENTORY_TIMEOUT_SECONDS'] = 10
app.config['FREIGHT_RPA_ONHAND_TIMEOUT_SECONDS'] = 10
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
first = _source('TIMEOUT_QUEUE_A', 'TIMEOUT_QUEUE_LOGIN')
second = _source('TIMEOUT_QUEUE_B', 'TIMEOUT_QUEUE_LOGIN_B')
@@ -537,7 +537,7 @@ def test_confirming_test_profile_binds_only_compatible_published_profile(app, tm
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
completed = _complete_test_run(source, tmp_path)
@@ -579,7 +579,7 @@ def test_rpa_profile_change_does_not_block_activation_hard_gates(app, tmp_path):
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
completed = _complete_test_run(source, tmp_path)
@@ -611,7 +611,7 @@ def test_configuration_test_rejects_enabled_source_and_stale_confirmation(app, t
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
completed = _complete_test_run(source, tmp_path)
@@ -645,7 +645,7 @@ def test_failed_callback_and_unrelated_profile_never_bind_source(app, tmp_path):
app.config['SHIPPING_NOTICE_STORAGE_ROOT'] = str(tmp_path / 'shipping')
app.config['FREIGHT_RPA_CREDENTIAL_KEY'] = Fernet.generate_key().decode('ascii')
with app.app_context(), patch(
'app.services.shipping_notice.rpa.write_inventory_export_batch_trigger', return_value='trigger.json',
'app.services.shipping_notice.onhand_trigger_batch.write_inventory_export_batch_trigger', return_value='trigger.json',
):
source = _source()
failed = inventory_configuration_test.start_test_export(source['id'], actor_id=None)