fix(multimodal): 冻结推理环境并隔离迟到导入错误

This commit is contained in:
2026-09-05 02:09:15 +08:00
parent 6ee6cd7d73
commit cb1c6dfcf5
8 changed files with 38 additions and 12 deletions
@@ -1,5 +1,5 @@
// @vitest-environment happy-dom
import { mount } from '@vue/test-utils'
import { flushPromises, mount } from '@vue/test-utils'
import { expect, it, vi } from 'vitest'
import RequestJsonEditor from './RequestJsonEditor.vue'
import { apiClient } from '@/services/apiClient'
@@ -38,6 +38,21 @@ it('ignores an imported configuration that finishes after a newer edit', async (
wrapper.unmount()
})
it('ignores an old import failure after a newer edit', async () => {
let fail!: (reason: Error) => void
vi.mocked(apiClient.post).mockReturnValue(new Promise((_resolve, reject) => { fail = reject }))
const wrapper = mount(RequestJsonEditor, {props:{modelValue:[]}})
const input = wrapper.get('input[type="file"]')
Object.defineProperty(input.element, 'files', {value:[new File(['{}'], 'old.json')], configurable:true})
await input.trigger('change')
await wrapper.findAll('button').find(button => button.text() === '添加请求规则')!.trigger('click')
fail(new Error('旧导入失败'))
await flushPromises()
expect(wrapper.text()).not.toContain('旧导入失败')
expect(wrapper.findAll('textarea')).toHaveLength(1)
wrapper.unmount()
})
it('restores defaults even from an invalid draft and reflects replacement configurations', async () => {
const wrapper = mount(RequestJsonEditor, {props:{modelValue:[{capability:'chat', body:{enable_thinking:false}}]}})
await wrapper.get('textarea').setValue('{invalid')
@@ -51,7 +51,7 @@ async function importRules(event: Event) {
if (current !== generation) return
rules.value = validated.request_overrides.map(rule => ({...rule, draft: JSON.stringify(rule.body, null, 2), error: ''}))
publish()
} catch(e) { transferError.value = (e as Error).message }
} catch(e) { if (current === generation) transferError.value = (e as Error).message }
}
async function exportRules() {
transferError.value = ''