Skip to content

Commit

Permalink
test: adapt backend unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Martin <phmartin@redhat.com>
  • Loading branch information
feloy committed Mar 21, 2024
1 parent f1aa903 commit b954c4d
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions packages/backend/src/managers/playgroundV2Manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ test('submit should throw an error if the server is stopped', async () => {
} as unknown as InferenceServer,
]);

await expect(manager.submit('0', 'dummyUserInput', '')).rejects.toThrowError('Inference server is not running.');
await expect(manager.submit('0', 'dummyUserInput', false)).rejects.toThrowError('Inference server is not running.');
});

test('submit should throw an error if the server is unhealthy', async () => {
Expand All @@ -109,7 +109,7 @@ test('submit should throw an error if the server is unhealthy', async () => {
const manager = new PlaygroundV2Manager(webviewMock, inferenceManagerMock, taskRegistryMock);
await manager.createPlayground('p1', { id: 'model1' } as ModelInfo, 'tracking-1');
const playgroundId = manager.getPlaygrounds()[0].id;
await expect(manager.submit(playgroundId, 'dummyUserInput', '')).rejects.toThrowError(
await expect(manager.submit(playgroundId, 'dummyUserInput', false)).rejects.toThrowError(
'Inference server is not healthy, currently status: unhealthy.',
);
});
Expand Down Expand Up @@ -175,7 +175,7 @@ test('valid submit should create IPlaygroundMessage and notify the webview', asy
vi.setSystemTime(date);

const playgrounds = manager.getPlaygrounds();
await manager.submit(playgrounds[0].id, 'dummyUserInput', '');
await manager.submit(playgrounds[0].id, 'dummyUserInput', false);

// Wait for assistant message to be completed
await vi.waitFor(() => {
Expand Down Expand Up @@ -208,9 +208,9 @@ test('valid submit should create IPlaygroundMessage and notify the webview', asy
});
});

test.each(['', 'my system prompt'])(
test.each([true, false])(
'valid submit should send a message with system prompt if non empty, system prompt is "%s"}',
async (systemPrompt: string) => {
async (systemPrompt: boolean) => {
vi.mocked(inferenceManagerMock.getServers).mockReturnValue([
{
status: 'running',
Expand Down Expand Up @@ -249,21 +249,17 @@ test.each(['', 'my system prompt'])(
{
content: 'dummyUserInput',
id: expect.any(String),
role: 'user',
role: systemPrompt ? 'system' : 'user',
timestamp: expect.any(Number),
},
];
if (systemPrompt) {
messages.push({
content: 'my system prompt',
role: 'system',
if (!systemPrompt) {
expect(createMock).toHaveBeenCalledWith({
messages,
model: 'dummyModelFile',
stream: true,
});
}
expect(createMock).toHaveBeenCalledWith({
messages,
model: 'dummyModelFile',
stream: true,
});
},
);

Expand Down Expand Up @@ -300,7 +296,11 @@ test('submit should send options', async () => {
await manager.createPlayground('playground 1', { id: 'dummyModelId' } as ModelInfo, 'tracking-1');

const playgrounds = manager.getPlaygrounds();
await manager.submit(playgrounds[0].id, 'dummyUserInput', '', { temperature: 0.123, max_tokens: 45, top_p: 0.345 });
await manager.submit(playgrounds[0].id, 'dummyUserInput', false, {
temperature: 0.123,
max_tokens: 45,
top_p: 0.345,
});

const messages: unknown[] = [
{
Expand Down

0 comments on commit b954c4d

Please sign in to comment.