Skip to content

Commit

Permalink
fix(CreateService): should use query model-id to select default mod…
Browse files Browse the repository at this point in the history
…el (containers#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]>
  • Loading branch information
axel7083 authored Sep 30, 2024
1 parent 78d41cf commit 46f4759
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
41 changes: 38 additions & 3 deletions packages/frontend/src/pages/CreateService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ test('should display connectionInfo message if there is no running connection',
} as unknown as ModelInfo,
]);
vi.mocked(modelsInfoStore).modelsInfo = modelsInfoList;
router.location.query.set('model-id', 'id');
render(CreateService);

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

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

await vi.waitFor(() => {
const banner = screen.queryByLabelText('Container connection info banner');
expect(banner).not.toBeInTheDocument();
});
});

test('model-id query should be used to select default model', async () => {
const modelsInfoList = writable<ModelInfo[]>([
{
id: 'model-id-1',
file: {
file: 'file',
path: '/path',
},
} as unknown as ModelInfo,
{
id: 'model-id-2',
file: {
file: 'file',
path: '/path',
},
} as unknown as ModelInfo,
]);
vi.mocked(modelsInfoStore).modelsInfo = modelsInfoList;
router.location.query.set('model-id', 'model-id-2');

render(CreateService);
const createBtn = screen.getByTitle('Create service');

await vi.waitFor(() => {
expect(createBtn).toBeEnabled();
});

await fireEvent.click(createBtn);

await vi.waitFor(() => {
expect(studioClient.requestCreateInferenceServer).toHaveBeenCalledWith({
modelsInfo: [expect.objectContaining({ id: 'model-id-2' })],
port: 8888,
connection: containerProviderConnection,
});
});
});
6 changes: 6 additions & 0 deletions packages/frontend/src/pages/CreateService.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ function refreshTasks(): void {
onMount(async () => {
containerPort = await studioClient.getHostFreePort();
// we might have a query parameter, then we should use it
const queryModelId = router.location.query.get('model-id');
if (queryModelId !== undefined && typeof queryModelId === 'string') {
model = localModels.find(mModel => mModel.id === queryModelId);
}
tasks.subscribe(tasks => {
processTasks(tasks);
});
Expand Down

0 comments on commit 46f4759

Please sign in to comment.