test(web): return WebSocket upgrades synchronously
This commit is contained in:
parent
dd1545b9f8
commit
8e9d0cf619
1 changed files with 42 additions and 39 deletions
|
|
@ -426,52 +426,55 @@ export async function fixture(browser: Browser, native = false) {
|
|||
hostname: '127.0.0.1',
|
||||
port: 0,
|
||||
maxRequestBodySize: WEB_API_MAX_REQUEST_BODY_SIZE,
|
||||
async fetch(request, server) {
|
||||
fetch(request, server) {
|
||||
const pathname = new URL(request.url).pathname;
|
||||
if (pathname === '/ws' && request.headers.get('upgrade') === 'websocket') {
|
||||
// Return upgrades directly; only the ordinary HTTP path needs asynchronous work.
|
||||
return wsRoute(request, server);
|
||||
}
|
||||
if (pathname.startsWith('/api/')) {
|
||||
if (
|
||||
(!pathname.startsWith('/api/v2/backtests') &&
|
||||
!pathname.startsWith('/api/v2/runs') &&
|
||||
!pathname.startsWith('/api/v2/datasets') &&
|
||||
!pathname.startsWith('/api/v2/strategies') &&
|
||||
!pathname.startsWith('/api/v2/strategy-versions') &&
|
||||
!pathname.startsWith('/api/v2/research-projects') &&
|
||||
!pathname.startsWith('/api/v2/research-agents') &&
|
||||
!pathname.startsWith('/api/v2/research-agent/') &&
|
||||
!pathname.startsWith('/api/v2/experiments') &&
|
||||
!pathname.startsWith('/api/v2/paper-deployments') &&
|
||||
!pathname.startsWith('/api/v2/hypotheses/') &&
|
||||
!pathname.startsWith('/api/v2/analysis-artifacts/') &&
|
||||
pathname !== '/api/auth/session') ||
|
||||
/\/(pause|resume|speed)$/.test(pathname)
|
||||
) {
|
||||
unexpectedNetwork.push(pathname);
|
||||
return new Response('Endpoint outside browser fixture scope', { status: 403 });
|
||||
return (async () => {
|
||||
if (pathname.startsWith('/api/')) {
|
||||
if (
|
||||
(!pathname.startsWith('/api/v2/backtests') &&
|
||||
!pathname.startsWith('/api/v2/runs') &&
|
||||
!pathname.startsWith('/api/v2/datasets') &&
|
||||
!pathname.startsWith('/api/v2/strategies') &&
|
||||
!pathname.startsWith('/api/v2/strategy-versions') &&
|
||||
!pathname.startsWith('/api/v2/research-projects') &&
|
||||
!pathname.startsWith('/api/v2/research-agents') &&
|
||||
!pathname.startsWith('/api/v2/research-agent/') &&
|
||||
!pathname.startsWith('/api/v2/experiments') &&
|
||||
!pathname.startsWith('/api/v2/paper-deployments') &&
|
||||
!pathname.startsWith('/api/v2/hypotheses/') &&
|
||||
!pathname.startsWith('/api/v2/analysis-artifacts/') &&
|
||||
pathname !== '/api/auth/session') ||
|
||||
/\/(pause|resume|speed)$/.test(pathname)
|
||||
) {
|
||||
unexpectedNetwork.push(pathname);
|
||||
return new Response('Endpoint outside browser fixture scope', { status: 403 });
|
||||
}
|
||||
const response = await routes.fetch(request);
|
||||
const delay = responseDelay;
|
||||
if (delay?.path === pathname) {
|
||||
responseDelay = undefined; // Only the selected read, not run-list metric reads.
|
||||
delay.captured.resolve();
|
||||
await delay.release.promise;
|
||||
delay.delivered.resolve();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
const response = await routes.fetch(request);
|
||||
const delay = responseDelay;
|
||||
if (delay?.path === pathname) {
|
||||
responseDelay = undefined; // Only the selected read, not run-list metric reads.
|
||||
delay.captured.resolve();
|
||||
await delay.release.promise;
|
||||
delay.delivered.resolve();
|
||||
if (pathname.startsWith('/assets/') && !pathname.includes('..')) {
|
||||
const file = Bun.file(
|
||||
new URL(`../../apps/stock/web-app/dist${pathname}`, import.meta.url)
|
||||
);
|
||||
return (await file.exists())
|
||||
? new Response(file)
|
||||
: new Response('Not found', { status: 404 });
|
||||
}
|
||||
return response;
|
||||
}
|
||||
if (pathname.startsWith('/assets/') && !pathname.includes('..')) {
|
||||
const file = Bun.file(
|
||||
new URL(`../../apps/stock/web-app/dist${pathname}`, import.meta.url)
|
||||
return new Response(
|
||||
Bun.file(new URL('../../apps/stock/web-app/dist/index.html', import.meta.url))
|
||||
);
|
||||
return (await file.exists())
|
||||
? new Response(file)
|
||||
: new Response('Not found', { status: 404 });
|
||||
}
|
||||
return new Response(
|
||||
Bun.file(new URL('../../apps/stock/web-app/dist/index.html', import.meta.url))
|
||||
);
|
||||
})();
|
||||
},
|
||||
websocket: {
|
||||
open(socket) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue