第三波收尾:跨模块整合、全站扫尾、检查脚本整合;网页工具认得本机代理的 fake-ip

整合(3c-integrate)
- 公共层:跨天时长(formatSpan / formatOffset / formatLapse)、本机署名(lib/actor)、检索分类色令牌、
  数据源目录(useDatasources)收进公共层;失败说明能一次列出多个写坏的自定义工具,查询超时指到数据源的查询时限
- 管理页收尾:设置页接入统一的离开前确认;检查脚本不再把沙箱里的真实值打进输出
- 画布 ↔ 右栏:点出具印章、点节点能跳到右栏对应位置;「定位」直接聚焦到出问题的字段
- 回答流 / 问数据 / 记录页:失败信息带「去哪修」且不再被翻译两遍;协作团队的结局按执行截取;
  等审批时断流重连、而运行已在空档里跑完的,补全事件

扫尾(3c-sweep)
- 术语统一:开始运行 / 继续运行、工作流最大步数;未保存的运行统一叫「未保存的工作流」(后端新运行同步)
- 沙箱报错不再带 Python 异常类名;新增 check-tokens,未定义的 CSS 变量为 0,两个旧别名迁移后删除

检查脚本(3c-checks)
- check-ui 跟上新界面(运行列表按 data 属性找行),加上令牌与选中态的回归断言,输出里的名字打码
- 新增 check-all:按顺序跑全部检查、汇总退出码,--repeat 列出偶发项
- 单节出错只记这一节失败、不再带崩整个脚本;外壳遥测浮层「重新检测」时焦点不再掉到 body

网页工具与 fake-ip
- Clash / mihomo 一类代理开 TUN + fake-ip 时,查什么都先拿到 198.18 段的假地址,被当成内网拦截。
  新增 AGENTLAB_HTTP_TOOL_FAKE_IP_RANGES(默认空):落在段里的解析结果改向公共 DNS(DoH)核实真实地址,
  公网放行、内网照拦、核实不了按拦截处理。DoH 默认先问境外的,境内公共 DNS 会对被封锁的域名返回污染结果
- 列表型环境变量接受逗号分隔(原来注释说逗号分隔、实际只认 JSON 数组);域名解析改为异步,不再阻塞事件循环

验证(沙箱):tsc 干净,pytest 866 passed(两遍),检查脚本全绿。
This commit is contained in:
ThearchyHelios
2026-09-27 23:37:32 +08:00
parent 587bf7e27c
commit 3e311ec551
98 changed files with 8431 additions and 3645 deletions
+272 -114
View File
@@ -7,8 +7,8 @@
//
// 待审批用 page.route 伪造(两条,最早的一条等了 8 天),离线用 page.route 直接
// 掐断 /api。所有非 GET 请求(主题切换会 PUT 设置)都在探针里应答,不写库。
// 跑之前前端得起着;对沙箱跑:
// AGENTLAB_WEB=http://localhost:5373 node scripts/check-shell.mjs
// 跑之前前端得起着(./scripts/dev.sh),默认连 5273。对别的实例(比如一份沙箱拷贝)跑时
// 带上地址:AGENTLAB_WEB=http://localhost:<前端端口> node scripts/check-shell.mjs
import { chromium } from '../frontend/node_modules/playwright-core/index.mjs'
const WEB = process.env.AGENTLAB_WEB ?? 'http://localhost:5273'
@@ -54,6 +54,7 @@ const browser = await chromium.launch({ executablePath: CHROME })
/** 一个带探针的新页面。state 可以在跑的过程中改:换待审批、断网 */
async function open({ theme = 'dark', state }) {
const ctx = await browser.newContext({ viewport: { width: 1280, height: 860 }, colorScheme: theme })
opened.add(ctx)
const page = await ctx.newPage()
page.errors = []
page.on('pageerror', (e) => page.errors.push(e.message))
@@ -91,6 +92,7 @@ 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 })
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()
})
@@ -103,16 +105,28 @@ const isMac = process.platform === 'darwin'
// 只跑其中几段:CHECK_ONLY=离开前确认,启动页 node scripts/check-shell.mjs(按段名包含匹配)
const ONLY = process.env.CHECK_ONLY?.split(',').map((s) => s.trim()).filter(Boolean)
const want = (name) => !ONLY?.length || ONLY.some((k) => name.includes(k))
/** 这一段要跑就打出段标题、返回 true */
const section = (name, title) => {
if (!want(name)) return false
console.log(title)
return true
/**
* 一节一节地跑:要跑就打出段标题(title 为空的是上一段的续篇,不另起标题)。某一节里
* 等待超时、元素找不到,只记成这一节失败,收掉它开的页面,接着跑下一节
*/
const opened = new Set()
async function section(name, title, fn) {
if (!want(name)) return
if (title) console.log(title)
try {
await fn()
} catch (e) {
const label = title ? title.replace(/^\n?=== | ===$/g, '') : name
check(`${label} 中途出错`, false, String(e?.message ?? e).split('\n')[0])
} finally {
for (const c of opened) await c.close().catch(() => {})
opened.clear()
}
}
const MOD = isMac ? 'Meta' : 'Control'
// ---------------------------------------------------------------------------
if (section('导航', '=== 导航 ===')) {
await section('导航', '=== 导航 ===', async () => {
const state = { approvals: PENDING, offline: false, writes: [] }
const { ctx, page } = await open({ state })
await page.goto(`${WEB}/chat`)
@@ -194,47 +208,49 @@ if (section('导航', '=== 导航 ===')) {
check('主题存进设置(PUT ui.theme,被探针拦下)', !!put && JSON.parse(put.body).values.ui.theme === 'light', put?.body ?? '没有请求')
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
}
})
// ---------------------------------------------------------------------------
if (section('待审批徽标', '\n=== 待审批徽标 ===')) for (const theme of ['dark', 'light']) {
const state = { approvals: PENDING, offline: false, writes: [] }
const { ctx, page } = await open({ theme, state })
await page.goto(`${WEB}/chat`)
await waitNav(page)
const badge = page.locator('[data-approval-badge]')
await badge.waitFor({ timeout: 8000 })
const b = await badge.boundingBox()
const icon = await nav(page).locator('a[href="/runs"] svg').boundingBox()
const [fg, bg, nums] = await badge.evaluate((el) => {
const s = getComputedStyle(el)
return [s.color, s.backgroundColor, s.fontVariantNumeric]
})
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')
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}`)
check('徽标数字等宽', /tabular-nums/.test(nums), nums)
check('徽标挂在图标右上角外侧,不压图标主体', b.x + b.width / 2 > icon.x + icon.width && b.y < icon.y,
`badge(${b.x},${b.y}) icon(${icon.x},${icon.y},${icon.width})`)
await section('待审批徽标', '\n=== 待审批徽标 ===', async () => {
for (const theme of ['dark', 'light']) {
const state = { approvals: PENDING, offline: false, writes: [] }
const { ctx, page } = await open({ theme, state })
await page.goto(`${WEB}/chat`)
await waitNav(page)
const badge = page.locator('[data-approval-badge]')
await badge.waitFor({ timeout: 8000 })
const b = await badge.boundingBox()
const icon = await nav(page).locator('a[href="/runs"] svg').boundingBox()
const [fg, bg, nums] = await badge.evaluate((el) => {
const s = getComputedStyle(el)
return [s.color, s.backgroundColor, s.fontVariantNumeric]
})
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')
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}`)
check('徽标数字等宽', /tabular-nums/.test(nums), nums)
check('徽标挂在图标右上角外侧,不压图标主体', b.x + b.width / 2 > icon.x + icon.width && b.y < icon.y,
`badge(${b.x},${b.y}) icon(${icon.x},${icon.y},${icon.width})`)
}
const ratio = contrast(fg, bg)
check(`徽标对比度 ≥ 4.5(${theme === 'dark' ? '深色' : '浅色'})`, ratio >= 4.5, ratio.toFixed(2))
if (theme === 'dark') {
await badge.hover()
await page.waitForTimeout(400)
const tip = badge.locator('span[aria-hidden]')
check('悬停徽标有提示', (await tip.isVisible()) && /最久已等/.test(await tip.innerText()))
await badge.click()
check('点徽标进待审批页签', await page.waitForURL(/\/runs\?tab=approvals/, { timeout: 5000 }).then(() => true, () => false), page.url())
}
await ctx.close()
}
const ratio = contrast(fg, bg)
check(`徽标对比度 ≥ 4.5(${theme === 'dark' ? '深色' : '浅色'})`, ratio >= 4.5, ratio.toFixed(2))
if (theme === 'dark') {
await badge.hover()
await page.waitForTimeout(400)
const tip = badge.locator('span[aria-hidden]')
check('悬停徽标有提示', (await tip.isVisible()) && /最久已等/.test(await tip.innerText()))
await badge.click()
check('点徽标进待审批页签', await page.waitForURL(/\/runs\?tab=approvals/, { timeout: 5000 }).then(() => true, () => false), page.url())
}
await ctx.close()
}
})
// ---------------------------------------------------------------------------
if (section('404', '\n=== 404 ===')) {
await section('404', '\n=== 404 ===', async () => {
const state = { approvals: [], offline: false, writes: [] }
const { ctx, page } = await open({ state })
await page.goto(`${WEB}/does-not-exist/at-all`)
@@ -249,10 +265,10 @@ if (section('404', '\n=== 404 ===')) {
await page.getByRole('link', { name: '回到问数据' }).click()
check('「回到问数据」回首页', await page.waitForURL(/\/chat/, { timeout: 5000 }).then(() => true, () => false), page.url())
await ctx.close()
}
})
// ---------------------------------------------------------------------------
if (section('标签页标题', '\n=== 标签页标题、favicon、后台提醒 ===')) {
await section('标签页标题', '\n=== 标签页标题、favicon、后台提醒 ===', async () => {
const state = { approvals: [], offline: false, writes: [] }
const { ctx, page } = await open({ state })
await page.goto(`${WEB}/runs`)
@@ -281,7 +297,9 @@ if (section('标签页标题', '\n=== 标签页标题、favicon、后台提醒 =
check('画布装好了(dev 构建的 window.__studio)', hasStudio)
if (hasStudio) {
const name = await page.evaluate(() => window.__studio.getState().workflow?.name)
check('编排页标题带工作流名', (await page.title()).startsWith(`编排 · ${name}`), await page.title())
// 工作流名是沙箱库里的真实名字,日志常被贴进报告:标题打出来之前换成占位
const masked = (t) => (name ? String(t).split(name).join('‹工作流名›') : String(t))
check('编排页标题带工作流名', (await page.title()).startsWith(`编排 · ${name}`), masked(await page.title()))
// 权限只在用户点开关时才要
check('进页面不自动要通知权限', (await page.evaluate(() => window.__permissionAsks)) === 0)
@@ -300,7 +318,7 @@ if (section('标签页标题', '\n=== 标签页标题、favicon、后台提醒 =
})
await page.waitForFunction(() => document.title.includes('● 运行中'), null, { timeout: 3000 }).catch(() => {})
// 只认外壳自己的前缀;前面若还挂着别的(比如以后画布自己加的计时),不算错
check('有运行在跑:标题加「● 运行中 n/N」', /(^|\s)● 运行中 \d+\/\d+ · 编排/.test(await page.title()), await page.title())
check('有运行在跑:标题加「● 运行中 n/N」', /(^|\s)● 运行中 \d+\/\d+ · 编排/.test(await page.title()), masked(await page.title()))
check('有运行在跑:favicon 蓝点', (await favicon()).status === 'running')
check('有运行在跑:品牌标起点节点亮起', /有运行在跑/.test(await nav(page).locator('a[href="/"]').getAttribute('aria-label')))
@@ -312,17 +330,17 @@ if (section('标签页标题', '\n=== 标签页标题、favicon、后台提醒 =
await page.waitForTimeout(1100)
await page.evaluate(() => window.__studio.setState({ runPhase: 'failed' }))
await page.waitForTimeout(200)
check('后台时失败:标题换成「✕ 运行失败」', /(^|\s)✕ 运行失败 · /.test(await page.title()), await page.title())
check('后台时失败:标题换成「✕ 运行失败」', /(^|\s)✕ 运行失败 · /.test(await page.title()), masked(await page.title()))
check('后台时失败:favicon 红点', (await favicon()).status === 'failed')
const notes = await page.evaluate(() => window.__notes)
check('后台时失败:发了一条系统通知', notes.length === 1 && /运行失败/.test(notes[0].title), JSON.stringify(notes))
check('后台时失败:发了一条系统通知', notes.length === 1 && /运行失败/.test(notes[0].title), masked(JSON.stringify(notes)))
await page.evaluate(() => {
delete document.hidden
document.dispatchEvent(new Event('visibilitychange'))
})
await page.waitForTimeout(200)
check('切回来:失败前缀撤掉', !(await page.title()).includes('运行失败'), await page.title())
check('切回来:失败前缀撤掉', !(await page.title()).includes('运行失败'), masked(await page.title()))
check('切回来:favicon 还原', (await favicon()).href === '/favicon.svg')
// 前台时结束不打扰
@@ -335,10 +353,10 @@ if (section('标签页标题', '\n=== 标签页标题、favicon、后台提醒 =
}
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
}
})
// ---------------------------------------------------------------------------
if (section('⌘K 命令面板', '\n=== ⌘K 命令面板 ===')) {
await section('⌘K 命令面板', '\n=== ⌘K 命令面板 ===', async () => {
const state = { approvals: PENDING, offline: false, writes: [] }
const { ctx, page } = await open({ state })
await page.goto(`${WEB}/runs`)
@@ -375,7 +393,8 @@ if (section('⌘K 命令面板', '\n=== ⌘K 命令面板 ===')) {
await dialog.getByRole('combobox').fill(wf.name)
await page.waitForTimeout(100)
const hit = dialog.locator(`[data-command="wf:${wf.id}"]`)
check('能搜到工作流', (await hit.count()) === 1, wf.name)
// 搜的是沙箱里真实的工作流名:不打出来
check('能搜到工作流', (await hit.count()) === 1, (await hit.count()) === 1 ? '' : `命中 ${await hit.count()} 项(名字不打出来)`)
await hit.click()
check('点工作流进它的画布', await page.waitForURL(new RegExp(`/studio/${wf.id}`), { timeout: 5000 }).then(() => true, () => false), page.url())
}
@@ -422,10 +441,60 @@ if (section('⌘K 命令面板', '\n=== ⌘K 命令面板 ===')) {
await page.keyboard.press('Escape')
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
}
})
// ---------------------------------------------------------------------------
if (section('快捷键说明', '\n=== ? 快捷键说明 ===')) {
await section('未保存的工作流', '\n=== 未保存的工作流:命令面板、后台提醒不露「临时图」===', async () => {
// 画布没保存就跑、问数据当场搭的运行,老后端记的名字是「临时图」。记录页早就换成了
// 「未保存的工作流」,命令面板的最近运行、待审批提示和后台通知以前还原样露着(3C 返工 D3)
const unsavedApproval = {
...PENDING[1], id: 'shell-ap-unsaved', run_id: 'shell-run-unsaved', title: '这批订单可以放行吗?',
workflow_id: null, workflow_name: '临时图', created_at: ago(3 * 60_000),
}
const unsavedRun = {
id: 'shell-run-unsaved', workflow_id: null, workflow_name: '临时图', status: 'succeeded', run_class: 'exploratory',
version: null, input: {}, output: {}, error: null, usage: {}, created_at: ago(5 * 60_000),
}
const state = { approvals: [], runs: [unsavedRun], offline: false, writes: [] }
const { ctx, page } = await open({ state })
await page.goto(`${WEB}/runs`)
await waitNav(page)
await page.waitForTimeout(500)
await nav(page).getByRole('button', { name: '后台提醒' }).click()
await page.evaluate(() => {
Object.defineProperty(document, 'hidden', { configurable: true, get: () => true })
document.dispatchEvent(new Event('visibilitychange'))
})
state.approvals = [unsavedApproval]
const noted = await page.waitForFunction(() => window.__notes.some((n) => n.tag === 'approval:shell-ap-unsaved'), null, { timeout: 12000 })
.then(() => true, () => false)
const note = (await page.evaluate(() => window.__notes.find((n) => n.tag === 'approval:shell-ap-unsaved'))) ?? {}
check('后台来了待审批:通知里写「未保存的工作流」,不写「临时图」',
noted && String(note.body).includes('未保存的工作流') && !String(note.body).includes('临时图'), String(note.body ?? '没发通知'))
await page.evaluate(() => {
delete document.hidden
document.dispatchEvent(new Event('visibilitychange'))
})
await page.keyboard.press(`${MOD}+KeyK`)
const dialog = page.getByRole('dialog', { name: '命令面板' })
await dialog.waitFor({ timeout: 3000 }).catch(() => {})
const approvalRow = dialog.locator('[data-command="approval:shell-ap-unsaved"]')
const runRow = dialog.locator('[data-command="run:shell-run-unsaved"]')
await runRow.waitFor({ timeout: 5000 }).catch(() => {})
const approvalText = await approvalRow.innerText().catch(() => '没有这一项')
const runText = await runRow.innerText().catch(() => '没有这一项')
check('命令面板的待审批:提示里写「未保存的工作流」', approvalText.includes('未保存的工作流') && !approvalText.includes('临时图'),
approvalText.replace(/\s+/g, ' '))
check('命令面板的最近运行:名字是「未保存的工作流」', runText.includes('未保存的工作流') && !runText.includes('临时图'),
runText.replace(/\s+/g, ' '))
await page.keyboard.press('Escape')
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
})
// ---------------------------------------------------------------------------
await section('快捷键说明', '\n=== ? 快捷键说明 ===', async () => {
const state = { approvals: [], offline: false, writes: [] }
const { ctx, page } = await open({ state })
await page.goto(`${WEB}/studio`)
@@ -446,10 +515,10 @@ if (section('快捷键说明', '\n=== ? 快捷键说明 ===')) {
check('Esc 关掉', await help.waitFor({ state: 'detached', timeout: 3000 }).then(() => true, () => false))
}
await ctx.close()
}
})
// ---------------------------------------------------------------------------
if (section('离开前确认', '\n=== 离开前确认 ===')) {
await section('离开前确认', '\n=== 离开前确认 ===', async () => {
// 页面有没保存的改动时登记一道守卫(lib/leave)。以前设置页只在捕获阶段拦 <a> 的
// 点击:⌘K、⌥ 数字直接调 navigate(),浏览器后退也不走 <a>,改到一半的表单就这么丢了。
// 这里用 dev 构建挂出的 window.__leave 登记一道测试守卫:每问一次记一笔,答案由脚本给
@@ -460,57 +529,93 @@ if (section('离开前确认', '\n=== 离开前确认 ===')) {
const hooked = await page.waitForFunction(() => !!window.__leave, null, { timeout: 5000 }).then(() => true, () => false)
check('dev 构建挂出了 window.__leave', hooked)
if (hooked) {
// 测试守卫要像页面守卫:选「离开」就等于页面卸载,守卫跟着撤;落地之后再登记。
// 以前它一直登记着、跨页不撤,⌥1 进 /chat 后 ChatPage 把地址 replace 成 /chat/<id>,
// 这次重定向也被它拦下、又问了几回,计数用 >= 判断,后面几步在点之前就「成立」了
await page.evaluate(() => {
window.__asks = []
window.__answer = null
window.__unguard = window.__leave.register({
confirm: (next) => new Promise((resolve) => {
window.__asks.push(next ? next.pathname + next.search : null)
window.__answer = resolve
}),
})
window.__guard = () => {
window.__unguard?.()
const off = window.__leave.register({
confirm: (next) => new Promise((resolve) => {
window.__asks.push(next ? next.pathname + next.search : null)
window.__answer = (ok) => {
if (ok) { off(); window.__unguard = null }
resolve(ok)
}
}),
})
window.__unguard = off
}
window.__guard()
})
const asks = () => page.evaluate(() => window.__asks.length)
const asked = (n) => page.waitForFunction((n) => window.__asks.length >= n, n, { timeout: 3000 }).then(() => true, () => false)
const lastAsk = () => page.evaluate(() => window.__asks.at(-1))
// 恰好问了 n 次:等到第 n 次,再多等一拍——StrictMode 下重复问一次也要抓得到
const asked = async (n) => {
const reached = await page.waitForFunction((n) => window.__asks.length >= n, n, { timeout: 3000 }).then(() => true, () => false)
await page.waitForTimeout(200)
return reached && (await asks()) === n
}
const answer = (ok) => page.evaluate((ok) => { const r = window.__answer; window.__answer = null; r?.(ok) }, ok)
const where = () => { const u = new URL(page.url()); return u.pathname + u.search }
const settle = () => page.waitForTimeout(250)
// 落地后页面可能还会自己 replace 一次(/chat → /chat/<id>):地址停住 500ms 才算稳
const landed = async () => {
let last = where()
for (let i = 0; i < 20; i++) {
await page.waitForTimeout(250)
const now = where()
if (now === last && i >= 1) return now
last = now
}
return last
}
const regard = () => page.evaluate(() => window.__guard())
const dialog = page.getByRole('dialog', { name: '命令面板' })
await page.keyboard.press(`${MOD}+KeyK`)
await dialog.getByRole('combobox').fill('设置')
await page.keyboard.press('Enter')
check('⌘K 跳页先问守卫,问的时候地址不动', await asked(1) && where().startsWith('/runs'), `${await asks()} 次 · ${where()}`)
check('守卫拿得到要去哪', (await page.evaluate(() => window.__asks[0])) === '/settings', await page.evaluate(() => window.__asks[0]))
check('⌘K 跳页先问守卫(恰好一次),问的时候地址不动', await asked(1) && where().startsWith('/runs'), `${await asks()} 次 · ${where()}`)
check('守卫拿得到要去哪', (await lastAsk()) === '/settings', await lastAsk())
await answer(false)
await settle()
check('选「留下」:还在原地,面板也关了', where().startsWith('/runs') && (await dialog.count()) === 0, where())
await page.evaluate(() => document.activeElement?.blur())
await page.keyboard.press('Alt+Digit1')
check('⌥1 切页先问守卫', await asked(2) && where().startsWith('/runs'), where())
check('⌥1 切页先问守卫(恰好一次),去向是问数据', await asked(2) && where().startsWith('/runs') && (await lastAsk()) === '/chat',
`${await asks()} 次 · ${await lastAsk()}`)
await answer(true)
check('选「离开」:去到问数据', await page.waitForURL(/\/chat/, { timeout: 5000 }).then(() => true, () => false), where())
const chatAt = await landed()
check('……守卫跟着撤了,页面自己的重定向不再被问', (await asks()) === 2, `${await asks()} 次 · ${chatAt}`)
await regard()
await nav(page).locator('a[href="/data"]').click()
check('点左侧导航先问守卫', await asked(3))
check('点左侧导航先问守卫(恰好一次),去向是 /data', await asked(3) && (await lastAsk()) === '/data', `${await asks()} 次 · ${await lastAsk()}`)
await answer(false)
await settle()
check('选「留下」:地址不变', where().startsWith('/chat'), where())
check('选「留下」:地址不变', where() === chatAt, `${where()},应为 ${chatAt}`)
await page.evaluate(() => history.back())
check('浏览器后退也先问守卫', await asked(4))
check('浏览器后退也先问守卫(恰好一次),去向是上一页', await asked(4) && (await lastAsk()) === '/runs', `${await asks()} 次 · ${await lastAsk()}`)
await answer(false)
await page.waitForTimeout(400)
check('选「留下」:地址退回原处', where().startsWith('/chat'), where())
check('选「留下」:地址退回原处', where() === chatAt, `${where()},应为 ${chatAt}`)
await page.evaluate(() => history.back())
await asked(5)
check('再后退又问一次(恰好一次)', await asked(5) && (await lastAsk()) === '/runs', `${await asks()} 次 · ${await lastAsk()}`)
await answer(true)
check('后退时选「离开」:真的退回去了', await page.waitForURL(/\/runs/, { timeout: 5000 }).then(() => true, () => false), where())
await landed()
await regard()
const before = await asks()
await page.locator('[data-approval-badge]').click()
await page.waitForURL(/tab=approvals/, { timeout: 5000 }).catch(() => {})
await settle()
check('同一页里只换 ?tab 不问', (await asks()) === before && /\/runs\?tab=approvals/.test(where()), `${await asks() - before} 次 · ${where()}`)
// 先建东西再跳的命令:得先问,不然人点了「留下」,会话已经建出来了
@@ -518,7 +623,8 @@ if (section('离开前确认', '\n=== 离开前确认 ===')) {
await page.keyboard.press(`${MOD}+KeyK`)
await dialog.getByRole('combobox').fill('新对话')
await page.keyboard.press('Enter')
check('⌘K「新对话」先问守卫', await asked(before + 1))
check('⌘K「新对话」先问守卫(恰好一次),去向还没定', await asked(before + 1) && (await lastAsk()) === null,
`${await asks() - before} 次 · ${await lastAsk()}`)
check('……问的时候还没建会话', !state.writes.some((w) => w.method === 'POST' && w.path === '/api/conversations'),
state.writes.map((w) => `${w.method} ${w.path}`).join(', '))
await answer(false)
@@ -529,11 +635,12 @@ if (section('离开前确认', '\n=== 离开前确认 ===')) {
await page.keyboard.press(`${MOD}+KeyK`)
await dialog.getByRole('combobox').fill('新建工作流')
await page.keyboard.press('Enter')
check('⌘K「新建工作流」先问守卫,再问名字', await asked(before + 2)
check('⌘K「新建工作流」先问守卫(恰好一次),再问名字', await asked(before + 2)
&& (await page.getByRole('dialog', { name: '新建工作流' }).count()) === 0)
await answer(false)
await settle()
check('选「留下」:不弹起名框', (await page.getByRole('dialog', { name: '新建工作流' }).count()) === 0 && where().startsWith('/runs'))
check('每一问都有了答复,没有悬着的确认', await page.evaluate(() => window.__answer === null))
// 关页、刷新:守卫在时浏览器会问(它只给通用文案),撤了就不问
const unloadAsks = []
@@ -556,10 +663,49 @@ if (section('离开前确认', '\n=== 离开前确认 ===')) {
}
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
}
})
await section('离开前确认 · 面板开着时后退', '\n=== 离开前确认 · 面板开着时后退 ===', async () => {
// 命令面板(z 更高、锁焦点)开着时浏览器后退:守卫的确认框被压在面板下面看不见,
// 焦点又被面板拉回搜索框,Tab、Enter 都落在面板上。用设置页真实的守卫走一遍
const state = { approvals: PENDING, offline: false, writes: [] }
const { ctx, page } = await open({ state })
await page.goto(`${WEB}/runs`)
await waitNav(page)
await nav(page).locator('a[href="/settings"]').click()
await page.getByRole('tab', { name: '偏好设置' }).click()
const actor = page.locator('#pref-actor')
await actor.waitFor({ timeout: 8000 })
await actor.fill(`${await actor.inputValue()}x`)
await page.getByText(/有 1 项(设置)?(还)?没保存|1 项未保存/).first().waitFor({ timeout: 3000 }).catch(() => {})
await page.keyboard.press(`${MOD}+KeyK`)
const palette = page.getByRole('dialog', { name: '命令面板' })
await palette.waitFor({ timeout: 3000 })
await page.evaluate(() => history.back())
const confirm = page.getByRole('dialog', { name: /有 1 项设置还没保存/ })
const shown = await confirm.waitFor({ timeout: 3000 }).then(() => true, () => false)
await page.waitForTimeout(250)
check('后退时面板先收起', (await palette.count()) === 0)
// isVisible 不管遮挡:取确认框正中那一点最上层的元素,得是它自己
const onTop = shown && await confirm.evaluate((el) => {
const b = el.getBoundingClientRect()
return el.contains(document.elementFromPoint(b.left + b.width / 2, b.top + b.height / 2))
})
check('离开确认框弹出来、在最上层看得见', onTop)
const inside = () => page.evaluate(() => !!document.activeElement?.closest('[role="dialog"][aria-modal="true"]:not([data-command-palette])'))
check('焦点在确认框里', await inside(), await page.evaluate(() => document.activeElement?.outerHTML.slice(0, 80)))
await page.keyboard.press('Tab')
check('Tab 之后焦点还在确认框里', await inside())
await confirm.getByRole('button', { name: '留下来保存' }).click()
await page.waitForTimeout(300)
check('选「留下」:还在偏好设置,改动还在', new URL(page.url()).pathname === '/settings/prefs'
&& (await actor.inputValue()).endsWith('x'), page.url())
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
})
// ---------------------------------------------------------------------------
if (section('离线横幅', '\n=== 离线横幅 ===')) {
await section('离线横幅', '\n=== 离线横幅 ===', async () => {
const state = { approvals: [], offline: false, writes: [] }
const { ctx, page } = await open({ state })
await page.goto(`${WEB}/chat`)
@@ -580,7 +726,7 @@ if (section('离线横幅', '\n=== 离线横幅 ===')) {
await page.getByRole('button', { name: '立即重试' }).first().click()
check('恢复后横幅消失', await banner.waitFor({ state: 'detached', timeout: 8000 }).then(() => true, () => false))
await ctx.close()
}
})
/**
* 启动页的播报区:只能有标题那一处,计时器、倒计时这些一秒一跳的字不能在里面,
@@ -597,31 +743,33 @@ const bootLiveRegions = (page) => page.evaluate(() => {
})
// ---------------------------------------------------------------------------
if (section('启动页', '\n=== 启动页 ===')) for (const theme of ['dark', 'light']) {
const state = { approvals: [], offline: true, writes: [] }
const { ctx, page } = await open({ theme, state })
await page.goto(`${WEB}/chat`)
const down = await page.getByText('连不上后端服务').first().waitFor({ timeout: 10000 }).then(() => true, () => false)
if (theme === 'dark') {
check('后端没起:启动页说清原因,不再一直「正在连接」', down)
check('给了重试和先进去两条路', await page.getByRole('button', { name: '立即重试' }).isVisible()
&& await page.getByRole('button', { name: '先进去看看' }).isVisible())
check('清单逐项写出失败', (await page.locator('[data-check][data-state="error"]').count()) >= 6)
const live = await bootLiveRegions(page)
check('读屏只播标题那一句:倒计时不在播报区里', live.ok, JSON.stringify(live))
state.offline = false
await page.getByRole('button', { name: '立即重试' }).click()
check('后端起来后点重试就进去', await waitNav(page).then(() => true, () => false))
} else {
const bootBg = await page.evaluate(() => getComputedStyle(document.querySelector('[data-boot]')).backgroundColor)
check('浅色主题下启动页也是浅色', bootBg === 'rgb(246, 247, 249)', bootBg)
await page.getByRole('button', { name: '先进去看看' }).click()
check('「先进去看看」进离线模式,横幅挂着', await page.locator('main').getByText('后端未连接').waitFor({ timeout: 5000 }).then(() => true, () => false))
await section('启动页', '\n=== 启动页 ===', async () => {
for (const theme of ['dark', 'light']) {
const state = { approvals: [], offline: true, writes: [] }
const { ctx, page } = await open({ theme, state })
await page.goto(`${WEB}/chat`)
const down = await page.getByText('连不上后端服务').first().waitFor({ timeout: 10000 }).then(() => true, () => false)
if (theme === 'dark') {
check('后端没起:启动页说清原因,不再一直「正在连接」', down)
check('给了重试和先进去两条路', await page.getByRole('button', { name: '立即重试' }).isVisible()
&& await page.getByRole('button', { name: '先进去看看' }).isVisible())
check('清单逐项写出失败', (await page.locator('[data-check][data-state="error"]').count()) >= 6)
const live = await bootLiveRegions(page)
check('读屏只播标题那一句:倒计时不在播报区里', live.ok, JSON.stringify(live))
state.offline = false
await page.getByRole('button', { name: '立即重试' }).click()
check('后端起来后点重试就进去', await waitNav(page).then(() => true, () => false))
} else {
const bootBg = await page.evaluate(() => getComputedStyle(document.querySelector('[data-boot]')).backgroundColor)
check('浅色主题下启动页也是浅色', bootBg === 'rgb(246, 247, 249)', bootBg)
await page.getByRole('button', { name: '先进去看看' }).click()
check('「先进去看看」进离线模式,横幅挂着', await page.locator('main').getByText('后端未连接').waitFor({ timeout: 5000 }).then(() => true, () => false))
}
await ctx.close()
}
await ctx.close()
}
})
if (want('启动页')) {
await section('启动页', '', async () => {
// 后端连着、只有一张表报错:照常进,但要说出来,不然那张表对应的下拉就是空的,看着像"没有"
const state = { approvals: [], offline: false, writes: [], broken: '/api/skills' }
const { ctx, page } = await open({ state })
@@ -639,9 +787,9 @@ if (want('启动页')) {
await page.locator('[role="status"] > div', { hasText: '没加载成功' }).getByRole('button', { name: '重试' }).click({ timeout: 5000 }).catch(() => {})
check('重试取回来:提示撤掉', await warn.waitFor({ state: 'detached', timeout: 5000 }).then(() => true, () => false))
await ctx.close()
}
})
if (want('启动页')) {
await section('启动页', '', async () => {
// 后端连得上、请求却卡着不回:「先进去看看」之后不能是一片绿加一屏「还没有工作流」
const state = { approvals: [], offline: false, writes: [], hang: true }
const { ctx, page } = await open({ state })
@@ -678,9 +826,9 @@ if (want('启动页')) {
check('提示随之撤掉', await warn.waitFor({ state: 'detached', timeout: 3000 }).then(() => true, () => false))
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
}
})
if (want('启动页')) {
await section('启动页', '', async () => {
// 只有一张表卡住(后端连着):每个请求最多等 15 秒,到点记成出错。遥测点从「加载中」
// 转成「降级」,提示也得跟着改口说「没加载成功」,而不是悄悄撤掉——那张表还是空的
const state = { approvals: [], offline: false, writes: [], hangPath: '/api/tools' }
@@ -708,9 +856,9 @@ if (want('启动页')) {
.then(() => true, () => false), await telemetry.getAttribute('data-tone'))
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
}
})
if (want('启动页')) {
await section('启动页', '', async () => {
// 取回来过的表,后来的刷新卡住了:手上的列表是真的(失败不清空),遥测点说「加载中」
// 就够了,不能再弹「列表可能不全,先别新建」吓人
const state = { approvals: [], offline: false, writes: [] }
@@ -721,21 +869,31 @@ if (want('启动页')) {
await page.waitForFunction(() => document.querySelector('[data-telemetry]')?.getAttribute('data-tone') === '在线', null, { timeout: 10000 }).catch(() => {})
state.hangPath = '/api/tools'
await telemetry.click()
await page.getByRole('dialog', { name: '后端连接' }).getByRole('button', { name: '重新检测' }).click()
const panel = page.getByRole('dialog', { name: '后端连接' })
await panel.getByRole('button', { name: '重新检测' }).click()
// 按钮进忙碌态是下一帧的事。以前按钮一 disabled,焦点就被甩到 body 上,Esc 再也到不了
// 浮层——点完立刻按 Esc 抢在前头才过得去,机器一忙就卡住。等两帧再按,测的就是忙着的时候
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))))
await page.keyboard.press('Escape')
const closed = await panel.waitFor({ state: 'detached', timeout: 1500 }).then(() => true, () => false)
check('重新检测之后 Esc 仍能关掉浮层,焦点没被甩到 body 上', closed,
closed ? '' : `焦点在 ${await page.evaluate(() => document.activeElement?.tagName)}`)
// 没关掉就替它关上,后面几项照常量,别让一处失败连带出 30 秒的超时
if (!closed) await telemetry.click()
await page.waitForTimeout(3800)
check('刷新卡住:遥测点说「加载中」', (await telemetry.getAttribute('data-tone')) === '加载中', await telemetry.getAttribute('data-tone'))
check('……但不弹「先别新建」:那张表之前取回来过', (await page.getByText(/先别新建/).count()) === 0)
await telemetry.click()
const panel = page.getByRole('dialog', { name: '后端连接' })
check('遥测浮层照样写出哪一项还没回来,但不劝别新建', /工具还没回来/.test(await panel.innerText()) && !/先别急着新建/.test(await panel.innerText()),
(await panel.innerText()).replace(/\n/g, ' '))
await panel.waitFor({ timeout: 3000 })
const panelText = await panel.innerText()
check('遥测浮层照样写出哪一项还没回来,但不劝别新建', /工具还没回来/.test(panelText) && !/先别急着新建/.test(panelText),
panelText.replace(/\n/g, ' '))
await page.keyboard.press('Escape')
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
}
})
if (want('启动页')) {
await section('启动页', '', async () => {
// 断线时在导航上换了主题:重连后补存进设置,不能被服务端的旧值翻回去
const state = { approvals: [], offline: true, writes: [] }
const { ctx, page } = await open({ state })
@@ -755,7 +913,7 @@ if (want('启动页')) {
check('重连后补存进设置(PUT ui.theme = light)', !!put && JSON.parse(put.body).values.ui.theme === 'light', put?.body ?? '没有请求')
check('没有未捕获的运行时错误', page.errors.length === 0, page.errors[0] ?? '')
await ctx.close()
}
})
await browser.close()
console.log(failed ? `\n✗ ${failed} 项未通过` : '\n✓ 外壳检查全部通过')