LibreChat/e2e/lighthouse/load.spec.ts
Danny Avila c883e9ef32
🔦 chore: Drop @lhci/cli and Run Lighthouse 13 Directly (#15687)
`@lhci/cli@0.15.1` pins `lighthouse` to an exact `12.6.1`, so the Lighthouse
lane could never move off a release whose `puppeteer-core` still depends on
`extract-zip` — an advisory with no patched version. That pin, not Lighthouse
itself, was holding 8 of the repository's 16 `npm audit` findings open.

LHCI was only ever a subprocess wrapper here: `audit.ts` shelled out to
`@lhci/cli/src/cli.js` for `collect` and `assert`, and LHCI's own node runner
shells out to `lighthouse/cli/index.js` in turn. Call that CLI directly, run
the three navigations in a loop, and assert the median budgets in TypeScript
next to the assertions `load.spec.ts` already makes.

- `npm audit`: 16 findings (7 high, 1 moderate, 8 low) -> 6 low. The remainder
  is the pre-existing `elliptic` chain under `vite-plugin-node-polyfills`,
  which has no fixed version and is unrelated to this lane.
- Lighthouse 13 removed `largest-contentful-paint-element` and moved the LCP
  node into `lcp-breakdown-insight`. Reading it through a `lcpElement` helper
  keeps the "the transcript must be the LCP element" guard working and makes
  the next rename fail loudly in one place.
- Reports move to `.lighthouse/` as `lhr-N.report.{json,html}`; cookie
  redaction, the API timing table and the desktop/provided-throttling settings
  are unchanged. Budgets are now printed as a table immediately before they are
  asserted, so the workflow's 80-line failure comment always contains them.
- `CHROME_PATH` and `LIGHTHOUSE_CHROME_FLAGS` are documented: chrome-launcher
  prefers the Windows Chrome under WSL, whose debugging port Linux cannot
  reach.
2026-09-06 23:20:22 -04:00

42 lines
1.9 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { seedConversations, seedMessages } from '../specs/mock/db';
import { getE2EUser } from '../setup/user';
import { auditPage, lcpElement } from './audit';
const conversationId = '16390000-0000-4000-8000-000000000001';
const title = 'Lighthouse latency audit';
const transcriptMarker = 'Serial database latency transcript';
test('serial database latency stays within web-vitals budgets', async ({ page, baseURL }) => {
const email = getE2EUser().email;
await seedConversations(email, [{ conversationId, title, updatedAt: new Date() }]);
await seedMessages(email, conversationId, [
{
messageId: '16390000-0000-4000-8000-000000000002',
parentMessageId: '00000000-0000-0000-0000-000000000000',
text: 'Explain why independent database reads should start together.',
isCreatedByUser: true,
sender: 'User',
},
{
messageId: '16390000-0000-4000-8000-000000000003',
parentMessageId: '16390000-0000-4000-8000-000000000002',
text: `${transcriptMarker}. Independent reads can overlap. Serial reads each add another database round trip and delay the visible conversation. Reuse loaded user data and preserve authorization checks when starting reads in parallel.`,
isCreatedByUser: false,
sender: 'Assistant',
},
]);
const url = `${baseURL}/c/${conversationId}`;
await page.goto(url);
await expect(page.locator('.message-render').filter({ hasText: transcriptMarker })).toBeVisible();
const cookies = await page.context().cookies();
const reports = await auditPage({ url, cookies });
expect(reports, 'Lighthouse must produce all three reports').toHaveLength(3);
for (const report of reports) {
expect(report.finalDisplayedUrl, 'Do not measure a login redirect').toBe(url);
expect(
lcpElement(report),
'The measured LCP must be the seeded transcript, not the shell or a spinner',
).toContain(transcriptMarker);
}
});