LibreChat/e2e/specs/mock/scenarios/highlight-throttle.spec.ts
lia-by-librechat[bot] b4afbb3a1e
🛝 perf: Render Chats Independently of Catalog Discovery (#17692)
* 🛝 perf: Render Chats Independently of Catalog Discovery

* Preserve Target Authorization and Passive Startup Intent

* Keep Startup Selection, Readiness, and Catalog Keys Consistent

* Preserve Remembered Targets and Validate Scoped Presets

* Retain Remembered Assistant Resource Aliases Across Endpoint Switches

* Apply URL Targets Before Waiting for Send Readiness

* Fix First-Page Agent Discovery and Await Model Selection

* Preserve Spec Access and Refresh Selected Assistant State

* Preserve Builder Deletion State and Start History Reads Earlier

* fix: Preserve Startup Recovery and History Read Ownership

* fix: Retain Express Query Routing in Assistant Lookups

* fix: Prioritize Route Reads and Recover Credential Changes

* fix: Bind Credential Revocation to Its Requested Scope

* fix: Refresh Credential Metadata After Pending Key Reads

* fix: Revalidate Inactive Credential Metadata on Target Mount

* fix: Preserve Reviewed Chat Resolutions After Rebase

* fix: Resolve Dev Conflicts and Preserve Startup Boundaries

* test: Preserve the ChatView Slot Target Boundary

* fix: Defer Terminal Delivery Until Subscription Attachment Completes

* fix: Contain Deferred Terminal Callback Failures

* test: Classify Historical Tool Name Capability Reads

* fix: Activate Requested Catalogs and Isolate Provider Failures

* fix: Keep Healthy Provider Choices Available During Catalog Recovery

* test: Exclude Copied Trace Bundles From Dependency Comparison

---------

Co-authored-by: Lia <lia@librechat.ai>
2026-11-09 11:11:22 -05:00

166 lines
6.7 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { DEFAULT_CODE_HIGHLIGHT_THROTTLE_MS } from 'librechat-data-provider';
import {
enableCodeInterpreter,
isAgentsStream,
messagesView,
MOCK_ENDPOINTS,
NEW_CHAT_PATH,
selectMockEndpoint,
sendMessage,
} from '../helpers';
const stopButton = (page: Parameters<typeof sendMessage>[0]) =>
page.getByRole('button', { name: 'Stop generating' });
const highlightedCode = (page: Parameters<typeof sendMessage>[0]) =>
messagesView(page).locator('code.hljs.language-bash').last();
/** The card's disclosure, which `ProgressText` owns. It carries an
* `aria-expanded` state only once the card has input to show, so waiting on
* this locator also waits for the first streamed argument chunk. */
const codeDisclosure = (page: Parameters<typeof sendMessage>[0]) =>
messagesView(page).locator('.progress-text-wrapper button[aria-expanded]').last();
async function openHighlightChat(page: Parameters<typeof sendMessage>[0]) {
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
await selectMockEndpoint(page, MOCK_ENDPOINTS[1]);
await enableCodeInterpreter(page);
}
/** Idempotent, because `autoExpandTools` opens the pane for an operator who
* turned it on; the default is off, so these runs do the opening themselves. */
async function openCodePane(page: Parameters<typeof sendMessage>[0]) {
const disclosure = codeDisclosure(page);
await expect(disclosure).toBeVisible({ timeout: 30000 });
if ((await disclosure.getAttribute('aria-expanded')) === 'false') {
await disclosure.click();
}
await expect(disclosure).toHaveAttribute('aria-expanded', 'true');
}
/**
* Opens the card, then waits for tokens.
*
* A closed pane is passed no code at all, so it tokenizes nothing and renders
* its raw text: opening the card is part of asserting anything about
* highlighting, and a scenario that skipped it would wait out its timeout
* against unhighlighted output no matter how the throttle behaved. Opening it
* while arguments are still streaming is also what puts the throttle under
* test, because that is the only time the input keeps changing.
*/
async function expectHighlightedCode(
page: Parameters<typeof sendMessage>[0],
expectedText: string | RegExp = 'line-119-☃',
) {
const code = highlightedCode(page);
/** History can replace highlighted live code with a collapsed preview. Retry
* opening, full text and tokens together so the replacement also hydrates. */
await expect(async () => {
await openCodePane(page);
await expect(code).toBeVisible();
const snapshot = await code.evaluate((element) => ({
text: element.textContent ?? '',
tokens: element.querySelectorAll('span').length,
}));
expect(snapshot.text).toMatch(expectedText);
expect(snapshot.tokens).toBeGreaterThan(0);
}).toPass({ timeout: 30000 });
}
/** The cadence `e2e/config/librechat.e2e.yaml` sets, off the schema default. */
const CONFIGURED_THROTTLE_MS = 250;
test.describe('streamed code highlighting', () => {
test('configured-highlight-cadence-reaches-client @scenario:configured-highlight-cadence-reaches-client', async ({
page,
}) => {
expect(CONFIGURED_THROTTLE_MS).not.toBe(DEFAULT_CODE_HIGHLIGHT_THROTTLE_MS);
/** The signed-in payload: the pre-login one carries only the fields a login page needs. */
const config = page.waitForResponse(
(response) =>
new URL(response.url()).pathname === '/api/config' &&
response.ok() &&
Boolean(response.request().headers()['authorization']),
{ timeout: 30000 },
);
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
const body = (await (await config).json()) as {
interface?: { codeHighlightThrottleMs?: number };
};
expect(body.interface?.codeHighlightThrottleMs).toBe(CONFIGURED_THROTTLE_MS);
});
test('streamed-code-highlights-after-settle @scenario:streamed-code-highlights-after-settle', async ({
page,
}) => {
test.setTimeout(120000);
await openHighlightChat(page);
await sendMessage(page, 'E2E_HIGHLIGHT_CODE:stream');
await expect(stopButton(page)).toBeVisible({ timeout: 30000 });
await expectHighlightedCode(page);
await expect(stopButton(page)).toBeHidden({ timeout: 120000 });
/** Persisting the streamed message rebuilds the card, and a rebuilt card
* starts closed, so the settled value is asserted through the same
* open-then-wait path instead of against the streaming card's tokens. */
await expectHighlightedCode(page);
});
test('interrupted-code-highlights-after-cancel @scenario:interrupted-code-highlights-after-cancel', async ({
page,
}) => {
test.setTimeout(120000);
await openHighlightChat(page);
await sendMessage(page, 'E2E_HIGHLIGHT_CODE:cancel');
await expect(stopButton(page)).toBeVisible({ timeout: 30000 });
/** Open the card while the arguments are still arriving, but stop the run
* before waiting on any token: waiting for a highlight first can outlast
* the stream and leave nothing to cancel. */
await openCodePane(page);
await stopButton(page).click();
await expect(stopButton(page)).toBeHidden({ timeout: 30000 });
/** Cancellation persists the partial message, which rebuilds the card the
* same way a completed run does. */
await expectHighlightedCode(page, /line-\d+-☃/);
});
test('regenerated-code-highlights-latest-branch @scenario:regenerated-code-highlights-latest-branch', async ({
page,
}) => {
test.setTimeout(180000);
await openHighlightChat(page);
await sendMessage(page, 'E2E_HIGHLIGHT_CODE:regenerate');
await expect(stopButton(page)).toBeHidden({ timeout: 120000 });
await expectHighlightedCode(page);
const assistant = messagesView(page).locator('.message-render').last();
await assistant.hover();
const regenerate = assistant.getByRole('button', { name: 'Regenerate', exact: true }).last();
await expect(regenerate).toBeVisible({ timeout: 30000 });
await Promise.all([
page.waitForResponse(isAgentsStream, { timeout: 30000 }),
regenerate.click(),
]);
await expect(stopButton(page)).toBeHidden({ timeout: 120000 });
await expectHighlightedCode(page);
});
test('restored-history-code-remains-highlighted @scenario:restored-history-code-remains-highlighted', async ({
page,
}) => {
test.setTimeout(180000);
await openHighlightChat(page);
await sendMessage(page, 'E2E_HIGHLIGHT_CODE:history');
await expect(stopButton(page)).toBeHidden({ timeout: 120000 });
await expectHighlightedCode(page);
const conversationUrl = page.url();
await page.reload({ timeout: 10000 });
await expect(page).toHaveURL(conversationUrl);
await expectHighlightedCode(page);
});
});