feat(shipping-notice): 添加 MinerU 订单附件表格结构化功能,更新环境配置和数据模型以支持新布局解析和文档模板管理
This commit is contained in:
1 parent
c4095b08da
commit
c35223d49d
148 files changed
+15709
-1353
No files matched your search
@@ -16,6 +16,7 @@ const api = vi.hoisted(() => ({
|
||||
listRuns: vi.fn(),
|
||||
markSeen: vi.fn(),
|
||||
retryRun: vi.fn(),
|
||||
reparseRun: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../api/shipping.api', () => ({
|
||||
@@ -24,6 +25,7 @@ vi.mock('../api/shipping.api', () => ({
|
||||
listWorkspaceShippingOrderExtractionRuns: api.listRuns,
|
||||
markWorkspaceShippingOrderExtractionRunSeen: api.markSeen,
|
||||
retryWorkspaceShippingOrderExtractionRun: api.retryRun,
|
||||
reparseWorkspaceShippingOrderExtractionRun: api.reparseRun,
|
||||
}));
|
||||
|
||||
const run = (patch: Partial<ShippingOrderExtractionRun>): ShippingOrderExtractionRun => ({
|
||||
@@ -49,6 +51,7 @@ const createHarness = () => {
|
||||
newLocalMessageId: vi.fn((prefix: string) => `${prefix}-${++localId}`),
|
||||
saveLocalMessageToBackend: vi.fn(async () => true),
|
||||
refreshNoticeIntakeStatuses: vi.fn(async () => undefined),
|
||||
getOrderExtractionReview: vi.fn(() => []),
|
||||
clearConsumedNoticeAttachments: vi.fn(),
|
||||
syncShippingConversationWorkspace: vi.fn(async () => true),
|
||||
refreshShippingActions: vi.fn(async () => undefined),
|
||||
@@ -134,7 +137,7 @@ describe('useShippingOrderExtractionRuns lifecycle', () => {
|
||||
});
|
||||
|
||||
it('retries a failed Run in place and resumes polling without creating a new user message', async () => {
|
||||
const failed = run({ run_no: 'SNER-RETRY', status: 'failed', phase: 'failed', error: { message: 'bad workflow' } });
|
||||
const failed = run({ run_no: 'SNER-RETRY', status: 'failed', phase: 'failed', error: { code: 'SHIPPING_NOTICE.ORDER_EXTRACTION_FAILED' } });
|
||||
const queued = run({ run_no: 'SNER-RETRY', status: 'queued', phase: 'manual_retry_queued', error: null });
|
||||
api.listRuns.mockResolvedValue({ items: [failed] });
|
||||
api.retryRun.mockResolvedValue({ run: queued, reused: false });
|
||||
@@ -146,7 +149,7 @@ describe('useShippingOrderExtractionRuns lifecycle', () => {
|
||||
await expect(harness.runs.retryRun('SNER-RETRY')).resolves.toBe(true);
|
||||
|
||||
expect(api.retryRun).toHaveBeenCalledWith('SNER-RETRY');
|
||||
expect(harness.options.refreshNoticeIntakeStatuses).toHaveBeenCalledTimes(1);
|
||||
expect(harness.options.refreshNoticeIntakeStatuses).toHaveBeenCalledTimes(2);
|
||||
expect(harness.messages.value).toHaveLength(1);
|
||||
expect(harness.messages.value[0]?.shipping_order_extraction_state?.status).toBe('extracting');
|
||||
expect(harness.runs.getActiveRunNo()).toBe('SNER-RETRY');
|
||||
@@ -162,6 +165,27 @@ describe('useShippingOrderExtractionRuns lifecycle', () => {
|
||||
expect(harness.options.onRetryError).toHaveBeenCalledWith('retry unavailable');
|
||||
expect(harness.runs.getActiveRunNo()).toBe('');
|
||||
});
|
||||
|
||||
it('creates a new Run for reidentification and switches polling to the new version', async () => {
|
||||
const source = run({ run_no: 'SNER-SOURCE', status: 'needs_review' });
|
||||
const replacement = run({
|
||||
run_no: 'SNER-REPLACEMENT', status: 'queued',
|
||||
reparse: { source_run_no: 'SNER-SOURCE', reason: 'field_mapping_error' },
|
||||
});
|
||||
api.listRuns.mockResolvedValue({ items: [source] });
|
||||
api.reparseRun.mockResolvedValue({ run: replacement, reused: false });
|
||||
api.getRun.mockResolvedValue(replacement);
|
||||
const harness = createHarness();
|
||||
harness.conversationId.value = 'conv-1';
|
||||
await harness.runs.restoreForConversation('conv-1');
|
||||
|
||||
await expect(harness.runs.reparseRun('SNER-SOURCE', 'field_mapping_error')).resolves.toBe(true);
|
||||
|
||||
expect(api.reparseRun).toHaveBeenCalledWith('SNER-SOURCE', { reason: 'field_mapping_error' });
|
||||
expect(harness.runs.getActiveRunNo()).toBe('SNER-REPLACEMENT');
|
||||
expect(harness.messages.value).toHaveLength(2);
|
||||
harness.runs.stopPolling();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -214,7 +238,7 @@ describe('mapOrderExtractionRunToMessageState', () => {
|
||||
vi.useFakeTimers();
|
||||
const active = run({ run_no: 'SNER-DUPLICATE', status: 'running' });
|
||||
const failed = run({
|
||||
run_no: 'SNER-DUPLICATE', status: 'failed', phase: 'failed', error: { message: 'provider unavailable' },
|
||||
run_no: 'SNER-DUPLICATE', status: 'failed', phase: 'failed', error: { code: 'SHIPPING_NOTICE.ORDER_EXTRACTION_PROVIDER_FAILED' },
|
||||
});
|
||||
api.listRuns.mockResolvedValue({ items: [active] });
|
||||
api.getRun.mockResolvedValue(failed);
|
||||
@@ -236,6 +260,33 @@ describe('mapOrderExtractionRunToMessageState', () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('refreshes Intake candidates and persists them on the terminal Run card without page reload', async () => {
|
||||
vi.useFakeTimers();
|
||||
const active = run({ run_no: 'SNER-REVIEW', status: 'running' });
|
||||
const terminal = run({ run_no: 'SNER-REVIEW', status: 'needs_review', result: { pending_count: 1 } });
|
||||
api.listRuns.mockResolvedValue({ items: [active] });
|
||||
api.getRun.mockResolvedValue(terminal);
|
||||
const harness = createHarness();
|
||||
harness.options.getOrderExtractionReview.mockReturnValue([{
|
||||
intakeNo: 'SNI-1',
|
||||
originalFilename: 'notice.eml',
|
||||
candidates: [{
|
||||
candidateNo: 'SNC-1', validationStatus: 'needs_review', selected: true,
|
||||
conflicts: [], businessSummary: { po_number: 'PO-1', lines: [] },
|
||||
}],
|
||||
}]);
|
||||
harness.conversationId.value = 'conv-1';
|
||||
|
||||
await harness.runs.restoreForConversation('conv-1');
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
|
||||
expect(harness.options.refreshNoticeIntakeStatuses).toHaveBeenCalled();
|
||||
expect(harness.messages.value[0]?.payload).toMatchObject({
|
||||
shipping_order_extraction_review: [{ intakeNo: 'SNI-1', candidates: [{ candidateNo: 'SNC-1' }] }],
|
||||
});
|
||||
harness.runs.stopPolling();
|
||||
});
|
||||
|
||||
it('maps completed result counters without guessing from text', () => {
|
||||
expect(mapOrderExtractionRunToMessageState(run({
|
||||
status: 'completed',
|
||||
@@ -250,7 +301,7 @@ describe('mapOrderExtractionRunToMessageState', () => {
|
||||
status: 'needs_review', result: { pending_count: 3 },
|
||||
}))).toMatchObject({ status: 'partially_completed', pending_count: 3, terminal: true });
|
||||
expect(mapOrderExtractionRunToMessageState(run({
|
||||
status: 'failed', error: { code: 'X', message: 'provider failed' },
|
||||
status: 'failed', error: { code: 'X' },
|
||||
}))).toMatchObject({ status: 'failed', message: '', terminal: true });
|
||||
});
|
||||
|
||||
@@ -264,6 +315,6 @@ describe('mapOrderExtractionRunToMessageState', () => {
|
||||
await harness.runs.restoreForConversation('conv-1');
|
||||
|
||||
expect(api.markSeen).toHaveBeenCalledWith('SNER-SEEN');
|
||||
expect(harness.options.loadHistory).toHaveBeenCalledTimes(1);
|
||||
expect(harness.options.loadHistory).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user