应用平台集成(前端):钩子按名字管理并只显示一次密钥、按新口径补算、应用助手对话历史、设置页按角色收起与身份设置补管理员用户名、按需视图每日上限、界面偏好按角色只存本地、使用者问数据用数据源名单并在运行流连不上时改轮询、能力字段待审阅、记录页按来源筛选与待办 id、编辑器的入口 / 表单 / 待办外观 JSON 分区、画布 ?publish=1、工具页绑定端点与 MCP 认证头掩码编辑、派给自己的新待办系统通知、样例与检查脚本改走待办接口(含统一复核后的修复)

This commit is contained in:
ThearchyHelios
2026-10-14 21:55:51 +08:00
parent d67349562a
commit 1dd4f93579
48 changed files with 2651 additions and 308 deletions
+135 -4
View File
@@ -4,7 +4,10 @@
// - 能力列表标出读写效果,同步得出和治理后不一致时标出来;治理带 version 保存(乐观锁),409 时载入最新的、不覆盖;
// - 端点的认证头只显示掩码,提交掩码值表示保持原值;允许访问内网只有管理员能开;测试连接按环境发;
// - 关登录(默认)时所有人等同管理员:治理、退役、身份设置都能改;
// - 设置页的身份、通知、审计三个页签在,通知渠道的地址只显示主机名。
// - 设置页的身份、通知、审计三个页签在,通知渠道的地址只显示主机名;
// - 能力字段的待审阅(D-i)复用数据目录的审阅队列:成批确认逐项带能力的治理版本;
// - 自定义工具可以绑定登记的端点(只填路径);MCP 的认证头按掩码编辑;本地子进程只有管理员能建、能改(A6);
// - 单点登录映射管理员:用户或组至少一项;开了登录的使用者在设置页只剩个人的主题和通知,换主题不写服务端(D-s)。
//
// 不写库:/api/capabilities、/api/endpoints、/api/auth、/api/users、/api/groups、/api/audit、/api/notify 全部伪造,
// 伪造的接口改一份内存里的数据。其余写请求一律 409 并记账,检查结束时必须是空的。
@@ -65,7 +68,24 @@ const ENDPOINTS = [{
},
}]
async function open(path, { conflict = false } = {}) {
// 形状同服务端 data/capability_review.review_queue:能力名、位置(指针、字段、写好的位置说法)、值、来源、状态、优先级、原因、运行次数、版本
const REVIEW = [
{ capability: 'erp_pay', system: 'erp', title: '付款', effect: 'write', pointer: '/amount', field: 'unit', field_text: '单位',
field_label: '返回字段 /amount 的单位', value: '元', display: '元', source: 'model', status: 'proposed', note: null, priority: 9,
reasons: ['写入能力', '被 12 次运行用过'], runs: 12, version: 4 },
{ capability: 'erp_query', system: 'erp', title: '查询', effect: 'read', pointer: '/items/*/name', field: 'label', field_text: '中文名',
field_label: '返回字段 /items/*/name 的中文名', value: '品名', display: '品名', source: 'naming', status: 'proposed', note: null,
priority: 3, reasons: ['被 3 次运行用过'], runs: 3, version: 2 },
]
const OFF = { mode: 'off', username: null, display_name: null, role: 'admin', groups: [], verified: false }
const MCP_ROWS = [
{ id: 'm1', name: 'files', transport: 'stdio', command: 'npx', args: ['-y', 'fs'], env: {}, url: null, enabled: true, headers: {},
endpoint_id: null, status: 'ok', last_error: null, tools_cache: [] },
{ id: 'm2', name: 'crm', transport: 'http', command: null, args: [], env: {}, url: 'https://crm.example.com/mcp', enabled: true,
headers: { Authorization: 'Bearer ****9a2c' }, endpoint_id: null, status: 'ok', last_error: null, tools_cache: [] },
]
async function open(path, { conflict = false, me = OFF } = {}) {
const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } })
opened.add(ctx)
const page = await ctx.newPage()
@@ -74,7 +94,7 @@ async function open(path, { conflict = false } = {}) {
page.on('pageerror', (e) => errors.push(e.message))
const json = (route, body, status = 200) => route.fulfill({ status, contentType: 'application/json', body: JSON.stringify(body) })
const state = { caps: JSON.parse(JSON.stringify(CAPS)), endpoints: JSON.parse(JSON.stringify(ENDPOINTS)), governs: [], endpointWrites: [],
tests: [], syncs: 0, settings: [] }
tests: [], syncs: 0, settings: [], reviews: [], batches: [], tools: [], mcp: [], prefs: [] }
await page.route(/\/api\//, (route) => {
const req = route.request()
@@ -82,8 +102,39 @@ async function open(path, { conflict = false } = {}) {
writes.push(`${req.method()} ${new URL(req.url()).pathname}`)
return json(route, { detail: '检查脚本不写库' }, 409)
})
await page.route(/\/api\/auth\/me$/, (route) => json(route, { mode: 'off', username: null, display_name: null, role: 'admin', groups: [], verified: false }))
await page.route(/\/api\/auth\/me$/, (route) => json(route, me))
await page.route(/\/api\/capabilities(\?.*)?$/, (route) => json(route, { items: state.caps }))
await page.route(/\/api\/capabilities\/review-queue(\?.*)?$/, (route) => {
const url = new URL(route.request().url())
state.reviews.push(url.search)
const name = url.searchParams.get('capability')
const items = REVIEW.filter((i) => !name || i.capability === name)
return json(route, { total: items.length, items })
})
await page.route(/\/api\/capabilities\/review\/batch$/, (route) => {
const body = route.request().postDataJSON()
state.batches.push(body)
return json(route, { results: body.items.map((i) => (i.capability === 'erp_query'
? { capability: i.capability, pointer: i.pointer, field: i.field, ok: false, version: null,
error: '能力「erp_query」的治理设置刚被修改过,请重新载入后再审阅', code: 'capability_conflict' }
: { capability: i.capability, pointer: i.pointer, field: i.field, ok: true, version: i.if_version + 1, error: null, code: null })) })
})
await page.route(/\/api\/custom-tools(\/[^/]+)?$/, (route) => {
const req = route.request()
if (req.method() === 'GET') return json(route, [])
state.tools.push({ method: req.method(), body: req.postDataJSON() })
return json(route, { id: 't1', ...req.postDataJSON() })
})
await page.route(/\/api\/mcp\/servers(\/[^/]+)?$/, (route) => {
const req = route.request()
if (req.method() === 'GET') return json(route, MCP_ROWS)
state.mcp.push({ method: req.method(), url: new URL(req.url()).pathname, body: req.postDataJSON() })
return json(route, { id: 'm9', ...req.postDataJSON() })
})
await page.route(/\/api\/settings$/, (route) => {
if (route.request().method() !== 'GET') { state.prefs.push(route.request().postDataJSON()); return json(route, {}) }
return me.mode !== 'off' && me.role === 'user' ? json(route, { detail: '没有权限' }, 403) : json(route, { ui: { theme: 'dark' } })
})
await page.route(/\/api\/capabilities\/sync$/, (route) => { state.syncs += 1; return json(route, { changed: 2 }) })
await page.route(/\/api\/capabilities\/[^/]+\/governance$/, (route) => {
const name = decodeURIComponent(new URL(route.request().url()).pathname.split('/')[3])
@@ -204,6 +255,86 @@ await section('设置:身份、通知、审计', async () => {
check('审计照实标自报署名', await row.count() === 1 && (await row.innerText()).includes('自报署名'))
})
await section('能力:待审阅复用数据目录的审阅队列,成批确认逐项带能力的治理版本', async () => {
const { page, state, errors } = await open('/tools/capabilities?view=review')
check('左栏换成待审阅视图', await page.locator('[data-capability-views="review"]').count() === 1)
const rows = page.locator('[data-review-item]')
check('列出待审阅的能力字段', await waitFor(page, async () => await rows.count() === 2), String(await rows.count()))
check('位置照服务端的说法(返回字段 /amount 的单位)', (await rows.first().locator('[data-review-where]').innerText()).includes('返回字段 /amount 的单位'))
check('使用次数照能力说', (await rows.first().innerText()).includes('被 12 次运行用过'))
check('不分「影响数字的项 / 名称和含义」', await page.locator('[data-review-kinds]').count() === 0)
await page.locator('[data-review-select-all]').check()
await page.locator('[data-review-action="confirm"]').click()
await page.locator('[role="dialog"]').getByRole('button', { name: /确认 2 项/ }).click()
check('成批确认:一次请求、逐项带能力名、位置、字段和治理版本', await waitFor(page, async () => state.batches.length === 1)
&& JSON.stringify(state.batches[0].items.map((i) => [i.capability, i.pointer, i.field, i.action, i.if_version]))
=== JSON.stringify([['erp_pay', '/amount', 'unit', 'confirm', 4], ['erp_query', '/items/*/name', 'label', 'confirm', 2]]),
JSON.stringify(state.batches[0]))
check('冲突的那项照实标出(说的是能力,不是表)', await waitFor(page, async () =>
(await page.locator('[data-review-summary]').innerText()).includes('所在能力刚被修改过')))
await rows.first().locator('[data-review-open]').click()
check('点开一项:右栏是这个能力的治理设置,标出那个位置', await page.locator('[data-capability-editor="erp_pay"] [data-capability-focus="/amount"]').count() === 1)
check('没有运行时报错', errors.length === 0, errors.slice(0, 2).join(' | '))
})
await section('自定义工具:绑定登记的端点,只填路径', async () => {
const { page, state } = await open('/tools/custom')
await page.getByRole('button', { name: '新建工具' }).first().click()
const dlg = page.locator('[role="dialog"]')
await dlg.locator('input[placeholder="query_order_status"]').fill('erp_order')
await dlg.locator('[data-custom-tool-endpoint]').selectOption('ep1')
check('绑定后只填路径,不再要完整地址', await dlg.locator('[data-custom-tool-path]').count() === 1
&& await dlg.locator('input[placeholder^="https://api.example.com"]').count() === 0)
await dlg.locator('[data-custom-tool-path]').fill('/orders/{{ order_id }}')
await dlg.getByRole('button', { name: '保存', exact: true }).click()
const body = (await waitFor(page, async () => state.tools.length === 1)) ? state.tools[0].body : null
check('保存的配置是 {endpoint, method, path, query},没有地址和请求头', body?.config?.endpoint === 'ep1'
&& body.config.path === '/orders/{{ order_id }}' && !('url' in body.config) && !('headers' in body.config), JSON.stringify(body?.config))
})
await section('MCP:认证头按掩码编辑;本地子进程只有管理员能建、能改', async () => {
const builder = { mode: 'local', username: 'li', display_name: '李工', role: 'builder', groups: [], verified: true }
const { page, state } = await open('/tools/mcp', { me: builder })
await page.locator('article', { hasText: 'files' }).getByRole('button', { name: '编辑' }).click()
let dlg = page.locator('[role="dialog"]')
check('搭建者打开本地子进程服务:只读,说明原因,没有保存', await dlg.locator('[data-mcp-stdio-locked]').count() === 1
&& await dlg.getByRole('button', { name: '保存', exact: true }).count() === 0)
await dlg.getByRole('button', { name: '取消' }).click()
await page.locator('article', { hasText: 'crm' }).getByRole('button', { name: '编辑' }).click()
dlg = page.locator('[role="dialog"]')
check('认证头显示掩码', await dlg.locator('[data-mcp-header-value]').first().inputValue() === 'Bearer ****9a2c')
check('传输方式里本地子进程不可选', await dlg.locator('option[value="stdio"]').isDisabled())
await dlg.getByRole('button', { name: '保存', exact: true }).click()
check('不改认证头:原样提交掩码(服务端认作保持原值)', await waitFor(page, async () => state.mcp.length === 1)
&& state.mcp[0].body?.headers?.Authorization === 'Bearer ****9a2c', JSON.stringify(state.mcp[0]?.body))
})
await section('身份:单点登录映射管理员,用户或组至少一项', async () => {
const { page } = await open('/settings/identity')
await page.locator('[data-identity-mode-option="oidc"]').click()
check('有「映射为管理员的用户」', await page.locator('[data-identity-admin-users]').count() === 1)
check('用户和组都没填:说明至少一项,不能保存', (await page.locator('[data-identity-oidc]').innerText()).includes('至少要配置一个映射为管理员的用户或组')
&& await page.locator('[data-identity-save]').isDisabled())
await page.locator('[data-identity-admin-users]').fill('admin')
check('只填了管理员用户:可以保存', await page.locator('[data-identity-save]').isEnabled())
})
await section('设置:开了登录的使用者只剩个人的主题和通知,换主题不写服务端', async () => {
const user = { mode: 'local', username: 'wang', display_name: '王五', role: 'user', groups: [], verified: true }
const { page, state, errors } = await open('/settings/identity', { me: user })
const tabs = (await page.locator('[role=tab]').allInnerTexts()).map((t) => t.trim())
check('页签只剩偏好设置和通知', tabs.length === 2 && tabs.some((t) => t.includes('偏好')) && tabs.some((t) => t.includes('通知')), tabs.join(' | '))
check('只给管理员的页签地址纠正到偏好设置', new URL(page.url()).pathname === '/settings/prefs', page.url())
check('偏好只有主题,没有署名和运行默认值', await page.locator('[data-prefs-personal]').count() === 1
&& await page.locator('#pref-actor').count() === 0 && await page.locator('[data-prefs-shared]').count() === 0)
await page.getByRole('radio', { name: /浅色/ }).click()
await page.waitForTimeout(300)
check('换主题只存本机,不往服务端写', state.prefs.length === 0, JSON.stringify(state.prefs))
check('说明主题只保存在当前浏览器', (await page.locator('body').innerText()).includes('主题只保存在当前浏览器中'))
check('没有报错提示', !(await page.locator('body').innerText()).includes('未能保存到设置'))
check('没有运行时报错', errors.length === 0, errors.slice(0, 2).join(' | '))
})
check('检查没有写库(兜底拦下的写请求)', writes.length === 0, writes.slice(0, 4).join('、'))
console.log(failed ? `\n${failed} 项未通过` : '\n全部通过')
await browser.close()