Merge pull request #2668 from langbot-app/test/quality-frontend-behavior

test(web): replace source guards with browser behavior checks
This commit is contained in:
huanghuoguoguo
2026-10-17 20:12:46 +08:00
committed by GitHub
3 changed files with 81 additions and 57 deletions
+81
View File
@@ -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,
}) => {
@@ -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',
@@ -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\(\)/);
});