chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑
This commit is contained in:
1 parent
5ef8329bd8
commit
4ec4e57005
183 files changed
+14653
-3936
No files matched your search
@@ -25,6 +25,7 @@ import {
|
||||
flattenBusinessFileProjections,
|
||||
businessFileKeys,
|
||||
} from './conversationProcessingProjection';
|
||||
import { normalizeShippingProcessingProjection } from './normalizeShippingProcessing';
|
||||
import type {
|
||||
ConversationProcessingProjection,
|
||||
ShippingProcessingProjection,
|
||||
@@ -813,6 +814,35 @@ describe('conversationProcessingProjection', () => {
|
||||
expect(projection?.recent_task_no).toBe('OT-SIBLING');
|
||||
});
|
||||
|
||||
it('uses backend status_groups instead of rebuilding a file list from work_items', () => {
|
||||
const workItems: ShippingProcessingProjection[] = [{
|
||||
workItemType: 'order_task', workItemNo: 'OT-LIVE', sourceType: 'direct_pdf',
|
||||
rootOrderTaskNo: 'OT-LIVE', shippingNoticeNo: null, conversationId: 'conv-live',
|
||||
submissionNo: 'SOS-LIVE', intakeNo: 'SNI-LIVE', status: 'waiting_review',
|
||||
stage: 'order_review', progressVersion: 9, lastActivityAt: '2026-08-16T00:00:00Z',
|
||||
currentGate: null, availableActions: ['open_order_review'], childOrderTasks: [],
|
||||
sourceSummary: { emailSubject: null, filename: 'live.pdf', documentCount: 1,
|
||||
parsedDocumentCount: 1, candidateCount: 1, customerName: null, poNumber: 'PO-LIVE' },
|
||||
}];
|
||||
const backendProjection = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 1, needs_action: 0, completed: 0, history: 0 },
|
||||
status_groups: {
|
||||
failed: [], waiting_human: [{
|
||||
user_task_no: 'OT-LIVE', group: 'needs_action', status_label: 'waiting_human',
|
||||
file_count: 1, can_append: false,
|
||||
}], processing: [], completed: [], cancelled: [], archived: [],
|
||||
},
|
||||
needs_action: [], processing: [{ user_task_no: 'OT-HISTORY', status_label: 'extracting' }],
|
||||
completed: [], history: [], focused_task_no: null, recent_task_no: null,
|
||||
};
|
||||
|
||||
const projection = resolveConversationProcessingFromUnified(workItems, backendProjection);
|
||||
|
||||
// 后端已排除的历史条目不允许被前端 work_items 重建回页面。
|
||||
expect(projection?.needs_action.map((task) => task.user_task_no)).toEqual(['OT-LIVE']);
|
||||
expect(projection?.processing).toEqual([]);
|
||||
});
|
||||
|
||||
it('merges focus metadata from embedded onto work_items-derived projection', () => {
|
||||
const derived = projectConversationProcessingFromWorkItems([{
|
||||
workItemType: 'order_task',
|
||||
@@ -939,6 +969,56 @@ describe('conversationProcessingProjection — normalize & semantic & stabilize'
|
||||
expect(buildTaskSemanticKey(before)).not.toBe(buildTaskSemanticKey(after));
|
||||
});
|
||||
|
||||
it('buildTaskSemanticKey: 后端撤销生命周期入口时必须改变签名', () => {
|
||||
const shared = {
|
||||
user_task_no: 'INTAKE:SNI-LIFECYCLE', group: 'needs_action' as const,
|
||||
status_label: 'waiting_human', file_count: 1, can_append: false,
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'waiting_review', blocking_reason: null,
|
||||
primary_action: null, secondary_actions: [],
|
||||
lifecycleEntries: [{ code: 'order_review' as const, state: 'current' as const, targetSurface: 'order_lifecycle_workbench' as const }],
|
||||
},
|
||||
};
|
||||
const revoked = {
|
||||
...shared,
|
||||
uiState: { ...shared.uiState, lifecycleEntries: [] },
|
||||
};
|
||||
expect(buildTaskSemanticKey(shared)).not.toBe(buildTaskSemanticKey(revoked));
|
||||
});
|
||||
|
||||
it('buildTaskSemanticKey: EML 子文件入口被撤销时必须替换聚合卡', () => {
|
||||
const child = {
|
||||
workItemNo: 'OT-LEAF-1',
|
||||
intakeNo: 'SNI-LEAF',
|
||||
status: 'waiting_human',
|
||||
stage: 'order_review',
|
||||
sourceSummary: { filename: 'leaf.pdf', documentId: 801 },
|
||||
uiState: {
|
||||
status: 'waiting_human', stage: 'order_review', blocking_reason: null,
|
||||
primary_action: null, secondary_actions: [],
|
||||
lifecycleEntries: [{
|
||||
code: 'order_review' as const, state: 'current' as const,
|
||||
targetSurface: 'order_lifecycle_workbench' as const,
|
||||
}],
|
||||
},
|
||||
} as any;
|
||||
const task = {
|
||||
user_task_no: 'INTAKE:SNI-LEAF', group: 'needs_action' as const,
|
||||
status_label: 'waiting_human', file_count: 1, can_append: false,
|
||||
uiState: { status: 'waiting_human', stage: 'order_review', blocking_reason: null, primary_action: null, secondary_actions: [] },
|
||||
aggregateChildren: [child],
|
||||
} as any;
|
||||
const revoked = {
|
||||
...task,
|
||||
aggregateChildren: [{
|
||||
...child,
|
||||
uiState: { ...child.uiState, lifecycleEntries: [] },
|
||||
}],
|
||||
};
|
||||
|
||||
expect(buildTaskSemanticKey(task)).not.toBe(buildTaskSemanticKey(revoked));
|
||||
});
|
||||
|
||||
it('buildTaskSemanticKey: authoritative ui_state without a primary action ignores stale legacy action', () => {
|
||||
const shared = {
|
||||
user_task_no: 'INTAKE:SNI-NO-ACTION', group: 'processing' as const,
|
||||
@@ -1173,6 +1253,161 @@ describe('conversationProcessingProjection — normalize & semantic & stabilize'
|
||||
expect(normalized.output_artifacts?.[0]?.action.enabled).toBe(true);
|
||||
});
|
||||
|
||||
it('normalizes backend lifecycle_entries in status groups without recreating entries', () => {
|
||||
const backendProjection = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 0, needs_action: 1, completed: 0, history: 0 },
|
||||
focused_task_no: null,
|
||||
recent_task_no: null,
|
||||
needs_action: [], processing: [], completed: [], history: [],
|
||||
status_groups: {
|
||||
failed: [],
|
||||
waiting_human: [{
|
||||
user_task_no: 'OT-LIFECYCLE-SNAKE', title: 'order.pdf', display_kind: 'single_document_task',
|
||||
document_names: ['order.pdf'], group: 'needs_action', status_label: 'waiting_human', file_count: 1,
|
||||
can_append: false, available_actions: [],
|
||||
ui_state: {
|
||||
status: 'waiting_human', stage: 'field_completeness', lifecycle_stage: 'order_review',
|
||||
lifecycle_entries: [{ code: 'intake_parse', state: 'available', target_surface: 'order_lifecycle_workbench' }, {
|
||||
code: 'order_review', state: 'current', target_surface: 'order_lifecycle_workbench',
|
||||
}],
|
||||
blocking_reason: null, primary_action: null, secondary_actions: [],
|
||||
},
|
||||
}],
|
||||
processing: [], completed: [], cancelled: [], archived: [],
|
||||
},
|
||||
} as unknown as ConversationProcessingProjection;
|
||||
|
||||
const normalized = normalizeConversationProcessingProjection(backendProjection);
|
||||
const task = normalized.status_groups!.waiting_human[0]!;
|
||||
|
||||
expect(task.uiState?.lifecycleStage).toBe('order_review');
|
||||
expect(task.uiState?.lifecycleEntries).toEqual([
|
||||
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
|
||||
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('normalizes embedded primary-action lifecycle navigation fields from backend snake_case', () => {
|
||||
const embedded = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 0, needs_action: 1, completed: 0, history: 0 },
|
||||
focused_task_no: null, recent_task_no: null,
|
||||
needs_action: [], processing: [], completed: [], history: [],
|
||||
status_groups: {
|
||||
failed: [],
|
||||
waiting_human: [{
|
||||
user_task_no: 'OT-FULFILLMENT-NAV', title: 'order.pdf', display_kind: 'single_document_task',
|
||||
document_names: ['order.pdf'], group: 'needs_action', status_label: 'waiting_human', file_count: 1,
|
||||
can_append: false, available_actions: [],
|
||||
ui_state: {
|
||||
status: 'waiting_human', stage: 'inventory_matching', lifecycle_stage: 'fulfillment_prep',
|
||||
lifecycle_entries: [], blocking_reason: null,
|
||||
primary_action: {
|
||||
code: 'open_inventory_match_review', execution_mode: 'navigate',
|
||||
target_surface: 'order_lifecycle_workbench', target_lifecycle_stage: 'fulfillment_prep',
|
||||
}, secondary_actions: [],
|
||||
},
|
||||
}],
|
||||
processing: [], completed: [], cancelled: [], archived: [],
|
||||
},
|
||||
} as unknown as ConversationProcessingProjection;
|
||||
|
||||
const action = normalizeConversationProcessingProjection(embedded)
|
||||
.status_groups!.waiting_human[0]!.uiState!.primary_action!;
|
||||
|
||||
expect(action.executionMode).toBe('navigate');
|
||||
expect(action.targetSurface).toBe('order_lifecycle_workbench');
|
||||
expect(action.targetLifecycleStage).toBe('fulfillment_prep');
|
||||
});
|
||||
|
||||
it('normalizes embedded secondary-action lifecycle navigation fields from backend snake_case', () => {
|
||||
const embedded = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 0, needs_action: 1, completed: 0, history: 0 },
|
||||
focused_task_no: null, recent_task_no: null,
|
||||
needs_action: [], processing: [], completed: [], history: [],
|
||||
status_groups: {
|
||||
failed: [],
|
||||
waiting_human: [{
|
||||
user_task_no: 'OT-VIEW-NAV', title: 'order.pdf', display_kind: 'single_document_task',
|
||||
document_names: ['order.pdf'], group: 'needs_action', status_label: 'waiting_human', file_count: 1,
|
||||
can_append: false, available_actions: [],
|
||||
ui_state: {
|
||||
status: 'waiting_human', stage: 'inventory_matching', lifecycle_stage: 'fulfillment_prep',
|
||||
lifecycle_entries: [], blocking_reason: null, primary_action: null,
|
||||
secondary_actions: [{
|
||||
code: 'view_result', enabled: true, execution_mode: 'navigate',
|
||||
target_surface: 'order_lifecycle_workbench', target_lifecycle_stage: 'fulfillment_prep',
|
||||
}],
|
||||
},
|
||||
}],
|
||||
processing: [], completed: [], cancelled: [], archived: [],
|
||||
},
|
||||
} as unknown as ConversationProcessingProjection;
|
||||
|
||||
const action = normalizeConversationProcessingProjection(embedded)
|
||||
.status_groups!.waiting_human[0]!.uiState!.secondary_actions[0]!;
|
||||
|
||||
// 次动作与主动作一样来自后端授权;缺失导航字段会使文件级查看结果静默失效。
|
||||
expect(action.executionMode).toBe('navigate');
|
||||
expect(action.targetSurface).toBe('order_lifecycle_workbench');
|
||||
expect(action.targetLifecycleStage).toBe('fulfillment_prep');
|
||||
});
|
||||
|
||||
it('fails closed for unsupported embedded primary-action navigation targets', () => {
|
||||
const embedded = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 0, needs_action: 1, completed: 0, history: 0 },
|
||||
focused_task_no: null, recent_task_no: null,
|
||||
needs_action: [], processing: [], completed: [], history: [],
|
||||
status_groups: {
|
||||
failed: [],
|
||||
waiting_human: [{
|
||||
user_task_no: 'OT-INVALID-NAV', title: 'order.pdf', display_kind: 'single_document_task',
|
||||
document_names: ['order.pdf'], group: 'needs_action', status_label: 'waiting_human', file_count: 1,
|
||||
can_append: false, available_actions: [],
|
||||
ui_state: {
|
||||
status: 'waiting_human', stage: 'inventory_matching', lifecycle_stage: 'fulfillment_prep',
|
||||
lifecycle_entries: [], blocking_reason: null,
|
||||
primary_action: {
|
||||
code: 'open_inventory_match_review', execution_mode: 'unknown',
|
||||
target_surface: 'unsupported_surface', target_lifecycle_stage: 'unsupported_stage',
|
||||
}, secondary_actions: [],
|
||||
},
|
||||
}],
|
||||
processing: [], completed: [], cancelled: [], archived: [],
|
||||
},
|
||||
} as unknown as ConversationProcessingProjection;
|
||||
|
||||
const action = normalizeConversationProcessingProjection(embedded)
|
||||
.status_groups!.waiting_human[0]!.uiState!.primary_action!;
|
||||
|
||||
expect(action.executionMode).toBeUndefined();
|
||||
expect(action.targetSurface).toBeNull();
|
||||
expect(action.targetLifecycleStage).toBeNull();
|
||||
});
|
||||
|
||||
it('keeps backend intake_parse primary-action target instead of dropping it', () => {
|
||||
const normalized = normalizeShippingProcessingProjection({
|
||||
work_item_no: 'OT-INTAKE-ACTION', source_type: 'direct_pdf', status: 'waiting_human',
|
||||
stage: 'intake_parse', progress_version: 1, last_activity_at: '2026-08-16T00:00:00Z',
|
||||
source_summary: {}, available_actions: [], child_order_tasks: [],
|
||||
ui_state: {
|
||||
status: 'waiting_human', stage: 'intake_parse', lifecycle_stage: 'intake_parse',
|
||||
lifecycle_entries: [{ code: 'intake_parse', state: 'current', target_surface: 'order_lifecycle_workbench' }],
|
||||
blocking_reason: null,
|
||||
primary_action: {
|
||||
code: 'open_intake_parse', parameters: {}, execution_mode: 'navigate',
|
||||
target_surface: 'order_lifecycle_workbench', target_lifecycle_stage: 'intake_parse',
|
||||
},
|
||||
secondary_actions: [],
|
||||
},
|
||||
});
|
||||
|
||||
// 后端指定接收解析时,前端仅透传该目标,不得由现有三阶段白名单裁决或改写。
|
||||
expect(normalized?.uiState?.primary_action?.targetLifecycleStage).toBe('intake_parse');
|
||||
expect(normalized?.uiState?.lifecycleEntries).toEqual([
|
||||
{ code: 'intake_parse', state: 'current', targetSurface: 'order_lifecycle_workbench', disabledReasonKey: null },
|
||||
]);
|
||||
});
|
||||
|
||||
it('resolveConversationProcessingFromUnified: work_items 为空时,embedded waiting_human 任务迁入 needs_action 且统一文案', () => {
|
||||
const embedded: ConversationProcessingProjection = {
|
||||
summary: { total_tasks: 1, total_files: 1, processing: 1, needs_action: 0, completed: 0, history: 0 },
|
||||
|
||||
Reference in new issue
Block a user