From b388e9725ed5357bbd51b9c1c4e8830995defb6b Mon Sep 17 00:00:00 2001 From: Brian Love Date: Fri, 15 May 2026 12:57:06 -0700 Subject: [PATCH] test(examples-chat): aimock regenerate scenario MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- examples/chat/aimock-e2e/regenerate.spec.ts | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/chat/aimock-e2e/regenerate.spec.ts diff --git a/examples/chat/aimock-e2e/regenerate.spec.ts b/examples/chat/aimock-e2e/regenerate.spec.ts new file mode 100644 index 000000000..73348cc3e --- /dev/null +++ b/examples/chat/aimock-e2e/regenerate.spec.ts @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT +import { test, expect } from '@playwright/test'; +import { sendPromptAndWait } from './test-helpers'; + +test('regenerate: re-running keeps 1 user / 1 assistant in the conversation', async ({ + page, +}) => { + // Reuse the smoke 'say hi briefly' fixture — aimock returns the same + // response on regenerate; the invariant we care about is the count. + await sendPromptAndWait(page, 'say hi briefly'); + + const userMessages = page.locator('chat-message[data-role="user"]'); + const assistantMessages = page.locator('chat-message[data-role="assistant"]'); + await expect(userMessages).toHaveCount(1); + await expect(assistantMessages).toHaveCount(1); + + // Click Regenerate on the assistant message (aria-label is the durable hook). + await page.getByRole('button', { name: 'Regenerate response' }).first().click(); + + // Wait for the regenerated assistant turn to finalize (data-streaming flips + // back to true then false). We can't reuse sendPromptAndWait here because + // there's no fresh prompt to send — instead poll until exactly one + // finalized assistant is present and the count holds at 1/1. + await expect + .poll( + async () => + page + .locator('chat-message[data-role="assistant"][data-streaming="false"]') + .count(), + { timeout: 45_000 }, + ) + .toBeGreaterThan(0); + + // Single-turn invariant: after regenerate, conversation stays at 1u/1a + // (the assistant message is replaced in place, not appended). + await expect(userMessages).toHaveCount(1); + await expect(assistantMessages).toHaveCount(1); +});