Skip to content

Commit e7ee24a

Browse files
authored
test(examples-chat): aimock regenerate scenario (#336)
Sends a prompt, waits for the assistant turn to finalize, clicks Regenerate response, asserts conversation count stays at 1 user / 1 assistant after the regenerated turn finalizes. Reuses the existing 'say hi briefly' fixture — aimock returns the same response on the regenerated call and the in-place replacement invariant is what we assert against.
1 parent b35b31b commit e7ee24a

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: MIT
2+
import { test, expect } from '@playwright/test';
3+
import { sendPromptAndWait } from './test-helpers';
4+
5+
test('regenerate: re-running keeps 1 user / 1 assistant in the conversation', async ({
6+
page,
7+
}) => {
8+
// Reuse the smoke 'say hi briefly' fixture — aimock returns the same
9+
// response on regenerate; the invariant we care about is the count.
10+
await sendPromptAndWait(page, 'say hi briefly');
11+
12+
const userMessages = page.locator('chat-message[data-role="user"]');
13+
const assistantMessages = page.locator('chat-message[data-role="assistant"]');
14+
await expect(userMessages).toHaveCount(1);
15+
await expect(assistantMessages).toHaveCount(1);
16+
17+
// Click Regenerate on the assistant message (aria-label is the durable hook).
18+
await page.getByRole('button', { name: 'Regenerate response' }).first().click();
19+
20+
// Wait for the regenerated assistant turn to finalize (data-streaming flips
21+
// back to true then false). We can't reuse sendPromptAndWait here because
22+
// there's no fresh prompt to send — instead poll until exactly one
23+
// finalized assistant is present and the count holds at 1/1.
24+
await expect
25+
.poll(
26+
async () =>
27+
page
28+
.locator('chat-message[data-role="assistant"][data-streaming="false"]')
29+
.count(),
30+
{ timeout: 45_000 },
31+
)
32+
.toBeGreaterThan(0);
33+
34+
// Single-turn invariant: after regenerate, conversation stays at 1u/1a
35+
// (the assistant message is replaced in place, not appended).
36+
await expect(userMessages).toHaveCount(1);
37+
await expect(assistantMessages).toHaveCount(1);
38+
});

0 commit comments

Comments
 (0)