refactor(ui): 「知识库绑定」改名为「测试知识库绑定」

与新的「生产知识库绑定」(发布 源库→目标库)配对,避免两处同名分不清。
同步改分区标题、说明、错误文案与测试断言。
This commit is contained in:
姚章浩
2026-10-08 15:55:34 +08:00
parent 6440e3f679
commit 71f6311399
5 changed files with 23 additions and 18 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ import type { ProductionBindings } from './productionBindings'
import type { KnowledgeBaseOption } from './routingBindings'
// 「生产知识库绑定」:发布链路的 源库 → 目标库 映射。这里选的是发布要写入的
// 生产(目标)知识库,与上面的「知识库绑定」(测试端收件库)是两件事。
// 生产(目标)知识库,与上面的「测试知识库绑定」(测试端收件库)是两件事。
export function ProductionBindingsSection() {
const auth = useOptionalAuth()
const isAdmin = auth?.identity?.role === 'admin'
+4 -4
View File
@@ -24,7 +24,7 @@ export function RoutingBindingsSection() {
setInternalDraft(next.internal_bound_by_ui ? next.internal_kb_id : '')
setExternalDraft(next.external_bound_by_ui ? next.external_kb_id : '')
try { setOptions(await fetchRoutingBindingOptions()) } catch { setOptions([]) }
} catch (cause) { setError(cause instanceof Error ? cause.message : '读取知识库绑定失败') }
} catch (cause) { setError(cause instanceof Error ? cause.message : '读取测试知识库绑定失败') }
finally { setLoading(false) }
}, [])
useEffect(() => { void load() }, [load])
@@ -41,7 +41,7 @@ export function RoutingBindingsSection() {
? `;同时把 ${next.replanned} 项还没上传的待入库重新指向新库${next.retired_duplicates ? `,${next.retired_duplicates} 项因新库里已有同篇而被退休` : ''}`
: ''
setMessage(`绑定已生效:对内 ${next.internal_kb_name || next.internal_kb_id.slice(0, 8) || '未绑定'} · 对外 ${next.external_kb_name || next.external_kb_id.slice(0, 8) || '未绑定'}。此后“来源与目录”的标记按新绑定路由${replan}。`)
} catch (cause) { setError(cause instanceof Error ? cause.message : '保存知识库绑定失败') }
} catch (cause) { setError(cause instanceof Error ? cause.message : '保存测试知识库绑定失败') }
finally { setSaving(false) }
}
@@ -63,7 +63,7 @@ export function RoutingBindingsSection() {
)
return <section className="settings-panel wide" id="settings-routing-bindings">
<div className="settings-section-heading"><div><h2>知识库绑定</h2><p>“来源与目录”里的对内 / 对外标记按这里的绑定分发到对应 WeKnora 知识库;保存后立即生效,无需重启。</p></div><button onClick={() => void load()} disabled={loading}>{loading ? '读取中…' : '重新读取'}</button></div>
<div className="settings-section-heading"><div><h2>测试知识库绑定</h2><p>“来源与目录”里的对内 / 对外标记按这里的绑定分发到对应的测试 WeKnora 知识库;保存后立即生效,无需重启。发布写入的生产知识库见「生产知识库绑定」。</p></div><button onClick={() => void load()} disabled={loading}>{loading ? '读取中…' : '重新读取'}</button></div>
{error ? <p className="error-message" role="alert">{error}</p> : null}
{bindings ? <div className="kb-binding-grid">
{renderSide('对内知识库', bindings.internal_kb_id, bindings.internal_kb_name, bindings.internal_env_fallback, bindings.internal_bound_by_ui)}
@@ -78,6 +78,6 @@ export function RoutingBindingsSection() {
<button onClick={() => void save()} disabled={saving || !dirty || sameSelection}>{saving ? '正在校验并保存…' : '保存绑定'}</button>
{message ? <p className="success-message" role="status">{message}</p> : null}
</div> : null}
{!isAdmin ? <p className="hint">仅管理员可修改知识库绑定。</p> : null}
{!isAdmin ? <p className="hint">仅管理员可修改测试知识库绑定。</p> : null}
</section>
}
+13 -8
View File
@@ -58,14 +58,19 @@ describe('SystemSettingsView',()=>{
it('lets an administrator bind the internal/external import knowledge bases from 系统设置',()=>{
// 组件一直在(RoutingBindingsSection),但从未挂到任何页面 —— 导入目标库只能靠
// 部署 env 钉死,换库必须重建容器。
const view=(section:'sources'|'bindings')=>renderToStaticMarkup(<AuthContext.Provider value={authValue('admin')}><SystemSettingsView sources={sources} connections={connections} monitor={monitor} settings={settings} productionEnabled={false} routingCapabilities={{internal_enabled:true,external_enabled:true}} loading={false} saving={false} error={null} saveMessage={null} onSave={vi.fn()} onSourcesChanged={vi.fn()} onRefresh={vi.fn()} initialSection={section} /></AuthContext.Provider>)
expect(view('sources')).toContain('知识库绑定')
const bound=view('bindings')
expect(bound).toContain('id="settings-routing-bindings"')
expect(bound).toContain('按这里的绑定分发到对应 WeKnora 知识库')
// 未读到绑定数据时(SSR 不跑 effect)面板也要如实存在,而不是空白。
expect(bound).toContain('读取中…')
})
const view=(section:'sources'|'bindings'|'production-bindings')=>renderToStaticMarkup(<AuthContext.Provider value={authValue('admin')}><SystemSettingsView sources={sources} connections={connections} monitor={monitor} settings={settings} productionEnabled={false} routingCapabilities={{internal_enabled:true,external_enabled:true}} loading={false} saving={false} error={null} saveMessage={null} onSave={vi.fn()} onSourcesChanged={vi.fn()} onRefresh={vi.fn()} initialSection={section} /></AuthContext.Provider>)
expect(view('sources')).toContain('测试知识库绑定')
expect(view('sources')).toContain('生产知识库绑定')
const bound=view('bindings')
expect(bound).toContain('id="settings-routing-bindings"')
expect(bound).toContain('分发到对应的测试 WeKnora 知识库')
// 未读到绑定数据时(SSR 不跑 effect)面板也要如实存在,而不是空白。
expect(bound).toContain('读取中…')
// 发布目标(源库 → 目标库)是独立分区,与测试端收件库分开。
const target=view('production-bindings')
expect(target).toContain('id="settings-production-bindings"')
expect(target).toContain('新发布的对内 / 对外内容按这里的绑定写入生产 WeKnora 的对应知识库')
})
it('does not show healthy simulation when the settings data failed to load',()=>{
const html=renderToStaticMarkup(<SystemSettingsView sources={[]} connections={[]} monitor={null} settings={null} productionEnabled={false} routingCapabilities={{internal_enabled:false,external_enabled:false}} loading={false} saving={false} error="加载失败" saveMessage={null} onSave={vi.fn()} onSourcesChanged={vi.fn()} onRefresh={vi.fn()} />)
expect(html).toContain('加载失败');expect(html).not.toContain('模拟运行中')
+1 -1
View File
@@ -41,7 +41,7 @@ type SectionKey = 'sources' | 'services' | 'bindings' | 'production-bindings' |
const sections: { key: SectionKey; label: string; adminOnly?: boolean }[] = [
{ key: 'sources', label: '数据源配置' },
{ key: 'services', label: '服务配置' },
{ key: 'bindings', label: '知识库绑定' },
{ key: 'bindings', label: '测试知识库绑定' },
{ key: 'production-bindings', label: '生产知识库绑定' },
{ key: 'storage', label: '存储与备份' },
{ key: 'refresh', label: '刷新策略' },
+4 -4
View File
@@ -43,9 +43,9 @@ function bindingProjection(item: Record<string, unknown>): RoutingBindings {
export async function fetchRoutingBindings(signal?: AbortSignal): Promise<RoutingBindings> {
const response = await fetch('/api/v1/routing-bindings', { signal, headers: { Accept: 'application/json' } })
if (!response.ok) throw new Error(`读取知识库绑定失败(HTTP ${response.status})`)
if (!response.ok) throw new Error(`读取测试知识库绑定失败(HTTP ${response.status})`)
const value = await response.json() as unknown
if (!record(value) || !record(value.data)) throw new Error('知识库绑定响应无效')
if (!record(value) || !record(value.data)) throw new Error('测试知识库绑定响应无效')
return bindingProjection(value.data)
}
@@ -68,11 +68,11 @@ export async function saveRoutingBindings(input: { internal_kb_id: string; exter
body: JSON.stringify(input),
})
if (!response.ok) {
let reason = `保存知识库绑定失败(HTTP ${response.status})`
let reason = `保存测试知识库绑定失败(HTTP ${response.status})`
try { const body = await response.json() as unknown; if (record(body) && typeof body.error === 'string') reason = body.error } catch { /* keep status text */ }
throw new Error(reason)
}
const value = await response.json() as unknown
if (!record(value) || !record(value.data)) throw new Error('知识库绑定响应无效')
if (!record(value) || !record(value.data)) throw new Error('测试知识库绑定响应无效')
return bindingProjection(value.data)
}