feat(shipping-notice): 落地 XFA 拆分、版面签名、统一进度与处理域履约
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a9fbac2fc
commit
d2b3d74def
571 files changed
+78064
-24681
No files matched your search
@@ -11,7 +11,7 @@ import type { ShippingOrderExtractionRun } from '../types/shipping.api.types';
|
||||
import type { ChatMessage } from '../types/chat.types';
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
createRun: vi.fn(),
|
||||
createSubmission: vi.fn(),
|
||||
getRun: vi.fn(),
|
||||
listRuns: vi.fn(),
|
||||
markSeen: vi.fn(),
|
||||
@@ -22,7 +22,7 @@ const api = vi.hoisted(() => ({
|
||||
}));
|
||||
|
||||
vi.mock('../api/shipping.api', () => ({
|
||||
createWorkspaceShippingOrderExtractionRun: api.createRun,
|
||||
createWorkspaceOrderExtractionSubmission: api.createSubmission,
|
||||
getWorkspaceShippingOrderExtractionRun: api.getRun,
|
||||
listWorkspaceShippingOrderExtractionRuns: api.listRuns,
|
||||
markWorkspaceShippingOrderExtractionRunSeen: api.markSeen,
|
||||
@@ -74,6 +74,8 @@ const createHarness = () => {
|
||||
onConversationResolved: vi.fn(async () => undefined),
|
||||
onRetryError: vi.fn(),
|
||||
onWorkflowRefresh: vi.fn(),
|
||||
getFocusedUserTaskNo: vi.fn(() => null),
|
||||
setFocusedUserTaskNo: vi.fn(),
|
||||
t: (key: string) => key,
|
||||
};
|
||||
return { messages, conversationId, options, runs: useShippingOrderExtractionRuns(options) };
|
||||
@@ -97,30 +99,58 @@ describe('useShippingOrderExtractionRuns lifecycle', () => {
|
||||
});
|
||||
|
||||
it('persists stable user and assistant formIds and does not write unchanged polling state again', async () => {
|
||||
const queued = run({ run_no: 'SNER-START', conversation_id: 'conv-created' });
|
||||
api.createRun.mockResolvedValue({ run: queued, reused: false });
|
||||
const queued = run({
|
||||
run_no: 'SNER-START',
|
||||
conversation_id: 'conv-created',
|
||||
user_task_no: 'OT-SNER-START',
|
||||
});
|
||||
api.createSubmission.mockResolvedValue({
|
||||
decision: 'created',
|
||||
user_task_no: 'OT-SNER-START',
|
||||
run_no: 'SNER-START',
|
||||
created_new: true,
|
||||
operation_id: 'op-1',
|
||||
});
|
||||
api.getRun.mockResolvedValue(queued);
|
||||
const harness = createHarness();
|
||||
|
||||
await harness.runs.startRun('解析附件', ['SNI-1'], [], 'batch-1');
|
||||
expect(api.createRun).toHaveBeenCalledWith(expect.objectContaining({ upload_batch_id: 'batch-1' }));
|
||||
expect(api.createSubmission).toHaveBeenCalledWith(expect.objectContaining({
|
||||
upload_batch_id: 'batch-1',
|
||||
intake_nos: ['SNI-1'],
|
||||
composer_context_id: expect.stringMatching(/^CMP-/),
|
||||
submission_id: expect.stringMatching(/^SUB-/),
|
||||
}));
|
||||
expect(harness.options.setFocusedUserTaskNo).toHaveBeenCalledWith('OT-SNER-START');
|
||||
expect(harness.conversationId.value).toBe('conv-created');
|
||||
expect(harness.options.onConversationResolved).toHaveBeenCalledWith('conv-created');
|
||||
expect(harness.messages.value.map((item) => item.payload?.formId)).toEqual([
|
||||
'shipping-order-extraction-user:SNER-START',
|
||||
'shipping-submission-decision:op-1',
|
||||
'shipping-order-extraction-run:SNER-START',
|
||||
]);
|
||||
expect(harness.options.saveLocalMessageToBackend).toHaveBeenCalledTimes(2);
|
||||
expect(harness.options.saveLocalMessageToBackend).toHaveBeenCalledTimes(3);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1000);
|
||||
expect(api.getRun).toHaveBeenCalledWith('SNER-START', expect.any(AbortSignal));
|
||||
expect(harness.options.saveLocalMessageToBackend).toHaveBeenCalledTimes(2);
|
||||
expect(harness.options.saveLocalMessageToBackend).toHaveBeenCalledTimes(3);
|
||||
harness.runs.stopPolling();
|
||||
});
|
||||
|
||||
it('persists an attachment-only user message when the run starts without a text note', async () => {
|
||||
const queued = run({ run_no: 'SNER-EMPTY-NOTE', conversation_id: 'conv-empty-note' });
|
||||
api.createRun.mockResolvedValue({ run: queued, reused: false });
|
||||
const queued = run({
|
||||
run_no: 'SNER-EMPTY-NOTE',
|
||||
conversation_id: 'conv-empty-note',
|
||||
user_task_no: 'OT-SNER-EMPTY-NOTE',
|
||||
});
|
||||
api.createSubmission.mockResolvedValue({
|
||||
decision: 'created',
|
||||
user_task_no: 'OT-SNER-EMPTY-NOTE',
|
||||
run_no: 'SNER-EMPTY-NOTE',
|
||||
created_new: true,
|
||||
operation_id: 'op-empty',
|
||||
});
|
||||
api.getRun.mockResolvedValue(queued);
|
||||
const harness = createHarness();
|
||||
|
||||
await harness.runs.startRun('', ['SNI-1'], [{
|
||||
@@ -181,17 +211,33 @@ describe('useShippingOrderExtractionRuns lifecycle', () => {
|
||||
});
|
||||
|
||||
it('aborts a hanging Run query after ten seconds and keeps polling as a transport failure', async () => {
|
||||
api.createRun.mockResolvedValue({ run: run({ run_no: 'SNER-TIMEOUT', conversation_id: 'conv-timeout' }), reused: false });
|
||||
api.getRun.mockImplementation((_runNo: string, signal: AbortSignal) => new Promise((_resolve, reject) => {
|
||||
signal.addEventListener('abort', () => reject(new DOMException('aborted', 'AbortError')), { once: true });
|
||||
}));
|
||||
api.createSubmission.mockResolvedValue({
|
||||
decision: 'created',
|
||||
user_task_no: 'OT-SNER-TIMEOUT',
|
||||
run_no: 'SNER-TIMEOUT',
|
||||
created_new: true,
|
||||
operation_id: 'op-timeout',
|
||||
});
|
||||
api.getRun.mockResolvedValue(run({ run_no: 'SNER-TIMEOUT', conversation_id: 'conv-timeout' }));
|
||||
// 首次 GET(提交后投影)已返回;后续轮询挂起直至 Abort。
|
||||
let pollCalls = 0;
|
||||
api.getRun.mockImplementation((_runNo: string, signal?: AbortSignal) => {
|
||||
pollCalls += 1;
|
||||
if (pollCalls === 1) {
|
||||
return Promise.resolve(run({ run_no: 'SNER-TIMEOUT', conversation_id: 'conv-timeout' }));
|
||||
}
|
||||
return new Promise((_resolve, reject) => {
|
||||
signal?.addEventListener('abort', () => reject(new DOMException('aborted', 'AbortError')), { once: true });
|
||||
});
|
||||
});
|
||||
const harness = createHarness();
|
||||
await harness.runs.startRun('解析附件', ['SNI-1'], []);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(11000);
|
||||
expect(api.getRun).toHaveBeenCalledWith('SNER-TIMEOUT', expect.any(AbortSignal));
|
||||
expect(harness.runs.getActiveRunNo()).toBe('SNER-TIMEOUT');
|
||||
expect(harness.messages.value[1]?.shipping_order_extraction_state?.status).toBe('queued');
|
||||
const runMessage = harness.messages.value.find((item) => item.shipping_order_extraction_state);
|
||||
expect(runMessage?.shipping_order_extraction_state?.status).toBe('queued');
|
||||
harness.runs.stopPolling();
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user