From 8e9d0cf6196512a54cea978f30d6c1bfe8595f6a Mon Sep 17 00:00:00 2001 From: Boki Date: Tue, 27 Oct 2026 12:34:00 -0400 Subject: [PATCH] test(web): return WebSocket upgrades synchronously --- test/e2e/fixture.ts | 81 +++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/test/e2e/fixture.ts b/test/e2e/fixture.ts index b88659d8..dde36ac6 100644 --- a/test/e2e/fixture.ts +++ b/test/e2e/fixture.ts @@ -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) {