refactor(agent-runtime, shipping-notice, frontend): 重构上下文体系,修复重试RPA无响应问题
- 替换原有的hxops_context模块为全新的代理运行时上下文平台协议,统一跨业务上下文注入逻辑 - 新增多语言操作繁忙提示文案(覆盖中、繁、英、泰四语),前端绑定页面繁忙状态实现操作阻断 - 调整RPA库存导出重试策略:移除可配置的最大自动重试次数,改为固定单次自动重试,手动重试需用户显式触发 - 优化任务用户态状态展示逻辑,优先展示具体的pending原因而非通用状态文案 - 重构任务焦点切换逻辑,统一事件日志与处理流程,复用switch_batch_focus工具函数 - 修复clearAllHistory函数残留UI问题,确保清空会话后完全复位发货通知相关视图 - 更新OpenAPI文档与静态快照,补充工具使用约束说明 - 新增调试打点日志与问题排查文档,完善全套单元测试与快照校验用例 - 更新RPA脚本的README文档,调整登录方式说明与浏览器 profile 路径配置 - 删除废弃的hxops_context模块,迁移所有相关调用到新的上下文体系
This commit is contained in:
1 parent
60dd0c0f58
commit
8846ce159f
102 files changed
+18289
-9072
No files matched your search
@@ -1,3 +1,6 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app import db
|
||||
@@ -383,6 +386,44 @@ def test_openapi_spec_public(app, client):
|
||||
assert "JSON 字符串" in map_json_schema["description"]
|
||||
submit_decision = spec["paths"]["/tools/submit_decision"]["post"]["requestBody"]["content"]["application/json"]["schema"]
|
||||
assert "retry_rpa" in submit_decision["properties"]["decision"]["enum"]
|
||||
spec_text = str(spec)
|
||||
assert "submit_decision" in spec_text
|
||||
assert "match_inventory" in spec_text
|
||||
assert "generate_shipment_excel" in spec_text
|
||||
assert "upload_to_freight" in spec_text
|
||||
assert "retry_task" in spec_text
|
||||
assert "confirm_inventory_source" in spec_text
|
||||
assert "唯一 task_id" in spec_text
|
||||
assert "模糊指代不能直接推进" in spec_text
|
||||
assert "状态机" in spec_text
|
||||
assert "不得自行宣布完成" in spec_text
|
||||
assert "不要在自然语言正文列出按钮清单" in spec_text
|
||||
submit_desc = spec["paths"]["/tools/submit_decision"]["post"]["description"]
|
||||
assert "唯一 task_id" in submit_desc
|
||||
assert "模糊指代" in submit_desc
|
||||
assert "needs_human 或 failed" in submit_desc
|
||||
assert "按钮由 HXOPS 前端渲染" in submit_desc
|
||||
|
||||
|
||||
def test_static_openapi_snapshot_contains_shipping_contract_keywords():
|
||||
"""静态 OpenAPI 快照应同步最新推进约束,避免 Dify 导入旧版说明。"""
|
||||
spec_path = Path(__file__).resolve().parents[2] / "docs" / "openapi" / "shipping_notice_tools.dify.json"
|
||||
spec = json.loads(spec_path.read_text(encoding="utf-8"))
|
||||
|
||||
assert spec["openapi"] == "3.0.0"
|
||||
assert "/tools/submit_decision" in spec["paths"]
|
||||
spec_text = str(spec)
|
||||
assert "reference_context" in spec_text
|
||||
assert "状态机" in spec_text
|
||||
assert "不得自行改写成完成" in spec_text
|
||||
assert "不要在自然语言正文列出按钮清单" in spec_text
|
||||
assert "match_inventory" in spec_text
|
||||
assert "generate_shipment_excel" in spec_text
|
||||
assert "upload_to_freight" in spec_text
|
||||
submit_desc = spec["paths"]["/tools/submit_decision"]["post"]["description"]
|
||||
assert "唯一 task_id" in submit_desc
|
||||
assert "模糊指代" in submit_desc
|
||||
assert "按钮由 HXOPS 前端渲染" in submit_desc
|
||||
|
||||
|
||||
def test_parse_inventory_from_chat_text(app, client):
|
||||
@@ -1390,11 +1431,11 @@ def test_submit_decision_confirm_inventory_mapping_enqueues_worker(app, client,
|
||||
|
||||
|
||||
@pytest.mark.auto_rpa
|
||||
def test_rpa_pending_timeout_recheck_triggers_next_inventory_export(app, client, tmp_path):
|
||||
def test_rpa_pending_timeout_recheck_marks_task_needs_human_after_single_attempt(app, client, tmp_path):
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from app.services.shipping_notice.batch_orchestrator import _run_single_task
|
||||
from app.services.shipping_notice.constants import PH_RPA_PENDING
|
||||
from app.services.shipping_notice.constants import PH_RPA_EXHAUSTED, PH_RPA_PENDING
|
||||
|
||||
headers = _tool_headers(app)
|
||||
trigger = tmp_path / "inventory_triggers"
|
||||
@@ -1437,12 +1478,13 @@ def test_rpa_pending_timeout_recheck_triggers_next_inventory_export(app, client,
|
||||
result = _run_single_task(task_id)
|
||||
task = ShippingTask.query.filter_by(task_no=task_id).first()
|
||||
assert task is not None
|
||||
assert result["status"] == "running"
|
||||
assert result["status"] == "needs_human"
|
||||
assert task.process_status == "waiting_inventory"
|
||||
assert task.pending_human_reason == PH_RPA_PENDING
|
||||
assert task.pending_human_reason == PH_RPA_EXHAUSTED
|
||||
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_failed").count() == 1
|
||||
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_triggered").count() == 2
|
||||
assert len(list(trigger.glob("inventory_export_*.json"))) == 1
|
||||
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_triggered").count() == 1
|
||||
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_exhausted").count() == 1
|
||||
assert len(list(trigger.glob("inventory_export_*.json"))) == 0
|
||||
|
||||
|
||||
@pytest.mark.auto_rpa
|
||||
@@ -1453,8 +1495,11 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
|
||||
|
||||
headers = _tool_headers(app)
|
||||
trigger = tmp_path / "inventory_triggers"
|
||||
inventory_drop = tmp_path / "inventory_drop"
|
||||
trigger.mkdir()
|
||||
inventory_drop.mkdir()
|
||||
app.config["FREIGHT_RPA_INVENTORY_TRIGGER_DIR"] = str(trigger)
|
||||
app.config["FREIGHT_INVENTORY_DROP_DIR"] = str(inventory_drop)
|
||||
|
||||
create_res = client.post(
|
||||
"/api/shipping-notice/tools/create_task",
|
||||
@@ -1513,11 +1558,11 @@ def test_retry_rpa_after_exhausted_starts_new_attempt_window(app, client, tmp_pa
|
||||
|
||||
|
||||
@pytest.mark.auto_rpa
|
||||
def test_batch_retry_rechecks_timed_out_rpa_pending_immediately(app, client, tmp_path):
|
||||
def test_batch_retry_marks_timed_out_rpa_pending_task_as_exhausted(app, client, tmp_path):
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from app.services.shipping_notice.batch_orchestrator import retry_batch_pending_tasks
|
||||
from app.services.shipping_notice.constants import PH_RPA_PENDING
|
||||
from app.services.shipping_notice.constants import PH_RPA_EXHAUSTED, PH_RPA_PENDING
|
||||
|
||||
headers = _tool_headers(app)
|
||||
trigger = tmp_path / "inventory_triggers"
|
||||
@@ -1573,10 +1618,11 @@ def test_batch_retry_rechecks_timed_out_rpa_pending_immediately(app, client, tmp
|
||||
assert result["started"] == 1
|
||||
assert result["skipped"] == 0
|
||||
assert task.process_status == "waiting_inventory"
|
||||
assert task.pending_human_reason == PH_RPA_PENDING
|
||||
assert task.pending_human_reason == PH_RPA_EXHAUSTED
|
||||
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_failed").count() == 1
|
||||
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_triggered").count() == 2
|
||||
assert len(list(trigger.glob("inventory_export_*.json"))) == 1
|
||||
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_triggered").count() == 1
|
||||
assert ShippingTaskEvent.query.filter_by(task_id=task.id, event_type="inventory_rpa_exhausted").count() == 1
|
||||
assert len(list(trigger.glob("inventory_export_*.json"))) == 0
|
||||
|
||||
|
||||
def test_submit_decision_by_conversation_id(app, client):
|
||||
|
||||
Reference in new issue
Block a user