32c7074f41
- 删除 KBBindingSnapshot 的 secret_entry_allowed 能力位与服务端 catalog/save 的 KB 传输门禁 - 非 HTTPS 控制台保留明文传输提示,但不再阻断 Key 录入 - 保留 QA AI 严格 HTTPS/回环校验、管理员认证、写意图头与 Key 不回显 - 补齐明文 HTTP 页面与服务端写入回归测试,同步运行手册和 CHANGELOG
89 lines
3.2 KiB
TypeScript
89 lines
3.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
duplicateSelection,
|
|
keyActionFor,
|
|
knowledgeBaseLabel,
|
|
parseKBBindingSnapshot,
|
|
shortKnowledgeBaseID,
|
|
} from './knowledgeBaseBindings'
|
|
import type { KBEnvironmentBinding } from './knowledgeBaseBindings'
|
|
|
|
const binding = (environment: 'test' | 'production'): KBEnvironmentBinding => ({
|
|
environment,
|
|
revision: 1,
|
|
base_url: `https://${environment}.example`,
|
|
key_configured: true,
|
|
key_source: 'sealed',
|
|
internal_kb_id: `${environment}-in`,
|
|
internal_kb_name: '内部资料',
|
|
external_kb_id: `${environment}-out`,
|
|
external_kb_name: '对外资料',
|
|
verification: 'verified',
|
|
checked_at: null,
|
|
updated_by: 'admin',
|
|
updated_at: null,
|
|
source: 'web',
|
|
storage_ready: true,
|
|
replanned: 0,
|
|
retired_duplicates: 0,
|
|
key_tail: '9f2c',
|
|
internal_fallback: '',
|
|
external_fallback: '',
|
|
frozen: 0,
|
|
retargetable: 0,
|
|
})
|
|
|
|
describe('knowledgeBaseBindings', () => {
|
|
it('parses both environments and never projects a key field', () => {
|
|
const parsed = parseKBBindingSnapshot({
|
|
data: {
|
|
environments: [binding('test'), binding('production')],
|
|
storage_ready: true,
|
|
secret_entry_allowed: true,
|
|
},
|
|
})
|
|
expect(parsed.test.base_url).toBe('https://test.example')
|
|
expect(parsed.production.internal_kb_name).toBe('内部资料')
|
|
expect(parsed.storage_ready).toBe(true)
|
|
expect((parsed as unknown as Record<string, unknown>).secret_entry_allowed).toBeUndefined()
|
|
const asRecord = parsed.test as unknown as Record<string, unknown>
|
|
expect(asRecord.api_key).toBeUndefined()
|
|
expect(asRecord.key_ciphertext).toBeUndefined()
|
|
})
|
|
|
|
it('rejects a snapshot missing an environment instead of inventing one', () => {
|
|
expect(() => parseKBBindingSnapshot({ data: { environments: [binding('test')], storage_ready: true } })).toThrow()
|
|
})
|
|
|
|
it('ignores the removed legacy transport capability', () => {
|
|
const parsed = parseKBBindingSnapshot({
|
|
data: {
|
|
environments: [binding('test'), binding('production')],
|
|
storage_ready: true,
|
|
secret_entry_allowed: false,
|
|
},
|
|
})
|
|
expect((parsed as unknown as Record<string, unknown>).secret_entry_allowed).toBeUndefined()
|
|
})
|
|
|
|
it('shows a short id next to the name so same-name bases are distinguishable', () => {
|
|
expect(shortKnowledgeBaseID('0b217e8a-1234-5678')).toBe('0b217e8a…')
|
|
expect(knowledgeBaseLabel('0b217e8a-1234-5678', '客户帮助中心')).toBe('客户帮助中心(0b217e8a…)')
|
|
expect(knowledgeBaseLabel('', '')).toBe('未绑定')
|
|
})
|
|
|
|
it('rejects using one base for both sides', () => {
|
|
expect(duplicateSelection('kb-1', 'kb-1')).toBe(true)
|
|
expect(duplicateSelection('kb-1', 'kb-2')).toBe(false)
|
|
expect(duplicateSelection('', '')).toBe(false)
|
|
})
|
|
|
|
it('forces a new key for any address other than the saved one', () => {
|
|
const saved = binding('test')
|
|
expect(keyActionFor(saved, 'https://test.example', false)).toBe('keep')
|
|
expect(keyActionFor(saved, 'https://other.example', false)).toBe('replace')
|
|
expect(keyActionFor({ ...saved, key_configured: false }, 'https://test.example', false)).toBe('replace')
|
|
expect(keyActionFor(saved, 'https://test.example', true)).toBe('replace')
|
|
})
|
|
})
|