Skip to content

Commit

Permalink
fix: uncaught errors in ModelPlayground (#256)
Browse files Browse the repository at this point in the history
* fix: uncaught errors in ModelPlayground

Signed-off-by: axel7083 <[email protected]>

* fix: missing mocked resolved value

Signed-off-by: axel7083 <[email protected]>

---------

Signed-off-by: axel7083 <[email protected]>
  • Loading branch information
axel7083 authored Feb 9, 2024
1 parent d105f16 commit d23e549
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
30 changes: 30 additions & 0 deletions packages/frontend/src/pages/ModelPlayground.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ beforeEach(() => {

test('playground should start when clicking on the play button', async () => {
mocks.playgroundQueriesSubscribeMock.mockReturnValue([]);
mocks.startPlaygroundMock.mockResolvedValue(undefined);
render(ModelPlayground, {
model: {
id: 'model1',
Expand All @@ -87,6 +88,35 @@ test('playground should start when clicking on the play button', async () => {
});
});

test('playground should display error when clicking on the play button and an error occurs', async () => {
mocks.playgroundQueriesSubscribeMock.mockReturnValue([]);
mocks.startPlaygroundMock.mockRejectedValue('bad error');
render(ModelPlayground, {
model: {
id: 'model1',
name: 'Model 1',
description: 'A description',
hw: 'CPU',
registry: 'Hugging Face',
popularity: 3,
license: '?',
url: 'https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/resolve/main/llama-2-7b-chat.Q5_K_S.gguf',
} as ModelInfo,
});

const play = screen.getByTitle('playground-action');
expect(play).toBeDefined();

await fireEvent.click(play);

await waitFor(() => {
expect(mocks.startPlaygroundMock).toHaveBeenCalledOnce();
const alert = screen.getByRole('alert');
expect(alert).toBeDefined();
expect(alert.textContent).toBe('Something went wrong while trying to start playground: bad error');
});
});

test('should display query without response', async () => {
mocks.playgroundQueriesSubscribeMock.mockReturnValue([
{
Expand Down
10 changes: 7 additions & 3 deletions packages/frontend/src/pages/ModelPlayground.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,20 @@
}
const onAction = () => {
if(playgroundState === undefined)
if(playgroundState === undefined || model?.id === undefined)
return;
switch (playgroundState.status) {
case "none":
case "stopped":
studioClient.startPlayground(model.id);
studioClient.startPlayground(model.id).catch((err: unknown) => {
error = `Something went wrong while trying to start playground: ${String(err)}`;
});
break;
case "running":
studioClient.stopPlayground(model.id);
studioClient.stopPlayground(model.id).catch((err: unknown) => {
error = `Something went wrong while trying to stop playground: ${String(err)}`;
});
break;
case "starting":
case "stopping":
Expand Down

0 comments on commit d23e549

Please sign in to comment.