feat(shipping-notice): 实现滚动履约功能,优化发货通知流程与代码清理

清理废弃的ShippingCase相关代码与依赖,统一使用ShippingNotice直接关联客户数据。调整库存网关依赖规则,支持仅对库存满足或已人工放行的订单行生成发货Excel,实现滚动履约逻辑。
This commit is contained in:
hugo committed 2026-08-26 02:47:07 +08:00
1 parent 7cfd5d167e
commit 1e5aedb9ed
235 files changed
+11394 -9613

No files matched your search

@@ -5,7 +5,7 @@
* 逻辑:标准模式无对话上下文、无常驻 PDF 列;底栏无「确认并创建任务」;
* 正式 OT / STP 对象级重试走 /retry 或 STP retry;敏感面板审计失败不打开。
*/
import { describe, expect, it, vi, beforeEach } from 'vitest';
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
import { computed, nextTick, ref } from 'vue';
import { flushPromises, mount } from '@vue/test-utils';
import { createI18n } from 'vue-i18n';
@@ -16,21 +16,34 @@ import { CHAT_PAGE_KEY } from '@/features/chat/composables/chat.context';
import {
auditWorkspaceShippingOrderReviewEligibilityDetails,
auditWorkspaceShippingOrderReviewVersionHistory,
getWorkspaceShippingFreightNoticeGroups,
getWorkspaceShippingTask,
decideWorkspaceShippingOrderReviewLineFulfillment,
waveWorkspaceShippingOrderReviewLineFulfillment,
retryWorkspaceShippingOrderStpAutoCreate,
retryShippingNoticeIntake,
} from '@/features/chat/api/shipping.api';
const { batchConfirmFreightMock, batchRpaFreightMock, downloadFreightArchiveMock } = vi.hoisted(() => ({
batchConfirmFreightMock: vi.fn().mockResolvedValue({ results: [] }),
batchRpaFreightMock: vi.fn().mockResolvedValue({ results: [] }),
downloadFreightArchiveMock: vi.fn().mockResolvedValue(undefined),
}));
const { downloadWorkspaceShippingLineInventoryFileMock } = vi.hoisted(() => ({
downloadWorkspaceShippingLineInventoryFileMock: vi.fn().mockResolvedValue(undefined),
}));
const { downloadWorkspaceShippingExcelFileMock } = vi.hoisted(() => ({
downloadWorkspaceShippingExcelFileMock: vi.fn().mockResolvedValue(undefined),
}));
const { downloadWorkspaceShippingNoticeExcelFileMock } = vi.hoisted(() => ({
downloadWorkspaceShippingNoticeExcelFileMock: vi.fn().mockResolvedValue(undefined),
}));
vi.mock('@/features/chat/shipping/shippingDownload', () => ({
downloadWorkspaceShippingLineInventoryFile: downloadWorkspaceShippingLineInventoryFileMock,
downloadWorkspaceShippingNoticeExcelFile: downloadWorkspaceShippingNoticeExcelFileMock,
downloadWorkspaceShippingNoticeExportArchive: downloadFreightArchiveMock,
}));
vi.mock('@/features/workspace/api/shipping-tasks.api', () => ({
downloadWorkspaceShippingExcelFile: downloadWorkspaceShippingExcelFileMock,
@@ -44,10 +57,16 @@ const ensureIntakeParseContextLoaded = vi.fn().mockResolvedValue(true);
const confirmMock = vi.fn();
const reloadLatestDraftMock = vi.fn().mockResolvedValue(undefined);
const refreshShippingProcessingMock = vi.fn().mockResolvedValue(undefined);
const startWorkflowProgressPollingMock = vi.fn();
const patchLineMock = vi.fn().mockResolvedValue(undefined);
const { submitProcessGatePrimaryActionMock } = vi.hoisted(() => ({
submitProcessGatePrimaryActionMock: vi.fn().mockResolvedValue({ outcome: 'submitted' }),
}));
/**
* 本文件每个用例均挂载完整工作台;统一卸载,避免跨用例残留 watch/router 响应式副作用。
*/
const mountedWrappers: Array<{ unmount: () => void }> = [];
const { postFormalGateActionMock } = vi.hoisted(() => ({
postFormalGateActionMock: vi.fn().mockResolvedValue({}),
}));
@@ -105,12 +124,20 @@ const reviewQueue = ref({
});
const workItem = ref<Record<string, any> | null>(null);
const reviewProgressContext = ref<Record<string, any> | null>(null);
/** Run 解析中的用户态进度;与真实 composable 返回契约保持一致。 */
const extractionLifecycleProgress = ref<Record<string, any> | null>(null);
/** 旧重解析横幅状态;回归用例确认它不再驱动独立黄色进度提示。 */
const statusMessage = ref<string | null>(null);
const runLoading = ref(false);
const runSwitchFailed = ref(false);
/** 与 activeCase 同源共享,供断言 Progress 优先阶段源。 */
const shippingProcessingProjection = ref<Record<string, any> | null>(null);
/** 正式任务投影的请求中状态;用于覆盖 Case 先到、Projection 后到的过渡窗口。 */
const shippingProcessingLoading = ref(false);
const intakeParseContext = ref<Record<string, any> | null>(null);
const requestedCaseNo = ref<string | null>(null);
const reviewEditable = ref(true);
const reviewFormalEditable = ref(false);
/** 每个用例必须从独立的 Case 图快照开始,避免嵌套 schema/draft 被浅拷贝污染。 */
function createActiveCaseFixture() {
@@ -170,6 +197,7 @@ vi.mock('@/features/chat/api/shipping.api', async (importOriginal) => {
auditWorkspaceShippingOrderReviewVersionHistory: vi.fn().mockResolvedValue({ audited: true, case_no: 'CASE-1' }),
auditWorkspaceShippingOrderReviewEligibilityDetails: vi.fn().mockResolvedValue({ audited: true, case_no: 'CASE-1' }),
decideWorkspaceShippingOrderReviewLineFulfillment: vi.fn().mockResolvedValue({ status: 'ok' }),
waveWorkspaceShippingOrderReviewLineFulfillment: vi.fn().mockResolvedValue({ status: 'ok' }),
retryWorkspaceShippingOrderStpAutoCreate: vi.fn().mockResolvedValue({
status: 'queued',
job_id: 901,
@@ -180,6 +208,9 @@ vi.mock('@/features/chat/api/shipping.api', async (importOriginal) => {
task_no: 'SN-MOCK',
status: 'created',
}),
getWorkspaceShippingFreightNoticeGroups: vi.fn().mockResolvedValue({ items: [] }),
batchConfirmWorkspaceShippingNoticesUploaded: (...args: unknown[]) => batchConfirmFreightMock(...args),
batchStartWorkspaceShippingNoticeRpaUpload: (...args: unknown[]) => batchRpaFreightMock(...args),
};
});
@@ -209,6 +240,7 @@ function createReviewComposableMock() {
caseProjectionVersion: ref(1),
caseLoadingContext: ref(null),
reviewProgressContext,
extractionLifecycleProgress,
workItem,
authoritativeOrderTaskNo: computed(() => {
const no = String(reviewProgressContext.value?.user_task_no || '').trim();
@@ -216,7 +248,7 @@ function createReviewComposableMock() {
return no;
}),
versions: ref([]),
statusMessage: ref(null),
statusMessage,
draftConflict: ref(null),
draftConflictDiffLines: ref([]),
buildEligibility: ref({ can_build: true, issues: [], lines: [] }),
@@ -224,7 +256,9 @@ function createReviewComposableMock() {
routingRecoveryLines: ref([]),
isViewingHistoricalVersion: computed(() => false),
isReadOnly: computed(() => false),
loading: ref(false),
initialLoading: ref(false),
runLoading,
runSwitchFailed,
loadFailed: ref(false),
caseSwitchLoading: ref(false),
caseSwitchFailed: ref(false),
@@ -281,13 +315,14 @@ function createReviewComposableMock() {
clearEvidenceDrawerFocus: vi.fn(),
requestSuggestion: vi.fn(),
decideSuggestion: vi.fn(),
editable: computed(() => true),
formalEditable: computed(() => false),
editable: computed(() => reviewEditable.value),
formalEditable: computed(() => reviewFormalEditable.value),
canEditFormalFields: computed(() => false),
isFieldEditable: () => true,
isWorkItemClosed: computed(() => false),
showWorkflowProgress: computed(() => false),
workflowProgressPolling: computed(() => false),
startWorkflowProgressPolling: startWorkflowProgressPollingMock,
shippingProcessingProjection,
shippingProcessingLoading,
shippingProcessingError: ref(null),
@@ -604,6 +639,7 @@ async function mountView(query: Record<string, string> = {}) {
lifecycle: {
navigation: '订单生命周期阶段',
current: '当前可处理',
processing: '处理中',
prerequisite: '请先完成当前阶段',
stages: {
intake_parse: '接收解析',
@@ -642,6 +678,10 @@ async function mountView(query: Record<string, string> = {}) {
stageLabel: {
waiting_system_start: '等待系统启动',
},
progress: {
step: { profile_matching: '正在匹配订单模板' },
lifecycleReason: { processing_slow: '当前步骤耗时较长,系统仍在继续。' },
},
},
shippingSessionWorkItem: {
versionLabel: 'V{version}',
@@ -676,6 +716,7 @@ async function mountView(query: Record<string, string> = {}) {
[CHAT_PAGE_KEY as symbol]: {
conversationId: 'conv-1',
messages: [],
bumpWorkflowRefresh: vi.fn(),
},
},
stubs: {
@@ -693,6 +734,7 @@ async function mountView(query: Record<string, string> = {}) {
},
},
});
mountedWrappers.push(wrapper);
await flushPromises();
return wrapper;
}
@@ -700,21 +742,79 @@ async function mountView(query: Record<string, string> = {}) {
/** 将共享 Case fixture 恢复为可编辑草稿,避免跨用例污染确认恢复态。 */
function resetActiveCaseFixture() {
activeCase.value = createActiveCaseFixture();
reviewRun.value = {
run_no: 'RUN-1',
items: [{
case_no: 'CASE-1', document_id: 1, file_name: 'po.pdf', status: 'draft',
issue_count: 0, available_actions: ['validate', 'confirm'],
}],
};
requestedCaseNo.value = null;
shippingProcessingProjection.value = null;
shippingProcessingLoading.value = false;
intakeParseContext.value = null;
extractionLifecycleProgress.value = null;
statusMessage.value = null;
runLoading.value = false;
runSwitchFailed.value = false;
}
describe('ShippingOrderReviewView layout phase 1', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.useRealTimers();
ensureIntakeParseContextLoaded.mockResolvedValue(true);
resetActiveCaseFixture();
reviewEditable.value = true;
reviewFormalEditable.value = false;
workItem.value = null;
reviewProgressContext.value = null;
});
afterEach(() => {
while (mountedWrappers.length) {
mountedWrappers.pop()?.unmount();
}
vi.useRealTimers();
});
it('puts customer PO line first and excludes internal line number and inventory source from the main table', async () => {
activeCase.value = {
...activeCase.value,
schema: {
...activeCase.value.schema,
fields: [
...activeCase.value.schema.fields,
{ field_id: 'fld-line-no', field_code: 'line_no', display_name: '内部项次', scope: 'line', value_type: 'string', required: true, options: [] },
{ field_id: 'fld-customer-po-line', field_code: 'customer_po_line_no', display_name: '客户 PO 项次', scope: 'line', value_type: 'string', required: true, options: [] },
{ field_id: 'fld-part-number', field_code: 'part_number', display_name: '料号', scope: 'line', value_type: 'string', required: true, options: [] },
],
},
draft: {
...activeCase.value.draft,
lines: [{
line_key: 'LINE-1',
values: {
'fld-line-no': { value: '10' },
'fld-customer-po-line': { value: '00010' },
'fld-part-number': { value: 'PN-ONE' },
'fld-inventory-source-hint': { value: 'DBS' },
},
machine_fields: [],
}],
},
};
const wrapper = await mountView();
const headers = wrapper.find('[data-testid="review-lines-scroll"]').findAll('th').map((item) => item.text());
// 关键断言:业务主键首列,内部项次和库存源线索不挤占默认主表宽度。
expect(headers.slice(0, 3)).toEqual(['#', '客户 PO 项次 *', '料号 *']);
expect(headers).not.toContain('内部项次 *');
expect(headers).not.toContain('库存源');
expect(wrapper.find('[data-testid="review-line-inventory-source"]').exists()).toBe(false);
});
it('keeps the requested replacement Case when the loaded Run updates the URL', async () => {
// 关键断言:新版 Run 先到而旧 URL Case 仍在时,不能拼出 RUN-NEW + CASE-OLD。
const wrapper = await mountView({ case_no: 'CASE-OLD' });
@@ -729,6 +829,50 @@ describe('ShippingOrderReviewView layout phase 1', () => {
expect((wrapper.vm as any).$route.query.case_no).toBe('CASE-NEW');
});
it('shows the five-stage Run progress and current parsing step before a Case is available', async () => {
activeCase.value = null as any;
reviewRun.value = { run_no: 'RUN-PARSING', items: [] };
extractionLifecycleProgress.value = {
lifecycle_stage: 'intake_parse', lifecycle_status: 'running',
current_step_i18n_key: 'chat.shippingProcessing.progress.step.profile_matching',
completed_step_codes: ['layout_parsing_completed'], health_status: 'normal',
};
const wrapper = await mountView();
expect(wrapper.get('[data-testid="review-run-lifecycle-progress"]').exists()).toBe(true);
expect(wrapper.get('[data-testid="review-run-lifecycle-current-step"]').text()).toContain('正在匹配订单模板');
expect(wrapper.find('[data-testid="review-lifecycle-stage-intake_parse"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-lifecycle-stage-upload_complete"]').exists()).toBe(true);
});
it('keeps the compact Run progress visible with a stable stalled reason', async () => {
activeCase.value = null as any;
reviewRun.value = { run_no: 'RUN-STALLED', items: [] };
extractionLifecycleProgress.value = {
lifecycle_stage: 'intake_parse', lifecycle_status: 'running',
current_step_i18n_key: 'chat.shippingProcessing.progress.step.profile_matching',
blocking_reason_i18n_key: 'chat.shippingProcessing.progress.lifecycleReason.processing_slow',
completed_step_codes: [], health_status: 'attention',
};
const wrapper = await mountView();
expect(wrapper.get('[data-testid="review-run-lifecycle-current-step"]').text()).toContain('当前步骤耗时较长');
});
it('uses the lifecycle progress below navigation instead of a legacy yellow reparse banner', async () => {
extractionLifecycleProgress.value = {
lifecycle_stage: 'intake_parse', lifecycle_status: 'running',
current_step_i18n_key: 'chat.shippingProcessing.progress.step.profile_matching',
completed_step_codes: ['layout_parsing_completed'], health_status: 'normal',
};
statusMessage.value = 'reparse_in_progress';
const wrapper = await mountView();
// 关键断言:重解析不再拥有第二条黄色横幅;唯一进度紧跟五阶段导航。
expect(wrapper.find('[data-testid="review-status-banner"]').exists()).toBe(false);
expect(wrapper.findAll('[data-testid="review-run-lifecycle-progress"]')).toHaveLength(1);
expect(wrapper.get('[data-testid="review-run-lifecycle-progress"]').text()).toContain('正在匹配订单模板');
});
it('loads a cross-Run file once through the route watcher', async () => {
const originalQueue = reviewQueue.value;
try {
@@ -759,6 +903,47 @@ describe('ShippingOrderReviewView layout phase 1', () => {
}
});
it('keeps old workbench content in place and shows only a non-layout-shifting loading indicator while a cross-Run target is loading', async () => {
// 关键断言:跨 Run 不能插入大块 skeleton 把旧内容推离视口;仅允许无布局占位的轻提示。
runLoading.value = true;
const wrapper = await mountView();
const shell = wrapper.get('[data-testid="review-case-workbench-shell"]');
expect(wrapper.find('[data-testid="review-workbench-scroll"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-case-switch-loading"]').exists()).toBe(false);
expect(wrapper.get('[data-testid="review-case-switch-indicator"]').exists()).toBe(true);
expect(shell.attributes('aria-busy')).toBe('true');
expect(shell.classes()).toContain('pointer-events-none');
expect((wrapper.vm as any).workbenchActionsExecutable).toBe(false);
});
it('does not read freight Notice groups while the selected file is outside freight upload', async () => {
// 关键断言:货代 Notice 聚合只服务货代上传面,不能加入普通文件切换关键路径。
activeCase.value = {
...activeCase.value,
status: 'confirmed', confirmed_task_no: 'SN-NOTICE-PREP', confirmed_task_id: 91, has_formal_ot: true,
};
const taskApi = await import('@/features/chat/api/shipping.api');
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
task_no: 'SN-NOTICE-PREP', status: 'processing', lines: [], events: [],
ui_state: { lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [], actions: { primary: null, secondary: [] } },
} as any);
await mountView({ lifecycle_stage: 'fulfillment_prep' });
await flushPromises();
expect(taskApi.getWorkspaceShippingFreightNoticeGroups).not.toHaveBeenCalled();
});
it('keeps the workbench shell visible with a local retry state when cross-Run loading fails', async () => {
// 关键断言:跨 Run 失败不能进入页面级 unavailable 分支,旧文件仍可见且可重试。
runSwitchFailed.value = true;
const wrapper = await mountView();
expect(wrapper.find('[data-testid="review-workbench-scroll"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="shipping-order-review-load-failed"]').exists()).toBe(false);
expect(wrapper.get('[data-testid="review-run-switch-failed"]').exists()).toBe(true);
});
it('uses the current-task card as the only Gate action entry for every formal-OT Gate', async () => {
activeCase.value = {
...activeCase.value,
@@ -806,7 +991,7 @@ describe('ShippingOrderReviewView layout phase 1', () => {
expect(wrapper.find('[data-testid="mock-process-gate"]').exists()).toBe(false);
});
it('submits a server-authorized Gate action from the current-task card without an action-code alias', async () => {
it('does not expose Excel regeneration from the current-task card', async () => {
activeCase.value = {
...activeCase.value,
status: 'confirmed', has_formal_ot: true, task_missing: false,
@@ -858,19 +1043,10 @@ describe('ShippingOrderReviewView layout phase 1', () => {
const wrapper = await mountView();
await flushPromises();
await wrapper.get('[data-testid="review-current-task-primary-action"]').trigger('click');
await flushPromises();
// 关键断言:旧 Projection 的 regenerate_excel 不可执行;正式任务的原始动作码
// 只委托统一 Gate 执行器,由其按后端版本与授权再次校验。
expect(submitProcessGatePrimaryActionMock).toHaveBeenCalledWith(
expect.objectContaining({
execution_no: 'EXEC-EXCEL-1',
current_blocking_gate: expect.objectContaining({ gate_code: 'artifact_generation' }),
}),
{ actionCode: 'regenerate_excel_artifact' },
);
// 关键断言:Excel Artifact 属于发货通知单对象,右侧任务摘要不得提供写入口。
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
expect(postFormalGateActionMock).not.toHaveBeenCalled();
expect(submitProcessGatePrimaryActionMock).not.toHaveBeenCalled();
});
it('does not submit an action merely because its code has a Gate-like prefix', async () => {
@@ -1461,6 +1637,86 @@ describe('ShippingOrderReviewView layout phase 1', () => {
expect(orderFooter.text()).toContain('提交订单');
});
it('switches the workbench to the backend current stage and marks it processing', async () => {
const originalQueue = reviewQueue.value;
try {
reviewQueue.value = {
...reviewQueue.value,
items: [{
...reviewQueue.value.items[0],
lifecycle_stage: 'order_review',
lifecycle_entries: [
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
{ code: 'order_review', state: 'current', targetSurface: 'order_lifecycle_workbench' },
{ code: 'fulfillment_prep', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
],
}],
};
const wrapper = await mountView({ lifecycle_stage: 'order_review' });
shippingProcessingProjection.value = {
stage: 'inventory_preparation', status: 'processing',
uiState: {
status: 'running', lifecycleStage: 'fulfillment_prep', lifecycleEntries: [],
primary_action: null, secondary_actions: [],
},
};
reviewQueue.value = {
...reviewQueue.value,
items: [{
...reviewQueue.value.items[0],
lifecycle_stage: 'fulfillment_prep',
lifecycle_entries: [
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
],
}],
};
await flushPromises();
// 关键断言:后端已推进时,仍停在旧当前阶段的页面必须自动进入新工作面并标注处理中。
expect((wrapper.vm as any).$router.currentRoute.value.query.lifecycle_stage).toBe('fulfillment_prep');
expect(wrapper.get('[data-testid="review-lifecycle-stage-fulfillment_prep"]').attributes('data-processing')).toBe('1');
} finally {
reviewQueue.value = originalQueue;
shippingProcessingProjection.value = null;
}
});
it('keeps a manually selected completed stage after the backend has already advanced', async () => {
const originalQueue = reviewQueue.value;
try {
reviewQueue.value = {
...reviewQueue.value,
items: [{
...reviewQueue.value.items[0],
lifecycle_stage: 'fulfillment_prep',
lifecycle_entries: [
{ code: 'intake_parse', state: 'available', targetSurface: 'order_lifecycle_workbench' },
{ code: 'order_review', state: 'available', targetSurface: 'order_lifecycle_workbench' },
{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' },
{ code: 'freight_upload', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
{ code: 'upload_complete', state: 'unavailable', targetSurface: 'order_lifecycle_workbench' },
],
}],
};
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
await wrapper.get('[data-testid="review-lifecycle-stage-order_review"]').findAll('button')[1].trigger('click');
await flushPromises();
// 后端并未再次推进时,主动回看订单复核必须保持该工作面,不能被 watcher 改回通知准备。
expect((wrapper.vm as { $route: { query: Record<string, string> } }).$route.query.lifecycle_stage)
.toBe('order_review');
} finally {
reviewQueue.value = originalQueue;
}
});
it('does not request intake context when its lifecycle entry is missing or unavailable', async () => {
shippingProcessingProjection.value = {
uiState: {
@@ -1643,7 +1899,7 @@ describe('ShippingOrderReviewView layout phase 1', () => {
expect(messageMocks.warning).not.toHaveBeenCalledWith('处理结果尚未生成');
});
it('uses case line fulfillment as a read-only fallback when formal preparation rows are temporarily empty', async () => {
it('normalizes Decimal quantity display in the case fallback while formal preparation rows are temporarily empty', async () => {
const taskApi = await import('@/features/chat/api/shipping.api');
// 正式任务详情延迟/失败不能阻塞已由 Case 投影下发的只读库存匹配事实。
vi.mocked(taskApi.getWorkspaceShippingTask).mockRejectedValue(new Error('detail unavailable'));
@@ -1656,7 +1912,7 @@ describe('ShippingOrderReviewView layout phase 1', () => {
line_fulfillment: {
lines: [{
line_key: 'line-1', reservation_id: 'RSV-FALLBACK', part_number: 'PN-FALLBACK',
required_qty: '8', available_qty: '5', shortage_qty: '3', inventory_source_code: 'DBS_DUB',
required_qty: '8.0', available_qty: '5.0', shortage_qty: '3.0', inventory_source_code: 'DBS_DUB',
}],
},
};
@@ -1674,7 +1930,9 @@ describe('ShippingOrderReviewView layout phase 1', () => {
expect(wrapper.get('[data-testid="review-lifecycle-fulfillment-prep"]').text()).toContain('RSV-FALLBACK');
expect(wrapper.get('[data-testid="review-lifecycle-fulfillment-prep"]').text()).toContain('PN-FALLBACK');
expect(wrapper.get('[data-testid="review-lifecycle-fulfillment-prep"]').text()).toContain('3');
const preparationText = wrapper.get('[data-testid="review-lifecycle-fulfillment-prep"]').text();
expect(preparationText).toContain('3');
expect(preparationText).not.toContain('3.0');
expect(wrapper.find('[data-testid="review-fulfillment-prep-workspace"]').exists()).toBe(true);
expect(messageMocks.warning).not.toHaveBeenCalledWith('处理结果尚未生成');
// 通知准备工作区必须属于五阶段导航的下方主区,不能仍停留在导航之前的状态摘要区。
@@ -1712,6 +1970,14 @@ describe('ShippingOrderReviewView layout phase 1', () => {
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
task_no: 'SN-FROZEN', status: 'processing', lines: [], events: [],
ui_state: {
process_gate: {
execution_no: 'EXEC-FROZEN-LINE',
current_blocking_gate: { gate_code: 'inventory_preparation', status: 'blocked_retryable' },
},
actions: {
primary: { code: 'retry_inventory_preparation', enabled: true, dispatch: 'mutation' },
secondary: [],
},
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [{ code: 'fulfillment_prep', state: 'current' }],
stage_context: {
preparation: {
@@ -1735,6 +2001,12 @@ describe('ShippingOrderReviewView layout phase 1', () => {
// 关键断言:订单基线列和库存事实合为唯一行级工作表,库存源不得退化为任务级 CRANE。
const workspace = wrapper.get('[data-testid="review-fulfillment-prep-workspace"]');
// 关键交互断言:明细在窄视口保持横向可读,行级操作列固定在右侧。
expect(workspace.classes()).toContain('review-fulfillment-prep-workspace');
expect(workspace.classes()).toContain('overflow-x-auto');
expect(workspace.get('table').classes()).toContain('review-fulfillment-prep-table');
expect(workspace.get('thead th:last-child').classes()).toContain('review-fulfillment-sticky-action-head');
expect(workspace.get('tbody tr:first-child td:last-child').classes()).toContain('review-fulfillment-sticky-action-cell');
expect(workspace.text()).toContain('RSV-FROZEN');
expect(workspace.text()).toContain('PN-FROZEN');
expect(workspace.text()).toContain('DBS');
@@ -1756,6 +2028,8 @@ describe('ShippingOrderReviewView layout phase 1', () => {
payload: { line_key: 'line-frozen' },
}),
);
// Gate 恢复受理后立即启动五阶段轮询,不依赖浏览器手动刷新。
expect(startWorkflowProgressPollingMock).toHaveBeenCalledTimes(1);
await wrapper.get('[data-testid="review-fulfillment-line-release-line-frozen"]').trigger('click');
expect(wrapper.get('[data-testid="review-release-inventory-dialog"]').text()).toContain('ODM ID');
expect(wrapper.get('[data-testid="review-release-inventory-dialog"]').text()).toContain('ODM-001');
@@ -1768,6 +2042,62 @@ describe('ShippingOrderReviewView layout phase 1', () => {
reason: '客户确认分批发货',
release_field_values: { '102': 'A-01' },
}));
// 放行写成功后立即释放弹窗;后续读取不得阻塞用户确认按钮。
expect(wrapper.find('[data-testid="review-release-inventory-dialog"]').exists()).toBe(false);
expect(startWorkflowProgressPollingMock).toHaveBeenCalledTimes(2);
});
it('keeps the manual notice-generation entry in the main workspace for an editable formal task', async () => {
const taskApi = await import('@/features/chat/api/shipping.api');
reviewEditable.value = false;
reviewFormalEditable.value = true;
activeCase.value = {
...activeCase.value,
status: 'confirmed', confirmed_task_id: 904, confirmed_task_no: 'SN-READY', has_formal_ot: true,
line_fulfillment: {
lines: [{
line_key: 'line-ready', line_status: 'pending_decision', can_fulfill_complete_line: true,
inventory_source: { code: 'DBS', label: 'DBS', status: 'resolved' },
}],
},
};
shippingProcessingProjection.value = {
uiState: {
lifecycleStage: 'fulfillment_prep',
lifecycleEntries: [{ code: 'fulfillment_prep', state: 'current', targetSurface: 'order_lifecycle_workbench' }],
primary_action: null,
secondary_actions: [],
},
};
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
task_no: 'SN-READY', status: 'processing', lines: [], events: [],
ui_state: {
lifecycle_stage: 'fulfillment_prep', lifecycle_entries: [{ code: 'fulfillment_prep', state: 'current' }],
stage_context: {
preparation: {
status: 'ready', has_match_result: true,
lines: [{
line_key: 'line-ready', reservation_id: 'RSV-READY', part_number: 'PN-READY',
required_qty: '20', available_qty: '65', shortage_qty: '0', source_code: 'DBS', status: 'matched',
}],
},
},
},
} as any);
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
await flushPromises();
const workspace = wrapper.get('[data-testid="review-fulfillment-prep-workspace"]');
expect(workspace.get('[data-testid="review-fulfillment-prep-confirm-wave"]').exists()).toBe(true);
expect(wrapper.findComponent({ name: 'ReviewFulfillmentDecisionPanel' }).exists()).toBe(false);
await workspace.get('[data-testid="review-fulfillment-line-select-line-ready"]').setValue(true);
await workspace.get('[data-testid="review-fulfillment-prep-confirm-wave"]').trigger('click');
expect(vi.mocked(waveWorkspaceShippingOrderReviewLineFulfillment)).toHaveBeenCalledWith('CASE-1', expect.objectContaining({
line_keys: ['line-ready'],
expected_draft_version: 1,
}));
});
it('keeps intake parse on the standard workbench and removes the inventory return row', async () => {
@@ -1953,9 +2283,9 @@ describe('ShippingOrderReviewView layout phase 1', () => {
} finally {
reviewQueue.value = originalQueue;
}
});
}, 15000);
it('opens the page-level evidence dialog from freight upload when the current-task action is manual upload', async () => {
it('keeps manual-upload confirmation out of the current-task card', async () => {
activeCase.value = {
...activeCase.value,
status: 'confirmed', confirmed_task_no: 'SN-UPLOAD-DIALOG', confirmed_task_id: 19, has_formal_ot: true,
@@ -1967,7 +2297,7 @@ describe('ShippingOrderReviewView layout phase 1', () => {
actions: {
primary: {
code: 'mark_manual_uploaded', kind: 'forward', enabled: true,
dispatch: 'dialog', ui_handler: 'manual_upload_evidence',
dispatch: 'dialog', ui_handler: 'manual_upload_confirmation',
target_surface: 'freight_upload', target_anchor: 'manual_upload',
requires_confirmation: false,
},
@@ -1975,17 +2305,24 @@ describe('ShippingOrderReviewView layout phase 1', () => {
},
summary: {}, steps: [],
},
} as any);
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
po_number: 'PO-DOWNLOAD',
items: [{ business_no: 'WYC26082401', po_number: 'PO-DOWNLOAD', lines: [
{ line_no: '10', part_number: 'PN-ONE', reservation_id: 'RSV-1', shipment_qty: '4' },
{ line_no: '20', part_number: 'PN-TWO', reservation_id: 'RSV-2', shipment_qty: '7' },
] }],
} as any);
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
await flushPromises();
await wrapper.get('[data-testid="review-current-task-primary-action"]').trigger('click');
await flushPromises();
expect(wrapper.find('[data-testid="manual-upload-evidence-dialog"]').exists()).toBe(true);
// 人工确认由主区选中发货通知单后的批量入口处理,右侧不再打开单任务弹窗。
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="manual-upload-evidence-dialog"]').exists()).toBe(false);
});
it('renders the authorized Excel download in every freight-upload order line instead of the task rail', async () => {
it('renders one Notice card and one business_no Excel download for freight upload', async () => {
activeCase.value = {
...activeCase.value,
status: 'confirmed', confirmed_task_no: 'SN-DOWNLOAD-DISPATCH', confirmed_task_id: 20, has_formal_ot: true,
@@ -2019,7 +2356,7 @@ describe('ShippingOrderReviewView layout phase 1', () => {
actions: {
primary: {
code: 'mark_manual_uploaded', kind: 'forward', enabled: true,
dispatch: 'dialog', ui_handler: 'manual_upload_evidence',
dispatch: 'dialog', ui_handler: 'manual_upload_confirmation',
requires_confirmation: false,
},
secondary: [{
@@ -2034,6 +2371,13 @@ describe('ShippingOrderReviewView layout phase 1', () => {
process_gate: { execution_no: 'EXEC-DOWNLOAD-DISPATCH' }, summary: {}, steps: [],
},
} as any);
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
po_number: 'PO-DOWNLOAD',
items: [{ business_no: 'WYC26082401', po_number: 'PO-DOWNLOAD', lines: [
{ line_no: '10', part_number: 'PN-ONE', reservation_id: 'RSV-1', shipment_qty: '4' },
{ line_no: '20', part_number: 'PN-TWO', reservation_id: 'RSV-2', shipment_qty: '7' },
] }],
} as any);
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
await flushPromises();
@@ -2042,13 +2386,13 @@ describe('ShippingOrderReviewView layout phase 1', () => {
expect(rows).toHaveLength(2);
expect(rows[0].text()).toContain('PN-ONE');
expect(rows[1].text()).toContain('PN-TWO');
expect(wrapper.find('[data-testid="review-current-task-recovery-download_excel"]').exists()).toBe(false);
expect(wrapper.findAll('[data-testid="review-freight-upload-download"]').length).toBeGreaterThanOrEqual(1);
await wrapper.get('[data-testid="review-freight-upload-download-LINE-1"]').trigger('click');
await wrapper.get('[data-testid="review-freight-upload-download"]').trigger('click');
await flushPromises();
// 下载是 Artifact 只读操作;订单行不按 PO 聚合,且不得伪装成 Gate mutation。
expect(downloadWorkspaceShippingExcelFileMock).toHaveBeenCalledWith('SN-DOWNLOAD-DISPATCH');
expect(downloadWorkspaceShippingNoticeExcelFileMock).toHaveBeenCalledWith('WYC26082401');
expect(messageMocks.success).not.toHaveBeenCalled();
expect(submitProcessGatePrimaryActionMock).not.toHaveBeenCalled();
});
@@ -2275,14 +2619,14 @@ describe('ShippingOrderReviewView layout phase 1', () => {
actions: {
primary: {
code: 'mark_manual_uploaded', kind: 'forward', enabled: true,
dispatch: 'dialog', ui_handler: 'manual_upload_evidence',
dispatch: 'dialog', ui_handler: 'manual_upload_confirmation',
},
secondary: [],
},
stage_context: {
upload: {
latest_attempt: { status: 'failed', mode: 'rpa', freight_ref_no: 'LATEST-FAILED' },
succeeded_attempt: { status: 'succeeded', mode: 'manual', freight_ref_no: 'VERIFIED-REF' },
succeeded_attempt: { status: 'succeeded', mode: 'manual', freight_ref_no: 'LEGACY-REF-MUST-NOT-BE-SHOWN' },
},
},
summary: {}, steps: [],
@@ -2293,21 +2637,93 @@ describe('ShippingOrderReviewView layout phase 1', () => {
await flushPromises();
const evidence = wrapper.get('[data-testid="review-lifecycle-upload-complete"]');
expect(evidence.text()).toContain('VERIFIED-REF');
expect(evidence.text()).toContain('succeeded');
expect(evidence.text()).not.toContain('LATEST-FAILED');
// 人工确认不再展示或依赖货代回执号,即使历史投影仍带有 freight_ref_no。
expect(evidence.text()).not.toContain('LEGACY-REF-MUST-NOT-BE-SHOWN');
expect(evidence.text()).not.toContain('failed');
expect(wrapper.find('[data-testid="review-current-task-primary-action"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="review-current-processing-retry"]').exists()).toBe(false);
});
it('renders empty optional schema fields as editable line columns', async () => {
it('aggregates freight upload by business_no and keeps one Excel action per notice', async () => {
activeCase.value = {
...activeCase.value,
status: 'confirmed', confirmed_task_no: 'SN-PO-WAVE-1', confirmed_task_id: 22, has_formal_ot: true,
};
const taskApi = await import('@/features/chat/api/shipping.api');
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
task_no: 'SN-PO-WAVE-1', business_no: 'WYC26082401', status: 'processing', upload_status: 'pending',
lines: [], events: [],
ui_state: { lifecycle_stage: 'freight_upload', lifecycle_entries: [], actions: { primary: null, secondary: [] }, stage_context: { upload: {} } },
} as any);
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
po_number: 'PO-100',
items: [
{ business_no: 'WYC26082401', po_number: 'PO-100', upload_status: 'pending', export_file_name: 'WYC26082401.xlsx', lines: [
{ line_no: '00010', part_number: 'PART-A', reservation_id: 'RSV-A', qty: '2' },
{ line_no: '00020', part_number: 'PART-B', reservation_id: 'RSV-B', qty: '1' },
] },
{ business_no: 'WYC26082402', po_number: 'PO-100', upload_status: 'pending', export_file_name: 'WYC26082402.xlsx', lines: [
{ line_no: '00030', part_number: 'PART-C', reservation_id: 'RSV-C', qty: '4' },
] },
],
} as any);
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
await flushPromises();
const groups = wrapper.findAll('[data-testid="review-freight-upload-notice"]');
expect(groups).toHaveLength(2);
expect(wrapper.text()).toContain('WYC26082401');
expect(wrapper.text()).toContain('WYC26082402');
expect(wrapper.text()).toContain('PART-A');
expect(wrapper.text()).toContain('PART-C');
expect(wrapper.findAll('[data-testid="review-freight-upload-download"]')).toHaveLength(2);
expect(wrapper.findAll('[data-testid="review-freight-upload-line"]')).toHaveLength(3);
expect(wrapper.findAll('[data-testid="review-freight-upload-download-SN-PO-WAVE-1"]')).toHaveLength(0);
});
it('sends selected business_nos for freight batch actions', async () => {
activeCase.value = { ...activeCase.value, status: 'confirmed', confirmed_task_no: 'SN-PO-BATCH', confirmed_task_id: 23, has_formal_ot: true };
const taskApi = await import('@/features/chat/api/shipping.api');
vi.mocked(taskApi.getWorkspaceShippingTask).mockResolvedValue({
task_no: 'SN-PO-BATCH', status: 'processing', lines: [], events: [],
ui_state: { lifecycle_stage: 'freight_upload', lifecycle_entries: [], actions: { primary: null, secondary: [] }, stage_context: { upload: {} } },
} as any);
vi.mocked(taskApi.getWorkspaceShippingFreightNoticeGroups).mockResolvedValue({
po_number: 'PO-BATCH', items: [
{ business_no: 'WYC26082411', po_number: 'PO-BATCH', lines: [] },
{ business_no: 'WYC26082412', po_number: 'PO-BATCH', lines: [] },
],
} as any);
const wrapper = await mountView({ lifecycle_stage: 'freight_upload' });
await flushPromises();
await wrapper.get('[aria-label="WYC26082411"]').setValue(true);
await wrapper.get('[aria-label="WYC26082412"]').setValue(true);
const buttons = wrapper.get('[data-testid="review-freight-upload-batch-toolbar"]').findAll('button');
await buttons[0].trigger('click');
await flushPromises();
expect(downloadFreightArchiveMock).toHaveBeenCalledWith(['WYC26082411', 'WYC26082412']);
await wrapper.get('[aria-label="WYC26082411"]').setValue(true);
await wrapper.get('[aria-label="WYC26082412"]').setValue(true);
await buttons[1].trigger('click');
await flushPromises();
expect(batchRpaFreightMock).toHaveBeenCalledWith(['WYC26082411', 'WYC26082412']);
await wrapper.get('[aria-label="WYC26082411"]').setValue(true);
await wrapper.get('[aria-label="WYC26082412"]').setValue(true);
await buttons[2].trigger('click');
await flushPromises();
expect(batchConfirmFreightMock).toHaveBeenCalledWith(['WYC26082411', 'WYC26082412']);
});
it('does not place internal inventory hint fields in the primary line table', async () => {
const wrapper = await mountView();
const inputs = wrapper.findAll('[data-testid="review-line-field-input"]');
// 关键断言:库存源线索即使非必填且尚无机器值,也必须作为 Schema 列显示并可编辑。
expect(wrapper.text()).toContain('库存源线索');
expect(inputs).toHaveLength(1);
expect(inputs[0].attributes('disabled')).toBeUndefined();
// 关键断言:主表只保留业务核对字段,库存源线索由行级履约详情承载。
expect(wrapper.text()).not.toContain('库存源线索');
expect(inputs).toHaveLength(0);
});
it('ignores a stale line change after the current draft has accepted the value', async () => {
@@ -2559,10 +2975,11 @@ describe('ShippingOrderReviewView audit and progress recovery', () => {
},
} as any);
const wrapper = await mountView();
// 正式 OT 动作只有进入履约工作面后才读取 ShippingTask.ui_state;测试必须提供真实阶段上下文。
const wrapper = await mountView({ lifecycle_stage: 'fulfillment_prep' });
await flushPromises();
expect(wrapper.get('[data-testid="review-current-task-primary-action"]').attributes('disabled')).toBeDefined();
expect(wrapper.get('[data-testid="review-current-processing-retry"]').attributes('disabled')).toBeDefined();
}, 15000);
it('keeps top / wide / narrow stage labels identical via Progress projection (waiting_system_start)', async () => {
@@ -2641,6 +3058,8 @@ describe('ShippingOrderReviewView audit and progress recovery', () => {
const wrapper = await mountView();
await flushPromises();
// 关键断言:failed 态主卡/底栏露出 STP 重试(非确认后 auto_progress)。
expect(wrapper.get('[data-testid="review-current-task-stage"]').text()).toContain('创建正式订单');
expect(wrapper.get('[data-testid="review-current-task-status"]').text()).toContain('自动处理失败');
const railBtn = wrapper.find('[data-testid="review-current-processing-retry"]');
const footerBtn = wrapper.find('[data-testid="review-retry-stp-auto-create"]');
expect(railBtn.exists() || footerBtn.exists()).toBe(true);
@@ -2649,6 +3068,28 @@ describe('ShippingOrderReviewView audit and progress recovery', () => {
expect(retryWorkspaceShippingOrderStpAutoCreate).toHaveBeenCalledWith('CASE-1');
}, 15000);
it('hides the duplicate submit-order guidance while STP auto-create is running', async () => {
activeCase.value = {
...activeCase.value,
status: 'ready',
available_actions: ['validate'],
automation: {
status: 'running',
retryable: false,
can_auto_create: true,
can_build: true,
phase: 'pre_ot_stp',
},
};
const wrapper = await mountView();
await flushPromises();
// 关键断言:系统接管建单后,底栏只能保留运行态,不得同时出现提交按钮及其旧说明。
expect(wrapper.find('[data-testid="review-footer-automating-hint"]').exists()).toBe(true);
expect(wrapper.find('[data-testid="review-submit-order-hint"]').exists()).toBe(false);
expect(wrapper.find('[data-testid="review-footer-actions"]').text()).not.toContain('提交订单');
}, 15000);
it('shows STP retry for manual_fallback without confirm-create (UI-02)', async () => {
activeCase.value = {
...activeCase.value,
File diff suppressed because it is too large. Load diff