Files
X-Financial/web/tests/expense-application-ontology.test.mjs
caoxiaozhu 7989f3a159 feat: 新增风险图谱算法与系统仪表盘及操作反馈体系
后端新增风险图谱算法模块、风险观察与反馈服务、规则 DSL
校验器和可解释性引擎,完善系统仪表盘和财务仪表盘统计,
优化 agent 运行和编排执行链路,清理旧开发文档,前端新增
系统趋势、负载热力图等多种仪表盘图表组件,完善操作反馈
对话框和工作台日期选择器,优化报销创建和审批详情交互,
补充单元测试覆盖。
2026-05-30 15:46:51 +08:00

86 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict'
import test from 'node:test'
import {
buildApplicationFieldsFromOntology,
expandApplicationTimeWithDays,
resolveApplicationReason,
resolveApplicationTimeRange,
resolvePromptField
} from '../src/utils/expenseApplicationOntology.js'
const structuredApplicationPrompt = [
'发生时间2026-05-25',
'地点:上海',
'事由:支撑国网服务器部署',
'天数3天'
].join('\n')
test('expense application fields use labeled reason and filter resolved missing slots', () => {
const fields = buildApplicationFieldsFromOntology(
{
scenario: 'expense',
intent: 'draft',
entities: [],
time_range: {},
missing_slots: ['time_range', 'location', 'reason', 'amount']
},
structuredApplicationPrompt,
{ name: '申请员工', departmentName: '交付部' }
)
assert.equal(fields.timeRange, '2026-05-25 至 2026-05-27')
assert.equal(fields.location, '上海')
assert.equal(fields.reason, '支撑国网服务器部署')
assert.deepEqual(
fields.missingSlots.map((item) => item.key),
['amount']
)
})
test('expense application prompt field parser supports multiline labels', () => {
assert.equal(resolvePromptField(structuredApplicationPrompt, ['事由']), '支撑国网服务器部署')
assert.equal(resolveApplicationReason(structuredApplicationPrompt), '支撑国网服务器部署')
})
test('expense application reason prefers model entity and strips context fragments', () => {
assert.equal(
resolveApplicationReason(
'发生时间去九江出差3天服务美团业务部署',
{
entities: [
{ type: 'location', value: '九江', normalized_value: '九江' },
{ type: 'reason', value: '服务美团业务部署', normalized_value: '服务美团业务部署' }
]
}
),
'服务美团业务部署'
)
assert.equal(resolveApplicationReason('发生时间去九江出差3天服务美团业务部署'), '服务美团业务部署')
})
test('expense application expands a single selected date with natural days', () => {
const prompt = [
'发生时间2026-05-25',
'去上海出差3天支撑国网服务器部署'
].join('\n')
assert.equal(expandApplicationTimeWithDays('2026-05-25', 3), '2026-05-25 至 2026-05-27')
assert.equal(resolveApplicationTimeRange({ time_range: {} }, prompt), '2026-05-25 至 2026-05-27')
})
test('expense application keeps explicit time range before applying days', () => {
assert.equal(
resolveApplicationTimeRange(
{
time_range: {
start_date: '2026-05-25',
end_date: '2026-05-27'
}
},
'去上海出差3天支撑国网服务器部署'
),
'2026-05-25 至 2026-05-27'
)
})