e34306b2db
build / build (push) Failing after 18s
发布管理:maintenanceSummary 只看 job.state === 'failed' 就给 held 处置文案; 窗口已 released 的旧作业(libsync-internal-1793399248431728863)因此自相矛盾。 改为仅 held 时给 recoveryError,已释放时给 releasedFailure(如实记录失败,不提供强制成功)。 版本记录:LoadVersionHistorySyncState 把可空的 finished_at 扫进 time.Time; 部署重启触发的同步在"进行中"时该列为 NULL,扫描失败使整页 500 (nginx access log:GET /api/v1/version-history?limit=30 → 500,74 字节错误体)。 改为指针接值再判空。前端同时区分"未配置/加载失败"并显示服务端 code。 RED/GREEN:新增 Go 集成用例(NULL finished_at)、两条前端用例; make verify 16/16 通过(local 档案)。
91 lines
3.2 KiB
TypeScript
91 lines
3.2 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import { fetchProductionBindingOptions, fetchProductionBindings, saveProductionBindings } from './productionBindings'
|
|
|
|
const binding = {
|
|
internal_kb_id: '0b217e8a-2a65-40a3-ab8f-34ac5c7a6f05',
|
|
external_kb_id: '',
|
|
internal_kb_name: '对内知识库-wiki',
|
|
external_kb_name: '',
|
|
updated_by: 'admin',
|
|
production_base_url: 'https://weknora-test.dobot.cn/',
|
|
production_connected: true,
|
|
production_message: '',
|
|
}
|
|
|
|
describe('production bindings API', () => {
|
|
it('reads the 源库 → 目标库 projection without leaking extra fields', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi
|
|
.fn()
|
|
.mockResolvedValue(new Response(JSON.stringify({ data: { ...binding, api_key: 'drop' } }), { status: 200 }))
|
|
)
|
|
const result = await fetchProductionBindings()
|
|
expect(result.internal_kb_name).toBe('对内知识库-wiki')
|
|
expect(result.production_connected).toBe(true)
|
|
expect(result).not.toHaveProperty('api_key')
|
|
vi.unstubAllGlobals()
|
|
})
|
|
it('lists production knowledge base options for the picker', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn().mockResolvedValue(
|
|
new Response(
|
|
JSON.stringify({
|
|
data: [
|
|
{ id: 'kb-1', name: '对内知识库-wiki', knowledge_count: 2069 },
|
|
{ id: '', name: '坏行' },
|
|
],
|
|
}),
|
|
{ status: 200 }
|
|
)
|
|
)
|
|
)
|
|
expect(await fetchProductionBindingOptions()).toEqual([
|
|
{ id: 'kb-1', name: '对内知识库-wiki', knowledge_count: 2069 },
|
|
])
|
|
vi.unstubAllGlobals()
|
|
})
|
|
it('saves with an idempotency key and surfaces a rejected base', async () => {
|
|
const fetchMock = vi
|
|
.fn()
|
|
.mockResolvedValueOnce(new Response(JSON.stringify({ data: binding }), { status: 200 }))
|
|
.mockResolvedValueOnce(
|
|
new Response(JSON.stringify({ error: '对内绑定的生产知识库在该 WeKnora 实例中不存在' }), { status: 400 })
|
|
)
|
|
vi.stubGlobal('fetch', fetchMock)
|
|
await expect(saveProductionBindings({ internal_kb_id: 'kb-1', external_kb_id: '' })).resolves.toMatchObject({
|
|
internal_kb_name: '对内知识库-wiki',
|
|
})
|
|
const [, init] = fetchMock.mock.calls[0]
|
|
expect(init.method).toBe('PUT')
|
|
expect(init.headers['Idempotency-Key']).toBeTruthy()
|
|
await expect(saveProductionBindings({ internal_kb_id: 'kb-ghost', external_kb_id: '' })).rejects.toThrow('不存在')
|
|
vi.unstubAllGlobals()
|
|
})
|
|
it('reports an unverified save honestly instead of pretending it was checked', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi
|
|
.fn()
|
|
.mockResolvedValue(
|
|
new Response(
|
|
JSON.stringify({
|
|
data: {
|
|
...binding,
|
|
production_connected: false,
|
|
production_message: '生产 WeKnora 不可用:dial tcp: timeout',
|
|
},
|
|
}),
|
|
{ status: 200 }
|
|
)
|
|
)
|
|
)
|
|
const result = await saveProductionBindings({ internal_kb_id: 'kb-1', external_kb_id: '' })
|
|
expect(result.production_connected).toBe(false)
|
|
expect(result.production_message).toContain('不可用')
|
|
vi.unstubAllGlobals()
|
|
})
|
|
})
|