Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🧻 fix: Keep Lighthouse Session Cookies Out of Failure Logs (#17410)
lia-by-librechat[bot]21f9bb57c616
diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.ymlindex a7e7c638a9..b0bc9ef1ec 100644--- a/.github/workflows/lighthouse.yml+++ b/.github/workflows/lighthouse.yml@@ -27,16 +27,25 @@ jobs:runs-on: ubuntu-latesttimeout-minutes: 20env:- E2E_CHROMIUM_CHANNEL: chrome+ E2E_CHROMIUM_CHANNEL: chromium+ LIGHTHOUSE_CHROME_FLAGS: --no-sandboxsteps:- uses: actions/checkout@v5- uses: actions/setup-node@v5with:node-version: '24.22.1'cache: npm+ - name: Test Lighthouse failure reporting+ run: node --test e2e/lighthouse.test.mts- run: npm ci+ - name: Install lockfile-pinned Chromium+ run: npx playwright install --with-deps --no-shell chromium+ - name: Select Lighthouse browser+ run: |+ chrome=$(node -p "require('@playwright/test').chromium.executablePath()")+ "$chrome" --version+ echo "CHROME_PATH=$chrome" >> "$GITHUB_ENV"- run: npm run e2e:prepare- - run: google-chrome --version- name: Audit serial database latencyid: auditshell: bashdiff --git a/e2e/lighthouse.test.mts b/e2e/lighthouse.test.mtsnew file mode 100644index 0000000000..8c4f55a3fc--- /dev/null+++ b/e2e/lighthouse.test.mts@@ -0,0 +1,67 @@+import path from 'node:path';+import { test } from 'node:test';+import { tmpdir } from 'node:os';+import { inspect } from 'node:util';+import assert from 'node:assert/strict';+import { mkdtemp, writeFile, readFile, rm } from 'node:fs/promises';++import { runLighthouse } from './lighthouse/process.mts';++for (const [failures, diagnostic, stderr] of [+ [0, 'NO_NAVSTART', 'Runtime error encountered: Trace failed (NO_NAVSTART)'],+ [1, 'NO_NAVSTART', 'Runtime error encountered: Trace failed (NO_NAVSTART)'],+ [2, 'NO_NAVSTART', 'Runtime error encountered: Trace failed (NO_NAVSTART)'],+ [2, 'CHROME_CONNECTION_FAILED', 'Unable to connect to Chrome'],+ [2, 'CHROME_PROTOCOL_TIMEOUT', 'Debugger protocol timed out while connecting to Chrome.'],+] as const) {+ test(`Lighthouse reports ${failures} ${diagnostic} attempts without disclosing child payloads`, async (t) => {+ const directory = await mkdtemp(path.join(tmpdir(), 'lighthouse-process-'));+ t.after(() => rm(directory, { recursive: true, force: true }));+ const cli = path.join(directory, 'cli.cjs');+ const counter = path.join(directory, 'attempts');+ const secret = 'disposable-session-cookie-sentinel';+ const url = 'https://example.test/c/private-conversation';+ await writeFile(+ cli,+ `+ const fs = require('node:fs');+ const counter = ${JSON.stringify(counter)};+ const attempt = fs.existsSync(counter) ? Number(fs.readFileSync(counter, 'utf8')) + 1 : 1;+ fs.writeFileSync(counter, String(attempt));+ console.log(${JSON.stringify(secret)});+ console.error(process.argv.join(' '));+ console.error(${JSON.stringify(stderr)});+ process.exit(attempt <= ${failures} ? 1 : 0);+ `,+ );+ const logs: string[] = [];+ t.mock.method(console, 'log', (message: string) => logs.push(message));+ const running = runLighthouse({+ cli,+ flags: [url, `--extra-headers=${JSON.stringify({ Cookie: `refreshToken=${secret}` })}`],+ output: path.join(directory, 'lhr-1'),+ run: 1,+ runs: 3,+ });+ if (failures === 2) {+ await assert.rejects(running, (error: Error) => {+ assert.equal(error.message, `Lighthouse process failed (exit 1, ${diagnostic}).`);+ assert.deepEqual(Object.getOwnPropertyNames(error), ['stack', 'message']);+ assert.ok(!inspect(error).includes(secret));+ assert.ok(!inspect(error).includes(url));+ return true;+ });+ } else {+ await running;+ assert.ok(logs.some((line) => line.endsWith('lhr-1.report.json')));+ }+ assert.equal(Number(await readFile(counter, 'utf8')), Math.min(failures + 1, 2));+ assert.equal(logs.filter((line) => line.includes('retrying')).length, failures === 0 ? 0 : 1);+ for (const line of logs) {+ assert.ok(!line.includes(secret));+ assert.ok(!line.includes(url));+ assert.ok(!line.includes('--extra-headers'));+ assert.ok(!line.includes('Command failed'));+ }+ });+}diff --git a/e2e/lighthouse/audit.ts b/e2e/lighthouse/audit.tsindex 3bf8ad25fb..28f6b3cbff 100644--- a/e2e/lighthouse/audit.ts+++ b/e2e/lighthouse/audit.ts@@ -1,12 +1,10 @@import fs from 'node:fs';import path from 'node:path';-import { promisify } from 'node:util';-import { execFile } from 'node:child_process';import { expect } from '@playwright/test';import type Result from 'lighthouse/types/lhr/lhr';import type { Cookie } from '@playwright/test';-const exec = promisify(execFile);+import { runLighthouse } from './process.mts';/** Median budgets keyed by Lighthouse audit id. */export type MedianBudgets = Record<string, number>;@@ -15,9 +13,6 @@ const REPORTS_DIRECTORY = '.lighthouse';const DEFAULT_RUNS = 3;-/** Attempts per run before a crashed Lighthouse process fails the audit. */-const RUN_ATTEMPTS = 2;-const DEFAULT_BUDGETS: MedianBudgets = {'largest-contentful-paint': 4500,'cumulative-layout-shift': 0.1,@@ -82,34 +77,7 @@ export async function auditPage({try {for (let run = 1; run <= runs; run++) {const output = path.join(directory, `lhr-${run}`);- for (let attempt = 1; ; attempt++) {- try {- const { stdout } = await exec(process.execPath, [- cli,- ...flags,- `--output-path=${output}`,- ]);- console.log(`Lighthouse run ${run}/${runs} wrote ${output}.report.json`);- if (stdout.trim()) {- console.log(stdout);- }- break;- } catch (error) {- if (attempt >= RUN_ATTEMPTS) {- throw error;- }- /** Lighthouse crashes out of a run it could not trace — NO_NAVSTART is- * the usual one, and its own message is "run Lighthouse again". The- * page is measured `runs` times for exactly this noise, so one lost- * process should cost a repeat, not the lane. A page that is really- * broken fails every attempt and still fails here. */- console.log(- `Lighthouse run ${run}/${runs} attempt ${attempt} did not complete, retrying: ${- error instanceof Error ? error.message.split('\n')[0] : String(error)- }`,- );- }- }+ await runLighthouse({ cli, flags, output, run, runs });}} finally {// Lighthouse embeds extraHeaders in reports; keep disposable session cookies out of artifacts.diff --git a/e2e/lighthouse/process.mts b/e2e/lighthouse/process.mtsnew file mode 100644index 0000000000..51e132ba09--- /dev/null+++ b/e2e/lighthouse/process.mts@@ -0,0 +1,63 @@+import { promisify } from 'node:util';+import { execFile } from 'node:child_process';++const exec = promisify(execFile);+const RUN_ATTEMPTS = 2;++function failureMessage(error: unknown): string {+ const details: string[] = [];+ if (error && typeof error === 'object') {+ if (+ 'code' in error &&+ typeof error.code === 'number' &&+ Number.isInteger(error.code) &&+ error.code >= 0 &&+ error.code <= 255+ ) {+ details.push(`exit ${error.code}`);+ }+ if ('stderr' in error && typeof error.stderr === 'string') {+ if (error.stderr.includes('(NO_NAVSTART)')) {+ details.push('NO_NAVSTART');+ }+ if (error.stderr.includes('Unable to connect to Chrome')) {+ details.push('CHROME_CONNECTION_FAILED');+ }+ if (error.stderr.includes('Debugger protocol timed out while connecting to Chrome.')) {+ details.push('CHROME_PROTOCOL_TIMEOUT');+ }+ }+ }+ return `Lighthouse process failed${details.length ? ` (${details.join(', ')})` : ''}.`;+}++export async function runLighthouse({+ cli,+ flags,+ output,+ run,+ runs,+}: {+ cli: string;+ flags: string[];+ output: string;+ run: number;+ runs: number;+}): Promise<void> {+ for (let attempt = 1; ; attempt++) {+ try {+ await exec(process.execPath, [cli, ...flags, `--output-path=${output}`]);+ console.log(`Lighthouse run ${run}/${runs} wrote ${output}.report.json`);+ return;+ } catch (error) {+ // Child errors embed CLI arguments, stdout and stderr, including session cookies.+ const message = failureMessage(error);+ if (attempt >= RUN_ATTEMPTS) {+ throw new Error(message);+ }+ console.log(+ `Lighthouse run ${run}/${runs} attempt ${attempt} did not complete, retrying: ${message}`,+ );+ }+ }+}