This commit is contained in:
@@ -1,6 +1,12 @@
|
|||||||
import { renderToStaticMarkup } from 'react-dom/server'
|
import { renderToStaticMarkup } from 'react-dom/server'
|
||||||
import { describe, expect, it, vi } from 'vitest'
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
import { SystemSettingsView, ppSourceConnections, visibleSaveMessage } from './SystemSettings'
|
import {
|
||||||
|
SystemSettingsView,
|
||||||
|
ppSourceConnections,
|
||||||
|
refreshSettingsInput,
|
||||||
|
serviceSettingsInput,
|
||||||
|
visibleSaveMessage,
|
||||||
|
} from './SystemSettings'
|
||||||
import { AuthContext } from './auth'
|
import { AuthContext } from './auth'
|
||||||
import type { MonitorOverview } from './monitor'
|
import type { MonitorOverview } from './monitor'
|
||||||
import type { CatalogSource } from './sourceCatalog'
|
import type { CatalogSource } from './sourceCatalog'
|
||||||
@@ -641,3 +647,43 @@ describe('ppSourceConnections(数据源配置的清单规则)', () => {
|
|||||||
expect(ppSourceConnections([])).toEqual([])
|
expect(ppSourceConnections([])).toEqual([])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// F03 回归:分区保存不能夹带另一分区未保存的草稿。
|
||||||
|
describe('保存边界(F03)', () => {
|
||||||
|
const server = {
|
||||||
|
document_refresh_seconds: 15,
|
||||||
|
resource_refresh_seconds: 30,
|
||||||
|
stalled_after_seconds: 1800,
|
||||||
|
finalizing_after_seconds: 7200,
|
||||||
|
ingestion_concurrency: 2,
|
||||||
|
test_weknora_base_url: 'https://server.test',
|
||||||
|
production_weknora_base_url: 'https://server.prod',
|
||||||
|
production_tenant_id: '10000',
|
||||||
|
production_knowledge_base_id: 'kb-server',
|
||||||
|
} as unknown as UISettings
|
||||||
|
|
||||||
|
it('保存刷新策略时忽略服务分区里未保存的地址', () => {
|
||||||
|
const input = refreshSettingsInput(server, {
|
||||||
|
documentRefresh: 60,
|
||||||
|
resourceRefresh: 60,
|
||||||
|
stalled: 3600,
|
||||||
|
finalizing: 14400,
|
||||||
|
concurrency: 4,
|
||||||
|
})
|
||||||
|
expect(input.test_weknora_base_url).toBe('https://server.test')
|
||||||
|
expect(input.production_weknora_base_url).toBe('https://server.prod')
|
||||||
|
expect(input.document_refresh_seconds).toBe(60)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('保存服务配置时忽略刷新分区里未保存的参数', () => {
|
||||||
|
const input = serviceSettingsInput(server, {
|
||||||
|
testEndpoint: 'https://draft.test',
|
||||||
|
endpoint: 'https://draft.prod',
|
||||||
|
productionTenantID: '20000',
|
||||||
|
productionKnowledgeBaseID: 'kb-draft',
|
||||||
|
})
|
||||||
|
expect(input.document_refresh_seconds).toBe(15)
|
||||||
|
expect(input.ingestion_concurrency).toBe(2)
|
||||||
|
expect(input.test_weknora_base_url).toBe('https://draft.test')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
+47
-22
@@ -75,6 +75,44 @@ const secondsLabel = (value: number) =>
|
|||||||
value < 60 ? `${value}秒` : value < 3600 ? `${value / 60}分钟` : `${value / 3600}小时`
|
value < 60 ? `${value}秒` : value < 3600 ? `${value / 60}分钟` : `${value / 3600}小时`
|
||||||
export const visibleSaveMessage = (message: string | null, dirty: boolean) => (dirty ? null : message)
|
export const visibleSaveMessage = (message: string | null, dirty: boolean) => (dirty ? null : message)
|
||||||
|
|
||||||
|
// 保存边界是纯函数:服务分区只取服务草稿,刷新分区只取刷新草稿,
|
||||||
|
// 另一侧一律用服务器当前值。组件与测试共用同一实现。
|
||||||
|
export interface ServiceDrafts {
|
||||||
|
testEndpoint: string
|
||||||
|
endpoint: string
|
||||||
|
productionTenantID: string
|
||||||
|
productionKnowledgeBaseID: string
|
||||||
|
}
|
||||||
|
export interface RefreshDrafts {
|
||||||
|
documentRefresh: 15 | 30 | 60
|
||||||
|
resourceRefresh: 30 | 60
|
||||||
|
stalled: 1800 | 3600
|
||||||
|
finalizing: 7200 | 14400
|
||||||
|
concurrency: number
|
||||||
|
}
|
||||||
|
export const serviceSettingsInput = (settings: UISettings, drafts: ServiceDrafts): UISettingsCandidateInput => ({
|
||||||
|
document_refresh_seconds: settings.document_refresh_seconds,
|
||||||
|
resource_refresh_seconds: settings.resource_refresh_seconds,
|
||||||
|
stalled_after_seconds: settings.stalled_after_seconds,
|
||||||
|
finalizing_after_seconds: settings.finalizing_after_seconds,
|
||||||
|
ingestion_concurrency: settings.ingestion_concurrency,
|
||||||
|
test_weknora_base_url: drafts.testEndpoint.trim(),
|
||||||
|
production_weknora_base_url: drafts.endpoint.trim(),
|
||||||
|
production_tenant_id: drafts.productionTenantID.trim(),
|
||||||
|
production_knowledge_base_id: drafts.productionKnowledgeBaseID.trim(),
|
||||||
|
})
|
||||||
|
export const refreshSettingsInput = (settings: UISettings, drafts: RefreshDrafts): UISettingsCandidateInput => ({
|
||||||
|
document_refresh_seconds: drafts.documentRefresh,
|
||||||
|
resource_refresh_seconds: drafts.resourceRefresh,
|
||||||
|
stalled_after_seconds: drafts.stalled,
|
||||||
|
finalizing_after_seconds: drafts.finalizing,
|
||||||
|
ingestion_concurrency: drafts.concurrency,
|
||||||
|
test_weknora_base_url: settings.test_weknora_base_url,
|
||||||
|
production_weknora_base_url: settings.production_weknora_base_url,
|
||||||
|
production_tenant_id: settings.production_tenant_id,
|
||||||
|
production_knowledge_base_id: settings.production_knowledge_base_id,
|
||||||
|
})
|
||||||
|
|
||||||
type ServiceHealthView = MonitorOverview['health'][number]
|
type ServiceHealthView = MonitorOverview['health'][number]
|
||||||
type ServiceView = MonitorOverview['services'][number]
|
type ServiceView = MonitorOverview['services'][number]
|
||||||
|
|
||||||
@@ -201,28 +239,15 @@ export function SystemSettingsView({
|
|||||||
)
|
)
|
||||||
// 保存边界:服务分区只带上自己这一组的输入,另一组一律用服务器当前值。
|
// 保存边界:服务分区只带上自己这一组的输入,另一组一律用服务器当前值。
|
||||||
// 否则“改了地址没保存、切到刷新策略保存”会把未确认的地址一起写进去。
|
// 否则“改了地址没保存、切到刷新策略保存”会把未确认的地址一起写进去。
|
||||||
const serviceInput = (): UISettingsCandidateInput => ({
|
// 两个分区都有独立草稿;缺 settings 时按钮本就不可点,这里只防一手。
|
||||||
document_refresh_seconds: settings?.document_refresh_seconds ?? documentRefresh,
|
const serviceInput = (): UISettingsCandidateInput =>
|
||||||
resource_refresh_seconds: settings?.resource_refresh_seconds ?? resourceRefresh,
|
settings
|
||||||
stalled_after_seconds: settings?.stalled_after_seconds ?? stalled,
|
? serviceSettingsInput(settings, { testEndpoint, endpoint, productionTenantID, productionKnowledgeBaseID })
|
||||||
finalizing_after_seconds: settings?.finalizing_after_seconds ?? finalizing,
|
: ({} as UISettingsCandidateInput)
|
||||||
ingestion_concurrency: settings?.ingestion_concurrency ?? concurrency,
|
const refreshInput = (): UISettingsCandidateInput =>
|
||||||
test_weknora_base_url: testEndpoint.trim(),
|
settings
|
||||||
production_weknora_base_url: endpoint.trim(),
|
? refreshSettingsInput(settings, { documentRefresh, resourceRefresh, stalled, finalizing, concurrency })
|
||||||
production_tenant_id: productionTenantID.trim(),
|
: ({} as UISettingsCandidateInput)
|
||||||
production_knowledge_base_id: productionKnowledgeBaseID.trim(),
|
|
||||||
})
|
|
||||||
const refreshInput = (): UISettingsCandidateInput => ({
|
|
||||||
document_refresh_seconds: documentRefresh,
|
|
||||||
resource_refresh_seconds: resourceRefresh,
|
|
||||||
stalled_after_seconds: stalled,
|
|
||||||
finalizing_after_seconds: finalizing,
|
|
||||||
ingestion_concurrency: concurrency,
|
|
||||||
test_weknora_base_url: settings?.test_weknora_base_url ?? '',
|
|
||||||
production_weknora_base_url: settings?.production_weknora_base_url ?? '',
|
|
||||||
production_tenant_id: settings?.production_tenant_id ?? '',
|
|
||||||
production_knowledge_base_id: settings?.production_knowledge_base_id ?? '',
|
|
||||||
})
|
|
||||||
const saveEndpoint = () => {
|
const saveEndpoint = () => {
|
||||||
setDirty(false)
|
setDirty(false)
|
||||||
onSave(serviceInput())
|
onSave(serviceInput())
|
||||||
|
|||||||
Reference in New Issue
Block a user