Merge remote-tracking branch 'origin/master' into dev/4.11.x

# Conflicts:
#	pyproject.toml
#	src/langbot/pkg/pipeline/controller.py
#	uv.lock
#	web/src/app/home/bots/components/bot-form/BotForm.tsx
#	web/src/app/home/components/home-sidebar/HomeSidebar.tsx
#	web/src/app/home/components/home-sidebar/SidebarDataContext.tsx
#	web/src/app/home/plugin-pages/page.tsx
#	web/src/app/infra/entities/api/index.ts
This commit is contained in:
huanghuoguoguo
2026-08-04 12:16:27 +08:00
75 changed files with 3809 additions and 713 deletions
@@ -0,0 +1,63 @@
import { expect, test } from '@playwright/test';
import {
installLangBotApiMocks,
makeWorkspaceEntry,
} from './fixtures/langbot-api';
function wrapped(data: unknown) {
return JSON.stringify({
code: 0,
message: 'ok',
data,
timestamp: Date.now(),
});
}
test('Cloud never exposes or requests storage analysis', async ({ page }) => {
const workspace = makeWorkspaceEntry(
'workspace-cloud',
'Cloud Workspace',
'cloud_projection',
);
await installLangBotApiMocks(page, {
authenticated: true,
workspaces: [workspace],
});
await page.route(
/\/api\/v1\/workspaces\/workspace-cloud\/(members|invitations)$/,
async (route) => {
const collection = route.request().url().endsWith('/members')
? 'members'
: 'invitations';
await route.fulfill({
status: 200,
contentType: 'application/json',
body: wrapped({ [collection]: [] }),
});
},
);
let storageAnalysisRequests = 0;
await page.route('**/api/v1/system/storage-analysis', async (route) => {
storageAnalysisRequests += 1;
await route.fulfill({
status: 200,
contentType: 'application/json',
body: wrapped({}),
});
});
await page.goto('/home/bots');
await page.getByRole('button', { name: /admin@example\.com/i }).click();
await expect(page.getByText('Storage Analysis', { exact: true })).toHaveCount(
0,
);
await page.goto('/home/bots?action=showStorageAnalysis');
await expect(page.getByRole('dialog')).toBeVisible();
await expect(page.getByRole('heading', { name: 'Workspace' })).toBeVisible();
await expect(page.getByText('Storage Analysis', { exact: true })).toHaveCount(
0,
);
expect(storageAnalysisRequests).toBe(0);
});
-1
View File
@@ -170,7 +170,6 @@ export function makeWorkspaceEntry(
'member.remove',
'member.update_role',
'member.view',
'owner.transfer',
'provider_secret.manage',
'resource.manage',
'resource.view',
+161
View File
@@ -165,3 +165,164 @@ test('an authenticated OSS invitation requires logout before registration', asyn
invitation: 'logout-invitation',
});
});
test('an authenticated Cloud Account can accept its invitation directly', async ({
page,
}) => {
await installLangBotApiMocks(page, {
authenticated: true,
storage: {
token: 'invited-account-token',
userEmail: 'invited@example.com',
},
});
await page.route('**/api/v1/user/account-info', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
code: 0,
data: {
initialized: true,
authenticated_invitation_acceptance_enabled: true,
password_login_enabled: false,
space_login_enabled: true,
},
msg: 'ok',
}),
});
});
await page.route('**/api/v1/invitations/inspect', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
code: 0,
data: {
invitation: {
uuid: 'cloud-invitation',
workspace_uuid: 'workspace-playwright',
normalized_email: 'invited@example.com',
role: 'viewer',
status: 'pending',
},
workspace: {
uuid: 'workspace-playwright',
name: 'Playwright Workspace',
},
},
msg: 'ok',
}),
});
});
let acceptanceAuthorization = '';
await page.route('**/api/v1/invitations/accept', async (route) => {
acceptanceAuthorization = route.request().headers().authorization ?? '';
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
code: 0,
data: {
token: 'accepted-cloud-account-token',
workspace_uuid: 'workspace-playwright',
},
msg: 'ok',
}),
});
});
await page.goto('/invitations/accept#token=cloud-invitation');
await expect(
page.getByRole('button', { name: 'Accept Invitation' }),
).toBeVisible();
await page.getByRole('button', { name: 'Accept Invitation' }).click();
await expect(page).toHaveURL(/\/home(?:\/monitoring)?$/);
expect(acceptanceAuthorization).toBe('Bearer invited-account-token');
});
test('Space OAuth accepts a pending invitation with the freshly authenticated account', async ({
page,
}) => {
await installLangBotApiMocks(page, {
authenticated: false,
storage: {
token: 'stale-other-account-token',
userEmail: 'other@example.com',
},
});
await page.addInitScript(() => {
sessionStorage.setItem(
'langbot_pending_invitation_token',
'matching-invitation',
);
});
await page.route('**/api/v1/user/space/callback', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
code: 0,
data: {
token: 'fresh-invited-account-token',
user: 'invited@example.com',
},
msg: 'ok',
}),
});
});
await page.route('**/api/v1/user/info', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
code: 0,
data: {
account_uuid: 'invited-account',
user: 'invited@example.com',
account_type: 'space',
has_password: false,
},
msg: 'ok',
}),
});
});
let acceptanceAuthorization = '';
await page.route('**/api/v1/invitations/accept', async (route) => {
acceptanceAuthorization = route.request().headers().authorization ?? '';
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({
code: 0,
data: {
token: 'accepted-invited-account-token',
workspace_uuid: 'workspace-playwright',
},
msg: 'ok',
}),
});
});
await page.goto('/auth/space/callback?code=oauth-code&state=oauth-state');
await expect(page).toHaveURL(/\/home(?:\/monitoring)?$/, {
timeout: 5_000,
});
expect(acceptanceAuthorization).toBe('Bearer fresh-invited-account-token');
expect(
await page.evaluate(() => ({
token: localStorage.getItem('token'),
userEmail: localStorage.getItem('userEmail'),
invitation: sessionStorage.getItem('langbot_pending_invitation_token'),
})),
).toEqual({
token: 'accepted-invited-account-token',
userEmail: 'invited@example.com',
invitation: null,
});
});
+88
View File
@@ -0,0 +1,88 @@
import { expect, test } from '@playwright/test';
import {
installLangBotApiMocks,
makeWorkspaceEntry,
} from './fixtures/langbot-api';
function wrapped(data: unknown) {
return JSON.stringify({
code: 0,
message: 'ok',
data,
timestamp: Date.now(),
});
}
test('loads a Cloud plugin page through the authenticated asset route', async ({
page,
}) => {
const workspace = makeWorkspaceEntry(
'workspace-cloud',
'Cloud Workspace',
'cloud_projection',
);
await installLangBotApiMocks(page, {
authenticated: true,
workspaces: [workspace],
});
await page.route('**/api/v1/plugins', async (route) => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: wrapped({
plugins: [
{
install_source: 'marketplace',
install_info: {},
debug: false,
manifest: {
manifest: {
metadata: {
author: 'langbot-team',
name: 'LangRAG',
version: '0.1.9',
label: { en_US: 'LangRAG', zh_Hans: 'LangRAG' },
},
spec: {
pages: [
{
id: 'observability',
path: 'components/pages/observability.html',
label: { en_US: 'Observability', zh_Hans: '观测面板' },
},
],
},
},
},
},
],
}),
});
});
let authenticatedAssetRequests = 0;
await page.route(
'**/api/v1/plugins/langbot-team/LangRAG/authenticated-assets/**',
async (route) => {
authenticatedAssetRequests += 1;
await route.fulfill({
status: 200,
contentType: 'text/html',
body: '<!doctype html><html><body><h1>LangRAG Observability</h1></body></html>',
});
},
);
await page.goto(
'/home/plugin-pages?id=langbot-team%2FLangRAG%2Fobservability',
);
await expect(
page
.frameLocator('iframe')
.getByRole('heading', { name: 'LangRAG Observability' }),
).toBeVisible();
expect(authenticatedAssetRequests).toBeGreaterThan(0);
await expect(page.getByText('Loading...')).toHaveCount(0);
});
+149
View File
@@ -0,0 +1,149 @@
import { expect, test } from '@playwright/test';
import { installLangBotApiMocks } from './fixtures/langbot-api';
function wrapped(data: unknown) {
return JSON.stringify({
code: 0,
message: 'ok',
data,
timestamp: Date.now(),
});
}
async function fulfill(
route: Parameters<Parameters<import('@playwright/test').Page['route']>[1]>[0],
data: unknown,
) {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: wrapped(data),
});
}
test('quota-reached create actions are disabled and explain the current limit', async ({
page,
}) => {
await installLangBotApiMocks(page, { authenticated: true });
await page.route('**/api/v1/system/info', (route) =>
fulfill(route, {
debug: false,
version: 'quota-e2e',
edition: 'community',
cloud_service_url: 'https://space.langbot.app',
enable_marketplace: true,
allow_modify_login_info: true,
disable_models_service: false,
limitation: {
max_bots: 2,
max_pipelines: 3,
max_extensions: 3,
max_knowledge_bases: 2,
},
outbound_ips: [],
wizard_status: 'completed',
wizard_progress: null,
}),
);
await page.route('**/api/v1/platform/bots**', (route) =>
fulfill(route, {
bots: Array.from({ length: 2 }, (_, index) => ({
uuid: `bot-${index}`,
name: `Bot ${index + 1}`,
description: '',
adapter: 'aiocqhttp',
enable: true,
updated_at: new Date().toISOString(),
})),
}),
);
await page.route('**/api/v1/pipelines**', (route) =>
fulfill(route, {
pipelines: Array.from({ length: 3 }, (_, index) => ({
uuid: `pipeline-${index}`,
name: `Pipeline ${index + 1}`,
description: '',
emoji: '⚙️',
updated_at: new Date().toISOString(),
})),
}),
);
await page.route('**/api/v1/knowledge/bases**', (route) =>
fulfill(route, {
bases: Array.from({ length: 2 }, (_, index) => ({
uuid: `kb-${index}`,
name: `Knowledge ${index + 1}`,
description: '',
emoji: '📚',
updated_at: new Date().toISOString(),
})),
}),
);
await page.route('**/api/v1/plugins**', (route) =>
fulfill(route, { plugins: [] }),
);
await page.route('**/api/v1/mcp/servers**', (route) =>
fulfill(route, {
servers: Array.from({ length: 3 }, (_, index) => ({
name: `mcp-${index}`,
mode: 'http',
enable: true,
runtime_info: { status: 'connected' },
})),
}),
);
await page.route('**/api/v1/skills**', (route) =>
fulfill(route, { skills: [] }),
);
await page.goto('/home/bots');
const botCreate = page.getByRole('button', {
name: 'Create Bots',
exact: true,
});
const pipelineCreate = page.getByRole('button', {
name: 'Create Pipelines',
exact: true,
});
const knowledgeCreate = page.getByRole('button', {
name: 'Create Knowledge',
exact: true,
});
const addExtension = page.getByRole('button', {
name: 'Add Extension',
exact: true,
});
await expect(botCreate).toBeDisabled();
await expect(pipelineCreate).toBeDisabled();
await expect(knowledgeCreate).toBeDisabled();
await expect(addExtension).toBeEnabled();
const botQuotaTrigger = botCreate.locator('..');
await botQuotaTrigger.hover();
await expect(
page.getByText(
'The Bots limit (2) for this workspace has been reached. Delete one existing item before creating another.',
),
).toBeVisible();
await botQuotaTrigger.focus();
await expect(botQuotaTrigger).toBeFocused();
await expect(
page.getByText(
'The Bots limit (2) for this workspace has been reached. Delete one existing item before creating another.',
),
).toBeVisible();
await addExtension.click();
await expect(page).toHaveURL(/\/home\/add-extension$/);
const manualAdd = page.getByRole('button', { name: 'Manual Add' });
await expect(manualAdd).toBeDisabled();
await manualAdd.locator('..').hover();
await expect(
page.getByText(
'The Extensions limit (3) for this workspace has been reached. Delete one existing item before creating another.',
),
).toBeVisible();
});
@@ -46,4 +46,14 @@ test('provider card represents owner and member owner-bound states explicitly',
assert.match(source, /ownerSpaceBound/);
assert.match(source, /models\.ownerMustBindSpace/);
assert.match(source, /models\.usesOwnerSpaceBilling/);
assert.match(source, /isWorkspaceOwner && \(\s*<Button/);
});
test('workspace member controls never offer ownership transfer', () => {
const source = read(
'src/app/home/components/workspace-settings/WorkspaceSettingsPanel.tsx',
);
assert.doesNotMatch(source, /canTransferOwner/);
assert.doesNotMatch(source, /workspace\.transferOwnership/);
assert.doesNotMatch(source, /<SelectItem value="owner">/);
});
@@ -0,0 +1,100 @@
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 currentDirectory = path.dirname(fileURLToPath(import.meta.url));
const webRoot = path.resolve(currentDirectory, '../..');
function readSource(relativePath) {
return fs.readFileSync(path.join(webRoot, relativePath), 'utf8');
}
const homeSidebarSource = readSource(
'src/app/home/components/home-sidebar/HomeSidebar.tsx',
);
const botFormSource = readSource(
'src/app/home/bots/components/bot-form/BotForm.tsx',
);
const kbFormSource = readSource(
'src/app/home/knowledge/components/kb-form/KBForm.tsx',
);
const settingsDialogSource = readSource(
'src/app/home/components/settings-dialog/SettingsDialog.tsx',
);
const pluginPageSource = readSource('src/app/home/plugin-pages/page.tsx');
const authenticatedPluginResourceSource = readSource(
'src/hooks/useAuthenticatedPluginResource.ts',
);
test('hides the entire workspace switcher slot for a singleton local workspace', () => {
assert.match(homeSidebarSource, /useWorkspaceBootstrap/);
assert.match(
homeSidebarSource,
/const showWorkspaceSwitcher\s*=\s*workspaces\.length\s*>\s*1\s*\|\|\s*currentWorkspace\?\.workspace\.source\s*===\s*'cloud_projection'/,
);
assert.match(
homeSidebarSource,
/\{showWorkspaceSwitcher\s*&&\s*\(\s*<div className="px-2[^>]*>\s*<WorkspaceSwitcher/,
);
});
test('keeps bot cards at the same vertical spacing as knowledge-base cards', () => {
assert.match(
botFormSource,
/<fieldset className="space-y-6" disabled=\{isLoading\}>/,
);
assert.match(kbFormSource, /<form[\s\S]*?className="space-y-6"/);
});
test('does not expose storage analysis in Cloud settings or via a deep link', () => {
assert.match(
homeSidebarSource,
/canViewStorageAnalysis\s*&&\s*\(\s*<DropdownMenuItem[\s\S]*?openSettings\('storageAnalysis'\)/,
);
assert.match(
settingsDialogSource,
/const canViewStorageAnalysis\s*=\s*currentWorkspace\?\.workspace\.source\s*!==\s*'cloud_projection'\s*&&\s*canViewAudit/,
);
assert.match(
settingsDialogSource,
/item\.id === 'storageAnalysis'[\s\S]*?return canViewStorageAnalysis/,
);
assert.match(
settingsDialogSource,
/section === 'storageAnalysis' && !canViewStorageAnalysis/,
);
assert.match(
settingsDialogSource,
/section === 'storageAnalysis' &&\s*canViewStorageAnalysis &&\s*\(\s*<StorageAnalysisPanel/,
);
});
test('loads plugin pages through the authenticated Workspace-scoped asset route', () => {
assert.match(pluginPageSource, /useAuthenticatedPluginAsset/);
assert.match(
pluginPageSource,
/useAuthenticatedPluginAsset\(\s*author,\s*pluginName,\s*pagePath,?\s*\)/,
);
assert.match(pluginPageSource, /src=\{assetUrl\}/);
assert.doesNotMatch(pluginPageSource, /getPluginAssetURL\(/);
assert.match(pluginPageSource, /plugins\.loadFailed/);
assert.match(pluginPageSource, /loadedAssetUrl !== assetUrl/);
});
test('revokes and reloads authenticated plugin resources when the Workspace changes', () => {
assert.match(authenticatedPluginResourceSource, /useCurrentWorkspace/);
assert.match(
authenticatedPluginResourceSource,
/const workspaceUuid = currentWorkspace\?\.workspace\.uuid;/,
);
assert.match(
authenticatedPluginResourceSource,
/\[author, name, filepath, resourceKey\]/,
);
assert.match(
authenticatedPluginResourceSource,
/resource\.key === resourceKey \? resource\.url : ''/,
);
});
@@ -0,0 +1,122 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
const root = process.cwd();
const quotaPath = path.join(
root,
'src/app/home/components/workspace-quota/useWorkspaceQuotaStatus.ts',
);
const sidebarPath = path.join(
root,
'src/app/home/components/home-sidebar/HomeSidebar.tsx',
);
const tooltipPath = path.join(
root,
'src/app/home/components/workspace-quota/WorkspaceQuotaTooltip.tsx',
);
const baseTooltipPath = path.join(root, 'src/components/ui/tooltip.tsx');
const addExtensionPath = path.join(root, 'src/app/home/add-extension/page.tsx');
const marketPath = path.join(
root,
'src/app/home/plugins/components/plugin-market/PluginMarketComponent.tsx',
);
const marketCardPath = path.join(
root,
'src/app/home/plugins/components/plugin-market/plugin-market-card/PluginMarketCardComponent.tsx',
);
const recommendationPath = path.join(
root,
'src/app/home/plugins/components/plugin-market/RecommendationLists.tsx',
);
const zhPath = path.join(root, 'src/i18n/locales/zh-Hans.ts');
test('workspace quota hook exposes reached states for every creatable resource', () => {
assert.equal(
fs.existsSync(quotaPath),
true,
'workspace quota hook is missing',
);
const source = fs.readFileSync(quotaPath, 'utf8');
for (const token of [
'botsReached',
'pipelinesReached',
'knowledgeBasesReached',
'extensionsReached',
'max_bots',
'max_pipelines',
'max_knowledge_bases',
'max_extensions',
]) {
assert.match(source, new RegExp(token));
}
});
test('sidebar quota-disables create controls and renders a tooltip', () => {
const source = fs.readFileSync(sidebarPath, 'utf8');
const tooltip = fs.readFileSync(tooltipPath, 'utf8');
const baseTooltip = fs.readFileSync(baseTooltipPath, 'utf8');
assert.match(source, /useWorkspaceQuotaStatus/);
assert.match(source, /quota\.disabled/);
assert.match(source, /disabled=\{quota\.disabled\}/);
assert.match(source, /WorkspaceQuotaTooltip/);
assert.match(tooltip, /TooltipContent/);
assert.match(tooltip, /limitation\.createDisabledTooltip/);
assert.match(tooltip, /limitation\.quotaLoadingTooltip/);
assert.match(tooltip, /tabIndex=\{0\}/);
assert.match(tooltip, /max-w-72 text-left/);
assert.doesNotMatch(tooltip, /text-center/);
assert.doesNotMatch(baseTooltip, /text-balance/);
assert.match(source, /config\.id === 'add-extension'/);
assert.doesNotMatch(
source,
/config\.id === 'add-extension'\s*\?\s*quotaStatus\.extensions/,
);
});
test('add-extension page disables all install entry points at the quota', () => {
const page = fs.readFileSync(addExtensionPath, 'utf8');
const market = fs.readFileSync(marketPath, 'utf8');
const card = fs.readFileSync(marketCardPath, 'utf8');
const recommendations = fs.readFileSync(recommendationPath, 'utf8');
assert.match(page, /extensionsReached/);
assert.match(page, /installDisabled=\{extensionsReached\}/);
assert.match(page, /disabled=\{extensionsReached/);
assert.match(page, /limitation\.createDisabledTooltip/);
assert.match(market, /installDisabled/);
assert.match(card, /installDisabled/);
assert.match(card, /disabled=\{installDisabled\}/);
assert.match(card, /TooltipContent/);
assert.match(card, /max-w-72 text-left/);
assert.doesNotMatch(card, /max-w-72 text-center/);
assert.match(recommendations, /installDisabled=\{installDisabled\}/);
assert.match(
recommendations,
/installDisabledTooltip=\{installDisabledTooltip\}/,
);
assert.match(page, /quota=\{extensionQuota\}/);
});
test('extension confirmation checks fail closed and enter an in-flight state first', () => {
const page = fs.readFileSync(addExtensionPath, 'utf8');
assert.match(page, /limitation\.quotaCheckFailed/);
assert.doesNotMatch(page, /If we can't check, let backend handle it/);
assert.match(
page,
/setGithubInstallStatus\(GithubInstallStatus\.INSTALLING\);\s+if \(!\(await checkExtensionsLimit\(\)\)\)/,
);
assert.match(
page,
/setGithubInstallStatus\(GithubInstallStatus\.SKILL_INSTALLING\);\s+if \(!\(await checkExtensionsLimit\(\)\)\)/,
);
});
test('quota tooltip copy is localized in Simplified Chinese', () => {
const source = fs.readFileSync(zhPath, 'utf8');
assert.match(source, /createDisabledTooltip/);
assert.match(source, /已达到.*上限/);
assert.match(source, /删除.*后再/);
});
@@ -0,0 +1,24 @@
import assert from 'node:assert/strict';
import fs from 'node:fs';
import test from 'node:test';
const source = fs.readFileSync(
new URL('../../src/app/auth/space/callback/page.tsx', import.meta.url),
'utf8',
);
test('direct launch assertion is fragment-only and removed before exchange', () => {
assert.doesNotMatch(source, /searchParams\.get\(['"]launch_assertion['"]\)/);
const readIndex = source.indexOf("fragmentParams.get('launch_assertion')");
const clearIndex = source.indexOf('window.history.replaceState');
const exchangeIndex = source.indexOf('handleOAuthCallback(', clearIndex);
assert.ok(readIndex >= 0, 'fragment assertion read is missing');
assert.ok(
clearIndex > readIndex,
'URL fragment is not cleared after copying the assertion',
);
assert.ok(
exchangeIndex > clearIndex,
'assertion exchange starts before the fragment is cleared',
);
});
@@ -50,15 +50,22 @@ test('places WorkspaceSwitcher between the sidebar header and Home navigation',
);
});
test('shows WorkspaceSwitcher for a current Cloud or OSS workspace even when it is the only workspace', () => {
test('hides WorkspaceSwitcher for the singleton local OSS workspace and keeps it for Cloud or multiple workspaces', () => {
assert.match(
workspaceSwitcherSource,
/if \(!currentWorkspace\) return null;/,
);
assert.doesNotMatch(workspaceSwitcherSource, /workspaces\.length\s*<=\s*1/);
assert.doesNotMatch(
assert.match(
homeSidebarSource,
/currentWorkspace\?\.workspace\.source\s*===\s*'cloud_projection'[\s\S]{0,200}<WorkspaceSwitcher/,
/const workspaces = useWorkspaceBootstrap\(\);/,
);
assert.match(
homeSidebarSource,
/const showWorkspaceSwitcher\s*=\s*workspaces\.length\s*>\s*1\s*\|\|\s*currentWorkspace\?\.workspace\.source\s*===\s*'cloud_projection'/,
);
assert.match(
homeSidebarSource,
/\{showWorkspaceSwitcher\s*&&\s*\(\s*<div className="px-2[^>]*>[\s\S]*?<WorkspaceSwitcher/,
);
});