mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
A route handler that calls `route.fetch()` can still be running when its test returns. Closing the browser context disposes the fetched response, the handler throws `Response has been disposed`, and Playwright reports that against a test whose assertions had all passed. With `failOnFlakyTests` on, that fails the shard.
Specs that answer requests through `route.fetch()` now take `test` from `e2e/specs/mock/fixtures.ts`. Its `context` fixture detaches the routes on the context and its pages with `unrouteAll({ behavior: 'ignoreErrors' })` before Playwright closes it; contexts a spec opens itself close through `closeContext`.
`ignoreErrors` rather than `wait`: a wait never ends for a handler parked on a promise the test leaves unsettled, and with two handlers in flight Playwright stops intercepting when the first finishes and continues the other request itself, so the second handler's `route.fulfill()` throws `Route is already handled!`.
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { NEW_CHAT_PATH } from '../helpers';
|
|
import { expect, test } from '../fixtures';
|
|
|
|
/**
|
|
* A token refresh that never answers must not freeze the app: the deadline published in the
|
|
* startup config (`clientLimits.refreshMs`, kept from the previous load) expires and the visitor lands on the sign-in page.
|
|
*/
|
|
test('a hung token refresh sends the visitor to login after the configured deadline @scenario:client-refresh-timeout', async ({
|
|
page,
|
|
}) => {
|
|
await page.route(
|
|
(url) => url.pathname === '/api/config',
|
|
async (route) => {
|
|
const response = await route.fetch();
|
|
const body = await response.json();
|
|
await route.fulfill({ response, json: { ...body, clientLimits: { refreshMs: 1500 } } });
|
|
},
|
|
);
|
|
let hangRefresh = false;
|
|
await page.route(
|
|
(url) => url.pathname === '/api/auth/refresh',
|
|
(route) => (hangRefresh ? new Promise<void>(() => undefined) : route.continue()),
|
|
);
|
|
|
|
/** The first load publishes the deadline; the next load's refresh starts with it already known. */
|
|
await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
|
|
await page.waitForFunction(() => localStorage.getItem('librechat:clientLimits') != null, null, {
|
|
timeout: 15000,
|
|
});
|
|
hangRefresh = true;
|
|
await page.goto(NEW_CHAT_PATH, { timeout: 15000, waitUntil: 'commit' });
|
|
|
|
await expect(page).toHaveURL(/\/login/, { timeout: 15000 });
|
|
await expect(page.getByTestId('login-button')).toBeVisible();
|
|
});
|