2026-07-14 16:03:05 +08:00
|
|
|
|
import assert from 'node:assert/strict'
|
|
|
|
|
|
import test from 'node:test'
|
|
|
|
|
|
|
|
|
|
|
|
import {
|
2026-07-14 17:16:23 +08:00
|
|
|
|
normalizeInitialConversationMessages,
|
|
|
|
|
|
normalizeSnapshotMessage,
|
|
|
|
|
|
serializeSessionMessages
|
2026-07-14 16:03:05 +08:00
|
|
|
|
} from '../src/views/scripts/travelReimbursementConversationStateModel.js'
|
|
|
|
|
|
|
|
|
|
|
|
test('Orchestrator 会话恢复 assistant 的 application preview,并保留既有结果字段', () => {
|
|
|
|
|
|
const applicationPreview = {
|
|
|
|
|
|
decision_id: 'decision-session-1',
|
|
|
|
|
|
fields: {
|
|
|
|
|
|
applicationType: '差旅费用申请',
|
|
|
|
|
|
location: '上海',
|
|
|
|
|
|
reason: '客户现场实施'
|
2026-07-14 17:16:23 +08:00
|
|
|
|
},
|
|
|
|
|
|
memoryApplications: [{
|
|
|
|
|
|
memoryId: 'memory-session-1',
|
|
|
|
|
|
fieldKey: 'reason',
|
|
|
|
|
|
fieldLabel: '申请事由',
|
|
|
|
|
|
value: '客户现场实施',
|
|
|
|
|
|
status: 'applied'
|
|
|
|
|
|
}]
|
2026-07-14 16:03:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
const [message] = normalizeInitialConversationMessages({
|
|
|
|
|
|
messages: [{
|
|
|
|
|
|
id: 'assistant-message-1',
|
|
|
|
|
|
role: 'assistant',
|
|
|
|
|
|
content: '申请预览已生成',
|
|
|
|
|
|
created_at: '2026-07-14T08:00:00Z',
|
|
|
|
|
|
message_json: {
|
|
|
|
|
|
orchestrator_payload: {
|
|
|
|
|
|
result: {
|
|
|
|
|
|
application_preview: applicationPreview,
|
2026-07-14 17:16:23 +08:00
|
|
|
|
learning_receipts: [{
|
|
|
|
|
|
memoryId: 'memory-session-2',
|
|
|
|
|
|
fieldKey: 'transport_mode',
|
|
|
|
|
|
fieldLabel: '出行方式',
|
|
|
|
|
|
value: '火车',
|
|
|
|
|
|
status: 'candidate'
|
|
|
|
|
|
}],
|
2026-07-14 16:03:05 +08:00
|
|
|
|
draft_payload: { claim_id: 'claim-draft-1' },
|
|
|
|
|
|
review_payload: { summary: '复核通过' },
|
|
|
|
|
|
risk_flags: [{ code: 'policy-limit' }]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}]
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
assert.deepEqual(message.applicationPreview, applicationPreview)
|
2026-07-14 17:16:23 +08:00
|
|
|
|
assert.equal(message.applicationLearningReceipts[0].memoryId, 'memory-session-2')
|
2026-07-14 16:03:05 +08:00
|
|
|
|
assert.deepEqual(message.draftPayload, { claim_id: 'claim-draft-1' })
|
|
|
|
|
|
assert.deepEqual(message.reviewPayload, { summary: '复核通过' })
|
|
|
|
|
|
assert.deepEqual(message.riskFlags, [{ code: 'policy-limit' }])
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-07-14 17:16:23 +08:00
|
|
|
|
test('本地快照跨刷新保留记忆应用和学习回执', () => {
|
|
|
|
|
|
const [serialized] = serializeSessionMessages([{
|
|
|
|
|
|
id: 'assistant-memory-snapshot',
|
|
|
|
|
|
role: 'assistant',
|
|
|
|
|
|
text: '申请预览',
|
|
|
|
|
|
applicationPreview: {
|
|
|
|
|
|
fields: { reason: '客户现场实施' },
|
|
|
|
|
|
memoryApplications: [{
|
|
|
|
|
|
memoryId: 'memory-local-applied',
|
|
|
|
|
|
fieldKey: 'reason',
|
|
|
|
|
|
fieldLabel: '申请事由',
|
|
|
|
|
|
value: '客户现场实施',
|
|
|
|
|
|
status: 'applied'
|
|
|
|
|
|
}]
|
|
|
|
|
|
},
|
|
|
|
|
|
applicationLearningReceipts: [{
|
|
|
|
|
|
memoryId: 'memory-local-candidate',
|
|
|
|
|
|
fieldKey: 'transport_mode',
|
|
|
|
|
|
fieldLabel: '出行方式',
|
|
|
|
|
|
value: '火车',
|
|
|
|
|
|
status: 'candidate'
|
|
|
|
|
|
}]
|
|
|
|
|
|
}])
|
|
|
|
|
|
const restored = normalizeSnapshotMessage(serialized)
|
|
|
|
|
|
|
|
|
|
|
|
assert.equal(restored.applicationPreview.memoryApplications[0].status, 'applied')
|
|
|
|
|
|
assert.equal(restored.applicationLearningReceipts[0].status, 'candidate')
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-07-14 16:03:05 +08:00
|
|
|
|
test('user 消息不能从 payload 恢复 application preview', () => {
|
|
|
|
|
|
const [message] = normalizeInitialConversationMessages({
|
|
|
|
|
|
messages: [{
|
|
|
|
|
|
id: 'user-message-1',
|
|
|
|
|
|
role: 'user',
|
|
|
|
|
|
content: '保存草稿',
|
|
|
|
|
|
message_json: {
|
|
|
|
|
|
orchestrator_payload: {
|
|
|
|
|
|
result: {
|
|
|
|
|
|
application_preview: { fields: { reason: '伪造预览' } }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}]
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
assert.equal(message.applicationPreview, null)
|
|
|
|
|
|
})
|