fix: prune missing image indexes and align instance creation payload
This commit is contained in:
@@ -16,7 +16,7 @@ export function CreateInstance({close, refresh}: {close: () => void; refresh: ()
|
||||
if (!active.current) return;
|
||||
if (!image) throw new Error('请选择可用的本地镜像。');
|
||||
setProgress('正在创建实例,请勿重复提交…');
|
||||
const created = await api.request<Instance>('/instances', 'POST', {name, image_id:image.image_id || image.id, version:image.version});
|
||||
const created = await api.request<Instance>('/instances', 'POST', {name, image_id:image.image_id || image.id});
|
||||
if (!created?.id) throw new Error('未收到实例确认,请刷新实例列表核实,勿重复提交。');
|
||||
if (active.current) {await refresh(); close();}
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ it('requires evidence and confirmation; cancel sends no admission mutation', ()
|
||||
form.props.onSubmit({preventDefault:vi.fn()});
|
||||
expect(window.confirm).toHaveBeenCalledOnce(); expect(request).not.toHaveBeenCalled();
|
||||
});
|
||||
it('creates only the selected verified exact image without build or intent requests', async () => {
|
||||
it('creates with only name and exact image ID, leaving version resolution to the server', async () => {
|
||||
const request = vi.spyOn(api, 'request').mockResolvedValue({id:'created'});
|
||||
vi.stubGlobal('FormData', class {get(key: string) {return key === 'image' ? 'ok' : 'name';}});
|
||||
const close = vi.fn(), refresh = vi.fn(async () => {});
|
||||
@@ -58,7 +58,7 @@ it('creates only the selected verified exact image without build or intent reque
|
||||
expect(nodes(form, n => n.type === 'select')).toHaveLength(1);
|
||||
expect(nodes(form, n => n.type === 'option' && n.props.value === 'exp')).toHaveLength(0);
|
||||
await form.props.onSubmit({preventDefault:vi.fn(), currentTarget:{}});
|
||||
expect(request.mock.calls).toEqual([['/instances', 'POST', {name:'name', image_id:'ok', version:'1.2.3'}]]);
|
||||
expect(request.mock.calls).toEqual([['/instances', 'POST', {name:'name', image_id:'ok'}]]);
|
||||
expect(refresh).toHaveBeenCalledOnce(); expect(close).toHaveBeenCalledOnce();
|
||||
});
|
||||
it('directs users to an administrator and disables creation when no verified image exists', async () => {
|
||||
|
||||
Reference in New Issue
Block a user