Merge branch 'hugo-shipping-notice' into dev
This commit is contained in:
commit
3985b34dda
606 files changed
+52167
-36839
No files matched your search
@@ -53,7 +53,7 @@ const buildBatchUiStateEvent = (
|
||||
task_no: taskNo,
|
||||
batch_no: batchNo,
|
||||
checkpoint,
|
||||
process_status: 'matched',
|
||||
match_status: 'matched',
|
||||
review_status: null,
|
||||
pending_human_reason: null,
|
||||
match_status: 'fulfillable',
|
||||
@@ -92,7 +92,7 @@ describe('useChat shipping_ui_state SSE', () => {
|
||||
|
||||
expect(message.shipping_ui_state?.task_no).toBe('SN-UNIT-001');
|
||||
expect(message.shipping_actions).toBeUndefined();
|
||||
expect((message.payload as { action_buttons?: unknown[] }).action_buttons).toEqual([]);
|
||||
expect((message.payload as { action_buttons?: unknown[] }).action_buttons).toBeUndefined();
|
||||
expect((message.payload as { shipping_batch_ui_state?: { batch_no?: string } }).shipping_batch_ui_state?.batch_no).toBe('SB-UNIT-001');
|
||||
});
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ export const applyShippingUiStateToMessage = (msg: ChatMessage, data: Record<str
|
||||
msg.shipping_ui_state = uiState;
|
||||
msg.shipping_actions = undefined;
|
||||
if (msg.type === 'shipping-match-result' && msg.payload && typeof msg.payload === 'object') {
|
||||
(msg.payload as { action_buttons?: ChatMessage['shipping_actions'] }).action_buttons = [];
|
||||
delete (msg.payload as { action_buttons?: ChatMessage['shipping_actions'] }).action_buttons;
|
||||
}
|
||||
msg.payload = {
|
||||
...(msg.payload && typeof msg.payload === 'object' ? msg.payload as Record<string, unknown> : {}),
|
||||
@@ -185,6 +185,7 @@ const normalizeShippingOrderExtractionState = (
|
||||
: null;
|
||||
return {
|
||||
status: status as ShippingOrderExtractionState['status'],
|
||||
uploadBatchId: String(data.uploadBatchId || '').trim() || null,
|
||||
summary: {
|
||||
totalDocuments: Math.max(0, Number(rawSummary.totalDocuments || 0)),
|
||||
pendingDocuments: Math.max(0, Number(rawSummary.pendingDocuments || 0)),
|
||||
@@ -207,6 +208,27 @@ const normalizeShippingOrderExtractionState = (
|
||||
: [],
|
||||
}
|
||||
: null,
|
||||
documents: Array.isArray(data.documents)
|
||||
? data.documents.map((item) => {
|
||||
const row = item && typeof item === 'object' ? item as Record<string, unknown> : {};
|
||||
return {
|
||||
unitId: Math.max(0, Number(row.unitId || 0)),
|
||||
documentId: Math.max(0, Number(row.documentId || 0)),
|
||||
intakeId: row.intakeId != null ? Math.max(0, Number(row.intakeId || 0)) || null : null,
|
||||
documentType: String(row.documentType || '').trim() || null,
|
||||
fileName: String(row.fileName || '').trim() || null,
|
||||
status: String(row.status || '').trim(),
|
||||
userVisibleStage: String(row.userVisibleStage || '').trim() || null,
|
||||
reasonCode: String(row.reasonCode || '').trim() || null,
|
||||
explainability: row.explainability && typeof row.explainability === 'object'
|
||||
? row.explainability as { message?: string | null }
|
||||
: null,
|
||||
emailSupplement: row.emailSupplement && typeof row.emailSupplement === 'object'
|
||||
? row.emailSupplement as { status?: string | null }
|
||||
: null,
|
||||
};
|
||||
})
|
||||
: [],
|
||||
selectionPlan: rawSelectionPlan
|
||||
? {
|
||||
selectionVersion: String(rawSelectionPlan.selectionVersion || '').trim() || null,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* features/chat/composables/useChatRouteSync.spec.ts
|
||||
* 用途:验证聊天路由初始化的关键首屏请求调度。
|
||||
* 依赖:vitest、useChatRouteSync。
|
||||
* 逻辑:历史会话列表属于后台辅助数据,不能阻塞指定 conversation 的消息与进度加载。
|
||||
*/
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
vi.mock('vue', () => ({
|
||||
onBeforeUnmount: vi.fn(),
|
||||
onMounted: vi.fn(),
|
||||
watch: vi.fn(),
|
||||
}));
|
||||
|
||||
import { useChatRouteSync } from './useChatRouteSync';
|
||||
|
||||
describe('useChatRouteSync', () => {
|
||||
it('starts the requested conversation before the history list resolves', async () => {
|
||||
let resolveHistory!: () => void;
|
||||
const loadHistory = vi.fn(() => new Promise<void>((resolve) => {
|
||||
resolveHistory = resolve;
|
||||
}));
|
||||
const loadConversation = vi.fn(async () => undefined);
|
||||
const routeSync = useChatRouteSync({
|
||||
deps: {
|
||||
route: {
|
||||
params: { agentId: '24' },
|
||||
query: { conversation_id: 'conversation-b' },
|
||||
},
|
||||
router: { push: vi.fn() },
|
||||
} as never,
|
||||
currentAgentId: { value: 24 } as never,
|
||||
presetQuestion: { value: '' } as never,
|
||||
shippingTaskIdFromQuery: { value: null } as never,
|
||||
isShippingNoticeAgent: { value: true } as never,
|
||||
resetChatStateForAgentChange: vi.fn(),
|
||||
cancelVoiceInput: vi.fn(),
|
||||
syncCurrentUserProfile: vi.fn(async () => undefined),
|
||||
loadAgent: vi.fn(async () => undefined),
|
||||
loadUserAgents: vi.fn(async () => undefined),
|
||||
loadHistory,
|
||||
loadConversation,
|
||||
resumeShippingTaskFromQuery: vi.fn(async () => undefined),
|
||||
handleSend: vi.fn(async () => undefined),
|
||||
createNewChatView: vi.fn(),
|
||||
onAuthLogout: vi.fn(),
|
||||
onViewportResize: vi.fn(),
|
||||
disposePeripherals: vi.fn(),
|
||||
scheduleScrollToBottom: vi.fn(),
|
||||
input: { value: '' } as never,
|
||||
});
|
||||
|
||||
const pending = routeSync.syncChatStateForRoute();
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(loadHistory).toHaveBeenCalledTimes(1);
|
||||
expect(loadConversation).toHaveBeenCalledWith('conversation-b', { force: true });
|
||||
});
|
||||
|
||||
resolveHistory();
|
||||
await pending;
|
||||
});
|
||||
});
|
||||
@@ -94,16 +94,23 @@ export function useChatRouteSync(options: UseChatRouteSyncOptions) {
|
||||
await loadUserAgents();
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
|
||||
await loadHistory();
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
|
||||
const convId = route.query.conversation_id as string;
|
||||
// 历史列表是辅助内容;直达会话时不能阻塞消息/货代 Projection 的首屏读取。
|
||||
const historyPromise = loadHistory();
|
||||
if (convId) {
|
||||
await loadConversation(convId, { force: true });
|
||||
await Promise.all([
|
||||
historyPromise,
|
||||
loadConversation(convId, { force: true }),
|
||||
]);
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
} else if (shippingTaskIdFromQuery.value || shippingBatchNoFromQuery?.value) {
|
||||
await historyPromise;
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
await resumeShippingTaskFromQuery();
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
} else {
|
||||
await historyPromise;
|
||||
if (syncToken !== routeSyncToken) return;
|
||||
}
|
||||
|
||||
if (presetQuestion.value) {
|
||||
|
||||
@@ -103,7 +103,7 @@ describe('useChatShipping persisted batch snapshot', () => {
|
||||
shipping_batch_ui_state: {
|
||||
batch_no: 'SB-EXISTING',
|
||||
current_focus_task_no: 'SN-EXISTING',
|
||||
tasks: [{ task_no: 'SN-EXISTING', source_type: 'email', process_status: 'pending_review' }],
|
||||
tasks: [{ task_no: 'SN-EXISTING', source_type: 'email', review_status: 'parse_review' }],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -133,7 +133,7 @@ describe('useChatShipping message recovery payload', () => {
|
||||
shipping_ui_state: {
|
||||
task_no: 'SN-OPEN-EXISTING',
|
||||
batch_no: 'SB-OPEN-EXISTING',
|
||||
process_status: 'waiting_inventory',
|
||||
inventory_lines_json: [{ reservation_id: 'R-1' }],
|
||||
steps: [],
|
||||
summary: {},
|
||||
action_buttons: [],
|
||||
|
||||
@@ -554,7 +554,7 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
|
||||
const hasRunningShippingBatchTasks = () =>
|
||||
shippingBatchTasks.value.some(
|
||||
(task) => !['uploaded', 'completed', 'closed', 'rejected'].includes(String(task.process_status || '').trim()),
|
||||
(task) => String(task.ui_state?.stage?.code || '').trim() !== 'upload_complete',
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -591,10 +591,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const normalizedTaskId = String(taskId || getActiveShippingTaskId() || '').trim().toUpperCase();
|
||||
if (!conversationKey || !normalizedTaskId || !isShippingNoticeAgent.value || isShippingActionBusy.value) return;
|
||||
const detail = activeShippingTaskDetail.value;
|
||||
// 任务详情接口当前不返回顶层 checkpoint,parse_review 需从详情状态字段回推。
|
||||
// 复核同步只消费后端统一 ui_state.checkpoint,不读取 review_status 等领域事实推导。
|
||||
const checkpoint = String(
|
||||
(detail?.step_payload as Record<string, unknown> | undefined)?.checkpoint
|
||||
|| detail?.review_status
|
||||
detail?.ui_state?.checkpoint?.code
|
||||
|| detail?.ui_state?.checkpoint_code
|
||||
|| '',
|
||||
).trim();
|
||||
if (checkpoint !== 'parse_review') return;
|
||||
@@ -722,18 +722,10 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
});
|
||||
|
||||
const { executeShippingDecision, executeShippingManualUpload } = createShippingDecisionHandlers({
|
||||
messages,
|
||||
conversationId,
|
||||
history,
|
||||
isShippingNoticeAgent,
|
||||
currentAgentId,
|
||||
getActiveShippingTaskId,
|
||||
getActiveShippingBatchNo: () => resolvedShippingBatchNo.value || shippingBatchNoFromQuery.value || '',
|
||||
loadHistory,
|
||||
refreshShippingActions,
|
||||
startChatTurn,
|
||||
msg,
|
||||
t,
|
||||
refreshShippingActions,
|
||||
msg,
|
||||
t,
|
||||
});
|
||||
|
||||
const {
|
||||
@@ -970,7 +962,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
const {
|
||||
handleShippingAutoUploadFile,
|
||||
handleShippingAutoUploadNoticeBatch,
|
||||
openShippingInventoryPicker,
|
||||
openShippingNoticePicker,
|
||||
selectShippingInventoryUploadTask,
|
||||
cancelShippingInventoryTaskSelection,
|
||||
@@ -1019,20 +1010,16 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
|
||||
const { handleShippingMenuAction, handleShippingActionClick } = createShippingMenuHandlers({
|
||||
isThinking,
|
||||
currentAgentId,
|
||||
getActiveShippingTaskId,
|
||||
getActiveShippingBatchNo: () => resolvedShippingBatchNo.value || shippingBatchNoFromQuery.value || '',
|
||||
messages,
|
||||
sendShippingMenuMessage,
|
||||
openShippingInventoryPicker,
|
||||
openShippingNoticePicker,
|
||||
openShippingCustomerDialog,
|
||||
executeShippingDecision,
|
||||
executeShippingManualUpload,
|
||||
refreshShippingActions,
|
||||
startChatTurn,
|
||||
msg,
|
||||
t,
|
||||
msg,
|
||||
t,
|
||||
});
|
||||
|
||||
const { tryHandleShippingSend, tryHandleShippingAttachmentAutoFlow } = createShippingSendHandlers({
|
||||
@@ -1058,7 +1045,6 @@ export function useChatShipping(options: UseChatShippingOptions) {
|
||||
loadHistory,
|
||||
sendShippingMenuMessage,
|
||||
startChatTurn,
|
||||
openShippingInventoryPicker,
|
||||
executeShippingDecision,
|
||||
executeShippingManualUpload,
|
||||
handleShippingMenuAction,
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* features/chat/composables/useProcurementContractChat.spec.ts
|
||||
* 用途:验证采购合同双文件选择后的即时可见状态。
|
||||
* 依赖:Vitest、Vue refs、useProcurementContractChat。
|
||||
* 逻辑:我方原合同选择后即展示本地文件名,FileAsset 上传仅补充可提交的资产编号。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { useProcurementContractChat } from './useProcurementContractChat';
|
||||
|
||||
const { uploadFileAsset } = vi.hoisted(() => ({ uploadFileAsset: vi.fn() }));
|
||||
|
||||
vi.mock('@/shared/api/file-assets.api', () => ({ uploadFileAsset }));
|
||||
|
||||
/** 构建只覆盖原合同选择流程的最小上下文。 */
|
||||
function createProcurementChat() {
|
||||
return useProcurementContractChat({
|
||||
currentAgent: ref({ agent_code: 'procurement_contract_review' }),
|
||||
currentAgentId: computed(() => 1),
|
||||
attachments: ref([]),
|
||||
messages: ref([]),
|
||||
isThinking: ref(false),
|
||||
isUploadingAttachments: ref(false),
|
||||
input: ref(''),
|
||||
clearAttachments: vi.fn(),
|
||||
saveLocalMessageToBackend: vi.fn(async () => undefined),
|
||||
loadHistory: vi.fn(async () => undefined),
|
||||
msg: { warning: vi.fn(), success: vi.fn(), info: vi.fn() },
|
||||
t: (key: string) => key,
|
||||
});
|
||||
}
|
||||
|
||||
describe('useProcurementContractChat original contract selection', () => {
|
||||
it('shows the selected original contract before its FileAsset upload finishes', async () => {
|
||||
let resolveUpload: ((value: { asset_no: string; original_filename: string }) => void) | undefined;
|
||||
uploadFileAsset.mockImplementation(() => new Promise((resolve) => { resolveUpload = resolve; }));
|
||||
const chat = createProcurementChat();
|
||||
const file = new File(['original'], '我方原合同.md', { type: 'text/markdown' });
|
||||
|
||||
const selecting = chat.handleOriginalContractSelected({ target: { files: [file], value: 'selected' } } as unknown as Event);
|
||||
|
||||
// 断言上传尚未完成时 UI 仍能立刻渲染已选择的我方原合同。
|
||||
expect(chat.originalContractName.value).toBe('我方原合同.md');
|
||||
expect(chat.originalContractAssetNo.value).toBeNull();
|
||||
|
||||
resolveUpload?.({ asset_no: 'FA-ORIGINAL-1', original_filename: '我方原合同.md' });
|
||||
await selecting;
|
||||
expect(chat.originalContractAssetNo.value).toBe('FA-ORIGINAL-1');
|
||||
});
|
||||
});
|
||||
@@ -131,12 +131,18 @@ export function useProcurementContractChat(options: ProcurementContractChatOptio
|
||||
const file = input.files?.[0];
|
||||
input.value = '';
|
||||
if (!file) return;
|
||||
// [STEP 1] 选择即展示,避免 FileAsset 网络上传期间输入栏看起来没有响应。
|
||||
originalContractAssetNo.value = null;
|
||||
originalContractName.value = file.name;
|
||||
options.isUploadingAttachments.value = true;
|
||||
try {
|
||||
const asset = await uploadFileAsset(file);
|
||||
// [STEP 2] 上传完成后才允许作为正式比对基准提交。
|
||||
originalContractAssetNo.value = asset.asset_no;
|
||||
originalContractName.value = asset.original_filename || file.name;
|
||||
} catch (e: unknown) {
|
||||
// 上传失败的临时卡片不可作为基准,必须移除,避免显示与提交状态不一致。
|
||||
clearOriginalContract();
|
||||
options.msg.warning(e instanceof Error ? e.message : options.t('chat.procurementContract.uploadFailed'));
|
||||
} finally {
|
||||
options.isUploadingAttachments.value = false;
|
||||
|
||||
Reference in new issue
Block a user