From 342d8436227e07ef7e529546ad8f45d5c07d52bd Mon Sep 17 00:00:00 2001 From: huanghuoguoguo <60681390+huanghuoguoguo@users.noreply.github.com> Date: Sat, 17 Oct 2026 04:08:51 +0000 Subject: [PATCH] test(web): replace source guards with browser behavior checks --- web/tests/e2e/login.spec.ts | 81 +++++++++++++++++++ .../unit/session-monitor-pagination.test.mjs | 15 ---- web/tests/unit/support-admin-session.test.mjs | 42 ---------- 3 files changed, 81 insertions(+), 57 deletions(-) delete mode 100644 web/tests/unit/support-admin-session.test.mjs diff --git a/web/tests/e2e/login.spec.ts b/web/tests/e2e/login.spec.ts index e60c78574..b2e3c964d 100644 --- a/web/tests/e2e/login.spec.ts +++ b/web/tests/e2e/login.spec.ts @@ -126,6 +126,87 @@ test('Space OAuth bootstraps a singleton before entering home', async ({ expect(selectedWorkspaceHeaders).toContain('workspace-playwright'); }); +test('support-admin launch keeps its Workspace scope without Account bootstrap', async ({ + page, +}) => { + const workspaceUuid = 'workspace-support-admin'; + const currentWorkspaceRequests: { + workspace?: string; + authorization?: string; + }[] = []; + let accountBootstrapRequests = 0; + page.on('request', (request) => { + if (new URL(request.url()).pathname === '/api/v1/workspaces/current') { + currentWorkspaceRequests.push({ + workspace: request.headers()['x-workspace-id'], + authorization: request.headers().authorization, + }); + } + }); + await installLangBotApiMocks(page, { + authenticated: true, + storage: { + langbot_active_workspace_uuid: 'workspace-from-another-account', + }, + workspaces: [makeWorkspaceEntry(workspaceUuid, 'Support Workspace')], + }); + await page.route('**/api/v1/user/space/callback', (route) => + route.fulfill({ + json: { + code: 0, + data: { + token: 'support-admin-token', + principal_type: 'support_admin', + workspace_uuid: workspaceUuid, + }, + }, + }), + ); + await page.route('**/api/v1/workspaces/bootstrap', (route) => { + accountBootstrapRequests += 1; + return route.fulfill({ status: 403, json: { code: 403 } }); + }); + await page.route('**/api/v1/system/info', (route) => + route.fulfill({ + json: { + code: 0, + data: { + edition: 'cloud', + cloud_service_url: 'https://space.langbot.app', + wizard_status: 'none', + limitation: { max_bots: -1, max_pipelines: -1, max_extensions: -1 }, + }, + }, + }), + ); + + await page.goto( + `/auth/space/callback#workspace_uuid=${workspaceUuid}&launch_assertion=support-launch`, + ); + + await expect(page).toHaveURL(/\/home(?:\/monitoring)?$/); + await expect(page.getByRole('button', { name: 'Dashboard' })).toBeVisible(); + expect(currentWorkspaceRequests.length).toBeGreaterThan(0); + for (const request of currentWorkspaceRequests) { + expect(request).toEqual({ + workspace: workspaceUuid, + authorization: 'Bearer support-admin-token', + }); + } + expect(accountBootstrapRequests).toBe(0); + expect( + await page.evaluate(() => ({ + token: localStorage.getItem('token'), + principalType: localStorage.getItem('authPrincipalType'), + workspace: localStorage.getItem('langbot_active_workspace_uuid'), + })), + ).toEqual({ + token: 'support-admin-token', + principalType: 'support_admin', + workspace: workspaceUuid, + }); +}); + test('Space OAuth sends a multi-Workspace Account to the chooser', async ({ page, }) => { diff --git a/web/tests/unit/session-monitor-pagination.test.mjs b/web/tests/unit/session-monitor-pagination.test.mjs index 38b09f306..cdb0f8812 100644 --- a/web/tests/unit/session-monitor-pagination.test.mjs +++ b/web/tests/unit/session-monitor-pagination.test.mjs @@ -87,21 +87,6 @@ test('backend filters sessions by user id or user name in the existing endpoint' ); }); -test('stale session and message page responses cannot overwrite the latest page', () => { - const monitor = read( - 'src/app/home/bots/components/bot-session/BotSessionMonitor.tsx', - ); - for (const token of [ - 'sessionRequestIdRef', - 'messageRequestIdRef', - 'requestId !== sessionRequestIdRef.current', - 'requestId !== messageRequestIdRef.current', - 'messageRequestIdRef.current += 1', - ]) { - includes(monitor, token, `stale response guard includes ${token}`); - } -}); - test('changing the session page or filters clears the selected detail', () => { const monitor = read( 'src/app/home/bots/components/bot-session/BotSessionMonitor.tsx', diff --git a/web/tests/unit/support-admin-session.test.mjs b/web/tests/unit/support-admin-session.test.mjs deleted file mode 100644 index 3e5135a77..000000000 --- a/web/tests/unit/support-admin-session.test.mjs +++ /dev/null @@ -1,42 +0,0 @@ -import assert from 'node:assert/strict'; -import fs from 'node:fs'; -import path from 'node:path'; -import test from 'node:test'; -import { fileURLToPath } from 'node:url'; - -const root = path.resolve( - path.dirname(fileURLToPath(import.meta.url)), - '../..', -); -const read = (file) => fs.readFileSync(path.join(root, file), 'utf8'); - -test('support-admin launch stores a scoped principal instead of starting an Account session', () => { - const callback = read('src/app/auth/space/callback/page.tsx'); - assert.match(callback, /response\.principal_type === 'support_admin'/); - assert.match( - callback, - /beginSupportAdminSession\(response\.token, response\.workspace_uuid\)/, - ); -}); - -test('support-admin workspace bootstrap never calls Account bootstrap', () => { - const source = read('src/app/infra/http/index.ts'); - assert.match(source, /export function beginSupportAdminSession/); - assert.match(source, /export function isSupportAdminSession\(\): boolean/); - const supportBranch = source.indexOf('if (isSupportAdminSession())'); - const accountBootstrap = source.indexOf( - 'backendClient.getWorkspaceBootstrap()', - ); - assert.ok(supportBranch >= 0); - assert.ok(accountBootstrap > supportBranch); - assert.match( - source.slice(supportBranch, accountBootstrap), - /initializeWorkspaceInfo\([\s\S]*status: 'ready'/, - ); - assert.match( - source, - /localStorage\.setItem\('authPrincipalType', 'support_admin'\)/, - ); - const homeLayout = read('src/app/home/layout.tsx'); - assert.match(homeLayout, /!isSupportAdminSession\(\)/); -});