feat: support resuming ongoing streams (#974)
This commit is contained in:
parent
45978c27a2
commit
a3221fbcdc
13 changed files with 1005 additions and 47 deletions
|
|
@ -80,4 +80,158 @@ test.describe
|
|||
const deletedChat = await response.json();
|
||||
expect(deletedChat).toMatchObject({ id: chatId });
|
||||
});
|
||||
|
||||
test('Ada cannot resume stream of chat that does not exist', async ({
|
||||
adaContext,
|
||||
}) => {
|
||||
const response = await adaContext.request.get(
|
||||
`/api/chat?chatId=${generateUUID()}`,
|
||||
);
|
||||
expect(response.status()).toBe(404);
|
||||
});
|
||||
|
||||
test('Ada can resume chat generation', async ({ adaContext }) => {
|
||||
const chatId = generateUUID();
|
||||
|
||||
const firstRequest = adaContext.request.post('/api/chat', {
|
||||
data: {
|
||||
id: chatId,
|
||||
message: {
|
||||
id: generateUUID(),
|
||||
role: 'user',
|
||||
content: 'Help me write an essay about Silcon Valley',
|
||||
parts: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Help me write an essay about Silicon Valley',
|
||||
},
|
||||
],
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
selectedChatModel: 'chat-model',
|
||||
},
|
||||
});
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
const secondRequest = adaContext.request.get(
|
||||
`/api/chat?chatId=${chatId}`,
|
||||
);
|
||||
|
||||
const [firstResponse, secondResponse] = await Promise.all([
|
||||
firstRequest,
|
||||
secondRequest,
|
||||
]);
|
||||
|
||||
const [firstStatusCode, secondStatusCode] = await Promise.all([
|
||||
firstResponse.status(),
|
||||
secondResponse.status(),
|
||||
]);
|
||||
|
||||
expect(firstStatusCode).toBe(200);
|
||||
expect(secondStatusCode).toBe(200);
|
||||
|
||||
const [firstResponseBody, secondResponseBody] = await Promise.all([
|
||||
await firstResponse.body(),
|
||||
await secondResponse.body(),
|
||||
]);
|
||||
|
||||
expect(firstResponseBody.toString()).toEqual(
|
||||
secondResponseBody.toString(),
|
||||
);
|
||||
});
|
||||
|
||||
test('Ada cannot resume chat generation that has ended', async ({
|
||||
adaContext,
|
||||
}) => {
|
||||
const chatId = generateUUID();
|
||||
|
||||
const firstRequest = await adaContext.request.post('/api/chat', {
|
||||
data: {
|
||||
id: chatId,
|
||||
message: {
|
||||
id: generateUUID(),
|
||||
role: 'user',
|
||||
content: 'Help me write an essay about Silcon Valley',
|
||||
parts: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Help me write an essay about Silicon Valley',
|
||||
},
|
||||
],
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
selectedChatModel: 'chat-model',
|
||||
},
|
||||
});
|
||||
|
||||
const secondRequest = adaContext.request.get(
|
||||
`/api/chat?chatId=${chatId}`,
|
||||
);
|
||||
|
||||
const [firstResponse, secondResponse] = await Promise.all([
|
||||
firstRequest,
|
||||
secondRequest,
|
||||
]);
|
||||
|
||||
const [firstStatusCode, secondStatusCode] = await Promise.all([
|
||||
firstResponse.status(),
|
||||
secondResponse.status(),
|
||||
]);
|
||||
|
||||
expect(firstStatusCode).toBe(200);
|
||||
expect(secondStatusCode).toBe(200);
|
||||
|
||||
const [, secondResponseContent] = await Promise.all([
|
||||
firstResponse.text(),
|
||||
secondResponse.text(),
|
||||
]);
|
||||
|
||||
expect(secondResponseContent).toEqual('');
|
||||
});
|
||||
|
||||
test('Babbage cannot resume chat generation that belongs to Ada', async ({
|
||||
adaContext,
|
||||
babbageContext,
|
||||
}) => {
|
||||
const chatId = generateUUID();
|
||||
|
||||
const firstRequest = adaContext.request.post('/api/chat', {
|
||||
data: {
|
||||
id: chatId,
|
||||
message: {
|
||||
id: generateUUID(),
|
||||
role: 'user',
|
||||
content: 'Help me write an essay about Silcon Valley',
|
||||
parts: [
|
||||
{
|
||||
type: 'text',
|
||||
text: 'Help me write an essay about Silicon Valley',
|
||||
},
|
||||
],
|
||||
createdAt: new Date().toISOString(),
|
||||
},
|
||||
selectedChatModel: 'chat-model',
|
||||
},
|
||||
});
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
const secondRequest = babbageContext.request.get(
|
||||
`/api/chat?chatId=${chatId}`,
|
||||
);
|
||||
|
||||
const [firstResponse, secondResponse] = await Promise.all([
|
||||
firstRequest,
|
||||
secondRequest,
|
||||
]);
|
||||
|
||||
const [firstStatusCode, secondStatusCode] = await Promise.all([
|
||||
firstResponse.status(),
|
||||
secondResponse.status(),
|
||||
]);
|
||||
|
||||
expect(firstStatusCode).toBe(200);
|
||||
expect(secondStatusCode).toBe(403);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue