feat(shipping-notice): 收敛阶段能力投影并修复库存 RPA 运行链路
下发 preparation capabilities 并与右卡展示同源授权; 库存 RPA 运行态请求内 memo;取消会话 Profile 本地 TTL; 并为 shipping-worker 挂载共享盘。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
f773237226
commit
a6edc4fe61
16 files changed
+433
-179
No files matched your search
@@ -1483,8 +1483,8 @@ def test_open_browser_reuses_dsv_session_profile_only_when_explicitly_enabled(mo
|
||||
assert worker._should_cleanup_browser_profile(profile_dir) is False
|
||||
|
||||
|
||||
def test_prepare_reusable_session_profile_expires_after_ttl(monkeypatch, tmp_path):
|
||||
"""超过 TTL 的持久 Profile 应被清空重建,迫使重新登录。"""
|
||||
def test_prepare_reusable_session_profile_keeps_existing_dir(tmp_path):
|
||||
"""持久 Profile 不按本地时间清空;已有内容应保留供站点会话继续复用。"""
|
||||
worker = _load_freight_rpa_worker()
|
||||
profile_dir = tmp_path / "dsv360__OLD_session"
|
||||
profile_dir.mkdir(parents=True)
|
||||
@@ -1495,7 +1495,6 @@ def test_prepare_reusable_session_profile_expires_after_ttl(monkeypatch, tmp_pat
|
||||
json.dumps({"created_at_unix": created, "connector_type": "dsv360", "profile_code": "OLD"}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setenv("SHIPPING_NOTICE_RPA_WORKER_SESSION_REUSE_TTL_HOURS", "24")
|
||||
|
||||
prepared = worker._prepare_reusable_session_profile(
|
||||
profile_dir,
|
||||
@@ -1504,9 +1503,11 @@ def test_prepare_reusable_session_profile_expires_after_ttl(monkeypatch, tmp_pat
|
||||
)
|
||||
|
||||
assert prepared == profile_dir
|
||||
assert not stale_marker.exists()
|
||||
assert stale_marker.exists()
|
||||
meta = json.loads((profile_dir / ".hxops_rpa_session_meta.json").read_text(encoding="utf-8"))
|
||||
assert float(meta["created_at_unix"]) > created
|
||||
assert float(meta["created_at_unix"]) == created
|
||||
assert "ttl_hours" not in meta
|
||||
|
||||
|
||||
def test_is_dsv_username_page_ignores_login_method_page_text():
|
||||
"""第二步方法选择页即使残留第一步文案,也不应被误判为邮箱页。"""
|
||||
|
||||
@@ -612,6 +612,65 @@ def test_stage_context_prefers_current_structured_inventory_match(app) -> None:
|
||||
assert "retry_inventory_preparation" in line["inventory_allowed_actions"]
|
||||
|
||||
|
||||
def test_stage_context_hides_inventory_actions_while_rpa_running(app) -> None:
|
||||
"""库存 RPA queued/running 时,工作台 preparation 行不得下发重试 RPA 动作。
|
||||
|
||||
与 Case 投影同源:inventory_rpa_is_running 在行循环外算一次;运行中 actions 为空。
|
||||
"""
|
||||
from app.models import ShippingTaskInventoryRpaAttempt
|
||||
|
||||
with app.app_context():
|
||||
user = User(username='ui-rpa-running', email='ui-rpa-running@example.com')
|
||||
db.session.add(user)
|
||||
db.session.flush()
|
||||
task = ShippingOrderTask(task_no='OT-UI-RPA-RUNNING', user_id=user.id, stage='inventory_matching')
|
||||
db.session.add(task)
|
||||
db.session.flush()
|
||||
snapshot = ShippingOrderSnapshot(
|
||||
task_id=task.id, extraction_id=1, schema_version_id=1,
|
||||
order_data_version=1, header_values_json={},
|
||||
)
|
||||
db.session.add(snapshot)
|
||||
db.session.flush()
|
||||
task.order_snapshot_id = snapshot.id
|
||||
snapshot_line = ShippingOrderSnapshotLine(
|
||||
snapshot_id=snapshot.id, position=0, line_no=1,
|
||||
reservation_id='RSV-RPA', part_number='PN-RPA', qty='10', field_values_json={},
|
||||
)
|
||||
db.session.add(snapshot_line)
|
||||
db.session.flush()
|
||||
db.session.add(ShippingNoticeLineInventoryMatch(
|
||||
task_id=task.id,
|
||||
snapshot_line_id=snapshot_line.id,
|
||||
line_no=1,
|
||||
line_index=0,
|
||||
match_result='matched',
|
||||
inventory_status='ready',
|
||||
required_qty='10',
|
||||
available_qty='7',
|
||||
matched_qty='7',
|
||||
shortage_qty='3',
|
||||
reservation_id='RSV-RPA',
|
||||
part_number='PN-RPA',
|
||||
inventory_source_code='DBS_DUB',
|
||||
is_current=True,
|
||||
))
|
||||
db.session.add(ShippingTaskInventoryRpaAttempt(
|
||||
task_no=task.task_no,
|
||||
source_code='DBS_DUB',
|
||||
attempt_no=1,
|
||||
source_run_no='PSR-UI-RPA-1',
|
||||
status='running',
|
||||
))
|
||||
db.session.commit()
|
||||
|
||||
preparation = build_task_ui_state(task, include_stage_context=True)['stage_context']['preparation']
|
||||
line = preparation['lines'][0]
|
||||
# 关键断言:RPA 运行中必须清空库存动作,前端 Bot 不得渲染/触发。
|
||||
assert line['user_line_status'] == 'acquiring_inventory'
|
||||
assert line['inventory_allowed_actions'] == []
|
||||
|
||||
|
||||
def test_stage_context_preparation_projects_source_ambiguity_and_lock(app, monkeypatch) -> None:
|
||||
"""行级 source_conflict 与候选源只读 Match;Excel 未生成时下发 source_options。"""
|
||||
monkeypatch.setattr(
|
||||
|
||||
@@ -59,7 +59,7 @@ def test_inventory_running_is_not_inferred_from_stage_automation_job():
|
||||
"""阶段推进 Job 运行中但未创建库存 Attempt 时,明细不得显示获取库存中。"""
|
||||
task = SimpleNamespace(task_no='OT-TEST-1')
|
||||
with patch(
|
||||
'app.services.shipping_notice.order_review_projection.ShippingTaskInventoryRpaAttempt.query',
|
||||
'app.services.shipping_notice.line_inventory_match_projection.ShippingTaskInventoryRpaAttempt.query',
|
||||
) as query:
|
||||
query.filter.return_value.first.return_value = None
|
||||
assert _inventory_rpa_is_running(task) is False
|
||||
@@ -69,7 +69,7 @@ def test_inventory_running_requires_queued_or_running_attempt():
|
||||
"""只有库存 RPA Attempt queued/running 才能投影 acquiring_inventory。"""
|
||||
task = SimpleNamespace(task_no='OT-TEST-2')
|
||||
with patch(
|
||||
'app.services.shipping_notice.order_review_projection.ShippingTaskInventoryRpaAttempt.query',
|
||||
'app.services.shipping_notice.line_inventory_match_projection.ShippingTaskInventoryRpaAttempt.query',
|
||||
) as query:
|
||||
query.filter.return_value.first.return_value = SimpleNamespace(status='queued')
|
||||
assert _inventory_rpa_is_running(task) is True
|
||||
|
||||
Reference in new issue
Block a user