mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-10-23 08:55:44 +08:00
fix(pipeline): decouple Runner from extension permissions (LANG-54) (#2723)
* fix(pipeline): decouple runner from extension allowlist Co-authored-by: multica-agent <[email protected]> * fix(pipeline): complete runner diagnostics and real runtime coverage Co-authored-by: multica-agent <[email protected]> --------- Co-authored-by: multica-agent <[email protected]>
This commit is contained in:
co-authored by
multica-agent
parent
5a6ddbff6f
commit
d9e4e7d9df
@@ -0,0 +1,167 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import {
|
||||
installLangBotApiMocks,
|
||||
pipelineMetadata,
|
||||
} from './fixtures/langbot-api';
|
||||
|
||||
test('independent Runner guidance remains visible with extensions disabled', async ({
|
||||
page,
|
||||
}) => {
|
||||
await installLangBotApiMocks(page, { authenticated: true });
|
||||
await page.route('**/api/v1/pipelines/*/extensions', (route) =>
|
||||
route.fulfill({
|
||||
json: {
|
||||
code: 0,
|
||||
data: {
|
||||
enable_all_plugins: false,
|
||||
enable_all_mcp_servers: false,
|
||||
enable_all_skills: false,
|
||||
bound_plugins: [],
|
||||
available_plugins: [],
|
||||
bound_mcp_servers: [],
|
||||
available_mcp_servers: [],
|
||||
bound_skills: [],
|
||||
available_skills: [],
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
await page.goto('/home/pipelines?id=boundary');
|
||||
await page.locator('[data-guide="pipeline-section-ai"]').click();
|
||||
await expect(
|
||||
page.getByText(
|
||||
'Select the Runner independently here, regardless of extension plugin switches. Its plugin must still be installed and available.',
|
||||
),
|
||||
).toBeVisible();
|
||||
await page.getByRole('button', { name: 'Extensions', exact: true }).click();
|
||||
await expect(
|
||||
page.getByText(
|
||||
'Only controls event listeners, tools and commands for this pipeline; does not affect the Runner selected in AI settings.',
|
||||
),
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
for (const problem of ['missing', 'disabled', 'runtime'] as const) {
|
||||
test(`Runner ${problem} diagnosis keeps the draft and opens repair separately`, async ({
|
||||
page,
|
||||
}) => {
|
||||
await installLangBotApiMocks(page, { authenticated: true });
|
||||
const id = 'plugin:langbot-team/LocalAgent/default';
|
||||
const config = {
|
||||
ai: { runner: { id }, runner_config: { [id]: { hidden: null } } },
|
||||
};
|
||||
const writes: unknown[] = [];
|
||||
await page.route('**/api/v1/pipelines/diagnosis', async (route) => {
|
||||
if (route.request().method() === 'PUT')
|
||||
writes.push(route.request().postDataJSON());
|
||||
await route.fulfill({
|
||||
json: {
|
||||
code: 0,
|
||||
data: {
|
||||
pipeline: {
|
||||
uuid: 'diagnosis',
|
||||
name: 'Diagnosis',
|
||||
description: '',
|
||||
emoji: '⚙️',
|
||||
config,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
await page.route('**/api/v1/system/status/plugin-system', (route) =>
|
||||
route.fulfill({
|
||||
json: {
|
||||
code: 0,
|
||||
data: {
|
||||
is_enable: true,
|
||||
is_connected: problem !== 'runtime',
|
||||
plugin_connector_error: '',
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
await page.route('**/api/v1/plugins', (route) =>
|
||||
route.fulfill({
|
||||
json: {
|
||||
code: 0,
|
||||
data: {
|
||||
plugins:
|
||||
problem === 'missing'
|
||||
? []
|
||||
: [
|
||||
{
|
||||
enabled: problem !== 'disabled',
|
||||
manifest: {
|
||||
manifest: {
|
||||
metadata: {
|
||||
author: 'langbot-team',
|
||||
name: 'LocalAgent',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
const originalMetadata = pipelineMetadata();
|
||||
const metadata = {
|
||||
configs: originalMetadata.configs.map((tab) => ({
|
||||
...tab,
|
||||
stages: tab.stages.map((stage) => ({
|
||||
...stage,
|
||||
config:
|
||||
stage.name === id
|
||||
? [
|
||||
{
|
||||
name: 'draft',
|
||||
type: 'string',
|
||||
label: { en_US: 'Draft marker', zh_Hans: '草稿标记' },
|
||||
required: false,
|
||||
default: '',
|
||||
},
|
||||
]
|
||||
: stage.config.map((field) =>
|
||||
problem === 'missing' && field.name === 'id'
|
||||
? { ...field, options: [] }
|
||||
: field,
|
||||
),
|
||||
})),
|
||||
})),
|
||||
};
|
||||
await page.route('**/api/v1/pipelines/_/metadata', (route) =>
|
||||
route.fulfill({ json: { code: 0, data: metadata } }),
|
||||
);
|
||||
await page.goto('/home/pipelines?id=diagnosis');
|
||||
await page.locator('[data-guide="pipeline-section-ai"]').click();
|
||||
const draft = page
|
||||
.getByRole('region', { name: 'Configuration', exact: true })
|
||||
.getByRole('textbox');
|
||||
await draft.fill('unsaved diagnosis draft');
|
||||
const alert = page
|
||||
.getByRole('alert')
|
||||
.filter({ hasText: 'Manage plugins and runtime' });
|
||||
await expect(alert).toContainText(
|
||||
{
|
||||
missing: 'The selected Runner or its plugin is missing.',
|
||||
disabled: 'The selected Runner plugin is disabled.',
|
||||
runtime: 'The Plugin Runtime is unavailable or disabled.',
|
||||
}[problem],
|
||||
);
|
||||
const repair = alert.getByRole('link', {
|
||||
name: 'Manage plugins and runtime',
|
||||
});
|
||||
await expect(repair).toHaveAttribute('target', '_blank');
|
||||
const popup = page.waitForEvent('popup');
|
||||
await repair.click();
|
||||
await (await popup).close();
|
||||
await expect(page).toHaveURL(/id=diagnosis/);
|
||||
await expect(draft).toHaveValue('unsaved diagnosis draft');
|
||||
await expect(
|
||||
page.getByRole('button', { name: 'Save', exact: true }),
|
||||
).toBeEnabled();
|
||||
expect(writes).toEqual([]);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.skip(
|
||||
!process.env.LANGBOT_RUNNER_PIPELINE_ID,
|
||||
'Requires the isolated real backend and SDK pytest fixture',
|
||||
);
|
||||
|
||||
test('real backend and SDK: save, copy and execute with extensions off', async ({
|
||||
page,
|
||||
request,
|
||||
}) => {
|
||||
const api = process.env.LANGBOT_RUNNER_API_URL!;
|
||||
const pipelineId = process.env.LANGBOT_RUNNER_PIPELINE_ID!;
|
||||
const token = process.env.LANGBOT_RUNNER_TOKEN!;
|
||||
const runnerId = 'plugin:e2e/agent-runner-qa/default';
|
||||
const headers = { Authorization: `Bearer ${token}` };
|
||||
await page.addInitScript(
|
||||
({ token }) => {
|
||||
localStorage.setItem('token', token);
|
||||
localStorage.setItem('userEmail', '[email protected]');
|
||||
localStorage.setItem('langbot_language', 'en-US');
|
||||
for (const key of [
|
||||
'langbot_sidebar_guide_v1',
|
||||
'langbot_pipeline_setup_guide_v1',
|
||||
]) {
|
||||
localStorage.setItem(key, 'completed');
|
||||
}
|
||||
},
|
||||
{ token },
|
||||
);
|
||||
await page.goto(`/home/pipelines?id=${pipelineId}`, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
});
|
||||
await page.getByRole('button', { name: 'Skip', exact: true }).click();
|
||||
await page
|
||||
.getByRole('dialog')
|
||||
.getByRole('button', { name: 'OK', exact: true })
|
||||
.click();
|
||||
await expect(
|
||||
page.getByRole('dialog', { name: 'Skip', exact: true }),
|
||||
).not.toBeVisible();
|
||||
await page.goto(`/home/pipelines?id=${pipelineId}`, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
});
|
||||
await page.locator('[data-guide="pipeline-section-ai"]').click();
|
||||
await expect(
|
||||
page.getByRole('combobox', { name: 'Runner', exact: true }),
|
||||
).toContainText('QA Echo Runner');
|
||||
const prefixInput = page
|
||||
.getByRole('region', { name: 'Configuration', exact: true })
|
||||
.getByRole('textbox');
|
||||
await prefixInput.fill('browser saved');
|
||||
const savedResponse = page.waitForResponse(
|
||||
(response) =>
|
||||
response.url().endsWith(`/api/v1/pipelines/${pipelineId}`) &&
|
||||
response.request().method() === 'PUT',
|
||||
);
|
||||
await page.getByRole('button', { name: 'Save', exact: true }).click();
|
||||
expect((await (await savedResponse).json()).code).toBe(0);
|
||||
await page.reload({ waitUntil: 'domcontentloaded' });
|
||||
await page.locator('[data-guide="pipeline-section-ai"]').click();
|
||||
await expect(prefixInput).toHaveValue('browser saved');
|
||||
await page.getByRole('button', { name: 'Management', exact: true }).click();
|
||||
await page.getByRole('button', { name: 'Copy', exact: true }).click();
|
||||
const copiedResponse = page.waitForResponse(
|
||||
(response) =>
|
||||
response.url().endsWith(`/api/v1/pipelines/${pipelineId}/copy`) &&
|
||||
response.request().method() === 'POST',
|
||||
);
|
||||
await page
|
||||
.getByRole('dialog')
|
||||
.getByRole('button', { name: 'Confirm', exact: true })
|
||||
.click();
|
||||
const copiedPayload = await (await copiedResponse).json();
|
||||
expect(copiedPayload.code).toBe(0);
|
||||
const copiedId = copiedPayload.data.uuid;
|
||||
for (const id of [pipelineId, copiedId]) {
|
||||
const response = await request.get(`${api}/api/v1/pipelines/${id}`, {
|
||||
headers,
|
||||
});
|
||||
expect(response.ok()).toBeTruthy();
|
||||
const stored = (await response.json()).data.pipeline;
|
||||
expect(stored.config.ai.runner.id).toBe(runnerId);
|
||||
expect(stored.config.ai.runner_config[runnerId]).toEqual({
|
||||
prefix: 'browser saved',
|
||||
hidden: { keep: [null, false, ' raw '] },
|
||||
});
|
||||
expect(stored.extensions_preferences.enable_all_plugins).toBe(false);
|
||||
expect(stored.extensions_preferences.plugins).toEqual([]);
|
||||
await page.goto(`/home/pipelines?id=${id}`, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
});
|
||||
const input = page.getByPlaceholder('Send Private Chat message...');
|
||||
await expect(input).toBeEnabled();
|
||||
await input.fill(`Chromium ${id}`);
|
||||
await input.press('Enter');
|
||||
await expect(
|
||||
page.getByText(`browser saved: Chromium ${id}`, { exact: true }),
|
||||
).toBeVisible({ timeout: 20_000 });
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,61 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import fs from 'node:fs';
|
||||
import test from 'node:test';
|
||||
import ts from 'typescript';
|
||||
|
||||
test('Runner diagnosis and draft-safe repair have all eight complete catalogs', () => {
|
||||
const locales = [
|
||||
'en-US',
|
||||
'zh-Hans',
|
||||
'zh-Hant',
|
||||
'ja-JP',
|
||||
'es-ES',
|
||||
'ru-RU',
|
||||
'th-TH',
|
||||
'vi-VN',
|
||||
];
|
||||
const expected = ['disabled', 'draft', 'missing', 'repair', 'runtime'];
|
||||
for (const locale of locales) {
|
||||
const source = fs.readFileSync(
|
||||
new URL(`../../src/i18n/locales/${locale}.ts`, import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
const ast = ts.createSourceFile(
|
||||
`${locale}.ts`,
|
||||
source,
|
||||
ts.ScriptTarget.Latest,
|
||||
true,
|
||||
);
|
||||
const found = [];
|
||||
function visit(node) {
|
||||
if (
|
||||
ts.isPropertyAssignment(node) &&
|
||||
node.name.getText(ast) === 'runnerDiagnosis'
|
||||
) {
|
||||
assert.ok(ts.isObjectLiteralExpression(node.initializer), locale);
|
||||
const fields = node.initializer.properties;
|
||||
assert.deepEqual(
|
||||
fields.map((field) => field.name.getText(ast)).sort(),
|
||||
expected,
|
||||
locale,
|
||||
);
|
||||
for (const field of fields) {
|
||||
assert.ok(
|
||||
ts.isStringLiteral(field.initializer) &&
|
||||
field.initializer.text.trim(),
|
||||
locale,
|
||||
);
|
||||
assert.equal(
|
||||
field.initializer.text.match(/{{[^}]+}}/g),
|
||||
null,
|
||||
locale,
|
||||
);
|
||||
}
|
||||
found.push(node);
|
||||
}
|
||||
ts.forEachChild(node, visit);
|
||||
}
|
||||
visit(ast);
|
||||
assert.equal(found.length, 1, locale);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user