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:
hugo committed 2026-07-03 17:01:42 +08:00
1 parent 60dd0c0f58
commit 8846ce159f
102 files changed
+18289 -9072

No files matched your search

@@ -1,26 +1,55 @@
/**
* features/chat/shipping/useChatShippingMenuHandler.spec.ts
* 用途:验证发货通知聊天菜单动作分流,避免 UI 按钮误走普通对话链路。
* 依赖:vitest、vue refs、useChatShippingMenuHandler。
* 逻辑:直接调用 createShippingMenuHandlers,覆盖 reparse_inventory 的 silent 决策提交、缺少 task 提示与上传器打开条件。
* 用途:验证发货聊天动作菜单在工作台显式 taskId 场景下会命中指定任务,而不是误用当前激活任务。
* 依赖:vitest、vue refs、shipping.api、useChatShippingMenuHandler。
* 逻辑:覆盖工作台点击 `retry_rpa` 与 `generate_excel` 两类动作,锁死统一按钮分发时的任务归属。
*/
import { ref } from 'vue';
import { describe, expect, it, vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { createShippingMenuHandlers, type ShippingMenuHandlerContext } from './useChatShippingMenuHandler';
import type { ChatMessage } from '../types/chat.types';
const {
confirmWorkspaceShippingInventorySource,
generateWorkspaceShippingExcel,
getWorkspaceShippingTask,
matchWorkspaceShippingInventory,
retryWorkspaceShippingUpload,
} = vi.hoisted(() => ({
confirmWorkspaceShippingInventorySource: vi.fn(),
generateWorkspaceShippingExcel: vi.fn(),
getWorkspaceShippingTask: vi.fn(),
matchWorkspaceShippingInventory: vi.fn(),
retryWorkspaceShippingUpload: vi.fn(),
}));
const { downloadWorkspaceShippingExcelFile } = vi.hoisted(() => ({
downloadWorkspaceShippingExcelFile: vi.fn(),
}));
vi.mock('@/features/chat/api/shipping.api', () => ({
confirmWorkspaceShippingInventorySource,
generateWorkspaceShippingExcel,
getWorkspaceShippingTask,
matchWorkspaceShippingInventory,
retryWorkspaceShippingUpload,
}));
vi.mock('./shippingDownload', () => ({
downloadWorkspaceShippingExcelFile,
}));
const createContext = (
overrides: Partial<ShippingMenuHandlerContext> = {},
): ShippingMenuHandlerContext => ({
isThinking: ref(false),
getActiveShippingTaskId: () => 'SN-FOCUS-001',
getActiveShippingTaskId: () => 'SN-ACTIVE-001',
messages: ref([]),
newLocalMessageId: vi.fn(() => 'local-id'),
newLocalMessageId: vi.fn((prefix: string) => `${prefix}-local-id`),
saveLocalMessageToBackend: vi.fn(async () => undefined),
sendShippingMenuMessage: vi.fn(async () => undefined),
openShippingInventoryMappingFormForTask: vi.fn(async () => true),
openShippingInventoryPicker: vi.fn(() => true),
openShippingNoticePicker: vi.fn(() => true),
openShippingInventoryPicker: vi.fn((_taskId?: string) => true),
openShippingNoticePicker: vi.fn((_taskId?: string) => true),
executeShippingDecision: vi.fn(async () => true),
executeShippingManualUpload: vi.fn(async () => true),
refreshShippingActions: vi.fn(async () => undefined),
@@ -33,61 +62,79 @@ const createContext = (
});
describe('useChatShippingMenuHandler', () => {
it('clears inventory state and opens picker for reparse_inventory without sending chat text', async () => {
beforeEach(() => {
confirmWorkspaceShippingInventorySource.mockReset();
generateWorkspaceShippingExcel.mockReset();
getWorkspaceShippingTask.mockReset();
matchWorkspaceShippingInventory.mockReset();
retryWorkspaceShippingUpload.mockReset();
downloadWorkspaceShippingExcelFile.mockReset();
});
it('uses explicit taskId for retry_rpa workspace actions', async () => {
const ctx = createContext();
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
const chatMsg = { role: 'assistant', content: '请重新上传库存' } as ChatMessage & { shipping_actions_used?: boolean };
await handleShippingMenuAction(
{ id: 'reparse_inventory', message: '重新上传库存' },
chatMsg,
{ id: 'retry_rpa', label: '重试 RPA', message: '重试 RPA' },
undefined,
{ taskId: 'sn-target-009' },
);
expect(chatMsg.shipping_actions_used).toBe(true);
expect(ctx.executeShippingDecision).toHaveBeenCalledTimes(1);
expect(ctx.executeShippingDecision).toHaveBeenCalledWith('reparse_inventory', '重新上传库存', { silent: true });
expect(ctx.openShippingInventoryPicker).toHaveBeenCalledTimes(1);
expect(ctx.sendShippingMenuMessage).not.toHaveBeenCalled();
expect(ctx.executeShippingDecision).toHaveBeenCalledWith(
'retry_rpa',
'重试 RPA',
{ taskId: 'SN-TARGET-009' },
);
expect(ctx.executeShippingDecision).not.toHaveBeenCalledWith(
'retry_rpa',
'重试 RPA',
{ taskId: 'SN-ACTIVE-001' },
);
});
it('keeps existing missing task warning when reparse_inventory has no active task', async () => {
const ctx = createContext({
getActiveShippingTaskId: () => '',
it('uses explicit taskId for generate_excel workspace actions', async () => {
generateWorkspaceShippingExcel.mockResolvedValue({
message: '发货文件已生成',
data: {},
});
const ctx = createContext();
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
await handleShippingMenuAction({ id: 'reparse_inventory', message: '重新上传库存' });
await handleShippingMenuAction(
{ id: 'generate_excel', label: '生成发货文件', message: '请生成发货文件' },
undefined,
{ taskId: 'sn-target-777' },
);
expect(ctx.msg.warning).toHaveBeenCalledWith('chat.shippingNoticeMissingTaskId');
expect(ctx.executeShippingDecision).not.toHaveBeenCalled();
expect(ctx.openShippingInventoryPicker).not.toHaveBeenCalled();
expect(ctx.sendShippingMenuMessage).not.toHaveBeenCalled();
expect(generateWorkspaceShippingExcel).toHaveBeenCalledWith('SN-TARGET-777');
expect(ctx.messages.value[0]?.content).toContain('SN-TARGET-777');
expect(ctx.messages.value[1]?.content).toContain('SN-TARGET-777');
});
it('does not open picker when reparse_inventory decision fails', async () => {
const ctx = createContext({
executeShippingDecision: vi.fn(async () => false),
});
it('passes explicit taskId into inventory picker actions', async () => {
const ctx = createContext();
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
await handleShippingMenuAction({ id: 'reparse_inventory', message: '重新上传库存' });
await handleShippingMenuAction(
{ id: 'upload_inventory_file', label: '上传库存文件', message: '请上传库存文件' },
undefined,
{ taskId: 'sn-picker-123' },
);
expect(ctx.executeShippingDecision).toHaveBeenCalledWith('reparse_inventory', '重新上传库存', { silent: true });
expect(ctx.openShippingInventoryPicker).not.toHaveBeenCalled();
expect(ctx.sendShippingMenuMessage).not.toHaveBeenCalled();
expect(ctx.openShippingInventoryPicker).toHaveBeenCalledWith('SN-PICKER-123');
});
it('does not mark button used when reparse_inventory has no active task', async () => {
const ctx = createContext({
getActiveShippingTaskId: () => '',
});
it('passes explicit taskId into notice picker actions', async () => {
const ctx = createContext();
const { handleShippingMenuAction } = createShippingMenuHandlers(ctx);
const chatMsg = { role: 'assistant', content: '请重新上传库存' } as ChatMessage & { shipping_actions_used?: boolean };
await handleShippingMenuAction({ id: 'reparse_inventory', message: '重新上传库存' }, chatMsg);
await handleShippingMenuAction(
{ id: 'replace_notice_file', label: '重新上传通知', message: '请重新上传通知' },
undefined,
{ taskId: 'sn-notice-123' },
);
expect(chatMsg.shipping_actions_used).toBeUndefined();
expect(ctx.executeShippingDecision).not.toHaveBeenCalled();
expect(ctx.openShippingInventoryPicker).not.toHaveBeenCalled();
expect(ctx.openShippingNoticePicker).toHaveBeenCalledWith('SN-NOTICE-123');
});
});