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 档案)。
66 lines
2.4 KiB
TypeScript
66 lines
2.4 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
import { fetchRoutingBindingOptions, fetchRoutingBindings, saveRoutingBindings } from './routingBindings'
|
|
|
|
const binding = {
|
|
internal_kb_id: '1b52c140-2e18-4676-afc5-4c7d8d190a8c',
|
|
external_kb_id: 'fd7db6aa-763a-46f1-84d2-ecc7c952a5ea',
|
|
internal_env_fallback: true,
|
|
external_env_fallback: false,
|
|
internal_bound_by_ui: false,
|
|
external_bound_by_ui: true,
|
|
internal_kb_name: '',
|
|
external_kb_name: 'governance-external-local',
|
|
updated_by: 'yao',
|
|
weknora_connected: true,
|
|
}
|
|
|
|
describe('routing bindings API', () => {
|
|
it('reads the active binding projection', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn().mockResolvedValue(new Response(JSON.stringify({ data: { ...binding, secret: 'drop' } }), { status: 200 }))
|
|
)
|
|
const result = await fetchRoutingBindings()
|
|
expect(result.internal_env_fallback).toBe(true)
|
|
expect(result.external_bound_by_ui).toBe(true)
|
|
expect(result).not.toHaveProperty('secret')
|
|
vi.unstubAllGlobals()
|
|
})
|
|
it('lists knowledge base options for the picker', async () => {
|
|
vi.stubGlobal(
|
|
'fetch',
|
|
vi.fn().mockResolvedValue(
|
|
new Response(
|
|
JSON.stringify({
|
|
data: [
|
|
{ id: 'kb-1', name: '对内', knowledge_count: 4 },
|
|
{ id: '', name: '坏行' },
|
|
],
|
|
}),
|
|
{ status: 200 }
|
|
)
|
|
)
|
|
)
|
|
expect(await fetchRoutingBindingOptions()).toEqual([{ id: 'kb-1', name: '对内', knowledge_count: 4 }])
|
|
vi.unstubAllGlobals()
|
|
})
|
|
it('saves bindings with an idempotency key and surfaces the server reason', async () => {
|
|
const fetchMock = vi
|
|
.fn()
|
|
.mockResolvedValueOnce(new Response(JSON.stringify({ data: binding }), { status: 200 }))
|
|
.mockResolvedValueOnce(new Response(JSON.stringify({ error: '对内与对外必须绑定不同的知识库' }), { status: 400 }))
|
|
vi.stubGlobal('fetch', fetchMock)
|
|
await expect(saveRoutingBindings({ internal_kb_id: 'kb-1', external_kb_id: '' })).resolves.toMatchObject({
|
|
internal_bound_by_ui: false,
|
|
})
|
|
const [, init] = fetchMock.mock.calls[0]
|
|
expect(init.method).toBe('PUT')
|
|
expect(init.headers['Idempotency-Key']).toBeTruthy()
|
|
await expect(saveRoutingBindings({ internal_kb_id: 'kb-1', external_kb_id: 'kb-1' })).rejects.toThrow(
|
|
'对内与对外必须绑定不同的知识库'
|
|
)
|
|
vi.unstubAllGlobals()
|
|
})
|
|
})
|