fix: prune missing image indexes and align instance creation payload

This commit is contained in:
2026-10-14 19:37:52 +08:00
parent 15910a086f
commit 3bf197206a
6 changed files with 125 additions and 24 deletions
+1 -1
View File
@@ -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();}
});
+2 -2
View File
@@ -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 () => {