Skip to content

Commit 46f4759

Browse files
authored
fix(CreateService): should use query model-id to select default model (#1801)
* fix: create service should the query model-id Signed-off-by: axel7083 <[email protected]> * fix: format Signed-off-by: axel7083 <[email protected]> --------- Signed-off-by: axel7083 <[email protected]>
1 parent 78d41cf commit 46f4759

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

packages/frontend/src/pages/CreateService.spec.ts

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ test('should display connectionInfo message if there is no running connection',
359359
} as unknown as ModelInfo,
360360
]);
361361
vi.mocked(modelsInfoStore).modelsInfo = modelsInfoList;
362-
router.location.query.set('model-id', 'id');
363362
render(CreateService);
364363

365364
await vi.waitFor(() => {
@@ -383,7 +382,6 @@ test('should display connectionInfo message if there is a podman connection with
383382
} as unknown as ModelInfo,
384383
]);
385384
vi.mocked(modelsInfoStore).modelsInfo = modelsInfoList;
386-
router.location.query.set('model-id', 'id');
387385
render(CreateService);
388386

389387
await vi.waitFor(() => {
@@ -404,11 +402,48 @@ test('there should be NO banner if there is a running podman connection having e
404402
} as unknown as ModelInfo,
405403
]);
406404
vi.mocked(modelsInfoStore).modelsInfo = modelsInfoList;
407-
router.location.query.set('model-id', 'id');
408405
render(CreateService);
409406

410407
await vi.waitFor(() => {
411408
const banner = screen.queryByLabelText('Container connection info banner');
412409
expect(banner).not.toBeInTheDocument();
413410
});
414411
});
412+
413+
test('model-id query should be used to select default model', async () => {
414+
const modelsInfoList = writable<ModelInfo[]>([
415+
{
416+
id: 'model-id-1',
417+
file: {
418+
file: 'file',
419+
path: '/path',
420+
},
421+
} as unknown as ModelInfo,
422+
{
423+
id: 'model-id-2',
424+
file: {
425+
file: 'file',
426+
path: '/path',
427+
},
428+
} as unknown as ModelInfo,
429+
]);
430+
vi.mocked(modelsInfoStore).modelsInfo = modelsInfoList;
431+
router.location.query.set('model-id', 'model-id-2');
432+
433+
render(CreateService);
434+
const createBtn = screen.getByTitle('Create service');
435+
436+
await vi.waitFor(() => {
437+
expect(createBtn).toBeEnabled();
438+
});
439+
440+
await fireEvent.click(createBtn);
441+
442+
await vi.waitFor(() => {
443+
expect(studioClient.requestCreateInferenceServer).toHaveBeenCalledWith({
444+
modelsInfo: [expect.objectContaining({ id: 'model-id-2' })],
445+
port: 8888,
446+
connection: containerProviderConnection,
447+
});
448+
});
449+
});

packages/frontend/src/pages/CreateService.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ function refreshTasks(): void {
156156
onMount(async () => {
157157
containerPort = await studioClient.getHostFreePort();
158158
159+
// we might have a query parameter, then we should use it
160+
const queryModelId = router.location.query.get('model-id');
161+
if (queryModelId !== undefined && typeof queryModelId === 'string') {
162+
model = localModels.find(mModel => mModel.id === queryModelId);
163+
}
164+
159165
tasks.subscribe(tasks => {
160166
processTasks(tasks);
161167
});

0 commit comments

Comments
 (0)