feat(account): 支持测试连接 Chat Completions 路径

This commit is contained in:
wucm667
2026-05-21 16:37:20 +08:00
parent 16793d3af0
commit ca60cede14
4 changed files with 348 additions and 10 deletions
@@ -513,6 +513,12 @@ const handleEvent = (event: {
}
break
case 'status':
if (event.text) {
addLine(event.text, 'text-cyan-300')
}
break
case 'image':
if (event.image_url) {
generatedImages.value.push({
@@ -147,4 +147,46 @@ describe('AccountTestModal', () => {
mode: 'compact'
})
})
it('renders Chat Completions path status from test SSE', async () => {
const encoder = new TextEncoder()
const chunks = [
encoder.encode('data: {"type":"status","text":"已通过 /v1/chat/completions 验证"}\n\n'),
encoder.encode('data: {"type":"test_complete","success":true}\n\n')
]
global.fetch = vi.fn().mockResolvedValue({
ok: true,
body: {
getReader: () => ({
read: vi.fn().mockImplementation(() => Promise.resolve(
chunks.length > 0
? { done: false, value: chunks.shift() }
: { done: true, value: undefined }
))
})
}
} as any)
const wrapper = mount(AccountTestModal, {
props: {
show: true,
account: buildAccount()
},
global: {
stubs: {
BaseDialog: BaseDialogStub,
Select: SelectStub,
TextArea: TextAreaStub,
Icon: true
}
}
})
await flushPromises()
;(wrapper.vm as any).selectedModelId = 'gpt-5.4'
await (wrapper.vm as any).startTest()
await flushPromises()
expect(wrapper.text()).toContain('已通过 /v1/chat/completions 验证')
})
})