feat(web): configure AI confidence threshold (#175)

This commit is contained in:
QiuSW
2026-08-31 17:30:04 +08:00
parent 4343ab5c94
commit d00f1591c2
2 changed files with 53 additions and 12 deletions
@@ -0,0 +1,42 @@
import { expect, test } from '@playwright/test'
const routeFor = (path: string) => [{ path: '/goauto-management', component: 'Layout', menuName: 'GoAutoManagement', title: '采采管理', visible: '0', children: [{ path, component: '/goauto/ai-matching-settings/index', menuName: 'GoAutoAiMatchingSettings', title: 'AI 规格匹配', visible: '0' }] }]
test('管理员可保存 AI 建议置信度阈值', async({ page, context }) => {
await context.addCookies([{ name: 'Admin-Token', value: 'prototype-test-token', domain: 'localhost', path: '/' }])
let saved: { autoConfirmMinConfidence?: number } = {}
await page.route('**/api/**', async route => {
const url = new URL(route.request().url())
if (url.pathname.startsWith('/src/api/')) return route.continue()
if (url.pathname.endsWith('/api/v1/getinfo')) return route.fulfill({ json: { code: 200, data: { roles: ['admin'], name: '管理员', avatar: '', introduction: '', permissions: [] }}})
if (url.pathname.endsWith('/api/v1/menurole')) return route.fulfill({ json: { code: 200, data: routeFor('/ai-matching-settings') }})
if (url.pathname.endsWith('/api/admin/v1/ai-matching-settings') && route.request().method() === 'PUT') { saved = route.request().postDataJSON(); return route.fulfill({ json: { code: 200, data: { enabled: true, provider: 'openai_compatible', baseUrl: 'http://provider/v1', model: 'test', timeoutSeconds: 180, autoConfirmMinConfidence: saved.autoConfirmMinConfidence, apiKey: 'secret' }}}) }
if (url.pathname.endsWith('/api/admin/v1/ai-matching-settings')) return route.fulfill({ json: { code: 200, data: { enabled: true, provider: 'openai_compatible', baseUrl: 'http://provider/v1', model: 'test', timeoutSeconds: 180, autoConfirmMinConfidence: 0.85, apiKey: 'secret' }}})
return route.fulfill({ json: { code: 200, data: [] }})
})
await page.goto('/#/ai-matching-settings')
const threshold = page.getByLabel('AI 建议置信度阈值')
await expect(threshold).toHaveValue('0.85')
const thresholdField = page.locator('.el-form-item').filter({ hasText: 'AI 建议置信度阈值' })
for (let index = 0; index < 10; index += 1) await thresholdField.getByRole('button', { name: '减少数值' }).click()
await expect(threshold).toHaveValue('0.75')
await page.getByRole('button', { name: '保存设置', exact: true }).click()
await expect.poll(() => saved.autoConfirmMinConfidence).toBe(0.75)
await expect(page.getByText('达到阈值才自动预填建议;范围 0~1。自动预填不等于自动确认或自动采购。', { exact: true })).toBeVisible()
})
test('非管理员只读查看 AI 建议置信度阈值', async({ page, context }) => {
await context.addCookies([{ name: 'Admin-Token', value: 'prototype-test-token', domain: 'localhost', path: '/' }])
await page.route('**/api/**', async route => {
const url = new URL(route.request().url())
if (url.pathname.startsWith('/src/api/')) return route.continue()
if (url.pathname.endsWith('/api/v1/getinfo')) return route.fulfill({ json: { code: 200, data: { roles: ['purchaser'], name: '采购员', avatar: '', introduction: '', permissions: [] }}})
if (url.pathname.endsWith('/api/v1/menurole')) return route.fulfill({ json: { code: 200, data: routeFor('/ai-matching-settings') }})
if (url.pathname.endsWith('/api/admin/v1/ai-matching-settings')) return route.fulfill({ json: { code: 200, data: { enabled: true, autoConfirmMinConfidence: 0.85 }}})
return route.fulfill({ json: { code: 200, data: [] }})
})
await page.goto('/#/ai-matching-settings')
await expect(page.getByText('0.85', { exact: true })).toBeVisible()
await expect(page.getByLabel('AI 建议置信度阈值')).toHaveCount(0)
await expect(page.getByRole('button', { name: '保存设置', exact: true })).toHaveCount(0)
})