LibreChat/e2e/specs/mock/scenarios/content-handler-message-refs.spec.ts
Marco Beretta 2db8d91745
⚡ perf: Preserve Message References in the Content Handler (#16072)
* ⚡ perf: Preserve Message References in the Content Handler

* test: cover content handler message reconciliation

* fix: preserve thread metadata for incomplete content events

* fix: retain fallback response thread identity

* fix: select parent from response thread

* fix: retain untagged conversation messages

* fix: preserve history while resolving parent

* fix: refresh cached response metadata

* fix: honor synchronized parent metadata

* fix: scope parent fallback to response thread

* fix: avoid cross-thread parent fallback

* fix: keep content handler selection semantics
2026-09-20 19:27:36 -04:00

55 lines
1.9 KiB
TypeScript

import { expect, test } from '@playwright/test';
import {
MOCK_ENDPOINTS,
NEW_CHAT_PATH,
messagesView,
replyPrompt,
replyText,
selectMockEndpoint,
sendMessageAndWaitForCompletion,
} from '../helpers';
const ORDERED_PIECE_COUNT = 64;
const orderedReplyPieces = Array.from(
{ length: ORDERED_PIECE_COUNT },
(_, index) => `piece-${String(index).padStart(3, '0')}`,
);
test.describe('content handler message reconciliation', () => {
test('keeps streamed replies ordered and visible after a follow-up turn and reload @scenario:streamed-replies-render-in-order-and-survive-reload', async ({
page,
}) => {
test.setTimeout(60_000);
const label = `content-handler-${Date.now()}`;
const orderedPrompt = `E2E_ORDERED_REPLY:${label}`;
const orderedReply = `E2E ordered reply ${label} ${orderedReplyPieces.join(' ')}`;
await page.goto(NEW_CHAT_PATH, { timeout: 10_000 });
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
const firstResponse = await sendMessageAndWaitForCompletion(page, orderedPrompt);
expect(firstResponse.ok()).toBeTruthy();
const messageRows = messagesView(page).locator('.message-render');
await expect(messageRows.last().locator('.message-content')).toHaveText(orderedReply, {
timeout: 30_000,
});
const secondResponse = await sendMessageAndWaitForCompletion(page, replyPrompt(label));
expect(secondResponse.ok()).toBeTruthy();
await expect(messageRows.last().locator('.message-content')).toHaveText(replyText(label), {
timeout: 30_000,
});
await expect(messageRows).toHaveCount(4);
await page.reload({ timeout: 10_000 });
await expect(messageRows).toHaveCount(4, { timeout: 30_000 });
await expect(messageRows.nth(1).locator('.message-content')).toHaveText(orderedReply, {
timeout: 30_000,
});
await expect(messageRows.last().locator('.message-content')).toHaveText(replyText(label), {
timeout: 30_000,
});
});
});