应用平台 FE-5 使用面:表单渲染器与子集校验、待办卡(会签进度、动作确认哈希卡、核实选项)、视图渲染与组件目录 v1 的渲染器(印章、指标点开出处、趋势与图表、表格、报告)、应用首页 / 应用页 / 发起 / 实例 / 待办 / 登录页、导航加「应用」与徽标按来源分开、按角色收起导航、401 跳登录与请求头;新检查脚本 check-apps、check-inbox、check-auth(含统一复核后的修复)

This commit is contained in:
ThearchyHelios
2026-10-14 20:05:23 +08:00
parent 0f32b8335e
commit 22021e76c3
35 changed files with 5097 additions and 179 deletions
+393
View File
@@ -0,0 +1,393 @@
// 应用使用面(/apps、/apps/:appId、/apps/:appId/p/:pageId、/apps/:appId/new/:entryId、/apps/:appId/i/:runId)的回归检查。
//
// 守的是这些「看着没坏、其实不对」的地方:
// - 应用首页三个页签(待办 / 应用 / 我发起的)记在地址上;关登录时挂一行说明(所有人都能用全部功能,签批人是自报署名);
// 需升级的应用照实标出来;
// - 应用页按视图模型渲染:印章四项(截至 / 口径 / 出具档位 / 来源)和服务端标出的错位照写;指标块的数是按钮,点开走
// 指标链接口(GET /runs/{id}/evidence/metrics/{node}/{metric}),面板里有指标步骤;没有出处的数照实标「无证据」;
// 趋势是自绘 SVG,升版不可比的地方画断开线并写明;「查看数据」给出表格视图;表格点表头排序、遮罩列写「已遮罩」;
// 不认识的组件写「此组件需要更新前端」,不报错、不空白;服务端解析出错的组件(problems)列在页面顶上;
// 有视图在生成时自动重取;
// - 入口页:必填没填本地拦下、错误挂到字段下面;服务端 422 的 {errors:[{path, code, message}]} 按 path 挂回字段,
// 对不上字段的列在表单顶上;⌘/Ctrl+Enter 发起;成功后进实例页;需升级时不让发起;
// - 实例页:状态、印章、进度、本实例的待办卡(就地处理)、动作状态(哈希前 8 位、环境);
// - 窄屏(390px)不出横向滚动。
//
// 页面是真页面(走真的应用外壳),/api/apps/**、/api/tasks/**、指标链接口在浏览器层答掉,数据是这里虚构的
// (「门店周报」「报销审批」);其余 GET 放行到服务端(外壳要它),写请求一律拦下、记在探针里,不碰真实写接口。
//
// node scripts/check-apps.mjs
// 对别的实例跑时带上地址:AGENTLAB_WEB=http://localhost:<前端端口> node scripts/check-apps.mjs
// CHECK_ONLY=首页,入口 只跑段名里含这些字的段。
import { chromium } from '../frontend/node_modules/playwright-core/index.mjs'
const WEB = process.env.AGENTLAB_WEB ?? 'http://localhost:5273'
const CHROME = process.env.CHROME_PATH ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
let failed = 0
const check = (name, cond, detail = '') => {
console.log(` ${cond ? '✓' : '✗'} ${name}${detail ? ` — ${detail}` : ''}`)
if (!cond) failed++
}
const ONLY = (process.env.CHECK_ONLY ?? '').split(',').map((s) => s.trim()).filter(Boolean)
const opened = new Set()
async function section(name, fn) {
if (ONLY.length && !ONLY.some((k) => name.includes(k))) return
console.log(`\n=== ${name} ===`)
try {
await fn()
} catch (e) {
check(`${name} 中途出错`, false, String(e?.message ?? e).split('\n')[0])
} finally {
for (const c of opened) await c.close().catch(() => {})
opened.clear()
}
}
const ago = (ms) => new Date(Date.now() - ms).toISOString()
const RUN = 'run_week_14'
// ---------------------------------------------------------------- 假数据
const APPS = [
{ id: 'app_weekly', name: '门店周报', description: '每周一看各门店的销售概况', icon: 'app', status: 'active',
published_version: 3, level: 'governed', needs_upgrade: false, pending_tasks: 0, my_role: 'manage', updated_at: ago(3600_000) },
{ id: 'app_claim', name: '报销审批', description: '员工发起报销,财务会签后付款', icon: 'app', status: 'active',
published_version: 2, level: 'published', needs_upgrade: true, pending_tasks: 1, my_role: 'use', updated_at: ago(7200_000) },
]
const STAMP = {
as_of: ago(86400_000), as_of_text: '截至 2026-10-13 10:05;统计期 week 2026-W41', pin: '周销售 v7', graph_hash: '3fa2c1d0',
calibers: [{ name: '周销售口径', version: 'v3' }], tier: 'formal', tier_text: '完整出具',
from: '定时任务「周一 10 点」第 14 次', sealed: true, notes: ['定时任务已改为运行 v8,本应用固定在 v7'],
}
const metricEv = (metric) => ({ run_id: RUN, kind: 'metric', node: 'kpi', metric, eid: `ev:metric:${metric}` })
const point = (i, value) => ({
run_id: `run_w${i}`, as_of: new Date(Date.UTC(2026, 8, 1 + i * 7)).toISOString(), value, text: `${value} 万元`,
evidence: { run_id: `run_w${i}`, kind: 'metric', node: 'kpi', metric: 'gmv', eid: `ev:${i}` },
})
const HOME = {
format: 'agentlab.view/1',
app: { id: 'app_weekly', name: '门店周报', version: 3, level: 'governed', needs_upgrade: false },
page: { id: 'home', title: '本周概览' },
pages: [{ id: 'home', title: '本周概览' }, { id: 'detail', title: '门店明细' }],
sources: { wk: { state: 'ok', run_id: RUN, stamp: STAMP } },
tree: [
{ id: 'stamp', type: 'stamp', props: {}, data: { view: 'wk', state: 'ok', stamp: STAMP } },
{ id: 'kpis', type: 'columns', props: { count: 2 }, children: [
{ id: 'gmv', type: 'metric', props: { label: '销售额' },
data: { state: 'ok', text: '45.68 万元', name: '销售额', unit: '', evidence: metricEv('gmv') } },
{ id: 'orders', type: 'metric', props: { label: '订单数' }, data: { state: 'ok', text: '1,284 单', name: '订单数' } },
] },
{ id: 'trend', type: 'series', props: { label: '销售额趋势' }, data: {
state: 'ok', mode: 'incomparable', unit: '万元',
series: [
{ version: 6, label: 'v6', points: [point(0, 40.1), point(1, 41.3), point(2, 39.8)] },
{ version: 7, label: 'v7', points: [point(3, 44.2), point(4, 45.68)] },
],
breaks: [{ after_run: 'run_w2', from: 6, to: 7, text: '口径从 v6 升到 v7,前后不可比' }],
} },
{ id: 'stores', type: 'table', props: { title: '门店排行' }, data: {
state: 'ok', columns: ['门店', '销售额', '店长手机'], masked: ['店长手机'], total_rows: 3, truncated: false,
rows: [['南山店', 120.5, '已遮罩'], ['福田店', 98.2, '已遮罩'], ['宝安店', 130.1, '已遮罩']],
evidence: { run_id: RUN, kind: 'query', node: 'q1', artifact: 'art_q1' },
} },
{ id: 'future', type: 'gauge3d', props: {} },
{ id: 'broken', type: 'metric', props: { label: '毛利率' }, data: { state: 'error' } },
],
forms: {},
problems: [{ component: 'broken', code: 'view.resolve_failed', message: '解析出错:KeyError' }],
}
const CLAIM_HOME = {
format: 'agentlab.view/1',
app: { id: 'app_claim', name: '报销审批', version: 2, level: 'published', needs_upgrade: false },
page: { id: 'home', title: '报销' },
pages: [{ id: 'home', title: '报销' }],
sources: {},
tree: [
{ id: 'new', type: 'entry_button', props: { entry: 'apply' }, data: { entry: 'apply', label: '发起报销', disabled: false } },
{ id: 'mine', type: 'instance_list', props: { entry: 'apply', who: 'mine' }, data: { who: 'mine', entry: 'apply', items: [] } },
],
forms: {
apply: {
format: 'agentlab.form/1', type: 'object', required: ['amount', 'reason'], 'x-order': ['amount', 'reason', 'kind'],
properties: {
amount: { type: 'number', title: '金额(元)', minimum: 0 },
reason: { type: 'string', title: '事由', 'x-widget': 'textarea', maxLength: 500 },
kind: { type: 'string', title: '类别', enum: ['travel', 'meal'], 'x-enum-labels': ['差旅', '餐费'] },
},
},
},
problems: [],
}
const TASK = {
id: 'task_fin', approval_id: 'ap_fin', run_id: 'run_claim_1', node_id: 'finance', app_id: 'app_claim', app_name: '报销审批',
app_version: 2, workflow_name: '报销流程', kind: 'approve', title: '财务审批', form: null, policy: { kind: 'all' },
status: 'pending', due_at: new Date(Date.now() + 3600_000).toISOString(), escalation_level: 0,
payload: { kind: 'human_node', message: '张三报销差旅 **1,200 元**,请审批' },
assignments: [
{ id: 'as1', principal_kind: 'user', principal: 'lisi', source: 'slot:finance', status: 'responded', responded_by: 'lisi',
responded_at: ago(600_000), decision: 'approve', verified: false },
{ id: 'as2', principal_kind: 'user', principal: 'wangwu', source: 'slot:finance', status: 'pending', responded_by: null,
responded_at: null, decision: null, verified: false },
],
can_respond: true, outcome: null, resolved_by: null, resolved_at: null, created_at: ago(1800_000),
}
const INSTANCE = {
run_id: 'run_claim_1', title: '张三 的报销', entry_id: 'apply', status: 'interrupted', started_by: '张三',
created_at: ago(1800_000), finished_at: null, pending_tasks: 1, tier: null,
view: {
format: 'agentlab.view/1',
app: { id: 'app_claim', name: '报销审批', version: 2, level: 'published', needs_upgrade: false },
page: { id: 'instance', title: '实例' }, pages: [{ id: 'home', title: '报销' }, { id: 'instance', title: '实例' }],
sources: { inst: { state: 'running', run_id: 'run_claim_1', stamp: null, message: '正在运行,完成后刷新页面' } },
tree: [
{ id: 'inst_header', type: 'instance_header', props: {}, data: {
state: 'ok', run_id: 'run_claim_1', title: '张三 的报销', status: 'interrupted', status_text: '等待处理',
started_by: '张三', created_at: ago(1800_000), finished_at: null, pending_tasks: 1, stamp: null } },
{ id: 'inst_timeline', type: 'instance_timeline', props: {}, data: {
state: 'ok', status: 'interrupted', status_text: '等待处理', steps: [
{ node: 'input', title: '报销单', state: 'done', at: ago(1790_000) },
{ node: 'finance', title: '财务审批', state: 'waiting', at: ago(1700_000) },
] } },
{ id: 'inst_tasks', type: 'task_list', props: { scope: 'instance' }, data: { scope: 'instance', items: [] } },
{ id: 'pay', type: 'action_status', props: { label: '付款' }, data: { state: 'ok', node: 'pay', records: [
{ id: 'act1', state: 'unknown', environment: 'prod', attempt: 1, payload_hash: '9c1e44ab', error: '请求超时' },
] } },
],
forms: {}, problems: [],
},
}
const METRIC_CHAIN = {
chain: [
{ step: 'metric', node_id: 'kpi', metric: 'gmv', name: '销售额', value: 456800, formula: 'sum(amount)',
substituted: 'sum(…) = 456800', inputs: [] },
],
seal: { sealed: true, ok: true, covered: true },
redacted: { columns: [] },
}
// ---------------------------------------------------------------- 浏览器
const browser = await chromium.launch({ executablePath: CHROME })
async function open({ width = 1280, height = 900, state }) {
const ctx = await browser.newContext({ viewport: { width, height } })
opened.add(ctx)
const page = await ctx.newPage()
page.errors = []
page.on('pageerror', (e) => page.errors.push(e.message))
await page.route((url) => url.pathname.startsWith('/api/'), (route) => {
const r = route.request()
const url = new URL(r.url())
const p = url.pathname
if (r.method() !== 'GET') {
state.writes.push({ method: r.method(), path: p, body: r.postData() })
if (p === '/api/apps/app_claim/entries/apply') {
const body = JSON.parse(r.postData() || '{}')
if (state.reject422) {
return route.fulfill({ status: 422, json: { detail: '表单没有通过校验', errors: [
{ path: 'amount', code: 'maximum', message: '不能大于 5000' },
{ path: 'approver', code: 'required', message: '缺少审批人' },
] } })
}
return route.fulfill({ status: 201, json: { run_id: 'run_claim_1', title: `${body.values?.reason ?? ''}` } })
}
if (p.startsWith('/api/tasks/') && p.endsWith('/respond')) {
return route.fulfill({ json: { task: { ...TASK, status: 'resolved', can_respond: false }, resolved: true } })
}
return route.fulfill({ status: 503, json: { detail: '检查脚本拦下了写请求' } })
}
if (p === '/api/auth/me') return route.fulfill({ json: { mode: 'off', username: null, display_name: null, role: 'admin', groups: [], verified: false } })
if (p === '/api/apps') return route.fulfill({ json: { items: APPS } })
if (p === '/api/apps/app_weekly/pages/home') {
state.pageHits = (state.pageHits ?? 0) + 1
return route.fulfill({ json: state.home ?? HOME })
}
if (p === '/api/apps/app_weekly/pages/detail') return route.fulfill({ json: { ...HOME, page: { id: 'detail', title: '门店明细' }, tree: [] } })
if (p === '/api/apps/app_claim/pages/home') return route.fulfill({ json: state.claimHome ?? CLAIM_HOME })
if (/^\/api\/apps\/[^/]+\/instances$/.test(p)) return route.fulfill({ json: { items: p.includes('app_claim') ? [INSTANCE] : [] } })
if (p === '/api/apps/app_claim/instances/run_claim_1') return route.fulfill({ json: INSTANCE })
if (p === `/api/runs/${RUN}/evidence/metrics/kpi/gmv`) {
state.chainHits = (state.chainHits ?? 0) + 1
return route.fulfill({ json: METRIC_CHAIN })
}
if (p === '/api/tasks/count') return route.fulfill({ json: { mine: 1, apps: 1, other: 0 } })
if (p === '/api/tasks') return route.fulfill({ json: { items: url.searchParams.get('status') === 'resolved' ? [] : [TASK] } })
if (p === '/api/tasks/task_fin') return route.fulfill({ json: TASK })
return route.continue()
})
return { ctx, page }
}
const noHScroll = (page) => page.evaluate(() => document.documentElement.scrollWidth <= innerWidth + 1)
// ---------------------------------------------------------------- 首页
await section('首页:三个页签、关登录说明、需升级', async () => {
const state = { writes: [] }
const { page } = await open({ state })
await page.goto(`${WEB}/apps`)
const tabs = page.getByRole('tablist', { name: '应用' })
await tabs.waitFor({ timeout: 15000 })
check('三个页签:待办、应用、我发起的', (await tabs.getByRole('tab').allInnerTexts()).map((t) => t.replace(/\d+/g, '').trim()).join(',') === '待办,应用,我发起的')
check('默认是待办页签', (await page.locator('[data-apps-home]').getAttribute('data-apps-home')) === 'inbox')
check('关登录时挂一行说明(自报署名)', /未开启登录/.test(await page.locator('[data-auth-off]').innerText()))
check('待办按应用分组', (await page.locator('[data-inbox-group="app_claim"]').count()) === 1)
check('会签的待办写进度', /1\/2 已同意/.test(await page.locator('[data-inbox-signoffs]').innerText()))
await tabs.getByRole('tab', { name: /应用/ }).click()
check('页签记在地址上', /tab=apps/.test(page.url()), page.url())
await page.locator('[data-app]').first().waitFor({ timeout: 5000 })
check('两个应用卡', (await page.locator('[data-app]').count()) === 2)
check('需升级的应用照实标出', (await page.locator('[data-app="app_claim"] [data-app-needs-upgrade]').count()) === 1)
check('能管理的应用有「编辑」,只能用的没有',
(await page.locator('[data-app="app_weekly"] a[href$="/edit"]').count()) === 1
&& (await page.locator('[data-app="app_claim"] a[href$="/edit"]').count()) === 0)
await page.getByRole('tab', { name: '我发起的' }).click()
await page.locator('[data-mine] [data-instance]').first().waitFor({ timeout: 5000 })
check('我发起的:合各应用的实例,链到实例页',
(await page.locator('[data-mine] a[href="/apps/app_claim/i/run_claim_1"]').count()) === 1)
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
})
// ---------------------------------------------------------------- 应用页
await section('应用页:印章、指标、出处、趋势、表格、未知组件', async () => {
const state = { writes: [] }
const { page } = await open({ state })
await page.goto(`${WEB}/apps/app_weekly`)
await page.locator('[data-view-renderer]').waitFor({ timeout: 15000 })
const stamp = page.locator('[data-stamp]').first()
const stampText = await stamp.innerText()
check('印章四项:截至、口径、出具档位、来源', ['截至', '口径', '出具档位', '来源'].every((k) => stampText.includes(k)), stampText.replace(/\n/g, ' '))
check('印章写口径名和哈希前 8 位', stampText.includes('周销售 v7 · 3fa2c1d0') && stampText.includes('周销售口径 v3'))
check('服务端标出的错位照写', (await stamp.locator('[data-stamp-note]').innerText()).includes('固定在 v7'))
check('页面有两页:页签', (await page.getByRole('tab').count()) >= 2)
const gmv = page.locator('[data-node="gmv"] button[data-evidence="metric"]')
check('指标块的数是按钮', (await gmv.innerText()).includes('45.68 万元'))
check('没有出处的数照实标「无证据」', (await page.locator('[data-node="orders"] [data-evidence="none"]').innerText()).includes('无证据'))
await gmv.click()
const panel = page.locator('[data-evidence-panel]')
check('点数字打开出处面板', await panel.waitFor({ timeout: 5000 }).then(() => true, () => false))
check('走的是指标链接口', state.chainHits === 1, `${state.chainHits ?? 0} 次`)
await page.keyboard.press('Escape')
const series = page.locator('[data-component="series"]')
check('趋势是 SVG', (await series.locator('svg[role="img"]').count()) === 1)
check('升版不可比处画断开线', (await series.locator('[data-plot-break]').count()) === 1)
check('升版说明写在图下', (await series.locator('[data-series-note]').innerText()).includes('前后不可比'))
check('两条线有图例', (await series.locator('ul li').count()) === 2)
await series.getByRole('button', { name: '查看数据' }).click()
check('「查看数据」给出表格视图', (await series.locator('table tbody tr').count()) === 5)
const table = page.locator('[data-component="table"]')
const firstCell = () => table.locator('tbody tr').first().locator('td').first().innerText()
check('表格按服务端给的顺序', (await firstCell()) === '南山店')
await table.getByRole('button', { name: /^销售额/ }).click()
check('点表头升序', (await firstCell()) === '福田店', await firstCell())
await table.getByRole('button', { name: /^销售额/ }).click()
check('再点降序', (await firstCell()) === '宝安店', await firstCell())
check('遮罩列写「已遮罩」', (await table.locator('td[data-masked]').count()) === 3)
check('不认识的组件写「此组件需要更新前端」', (await page.locator('[data-unknown-component="gauge3d"]').innerText()).includes('此组件需要更新前端'))
check('服务端解析出错的组件列在顶上', (await page.locator('[data-view-problems]').innerText()).includes('解析出错'))
check('出错的组件就地说明', (await page.locator('[data-node="broken"] [data-block-state="error"]').count()) === 1)
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
})
await section('应用页:视图生成中自动重取、需升级提示', async () => {
const running = { ...HOME, app: { ...HOME.app, needs_upgrade: true },
sources: { wk: { state: 'running', run_id: RUN, stamp: null, message: '正在运行,完成后刷新页面' } },
tree: [{ id: 'stamp', type: 'stamp', props: {}, data: { view: 'wk', state: 'running', stamp: null, message: '正在运行,完成后刷新页面' } }] }
const state = { writes: [], home: running }
const { page } = await open({ state })
await page.goto(`${WEB}/apps/app_weekly`)
await page.locator('[data-view-renderer]').waitFor({ timeout: 15000 })
check('需升级照实提示', (await page.locator('[data-app-needs-upgrade]').count()) === 1)
check('生成中写明在等', (await page.locator('[data-block-state="running"]').count()) === 1)
const before = state.pageHits
state.home = HOME
await page.waitForTimeout(6000)
check('有视图在生成时 5 秒后自动重取', state.pageHits > before, `${before} → ${state.pageHits}`)
check('生成完换上数据', (await page.locator('[data-node="gmv"]').count()) === 1)
})
// ---------------------------------------------------------------- 入口
await section('入口:本地校验、422 挂回字段、发起后进实例页', async () => {
const state = { writes: [] }
const { page } = await open({ state })
await page.goto(`${WEB}/apps/app_claim/new/apply`)
const form = page.locator('[data-schema-form]')
await form.waitFor({ timeout: 15000 })
check('标题用发起按钮上的名字', (await page.locator('h2').first().innerText()) === '发起报销')
check('必填有星号', (await form.locator('[data-field="amount"] label span[aria-hidden]').innerText()) === '*')
check('字段按 x-order 排', (await form.locator('[data-field]').evaluateAll((els) => els.map((e) => e.getAttribute('data-field')))).join(',') === 'amount,reason,kind')
check('枚举画成下拉,显示中文', (await form.locator('[data-field="kind"] option').allInnerTexts()).includes('差旅'))
await page.locator('[data-entry-submit]').click()
check('必填没填本地拦下,不发请求', !state.writes.some((w) => w.path.endsWith('/entries/apply')))
check('错误挂在字段下面', (await form.locator('[data-field="amount"] [data-field-error="required"]').count()) === 1)
await form.locator('[data-field="amount"] input').fill('1.')
check('数字框能打出小数点', (await form.locator('[data-field="amount"] input').inputValue()) === '1.')
await form.locator('[data-field="amount"] input').fill('9000')
await form.locator('[data-field="reason"] textarea').fill('出差深圳')
state.reject422 = true
await page.locator('[data-entry-submit]').click()
await form.locator('[data-field="amount"] [data-field-error="maximum"]').waitFor({ timeout: 5000 }).catch(() => {})
check('服务端 422 按 path 挂回字段', (await form.locator('[data-field="amount"] [data-field-error="maximum"]').innerText()).includes('5000'))
check('对不上字段的错误列在表单顶上', (await form.locator('[data-form-errors]').innerText()).includes('缺少审批人'))
const sent = JSON.parse(state.writes.find((w) => w.path.endsWith('/entries/apply')).body)
check('交上去的金额是数,不是字符串', sent.values.amount === 9000, JSON.stringify(sent.values))
state.reject422 = false
await form.locator('[data-field="amount"] input').fill('1200')
await form.locator('[data-field="reason"] textarea').press(process.platform === 'darwin' ? 'Meta+Enter' : 'Control+Enter')
check('⌘/Ctrl+Enter 发起,成功后进实例页', await page.waitForURL(/\/apps\/app_claim\/i\/run_claim_1/, { timeout: 5000 }).then(() => true, () => false), page.url())
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
})
await section('入口:需升级时不让发起', async () => {
const state = { writes: [], claimHome: { ...CLAIM_HOME, app: { ...CLAIM_HOME.app, needs_upgrade: true } } }
const { page } = await open({ state })
await page.goto(`${WEB}/apps/app_claim/new/apply`)
await page.locator('[data-schema-form]').waitFor({ timeout: 15000 })
check('写明需升级', (await page.locator('[data-app-needs-upgrade]').count()) === 1)
check('发起按钮停用', await page.locator('[data-entry-submit]').isDisabled())
})
// ---------------------------------------------------------------- 实例
await section('实例页:状态、进度、待办卡、动作状态', async () => {
const state = { writes: [] }
const { page } = await open({ state })
await page.goto(`${WEB}/apps/app_claim/i/run_claim_1`)
await page.locator('[data-view-renderer]').waitFor({ timeout: 15000 })
check('写出发起人', (await page.locator('[data-instance-page]').innerText()).includes('由「张三」发起'))
check('进度按节点列出', (await page.locator('[data-timeline-step]').count()) === 2)
await page.locator('[data-component="task_list"] [data-task]').waitFor({ timeout: 5000 })
check('本实例的待办就地处理(完整的待办卡)', (await page.locator('[data-component="task_list"] [data-task-approve]').count()) === 1)
check('动作状态写结果未知和环境', /结果未知/.test(await page.locator('[data-action="unknown"]').innerText())
&& /生产环境/.test(await page.locator('[data-action="unknown"]').innerText()))
check('关登录(等同管理员)时接运行流', (await page.locator('[data-instance-follow]').getAttribute('data-instance-follow')) === 'stream')
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
})
await section('窄屏:390px 不出横向滚动', async () => {
const state = { writes: [] }
const { page } = await open({ width: 390, height: 844, state })
for (const path of ['/apps', '/apps/app_weekly', '/apps/app_claim/new/apply', '/apps/app_claim/i/run_claim_1']) {
await page.goto(`${WEB}${path}`)
await page.waitForTimeout(800)
check(`${path} 没有横向滚动`, await noHScroll(page))
}
})
await browser.close()
console.log(failed ? `\n✗ ${failed} 项未通过` : '\n✓ 全部通过')
process.exit(failed ? 1 : 0)
+207
View File
@@ -0,0 +1,207 @@
// 登录与按角色收起的外壳(/login、导航、账户菜单、401 跳登录、防跨站请求头)的回归检查。
//
// 守的是这些「看着没坏、其实不对」的地方:
// - 开了登录、没登录:任何页面都送到 /login?next=原处,登录成功后回到原处;登录页按服务端说的登录方式给账号密码表单
// 或单点登录按钮(单点登录时本地账号收在下面);密码不对写人话;单点登录回调失败带回的原因照写;next 只认站内路径;
// - 会话中途失效:任何接口回 401 都整页跳登录页,带上原处;
// - 非 GET 请求都带 X-AgentLab-Request 头(服务端开登录时据此防跨站);
// - 使用者(user 角色):导航只有「应用」和「设置」,别的地址送回应用首页,⌥ 数字切不到看不见的页;没有署名框,
// 账户菜单写显示名、角色、退出登录;待办卡写「以登录身份处理」;
// - 搭建者:导航九项都在,账户菜单写搭建者;
// - 关登录:/login 直接回首页;导航底部是署名入口,没有账户菜单;应用首页挂「未开启登录」的说明。
//
// 身份接口在浏览器层答掉(/api/auth/**),按 state 切登录方式和角色;其余 GET 放行(外壳要它),写请求拦下记在探针里。
// 编排者的完整关口另起一套开着 local 登录的服务跑真接口,见 docs/design §6.3。
//
// node scripts/check-auth.mjs
// 对别的实例跑时带上地址:AGENTLAB_WEB=http://localhost:<前端端口> node scripts/check-auth.mjs
import { chromium } from '../frontend/node_modules/playwright-core/index.mjs'
const WEB = process.env.AGENTLAB_WEB ?? 'http://localhost:5273'
const CHROME = process.env.CHROME_PATH ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
let failed = 0
const check = (name, cond, detail = '') => {
console.log(` ${cond ? '✓' : '✗'} ${name}${detail ? ` — ${detail}` : ''}`)
if (!cond) failed++
}
const ONLY = (process.env.CHECK_ONLY ?? '').split(',').map((s) => s.trim()).filter(Boolean)
const opened = new Set()
async function section(name, fn) {
if (ONLY.length && !ONLY.some((k) => name.includes(k))) return
console.log(`\n=== ${name} ===`)
try {
await fn()
} catch (e) {
check(`${name} 中途出错`, false, String(e?.message ?? e).split('\n')[0])
} finally {
for (const c of opened) await c.close().catch(() => {})
opened.clear()
}
}
const PEOPLE = {
user: { username: 'zhangsan', display_name: '张三', role: 'user', groups: ['财务'] },
builder: { username: 'lisi', display_name: '李四', role: 'builder', groups: [] },
}
const TASK = {
id: 'task_x', approval_id: 'ap_x', run_id: 'run_x', node_id: 'finance', app_id: 'app_claim', app_name: '报销审批',
app_version: 2, workflow_name: '报销流程', kind: 'approve', title: '财务审批', form: null, policy: { kind: 'any' },
status: 'pending', due_at: null, escalation_level: 0, payload: { kind: 'human_node', message: '请审批' },
assignments: [{ id: 'a1', principal_kind: 'user', principal: 'zhangsan', source: 'slot:finance', status: 'pending',
responded_by: null, responded_at: null, decision: null, verified: false }],
can_respond: true, outcome: null, resolved_by: null, resolved_at: null, created_at: new Date().toISOString(),
}
const browser = await chromium.launch({ executablePath: CHROME })
/**
* state.mode:off / local / oidc;state.who:登录了是谁(user / builder),没登录为空;state.expire:之后的接口一律回 401
*/
async function open(state) {
const ctx = await browser.newContext({ viewport: { width: 1280, height: 860 } })
opened.add(ctx)
const page = await ctx.newPage()
page.errors = []
page.on('pageerror', (e) => page.errors.push(e.message))
await page.route((url) => url.pathname.startsWith('/api/'), (route) => {
const r = route.request()
const p = new URL(r.url()).pathname
const headers = r.headers()
if (r.method() !== 'GET') {
state.writes.push({ method: r.method(), path: p, csrf: headers['x-agentlab-request'], body: r.postData() })
if (p === '/api/auth/login') {
const body = JSON.parse(r.postData() || '{}')
if (body.password !== 'right') return route.fulfill({ status: 401, json: { detail: '用户名或密码不正确' } })
state.who = body.username === 'lisi' ? 'builder' : 'user'
return route.fulfill({ json: { mode: state.mode, ...PEOPLE[state.who], verified: true } })
}
if (p === '/api/auth/logout') { state.who = null; return route.fulfill({ status: 204, body: '' }) }
return route.fulfill({ json: {} })
}
if (p === '/api/health') return route.continue()
if (p === '/api/auth/me') {
if (state.mode === 'off') return route.fulfill({ json: { mode: 'off', username: null, display_name: null, role: 'admin', groups: [], verified: false } })
if (!state.who) return route.fulfill({ status: 401, json: { detail: '请先登录', code: 'auth_required', mode: state.mode } })
return route.fulfill({ json: { mode: state.mode, ...PEOPLE[state.who], verified: true } })
}
if (state.mode !== 'off' && (!state.who || state.expire)) {
return route.fulfill({ status: 401, json: { detail: '请先登录', code: 'auth_required', mode: state.mode } })
}
if (p === '/api/apps') return route.fulfill({ json: { items: [] } })
if (p === '/api/tasks/count') return route.fulfill({ json: { mine: 1, apps: 1, other: 0 } })
if (p === '/api/tasks') return route.fulfill({ json: { items: [TASK] } })
if (p === '/api/tasks/task_x') return route.fulfill({ json: TASK })
// 使用者碰不到这些:服务端回 403
if (state.who === 'user' && /^\/api\/(workflows|approvals|runs|tools|providers|skills|kb|datasources)/.test(p)) {
return route.fulfill({ status: 403, json: { detail: '没有权限' } })
}
return route.continue()
})
return page
}
const nav = (page) => page.locator('nav[aria-label="主导航"]')
const navLabels = (page) => nav(page).locator('li > a[aria-keyshortcuts] > span:not([aria-hidden])').allInnerTexts()
await section('没登录:送到登录页,登录后回原处', async () => {
const state = { mode: 'local', who: null, writes: [] }
const page = await open(state)
await page.goto(`${WEB}/apps?tab=inbox`)
check('送到 /login 并带上原处', await page.waitForURL(/\/login\?next=%2Fapps%3Ftab%3Dinbox/, { timeout: 15000 }).then(() => true, () => false), page.url())
await page.locator('[data-login-form]').waitFor({ timeout: 8000 })
check('账号密码登录:有表单、没有单点登录按钮', (await page.locator('[data-login-oidc]').count()) === 0)
check('登录页不在外壳里(没有导航)', (await nav(page).count()) === 0)
await page.locator('#login-username').fill('zhangsan')
await page.locator('#login-password').fill('wrong')
await page.getByRole('button', { name: '登录' }).click()
check('密码不对写人话', (await page.locator('[data-login-error]').innerText()).includes('用户名或密码不正确'))
const tried = state.writes.find((w) => w.path === '/api/auth/login')
check('登录请求带 X-AgentLab-Request 头', tried?.csrf === '1', String(tried?.csrf))
check('密码不对不跳走(登录接口自己的 401 不触发跳转)', /\/login/.test(page.url()))
await page.locator('#login-password').fill('right')
await page.getByRole('button', { name: '登录' }).click()
check('登录后回到原处', await page.waitForURL(/\/apps\?tab=inbox/, { timeout: 15000 }).then(() => true, () => false), page.url())
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
})
await section('使用者:导航只有应用和设置、账户菜单、没有署名框', async () => {
const state = { mode: 'local', who: 'user', writes: [] }
const page = await open(state)
await page.goto(`${WEB}/apps`)
await nav(page).waitFor({ timeout: 15000 })
check('导航只有「应用」「设置」', (await navLabels(page)).join(',') === '应用,设置', (await navLabels(page)).join(','))
check('没有署名入口', (await nav(page).locator('a[href="/settings/prefs"]').count()) === 0)
check('没有「未开启登录」的说明', (await page.locator('[data-auth-off]').count()) === 0)
await nav(page).locator('[data-account]').click()
const menu = page.locator('[data-account-menu]')
check('账户菜单:显示名、角色', (await menu.innerText()).includes('张三') && (await menu.locator('[data-account-role]').innerText()) === '使用者')
await page.keyboard.press('Escape')
await page.goto(`${WEB}/studio`)
check('看不到的页面送回应用首页', await page.waitForURL(/\/apps(\?|$)/, { timeout: 8000 }).then(() => true, () => false), page.url())
await page.locator('main').click({ position: { x: 600, y: 400 } }).catch(() => {})
await page.keyboard.press('Alt+Digit2')
await page.waitForTimeout(500)
check('⌥2 切不到编排', !/\/studio/.test(page.url()), page.url())
await page.goto(`${WEB}/apps/inbox/task_x`)
await page.locator('[data-task]').waitFor({ timeout: 8000 })
check('待办卡写登录身份,不写署名', (await page.locator('[data-task-signer]').getAttribute('data-task-signer')) === 'verified'
&& (await page.locator('[data-task-signer]').innerText()).includes('张三(zhangsan)'))
await nav(page).locator('[data-account]').click()
await page.locator('[data-logout]').click()
check('退出登录回到登录页', await page.waitForURL(/\/login/, { timeout: 8000 }).then(() => true, () => false), page.url())
check('退出请求带 X-AgentLab-Request 头', state.writes.find((w) => w.path === '/api/auth/logout')?.csrf === '1')
})
await section('会话中途失效:401 整页跳登录', async () => {
const state = { mode: 'local', who: 'user', writes: [] }
const page = await open(state)
await page.goto(`${WEB}/apps?tab=apps`)
await nav(page).waitFor({ timeout: 15000 })
state.expire = true
await page.getByRole('tab', { name: '我发起的' }).click()
check('任何接口回 401 都跳 /login,带上原处', await page.waitForURL(/\/login\?next=/, { timeout: 15000 }).then(() => true, () => false), page.url())
})
await section('搭建者:导航九项、账户菜单', async () => {
const state = { mode: 'local', who: 'builder', writes: [] }
const page = await open(state)
await page.goto(`${WEB}/apps`)
await nav(page).waitFor({ timeout: 15000 })
check('导航九项都在', (await navLabels(page)).length === 9, (await navLabels(page)).join(','))
await nav(page).locator('[data-account]').click()
check('账户菜单写搭建者', (await page.locator('[data-account-role]').innerText()) === '搭建者')
})
await section('单点登录:按钮、本地账号收在下面、回调失败的原因', async () => {
const state = { mode: 'oidc', who: null, writes: [] }
const page = await open(state)
await page.goto(`${WEB}/login?next=%2Fapps&error=${encodeURIComponent('身份提供方拒绝了授权')}`)
const btn = page.locator('[data-login-oidc]')
await btn.waitFor({ timeout: 15000 })
check('单点登录按钮带上 next', (await btn.getAttribute('href')) === '/api/auth/oidc/start?next=%2Fapps', await btn.getAttribute('href'))
check('本地账号收在下面', (await page.locator('[data-login-form]').count()) === 0)
check('回调失败的原因照写', (await page.locator('[data-login-error]').innerText()).includes('拒绝了授权'))
await page.goto(`${WEB}/login?next=${encodeURIComponent('//evil.example/x')}`)
await btn.waitFor({ timeout: 8000 })
check('站外的 next 不认', (await btn.getAttribute('href')) === '/api/auth/oidc/start?next=%2F', await btn.getAttribute('href'))
})
await section('关登录:登录页回首页、署名入口、说明行', async () => {
const state = { mode: 'off', who: null, writes: [] }
const page = await open(state)
await page.goto(`${WEB}/login`)
check('/login 回首页', await page.waitForURL(/\/chat/, { timeout: 15000 }).then(() => true, () => false), page.url())
await nav(page).waitFor({ timeout: 8000 })
check('导航九项', (await navLabels(page)).length === 9)
check('底部是署名入口', (await nav(page).locator('a[href="/settings/prefs"]').count()) === 1)
check('没有账户菜单', (await nav(page).locator('[data-account]').count()) === 0)
await page.goto(`${WEB}/apps`)
check('应用首页挂「未开启登录」的说明', await page.locator('[data-auth-off]').waitFor({ timeout: 8000 }).then(() => true, () => false))
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
})
await browser.close()
console.log(failed ? `\n✗ ${failed} 项未通过` : '\n✓ 全部通过')
process.exit(failed ? 1 : 0)
+253
View File
@@ -0,0 +1,253 @@
// 待办箱与待办卡(/apps?tab=inbox、/apps/inbox/:taskId,run/TaskCard)的回归检查。
//
// 守的是这些「看着没坏、其实不对」的地方:
// - 会签进度:派给了谁、谁同意了、按策略还差几人(全体同意 / 至少 m 人),撤回的派单淡显在最后;
// - 时限与升级:剩多久、超了多久(红)、升级过几次;悬停写明超时只会提醒、升级或驳回,不会自动批准;
// - 动作确认的哈希卡:遮罩后的预览、内容哈希只写前 8 位(完整的在悬停里)、环境(生产环境醒目);确认时把哈希原样
// 带回(payload_hash 一字不差),内容不能在这里改;缺哈希时不让确认;
// - 核实待办:三个选项(已生效 + 外部单号 / 未生效重新发送 / 未生效放弃),没选不提交,选了已生效不填单号不提交;
// 提交的结论和单号照约定交给待办接口;
// - 等外部系统(signal):只有说明和关联键,没有批准、驳回;
// - 不是派给我的(can_respond 为假):只读,写明原因;
// - 补充输入带表单的:本地校验,服务端 422 的错误挂回字段;
// - 关登录时签批人一行写本机署名;会签只记下一票(resolved 为假)时提示「等待其他人处理」。
//
// 接口全部在浏览器层答掉(/api/tasks/**),数据是这里虚构的;写请求记在探针里。
//
// node scripts/check-inbox.mjs
// 对别的实例跑时带上地址:AGENTLAB_WEB=http://localhost:<前端端口> node scripts/check-inbox.mjs
import { chromium } from '../frontend/node_modules/playwright-core/index.mjs'
const WEB = process.env.AGENTLAB_WEB ?? 'http://localhost:5273'
const CHROME = process.env.CHROME_PATH ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
let failed = 0
const check = (name, cond, detail = '') => {
console.log(` ${cond ? '✓' : '✗'} ${name}${detail ? ` — ${detail}` : ''}`)
if (!cond) failed++
}
const ONLY = (process.env.CHECK_ONLY ?? '').split(',').map((s) => s.trim()).filter(Boolean)
const opened = new Set()
async function section(name, fn) {
if (ONLY.length && !ONLY.some((k) => name.includes(k))) return
console.log(`\n=== ${name} ===`)
try {
await fn()
} catch (e) {
check(`${name} 中途出错`, false, String(e?.message ?? e).split('\n')[0])
} finally {
for (const c of opened) await c.close().catch(() => {})
opened.clear()
}
}
const ago = (ms) => new Date(Date.now() - ms).toISOString()
const HASH = '9c1e44ab07d2f3a1c4b5e6f708192a3b4c5d6e7f8091a2b3c4d5e6f708192a3b'
const assignment = (id, principal, status, decision = null, extra = {}) => ({
id, principal_kind: 'user', principal, source: 'slot:finance', status, responded_by: status === 'responded' ? principal : null,
responded_at: status === 'responded' ? ago(600_000) : null, decision, verified: false, ...extra,
})
const base = {
approval_id: null, run_id: 'run_claim_1', node_id: 'finance', app_id: 'app_claim', app_name: '报销审批', app_version: 2,
workflow_name: '报销流程', form: null, policy: { kind: 'any' }, status: 'pending', due_at: null, escalation_level: 0,
payload: {}, assignments: [assignment('a0', 'zhangsan', 'pending')], can_respond: true, outcome: null, resolved_by: null,
resolved_at: null, created_at: ago(1800_000),
}
const TASKS = {
signoff: {
...base, id: 'signoff', approval_id: 'ap1', kind: 'approve', title: '财务会签', policy: { kind: 'quorum', m: 2 },
due_at: ago(2 * 3600_000), escalation_level: 1, node_label: '财务审批',
payload: { kind: 'human_node', message: '张三报销差旅 1,200 元' },
assignments: [
assignment('a1', 'lisi', 'responded', 'approve'),
assignment('a2', 'wangwu', 'pending'),
assignment('a3', 'zhaoliu', 'pending'),
assignment('a4', 'qianqi', 'withdrawn'),
],
},
confirm: {
...base, id: 'confirm', approval_id: 'ap2', kind: 'action_confirm', title: '确认付款', node_id: 'pay',
payload: { kind: 'action_confirm', capability: 'erp_pay', tool: 'erp_pay', environment: 'prod', payload_hash: HASH, attempt: 1,
preview: { 收款人: '张三', 金额: 1200, 银行账号: '已遮罩' } },
},
nohash: {
...base, id: 'nohash', approval_id: 'ap3', kind: 'action_confirm', title: '确认付款(缺哈希)', node_id: 'pay',
payload: { kind: 'action_confirm', capability: 'erp_pay', environment: 'test', preview: {} },
},
reconcile: {
...base, id: 'reconcile', kind: 'reconcile', title: '核实写入结果:erp_pay', node_id: 'pay',
payload: { kind: 'reconcile', action_id: 'act1', capability: 'erp_pay', environment: 'prod', payload_hash: HASH, attempt: 1,
idem_key: `${HASH.slice(0, 16)}:1`, state: 'unknown', error: '请求超时', request_at: ago(3600_000), preview: { 金额: 1200 } },
},
signal: {
...base, id: 'signal', kind: 'signal', title: '等付款回调', can_respond: false,
assignments: [{ ...assignment('h1', 'paid', 'pending'), principal_kind: 'hook' }],
payload: { kind: 'signal', correlation: 'order-8812', hook: 'paid' },
},
readonly: {
...base, id: 'readonly', approval_id: 'ap4', kind: 'approve', title: '总监审批', can_respond: false,
payload: { kind: 'human_node', message: '金额超过一万,需要总监批准' },
},
input: {
...base, id: 'input', approval_id: 'ap5', kind: 'input', title: '补填发票信息',
form: { format: 'agentlab.form/1', type: 'object', required: ['invoice'], properties: {
invoice: { type: 'string', title: '发票号', maxLength: 20 }, date: { type: 'string', title: '开票日期', format: 'date' } } },
payload: { kind: 'human_node', message: '请补填发票号' },
},
}
const browser = await chromium.launch({ executablePath: CHROME })
async function open(state) {
const ctx = await browser.newContext({ viewport: { width: 1280, height: 900 } })
opened.add(ctx)
const page = await ctx.newPage()
page.errors = []
page.on('pageerror', (e) => page.errors.push(e.message))
await page.addInitScript(() => localStorage.setItem('agentlab_actor', '审批人甲'))
await page.route((url) => url.pathname.startsWith('/api/'), (route) => {
const r = route.request()
const p = new URL(r.url()).pathname
if (r.method() !== 'GET') {
const body = r.postData() ? JSON.parse(r.postData()) : null
state.writes.push({ method: r.method(), path: p, body })
const m = p.match(/^\/api\/tasks\/([^/]+)\/respond$/)
if (m) {
if (m[1] === 'input' && state.reject422) {
return route.fulfill({ status: 422, json: { detail: '表单没有通过校验', code: 'form_invalid', errors: [
{ path: 'invoice', code: 'max_length', message: '最多 20 个字' }] } })
}
const t = TASKS[m[1]]
// 会签:这一票记下了,还没凑齐
const resolved = m[1] !== 'signoff'
return route.fulfill({ json: { task: { ...t, status: resolved ? 'resolved' : 'pending' }, resolved } })
}
return route.fulfill({ status: 503, json: { detail: '检查脚本拦下了写请求' } })
}
if (p === '/api/auth/me') return route.fulfill({ json: { mode: 'off', username: null, display_name: null, role: 'admin', groups: [], verified: false } })
if (p === '/api/tasks/count') return route.fulfill({ json: { mine: Object.keys(TASKS).length, apps: Object.keys(TASKS).length, other: 0 } })
if (p === '/api/tasks') return route.fulfill({ json: { items: Object.values(TASKS) } })
const m = p.match(/^\/api\/tasks\/([^/]+)$/)
if (m && TASKS[m[1]]) return route.fulfill({ json: TASKS[m[1]] })
return route.continue()
})
return page
}
const card = (page) => page.locator('[data-task]').first()
await section('会签进度、时限、升级', async () => {
const state = { writes: [] }
const page = await open(state)
await page.goto(`${WEB}/apps/inbox/signoff`)
await card(page).waitFor({ timeout: 15000 })
const s = page.locator('[data-signoffs]')
check('至少 2 人同意:进度写 1/2', (await s.innerText()).includes('1/2 已同意') && (await s.getAttribute('data-signoffs-need')) === '2')
check('策略写明', (await s.innerText()).includes('需 2 人同意'))
check('每个派单一行,撤回的在最后', (await s.locator('li').count()) === 4
&& (await s.locator('li').last().getAttribute('data-assignment')) === 'withdrawn')
const due = page.locator('[data-task-due]')
check('超时写「已超时」并标红', (await due.getAttribute('data-task-due')) === 'overdue' && /已超时/.test(await due.innerText()))
check('悬停写明不会自动批准', /不会自动批准/.test(await due.getAttribute('title')))
check('升级过写明', (await page.locator('[data-task-escalated]').innerText()).includes('已升级'))
check('卡头写节点名', (await card(page).innerText()).includes('节点「财务审批」'))
check('关登录时签批人写本机署名', (await page.locator('[data-task-signer="actor"]').innerText()).includes('审批人甲'))
await page.locator('[data-task-approve]').click()
await page.waitForTimeout(300)
const sent = state.writes.find((w) => w.path === '/api/tasks/signoff/respond')
check('批准走待办接口,decision 是 approve', sent?.body?.decision === 'approve', JSON.stringify(sent?.body))
check('只记下一票时提示等待其他人', await page.getByText('已记下你的意见,等待其他人处理').waitFor({ timeout: 3000 }).then(() => true, () => false))
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
})
await section('动作确认的哈希卡', async () => {
const state = { writes: [] }
const page = await open(state)
await page.goto(`${WEB}/apps/inbox/confirm`)
const box = page.locator('[data-action-confirm]')
await box.waitFor({ timeout: 15000 })
check('哈希只写前 8 位', (await box.locator('[data-action-hash]').innerText()) === HASH.slice(0, 8))
check('完整哈希在悬停里', (await box.locator('[data-action-hash]').getAttribute('title')).includes(HASH))
check('环境:生产环境', (await box.locator('[data-action-env]').innerText()) === '生产环境')
check('遮罩后的预览照写', (await box.locator('[data-action-preview]').innerText()).includes('已遮罩'))
check('内容不能在这里改:没有输入框改参数', (await box.locator('textarea').count()) === 0)
await box.locator('[data-action-confirm-send]').click()
await page.waitForTimeout(300)
const sent = state.writes.find((w) => w.path === '/api/tasks/confirm/respond')
check('确认时哈希原样带回', sent?.body?.payload_hash === HASH && sent?.body?.decision === 'approve', JSON.stringify(sent?.body))
})
await section('动作确认:缺哈希不让确认', async () => {
const page = await open({ writes: [] })
await page.goto(`${WEB}/apps/inbox/nohash`)
const box = page.locator('[data-action-confirm]')
await box.waitFor({ timeout: 15000 })
check('写明缺少内容哈希', (await box.innerText()).includes('缺少内容哈希'))
check('确认按钮停用', await box.locator('[data-action-confirm-send]').isDisabled())
})
await section('核实待办:三个选项', async () => {
const state = { writes: [] }
const page = await open(state)
await page.goto(`${WEB}/apps/inbox/reconcile`)
const box = page.locator('[data-reconcile]')
await box.waitFor({ timeout: 15000 })
check('三个选项', (await box.locator('[data-reconcile-option]').count()) === 3)
check('写明不会自动重发', (await box.innerText()).includes('不会自动重发'))
await box.locator('[data-reconcile-submit]').click()
check('没选不提交', !state.writes.length)
await box.locator('[data-reconcile-option="confirmed"] input').check()
await box.locator('[data-reconcile-submit]').click()
check('选了已生效不填单号不提交', !state.writes.length)
await box.locator('[data-reconcile-external]').fill('ERP-20261014-0001')
await box.locator('[data-reconcile-submit]').click()
await page.waitForTimeout(300)
const sent = state.writes.find((w) => w.path === '/api/tasks/reconcile/respond')
check('已生效 + 外部单号', sent?.body?.decision === 'confirmed' && sent?.body?.external_id === 'ERP-20261014-0001', JSON.stringify(sent?.body))
})
await section('等外部系统、只读', async () => {
const page = await open({ writes: [] })
await page.goto(`${WEB}/apps/inbox/signal`)
await page.locator('[data-task-signal]').waitFor({ timeout: 15000 })
check('写明由外部系统完成,带关联键', (await page.locator('[data-task-signal]').innerText()).includes('order-8812'))
check('没有批准、驳回', (await page.locator('[data-task-approve], [data-task-reject]').count()) === 0)
await page.goto(`${WEB}/apps/inbox/readonly`)
await page.locator('[data-task-readonly]').waitFor({ timeout: 15000 })
check('不是派给我的:只读并写明', (await page.locator('[data-task-readonly]').innerText()).includes('没有派给你'))
check('没有批准、驳回', (await page.locator('[data-task-approve], [data-task-reject]').count()) === 0)
})
await section('补充输入:表单校验、422 挂回字段', async () => {
const state = { writes: [] }
const page = await open(state)
await page.goto(`${WEB}/apps/inbox/input`)
const form = page.locator('[data-schema-form]')
await form.waitFor({ timeout: 15000 })
await page.locator('[data-task-approve]').click()
check('必填没填本地拦下', !state.writes.length && (await form.locator('[data-field="invoice"] [data-field-error="required"]').count()) === 1)
await form.locator('[data-field="invoice"] input').fill('FP-001')
await form.locator('[data-field="date"] input').fill('2026-10-14')
state.reject422 = true
await page.locator('[data-task-approve]').click()
await form.locator('[data-field-error="max_length"]').waitFor({ timeout: 3000 }).catch(() => {})
check('服务端 422 挂回字段', (await form.locator('[data-field="invoice"] [data-field-error="max_length"]').count()) === 1)
const sent = state.writes.find((w) => w.path === '/api/tasks/input/respond')
check('提交的是表单的值,decision 是 submit', sent?.body?.decision === 'submit' && sent?.body?.values?.invoice === 'FP-001', JSON.stringify(sent?.body))
})
await section('待办箱:列表和徽标', async () => {
const page = await open({ writes: [] })
await page.goto(`${WEB}/apps?tab=inbox`)
await page.locator('[data-inbox-task]').first().waitFor({ timeout: 15000 })
check('每条待办一行,链到详情', (await page.locator('[data-inbox-task]').count()) === Object.keys(TASKS).length)
check('「应用」导航上的徽标数应用里的待办', (await page.locator('[data-apps-badge]').innerText()).trim() === String(Object.keys(TASKS).length))
check('页签上带数', /\d/.test(await page.getByRole('tab', { name: /待办/ }).innerText()))
})
await browser.close()
console.log(failed ? `\n✗ ${failed} 项未通过` : '\n✓ 全部通过')
process.exit(failed ? 1 : 0)
+36 -6
View File
@@ -92,6 +92,12 @@ async function open({ theme = 'dark', state }) {
// 主题以本地为准,别让沙箱库里存的偏好把这次检查的主题改掉
if (url.pathname === '/api/settings') return route.fulfill({ json: { ui: { theme } } })
if (url.pathname === '/api/approvals') return route.fulfill({ json: state.approvals })
// 导航上的两个徽标按来源分开数:「记录」数不属于应用的(other),「应用」数应用里的(apps)。这里的待审批都不属于应用
if (url.pathname === '/api/tasks/count') {
const other = state.approvals.filter((a) => a.status === 'pending').length
const apps = state.appTasks ?? 0
return route.fulfill({ json: { mine: other + apps, apps, other } })
}
if (url.pathname === '/api/runs' && state.runs) return route.fulfill({ json: state.runs })
if (state.broken === url.pathname) return route.fulfill({ status: 500, json: { detail: '数据库锁住了,稍后重试' } })
return route.continue()
@@ -135,11 +141,12 @@ await section('导航', '=== 导航 ===', async () => {
const box = await nav(page).boundingBox()
check('导航宽 64px(w-16)', Math.round(box.width) === 64, `${box.width}`)
const labels = await nav(page).locator('li > a[aria-keyshortcuts] > span:not([aria-hidden])').allInnerTexts()
// 定时任务是后加的,排在设置前面;设置留在最底下,快捷键还是 ⌥7(定时任务用 ⌥8)
check('导航项:问数据、编排、记录、数据、工具、知识、定时任务、设置',
labels.join(',') === '问数据,编排,记录,数据,工具,知识,定时任务,设置', labels.join(','))
// 定时任务是后加的,排在设置前面;设置留在最底下,快捷键还是 ⌥7(定时任务用 ⌥8)。应用(⌥9)排在编排后面
check('导航九项:问数据、编排、应用、记录、数据、工具、知识、定时任务、设置',
labels.join(',') === '问数据,编排,应用,记录,数据,工具,知识,定时任务,设置', labels.join(','))
const keys = await nav(page).locator('li > a[aria-keyshortcuts]').evaluateAll((els) => els.map((el) => el.getAttribute('aria-keyshortcuts')))
check('设置仍是 ⌥7,定时任务是 ⌥8', keys[6] === 'Alt+8' && keys[7] === 'Alt+7', keys.join(','))
check('原有快捷键都没动:问数据 ⌥1、编排 ⌥2、记录 ⌥3 … 设置 ⌥7、定时任务 ⌥8;应用是 ⌥9',
keys.join(',') === 'Alt+1,Alt+2,Alt+9,Alt+3,Alt+4,Alt+5,Alt+6,Alt+8,Alt+7', keys.join(','))
const fontSize = await nav(page).locator('li > a[aria-keyshortcuts] > span:not([aria-hidden])').first()
.evaluate((el) => getComputedStyle(el).fontSize)
check('导航标签 11px', fontSize === '11px', fontSize)
@@ -168,6 +175,8 @@ await section('导航', '=== 导航 ===', async () => {
check('⌥3 切到记录页', await page.waitForURL(/\/runs(\?|$)/, { timeout: 5000 }).then(() => true, () => false), page.url())
await page.keyboard.press('Alt+Digit8')
check('⌥8 切到定时任务页', await page.waitForURL(/\/schedules(\?|$)/, { timeout: 5000 }).then(() => true, () => false), page.url())
await page.keyboard.press('Alt+Digit9')
check('⌥9 切到应用页', await page.waitForURL(/\/apps(\?|$)/, { timeout: 5000 }).then(() => true, () => false), page.url())
await page.goto(`${WEB}/settings/datasources`)
check('旧地址 /settings/datasources 重定向到 /data', await page.waitForURL(/\/data(\/|$)/, { timeout: 8000 }).then(() => true, () => false), page.url())
@@ -184,7 +193,7 @@ await section('导航', '=== 导航 ===', async () => {
const t = document.querySelector('[data-telemetry]').getBoundingClientRect()
return { ok: n.scrollHeight <= innerHeight && t.bottom <= innerHeight, tel: Math.round(t.bottom), vh: innerHeight }
})
for (const h of [600, 480]) {
for (const h of [600, 520, 480]) {
await page.setViewportSize({ width: 1280, height: h })
await page.waitForTimeout(150)
const fit = await bottomFits()
@@ -237,7 +246,7 @@ await section('待审批徽标', '\n=== 待审批徽标 ===', async () => {
})
if (theme === 'dark') {
check('徽标是链接,指向 /runs?tab=approvals', (await badge.getAttribute('href')) === '/runs?tab=approvals')
check('导航项「记录」本身仍然进 /runs', (await nav(page).locator('a[aria-keyshortcuts]').nth(2).getAttribute('href')) === '/runs')
check('导航项「记录」本身仍然进 /runs', (await nav(page).locator('a[aria-keyshortcuts]').nth(3).getAttribute('href')) === '/runs')
const label = await badge.getAttribute('aria-label')
check('徽标读屏文字:条数 + 最久等了多久', /2 项待审批/.test(label) && /最久已等待 8 天/.test(label), label)
check('徽标至少 16×16', b.width >= 16 && b.height >= 16, `${b.width}×${b.height}`)
@@ -259,6 +268,27 @@ await section('待审批徽标', '\n=== 待审批徽标 ===', async () => {
}
})
// ---------------------------------------------------------------------------
await section('应用徽标', '\n=== 应用徽标:按来源分开数 ===', async () => {
// 应用里派给我的待办数在「应用」上,不属于应用的在「记录」上,同一条不在两处各数一次
const state = { approvals: PENDING, appTasks: 3, offline: false, writes: [] }
const { ctx, page } = await open({ state })
await page.goto(`${WEB}/chat`)
await waitNav(page)
const apps = page.locator('[data-apps-badge]')
await apps.waitFor({ timeout: 8000 })
check('「应用」上的徽标数应用里的待办', (await apps.innerText()).trim() === '3', await apps.innerText())
check('「应用」的徽标指向待办页签', (await apps.getAttribute('href')) === '/apps?tab=inbox', await apps.getAttribute('href'))
const runs = page.locator('[data-approval-badge]')
check('「记录」上的徽标只数不属于应用的', (await runs.innerText()).trim() === '2', await runs.innerText())
check('应用里有待办时「记录」的徽标不说最久等了多久(那份列表含应用里的)',
!/最久已等待/.test(await runs.getAttribute('aria-label')), await runs.getAttribute('aria-label'))
state.appTasks = 0
check('应用里的待办处理完,「应用」的徽标消失', await apps.waitFor({ state: 'detached', timeout: 10000 }).then(() => true, () => false))
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
})
// ---------------------------------------------------------------------------
await section('404', '\n=== 404 ===', async () => {
const state = { approvals: [], offline: false, writes: [] }