可点击证据第三期:表名字段名和引文也点得开、可疑实体与结论句、受管门禁 G1–G5、证据审计导出

一、表结构、实体与引文

- 数据源工具查库时顺带存一份表结构快照(schema_snapshot),和查询快照一起进台账、进封存;
  台账里的查询记下 SQL 用到的表
- 报告里的表名、字段名可以点:反引号里的名字一律核对,正文里的裸名字只在明显是标识符时才自动链接,
  常见英文单词不链接;点开看到它出现在哪次查询、类型、所属的表,快照被截断时写明
- 找不到的名字标成可疑实体:在快照、SQL、结果列里都没有的记「可能是编造的名字」并给出最接近的 3 个;
  快照被截断、核对不了的记「核对不了」,不冤枉成编造
- 检索引文 [[q:K1|原文]]:原文在检索快照的命中片段里逐字出现(空白归一化后)才算有出处,点开高亮原文位置
- 自动链接的名字不算句子的引用,只有写作者写的引用才算

二、结论句与出具

- 报告节点新增 claims:off(默认,保持原样)或 require_citation(没有引用的结论句计入缺口)
- 受管级别的正式运行里,可疑实体和没有引用的结论句按「有缺口」降档,不拦截;探索运行和已发布级别只标注
- 契约的 claims 和报告节点的设置取更严的那个;受管正式运行里写 ignore 也按降档处理,并给出警告
- 出具横幅除了数字,也写出可疑实体和没有引用的结论句

三、受管门禁 G1–G5(只看图和配置)

- G1 带契约的出口,成果字段的文字只能来自报告撰写节点
- G2 模型写的文字不绕过报告撰写节点直接流进出口
- G3 报告撰写节点写明 numbers: strict、on_violation: fail、claims: require_citation
- G4 口径卡的输入不来自计算角色的沙箱代码
- G5 给口径卡供数的 agent 配 output_schema 并开 cite_fields
- 受管级别是错误、挡住发布;已发布级别只给警告;已经发布的版本照常运行,下次发布时按新规则检查
- 每条规则都接进发布前自动修复(一键修复 / 给选项 / 交给 Copilot);禁止的改动补上关 cite_fields、
  删 output_schema、放宽契约 claims;Copilot 兜底不许自己把代码节点标成 source、不许放宽报告节点
- 发布弹窗里选「交给 Copilot」时明确写「正在交给 Copilot」

四、旧运行与审计

- 没有契约的旧答案:数字和已封存的查询单元格、口径卡值按数值比对,每个数最多 3 个候选,
  默认折叠,写明「猜测的来源,不能当证据」
- 有契约的旧运行:候选只从已封存的口径卡里找,人为插进工件表的行不当证据
- 证据审计:GET /api/runs/{id}/evidence/audit 按「无证据 / 可疑实体 / 有出处 / 旧运行猜测」分组,
  可导出 JSON 和 CSV(带封存状态);记录页和画布上的报告节点显示「有出处 N · 无证据 M」

五、SQL 守卫修正(安全)

- 去注释改成单遍扫描,认得字符串和各方言的引号(单引号转义、MySQL 反斜杠与 #、PostgreSQL 的 $$ 与嵌套注释、
  Oracle 的 q'[…]'、SQLite 的方括号);以前字符串里的 -- 会被当成注释,SELECT '--'; DROP … 这类写法能骗过多语句拦截
- 看不到服务器设置时每种读法都扫一遍,读法之间切分不一致就拒绝,任何一种读法是写操作就按写操作处理
- 执行查询和工具危险判定都按数据源的方言检查

六、其他

- 修掉检查脚本里画布检查的一处竞态,并行估时按实测更新
This commit is contained in:
ThearchyHelios
2026-09-29 05:26:34 +08:00
parent fcdcc30d4e
commit d071bf119f
65 changed files with 15316 additions and 378 deletions
+3 -2
View File
@@ -52,9 +52,10 @@ const ORDER = [
]
// 最近一次全量里各项的耗时(秒)。只决定排队顺序:长的先开跑,短的填空,结果不受影响。
// 新加的检查不在表里就按 60 秒算
// 2026-09-29 三期收尾那一次四道并行的实测(秒):只用来排先后,长的先跑
const ESTIMATE = {
'run-states': 220, 'canvas-fx': 181, stream: 162, studio: 125, chat: 124, manage: 115, runs: 91,
shell: 84, 'ui-kit': 69, ui: 61, evidence: 56, publish: 31, guards: 10, 'canvas-layout': 4, tokens: 1, trace: 1, decode: 1,
'run-states': 299, 'canvas-fx': 264, stream: 176, chat: 164, studio: 153, manage: 142, runs: 105,
shell: 85, 'ui-kit': 74, evidence: 67, ui: 67, publish: 54, guards: 17, 'canvas-layout': 8, tokens: 1, trace: 1, decode: 1,
}
// 量时间最多、以前并行最容易挂的:同一时刻最多跑其中一项
const EXCLUSIVE = new Set(['run-states', 'canvas-fx'])
+280 -3
View File
@@ -27,6 +27,11 @@ const fx = JSON.parse(readFileSync(`${root}frontend/src/run/__tests__/evidence-d
// 第二期:报告直接引用查询单元格、整表,口径卡的输入核对到 agent 字段和查询快照。文档同样是
// compose_doc 真跑出来的(查询快照走 loader),片段接口的答复按方案第 5 节和 NOTES-A2 的形状拼
const fxq = JSON.parse(readFileSync(`${root}frontend/src/run/__tests__/evidence-query.json`, 'utf8'))
// 第三期:表名字段名(反引号里的、标记的、自动链接的)、可疑实体、核对不了的名字、逐字引文,
// 以及没有契约的旧运行按数值猜的候选。文档和猜测都是后端真跑出来的(compose_doc / guess_sources)
const fxe = JSON.parse(readFileSync(`${root}frontend/src/run/__tests__/evidence-entity.json`, 'utf8'))
/** 夹具里某段文字是哪个片段:检查按文字认片段,重新生成夹具时编号变了也不用改 */
const segOf = (doc, text) => doc.blocks.flatMap((b) => b.units.flatMap((u) => u.segments)).find((s) => s.text === text)?.id
let failed = 0
const check = (name, cond, detail = '') => {
@@ -55,10 +60,10 @@ async function routed(page) {
const url = new URL(req.url())
if (req.method() !== 'GET') return r.abort()
const seg = url.pathname.match(/\/api\/runs\/([^/]+)\/evidence\/segments\/([^/]+)$/)
// 按运行认夹具:第二期那份(查询链)和第一期那份各有自己的片段
const set = url.pathname.includes(`/runs/${fxq.run_id}/`) ? fxq : fx
// 按运行认夹具:第一期、第二期(查询链)、第三期(实体、引文)各有自己的片段
const set = url.pathname.includes(`/runs/${fxq.run_id}/`) ? fxq : url.pathname.includes(`/runs/${fxe.run_id}/`) ? fxe : fx
if (seg) {
hits.push(`${set === fxq ? 'q:' : ''}${decodeURIComponent(seg[2])}`)
hits.push(`${set === fxq ? 'q:' : set === fxe ? 'e:' : ''}${decodeURIComponent(seg[2])}`)
const body = set.segments[decodeURIComponent(seg[2])]
return body ? r.fulfill({ json: body })
: r.fulfill({ status: 404, json: { detail: '报告里没有这个片段', code: 'evidence_segment_not_found' } })
@@ -1125,6 +1130,48 @@ await section('studio', '报告撰写节点:画布认得、检查器能配(R
check('「指标来自」只列上游的口径卡(下游那张不列)', opts.length === 1 && opts[0].includes('周报口径'), opts.join(' | '))
const onViolation = await p.locator('[data-field="on_violation"] option').allInnerTexts()
check('违规时的默认写明按运行类别', onViolation[0]?.includes('探索运行照常产出'), onViolation.join(' | '))
// 三期:结论句策略 claims(off / require_citation,judge 是四期的,不出现在选项里)和表名字段名核对 entities
// 表名字段名核对收在「高级选项」里(很少要改),先展开
await p.locator('button[aria-expanded]', { hasText: '高级选项' }).click().catch(() => {})
await p.waitForTimeout(100)
const all = await p.evaluate(() => [...document.querySelectorAll('[data-field]')].map((el) => el.getAttribute('data-field')))
check('检查器有结论句策略、表名字段名核对(高级选项里)两项', fields.includes('claims') && all.includes('entities')
&& !fields.includes('entities'), all.join(','))
const claimVals = await p.locator('[data-field="claims"] option').evaluateAll((els) => els.map((e) => e.value))
check('结论句策略只有 off / require_citation,没有 judge', claimVals.join(',') === 'off,require_citation', claimVals.join(','))
const claimsLabel = await p.locator('[data-field="claims"] label').first().innerText().catch(() => '')
check('结论句策略有中文标签(发布前修复的预览也用它)', /结论句/.test(claimsLabel) && !/claims/.test(claimsLabel), claimsLabel)
const claimsHelp = await p.locator('[data-field="claims"]').innerText()
check('……说明写明「结论句裁判在后续版本支持」、受管级别要显式选', claimsHelp.includes('结论句裁判在后续版本支持')
&& claimsHelp.includes('受管'), claimsHelp.replace(/\s+/g, ' ').slice(0, 160))
check('没写 claims 时显示默认的 off', await p.locator('[data-field="claims"] select').inputValue() === 'off'
|| (await p.locator('[data-field="claims"] select').evaluate((el) => el.options[el.selectedIndex]?.value)) === 'off')
const entityVals = await p.locator('[data-field="entities"] option').evaluateAll((els) => els.map((e) => e.value))
check('表名字段名核对:link / off', entityVals.join(',') === 'link,off', entityVals.join(','))
await p.locator('[data-field="claims"] select').selectOption('require_citation')
const cfgOf = () => p.evaluate(() => window.__studio.getState().nodes.find((n) => n.id === 'write')?.data.config)
check('选「要求挂依据」写进 config.claims', (await cfgOf())?.claims === 'require_citation')
// 手写或别处写进来的 judge:不能悄悄显示成 off,要照实写出来并说后续版本支持
await p.evaluate(() => {
const st = window.__studio.getState()
const n = st.nodes.find((x) => x.id === 'write')
st.updateNode('write', { config: { ...n.data.config, claims: 'judge' } })
})
await p.waitForTimeout(150)
const shown = await p.locator('[data-field="claims"] select').evaluate((el) => el.options[el.selectedIndex]?.textContent ?? '')
check('config 里写着 judge:下拉照实显示 judge 并说后续版本支持,不装成 off', shown.includes('judge') && shown.includes('后续版本'), shown)
const fixLabel = await p.evaluate(async () => {
// 按页面自己加载时的地址 import:改过的模块地址带 ?t=,直接写 /src/… 会拿到另一份实例
const url = performance.getEntriesByType('resource').map((e) => e.name)
.find((n) => { try { return new URL(n).pathname === '/src/canvas/issues.ts' } catch { return false } })
const m = await import(url ?? '/src/canvas/issues.ts')
return [m.fixFieldLabel('claims', 'report'), m.fixFieldLabel('contract.claims.on_uncited', 'output'),
m.fixValueText('ignore', 'contract.claims.on_uncited'), m.fixValueText('degrade', 'contract.claims.on_uncited')]
}).catch((e) => [String(e)])
check('发布前修复预览里 claims 这个字段写中文名', fixLabel[0] === claimsLabel.trim() && !/claims/.test(fixLabel[0]), fixLabel[0])
check('契约 claims 的 on_uncited(ignore 改成 degrade 那条修复):字段和值都写中文',
!/claims|on_uncited/.test(fixLabel[1] ?? 'claims') && fixLabel[2] === '只标出来,不算缺口' && fixLabel[3] === '计入缺口、出具降档',
JSON.stringify(fixLabel.slice(1)))
if (SHOTS) {
for (const theme of ['dark', 'light']) {
await p.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
@@ -1309,6 +1356,236 @@ await section('config', '配置项:agent 的 cite_fields、code 的证据角
await ctx.close()
})
// ------------------------------------------------------------------ 第三期:实体、引文、旧运行的猜测
const E = {
num: segOf(fxe.doc, '45,678.5'), orders: segOf(fxe.doc, 'orders'), week: segOf(fxe.doc, 'orders.week'),
refunds: segOf(fxe.doc, '`refunds`'), column: segOf(fxe.doc, '`refunds.refund_amount`'),
coupon: segOf(fxe.doc, '`orders.coupon_code`'), discount: segOf(fxe.doc, 'orders.discount'),
promo: segOf(fxe.doc, '`promo_events`'), customers: segOf(fxe.doc, 'customers'), bare: segOf(fxe.doc, '30'),
quote: segOf(fxe.doc, '退款金额以财务确认日为准,未确认的退款不计入当周'), miss: segOf(fxe.doc, '周报一律按自然周统计'),
}
const ent = '#evidence-entity'
await section('entity', '三期:表名字段名、可疑实体、逐字引文——四通道分得开', async () => {
check('夹具里认得出每一种片段', Object.values(E).every(Boolean), JSON.stringify(E))
const look = await page.evaluate(([sel, E]) => Object.fromEntries(Object.entries(E).map(([k, id]) => {
const el = document.querySelector(`${sel} [data-seg="${id}"]`)
if (!el) return [k, null]
const cs = getComputedStyle(el)
return [k, { style: cs.textDecorationStyle, color: cs.textDecorationColor, state: el.getAttribute('data-ev-state'),
kind: el.getAttribute('data-ev-kind'), label: el.getAttribute('aria-label') ?? '', text: el.innerText,
code: !!el.querySelector('code'), before: getComputedStyle(el, '::before').content }]
})), [ent, E])
check('有出处的实体和数字同一套「有出处」线型:实线、同一个颜色', look.orders?.state === 'deterministic'
&& look.orders.style === 'solid' && look.orders.color === look.num?.color, JSON.stringify([look.orders, look.num?.color]))
check('可疑实体用「无证据」的线型(点状),和有出处的实体线型不同', look.coupon?.state === 'suspect'
&& look.coupon.style === 'dotted' && look.coupon.style !== look.orders?.style, JSON.stringify(look.coupon))
check('标记写的可疑实体([[c:…]] 编造的字段)同样标成可疑', look.discount?.state === 'suspect' && look.discount.style === 'dotted',
JSON.stringify(look.discount))
check('可疑实体的 aria-label 写「可能是编造的名字」,名字不带反引号', look.coupon?.label.startsWith('orders.coupon_code,')
&& look.coupon.label.includes('可能是编造的名字'), look.coupon?.label)
check('核对不了的名字:点状线、自己的说法,不说「编造」', look.promo?.state === 'unverified' && look.promo.style === 'dotted'
&& look.promo.label.includes('核对不了') && !look.promo.label.includes('编造'), look.promo?.label)
check('核对不了和可疑实体颜色不同(它只是标注,不醒目)', look.promo?.color !== look.coupon?.color, `${look.promo?.color} / ${look.coupon?.color}`)
check('反引号里的实体按行内代码画,不露反引号', look.refunds?.code && !look.refunds.text.includes('`')
&& look.column?.code, JSON.stringify([look.refunds, look.column?.text]))
check('自动链接的名字(正文里的已知表名)也是有出处的实体', look.customers?.state === 'deterministic' && look.customers.kind === 'entity')
check('aria-label:实体说清是表还是字段、出现在哪几次查询', look.orders?.label === 'orders,有出处:表 orders · 出现在查询 Q1、Q2',
look.orders?.label)
check('引文片段用引用样式:前面挂引号、实线', look.quote?.kind === 'quote' && look.quote.before.includes('“')
&& look.quote.style === 'solid' && look.quote.state === 'deterministic', JSON.stringify(look.quote))
check('原话对不上的引文照样是引用样式,但线型换成点状(无证据)', look.miss?.kind === 'quote' && look.miss.before.includes('“')
&& look.miss.style === 'dotted' && look.miss.state === 'none', JSON.stringify(look.miss))
check('引文的 aria-label 写出出处', look.quote?.label.includes('有出处') && look.quote.label.includes('运营手册 · 退款'), look.quote?.label)
const tags = await page.locator(`${ent} .ev-tag`).allInnerTexts()
check('句末小标签:可疑名字挂「?!可疑名字」,和「?无证据」分开', tags.includes('?!可疑名字') && tags.includes('?无证据'), tags.join('|'))
const tally = await page.locator(`${ent} [data-evidence-tally]`).innerText().catch(() => '')
check('证据条另说可疑名字的个数', tally.includes('可疑名字 2'), tally)
const summary = await page.locator(`${ent} [data-evidence-summary]`).innerText().catch(() => '')
check('读屏摘要写出可疑实体、核对不了的个数', summary.includes('2 个可能是编造的名字') && summary.includes('1 个名字核对不了'), summary)
// n / N:可疑实体进跳转(异常态),核对不了的不进(只是标注)
await page.locator(`${ent} [data-seg="${E.num}"]`).focus()
const jumps = []
for (let i = 0; i < 5; i++) {
await page.keyboard.press('n')
jumps.push(await active(page))
}
check('n 依次跳到裸数字、可疑实体、原话对不上的引文,跳过核对不了的名字',
jumps.join(',') === [E.bare, E.coupon, E.discount, E.miss, E.bare].join(','), jumps.join(','))
})
await section('e-panel', '三期:面板里的实体步骤、可疑实体的提示、引文步骤', async () => {
const p = panel(page)
await page.locator(`${ent} [data-seg="${E.week}"]`).click()
await page.waitForSelector('[data-evidence-panel] [data-ev-entity-type]', { timeout: 4000 }).catch(() => {})
check('面板标题是名字本身', (await p.locator('h3').innerText().catch(() => '')) === 'orders.week')
check('实体步骤写字段类型', (await p.locator('[data-ev-entity-type]').innerText().catch(() => '')).includes('VARCHAR(8)'))
check('实体步骤写表结构快照的同步时间', (await p.locator('[data-ev-entity-synced]').innerText().catch(() => '')).includes('2026-09-20'),
await p.locator('[data-ev-entity-synced]').innerText().catch(() => ''))
check('快照不全时照实说只存了一部分', (await p.innerText()).includes('只存了一部分'))
check('实体的来历:表结构快照', (await p.locator('[data-ev-entity-source]').allInnerTexts()).some((t) => t.includes('表结构快照')))
await page.locator(`${ent} [data-seg="${E.orders}"]`).click()
await page.waitForTimeout(250)
const queries = await p.locator('[data-ev-entity-queries]').innerText().catch(() => '')
check('表:出现在哪几次查询里', queries.includes('Q1') && queries.includes('Q2'), queries)
const srcs = await p.locator('[data-ev-entity-source]').allInnerTexts()
check('表的来历逐条列:表结构快照、查询 SQL', srcs.some((t) => t.includes('查询 Q2') && t.includes('SQL')), srcs.join(' | '))
check('实体步骤取自证据接口(按 runId:segId 取了一次)', harness.hits.includes(`e:${E.orders}`), harness.hits.filter((h) => h.startsWith('e:')).join(','))
await page.locator(`${ent} [data-seg="${E.discount}"]`).click()
// 提示要等片段接口回来(先显示「正在取」):等到名字出来再读
await page.waitForSelector('[data-evidence-panel] [data-ev-closest-name]', { timeout: 4000 }).catch(() => {})
const reason = await p.locator('[data-ev-reason]').innerText().catch(() => '')
check('可疑实体说清为什么:本次运行里哪里都没有这个名字', reason.includes('可能是编造的名字'), reason.slice(0, 80))
const closest = await p.locator('[data-ev-closest-name]').allInnerTexts()
check('可疑实体给出最接近的已知名字(最多 3 个,不带 c: 前缀)', closest.length >= 1 && closest.length <= 3
&& closest.includes('orders.amount') && closest.every((n) => !n.startsWith('c:')), closest.join(','))
check('可疑实体的面板徽标:?! 可能是编造的名字', (await p.locator('[data-ev-badge]').innerText().catch(() => '')).includes('可能是编造的名字'))
await page.locator(`${ent} [data-seg="${E.promo}"]`).click()
await page.waitForTimeout(250)
const promo = await p.innerText()
check('核对不了的名字:说快照不全、核对不了,不说编造', promo.includes('核对不了') && !promo.includes('编造'), promo.slice(0, 120))
await page.locator(`${ent} [data-seg="${E.quote}"]`).click()
await page.waitForSelector('[data-evidence-panel] [data-ev-quote-hit]', { timeout: 4000 }).catch(() => {})
const src = await p.locator('[data-ev-quote-source]').innerText().catch(() => '')
check('引文步骤:原文所在的文档和片段', src.includes('运营手册 · 退款') && src.includes('第 3 段'), src)
const hit = await p.locator('[data-ev-quote-hit]').innerText().catch(() => '')
check('引文在原文里的位置高亮出来,就是那句原话', hit === '退款金额以财务确认日为准,未确认的退款不计入当周', hit)
const ctx = await p.locator('[data-ev-quote]').innerText().catch(() => '')
check('高亮前后带着原文的上下文', ctx.includes('第三章 退款口径') && ctx.includes('部分退款'), ctx.slice(0, 80))
await page.locator(`${ent} [data-seg="${E.miss}"]`).click()
await page.waitForTimeout(250)
const miss = await p.innerText()
check('原话对不上的引文:说清找不到这句原话', miss.includes('找不到这句原话'), miss.slice(0, 120))
await page.keyboard.press('Escape')
if (SHOTS) {
for (const theme of ['dark', 'light']) {
await page.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
for (const [name, id] of [['entity', E.orders], ['suspect', E.discount], ['quote', E.quote]]) {
await page.locator(`${ent} [data-seg="${id}"]`).click()
await page.waitForTimeout(350)
await page.screenshot({ path: `${SHOTS}/evidence3-${name}-${theme}.png` })
}
await page.keyboard.press('Escape')
}
await page.evaluate(() => document.documentElement.setAttribute('data-theme', 'dark'))
}
})
await section('e-narrow', '三期在 360px:栏内展开不横向滚动;减少动效', async () => {
const narrow = '#evidence-entity-narrow'
const overflow = () => page.evaluate((sel) => {
const el = document.querySelector(sel)
return { sw: el.scrollWidth, cw: el.clientWidth }
}, narrow)
for (const id of [E.quote, E.discount, E.orders]) {
await page.locator(`${narrow} [data-seg="${id}"]`).click()
await page.waitForSelector(`${narrow} [data-evidence-panel="inline"]`, { timeout: 4000 }).catch(() => {})
await page.waitForTimeout(250)
const o = await overflow()
check(`360px 栏内面板(${id})不出横向滚动`, o.sw <= o.cw, JSON.stringify(o))
}
await page.keyboard.press('Escape')
const r = await open('/ui-harness.html?evidence=1', { reduced: true, w: 360, h: 780 })
const scroll = () => r.page.evaluate(() => ({ sw: document.documentElement.scrollWidth, vw: innerWidth }))
await r.page.locator(`${ent} [data-seg="${E.quote}"]`).click()
await r.page.waitForSelector('[data-evidence-panel] [data-ev-quote]', { timeout: 4000 }).catch(() => {})
const s1 = await scroll()
check('360px 屏幕:引文面板(底部抽屉)整页不横向滚动', s1.sw <= s1.vw, JSON.stringify(s1))
const anim = await r.page.evaluate(() => document.querySelector('[data-evidence-panel]')?.getAnimations({ subtree: true })
.filter((a) => !(a instanceof CSSTransition && Number(a.effect?.getTiming().duration) <= 0.01)).length ?? -1)
check('减少动效:引文面板没有动画', anim === 0, String(anim))
await r.page.keyboard.press('Escape')
await r.page.locator('#evidence-guess [data-ev-guess-toggle]').click().catch(() => {})
await r.page.waitForTimeout(150)
const s2 = await scroll()
check('360px 屏幕:展开猜测之后整页不横向滚动', s2.sw <= s2.vw
&& await r.page.locator('#evidence-guess [data-ev-guess]').getAttribute('data-open').catch(() => null) === 'true', JSON.stringify(s2))
const guessAnim = await r.page.evaluate(() => document.querySelector('#evidence-guess [data-ev-guess]')?.getAnimations({ subtree: true })
.filter((a) => !(a instanceof CSSTransition && Number(a.effect?.getTiming().duration) <= 0.01)).length ?? -1)
check('减少动效:展开猜测没有动画', guessAnim === 0, String(guessAnim))
check('没有运行时报错(三期 360px)', r.errors.length === 0, r.errors.join(' | '))
await r.ctx.close()
})
await section('banner', '出具横幅那一行:数字都有出处时,可疑名字、没挂依据的结论句也写出来', async () => {
const at = (key) => page.locator(`#issuance-line [data-issuance-case="${key}"]`)
const line = await at('suspect').locator('[data-evidence-line]').innerText().catch(() => '')
check('数字那半句照旧:3 个数字都有出处', line.includes('3 个数字都有出处'), line)
check('可疑名字另起一句:?! 可疑名字 2', await at('suspect').locator('[data-evidence-line-suspect]').count() === 1
&& line.includes('?! 可疑名字 2'), line)
check('没挂依据的结论句另起一句:没挂依据的结论句 1', await at('suspect').locator('[data-evidence-line-claims]').count() === 1
&& line.includes('没挂依据的结论句 1'), line)
const next = at('suspect').locator('[data-evidence-next]')
check('数字都有出处、只有可疑名字时也给「定位下一处」', await next.count() === 1)
await page.evaluate(() => { window.__issuanceNext = 0 })
await next.click()
check('点了它就去找下一处', await page.evaluate(() => window.__issuanceNext) === 1)
const clean = await at('clean').locator('[data-evidence-line]').innerText().catch(() => '')
check('都干净的那一份:只有数字那半句,不给「定位下一处」', clean.includes('3 个数字都有出处')
&& await at('clean').locator('[data-evidence-line-suspect], [data-evidence-line-claims], [data-evidence-next]').count() === 0, clean)
const names = await at('names').locator('[data-evidence-line]').innerText().catch(() => '')
check('一个数字都没有、只有可疑名字:这一行照样出来,开头不带「·」,也给「定位下一处」',
names.trim().startsWith('?! 可疑名字 1') && await at('names').locator('[data-evidence-next]').count() === 1, names)
})
await section('guess', '旧运行按数值猜的候选:默认折叠,展开写明「猜测」,淡点状线', async () => {
const g = '#evidence-guess'
const box = page.locator(`${g} [data-ev-guess]`)
check('默认折叠', await box.getAttribute('data-open').catch(() => null) === 'false')
check('折叠时看不到候选(不在页面上,不只是藏起来)', await page.locator(`${g} [data-ev-state="candidate"]`).count() === 0)
const head = await page.locator(`${g} [data-ev-guess-toggle]`).innerText().catch(() => '')
check('折叠的标题就写明「猜测」', head.includes('猜测'), head)
const toggle = page.locator(`${g} [data-ev-guess-toggle]`)
check('展开按钮是 button,带 aria-expanded=false', await toggle.evaluate((el) => el.tagName).catch(() => '') === 'BUTTON'
&& await toggle.getAttribute('aria-expanded').catch(() => null) === 'false')
const answer = await page.locator(`${g}`).innerText().catch(() => '')
check('折叠时答案本身照常显示', answer.includes('本周销售额 45,678.5 元'), answer.slice(0, 60))
await toggle.click()
await page.waitForTimeout(150)
check('展开后 aria-expanded=true', await toggle.getAttribute('aria-expanded').catch(() => null) === 'true')
const note = await page.locator(`${g} [data-ev-guess-note]`).innerText().catch(() => '')
check('展开后写明「猜测的来源,不能当证据」', note.includes('猜测的来源,不能当证据'), note)
const cands = await page.evaluate((sel) => [...document.querySelectorAll(`${sel} [data-ev-state="candidate"]`)].map((el) => {
const cs = getComputedStyle(el)
// 候选是 Markdown 里的行内标记(保留旧答案的版式),读屏靠标记里那句 sr-only 的「猜测的来源:…」
return { style: cs.textDecorationStyle, color: cs.textDecorationColor, line: el.getAttribute('data-ev-line'),
label: el.textContent ?? '', title: el.getAttribute('title') ?? '', text: el.firstChild?.textContent ?? '' }
}), g)
check('有候选的数字画成候选(4 个)', cands.length === 4, cands.map((c) => c.text).join(','))
check('候选用淡点状线,不用确定性的实线', cands.length > 0 && cands.every((c) => c.style === 'dotted' && c.line === 'dotted'),
JSON.stringify(cands[0]))
const detColor = await page.evaluate((sel) => {
const el = document.querySelector(`${sel} [data-ev-state="deterministic"]`)
return el ? getComputedStyle(el).textDecorationColor : ''
}, ent)
check('候选的线和「有出处」不是一个颜色', cands.length > 0 && cands.every((c) => c.color !== detColor), `${cands[0]?.color} / ${detColor}`)
check('候选给读屏写「猜测的来源」和候选出处,悬停也看得到', cands[0]?.label.includes('猜测的来源') && cands[0].label.includes('Q1')
&& cands[0].title.includes('Q1'), cands[0]?.label)
const list = await page.locator(`${g} [data-ev-candidates]`).innerText().catch(() => '')
check('候选清单:每个数字可能来自哪一格', list.includes('查询 Q1') && list.includes('gmv'), list.slice(0, 120))
const plain = await page.evaluate((sel) => [...document.querySelectorAll(`${sel} [data-ev-guess-body] [data-ev-state]`)]
.map((el) => el.firstChild?.textContent ?? ''), g)
check('没猜到候选的数字不画线(40%、50,000)', !plain.includes('40%') && !plain.includes('50,000'), plain.join(','))
await toggle.click()
await page.waitForTimeout(100)
check('再点一次收起', await box.getAttribute('data-open').catch(() => null) === 'false')
if (SHOTS) {
await toggle.click()
for (const theme of ['dark', 'light']) {
await page.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
await page.waitForTimeout(200)
await page.locator(g).screenshot({ path: `${SHOTS}/evidence3-guess-${theme}.png` })
}
await page.evaluate(() => document.documentElement.setAttribute('data-theme', 'dark'))
await toggle.click()
}
})
if (SHOTS) {
for (const theme of ['dark', 'light']) {
await page.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
+87 -3
View File
@@ -100,6 +100,23 @@ const DUP = {
edges: chain('in', 'ask1', 'ask2', 'caliber', 'done'),
}
/**
* 两个 choice:沙箱代码喂口径卡(G4),候选里「交给 Copilot」那一项带 handoff 标记;成果字段接哪个报告
* (G1),唯一的候选是一个 id 恰好叫 copilot 的报告撰写节点——它只是普通候选,不是「交给 Copilot」
*/
const HANDOFF = {
nodes: [
node('in', 'input', 0, '入口', { fields: [{ name: 'week', required: true }] }),
node('calc', 'code', 240, '计算', { code: 'print(1)', assign_to: 'calc' }),
node('caliber', 'metrics', 480, '周报口径', { caliber: '周报口径', caliber_version: 'v1',
metrics: [{ id: 'ratio', name: '比例', expression: 'vars.calc.ratio' }] }),
node('copilot', 'report', 720, '报告撰写', { instructions: '写周报', numbers: 'strict', on_violation: 'fail', claims: 'require_citation' }),
node('done', 'output', 960, '成果', { fields: [{ name: 'report', value: '{{ vars.story }}' }],
contract: { report_from: 'copilot', metrics_from: ['caliber'], required: ['ratio'], strict: true } }),
],
edges: chain('in', 'calc', 'caliber', 'copilot', 'done'),
}
const wf = (id, name, graph, extra = {}) => ({
id, name, description: '检查脚本伪造的工作流', graph, tags: [], version: 3, is_template: false,
status: 'draft', published_version: null, published_by: null, run_count: 0,
@@ -111,6 +128,7 @@ const FAKES = {
'pf-lib': wf('pf-lib', '__publish_check_lib__', { nodes: [], edges: [] }, { status: 'published', published_version: 4 }),
'pf-bare': wf('pf-bare', '__publish_check_bare__', BARE, { status: 'governed', published_version: 2 }),
'pf-dup': wf('pf-dup', '__publish_check_dup__', DUP, { status: 'governed', published_version: 2 }),
'pf-handoff': wf('pf-handoff', '__publish_check_handoff__', HANDOFF, { status: 'governed', published_version: 2 }),
// 带全图默认的图:画布只管节点和连线,保存、检查、修复都得把 defaults 原样带着
'pf-defs': wf('pf-defs', '__publish_check_defaults__', { ...EASY, defaults: { approval: 'always', model: 'demo-model' } }),
}
@@ -162,6 +180,19 @@ function lint(graph, level, { followsNever = false } = {}) {
add(n, 'governed.subgraph_unpinned', `${who(n)}(子工作流)没有钉住版本,口径会随上游最新版漂移`,
{ kind: 'auto', label: '钉到它最新的已发布版本 v4', preview: { field: 'workflow_version', before: null, after: 4 } })
}
if (n.type === 'code' && c.evidence_role !== 'source') {
add(n, 'governed.caliber_compute_input', `${who(n)}(沙箱代码)的产出喂给了口径卡,而它的角色是计算`, {
kind: 'choice', label: `${who(n)}的产出喂给了口径卡:它是在取数,还是在做计算?`,
options: [{ value: 'source', label: '它在取数:标成 source(取数)' },
{ value: 'copilot', label: '它在做计算:交给 Copilot 把计算挪进口径卡', handoff: true }],
})
}
if (n.type === 'output' && c.contract?.report_from && !(c.fields ?? []).every((f) => f.value.includes(`nodes.${c.contract.report_from}.`))) {
add(n, 'governed.exit_text_source', `${who(n)}的成果字段取的不是报告撰写节点的正文`, {
kind: 'choice', label: '把成果字段改成取哪个报告撰写节点的正文',
options: graph.nodes.filter((r) => r.type === 'report').map((r) => ({ value: r.id, label: who(r), hint: '报告撰写' })),
})
}
if (n.type === 'supervisor') {
add(n, 'governed.supervisor', `${who(n)}(多 Agent 协作):受管模板不允许全动态规划的节点`,
{ kind: 'assist', label: '换成固定编排是结构性的改动,交给 Copilot' })
@@ -202,6 +233,7 @@ function autofix(body, { unpublished = false, followsNever = false } = {}) {
const changes = []
const rejected = []
const applied = []
const handoff = []
const byId = (id) => graph.nodes.find((n) => n.id === id)
for (const id of body.apply ?? []) {
const fix = before.fixes.find((f) => f.id === id)
@@ -230,6 +262,15 @@ function autofix(body, { unpublished = false, followsNever = false } = {}) {
if (!Array.isArray(v) || !v.length) { rejected.push({ fix_id: id, reason: '要人选:没给选择' }); continue }
const contract = { report_from: 'write', metrics_from: ['caliber'], strict: true, required: v }
change('contract', null, contract); c.contract = contract
} else if (fix.code === 'governed.caliber_compute_input') {
const v = body.choices?.[id]
// 只认候选上的 handoff 标记,和后端 autofix._handoff 一样
if (fix.options.some((o) => o.handoff && o.value === v)) { handoff.push(id); continue }
change('evidence_role', c.evidence_role ?? null, v); c.evidence_role = v
} else if (fix.code === 'governed.exit_text_source') {
const v = body.choices?.[id]
const to = `{{ nodes.${v}.text }}`
change('fields[0].value', c.fields[0].value, to); c.fields[0].value = to
} else if (fix.code === 'contract.required_missing') {
const v = body.choices?.[id]
if (!Array.isArray(v) || !v.length) { rejected.push({ fix_id: id, reason: '要人选:没给选择' }); continue }
@@ -238,7 +279,7 @@ function autofix(body, { unpublished = false, followsNever = false } = {}) {
applied.push(id)
}
let assist = null
if (body.assist) {
if (body.assist || handoff.length) {
const team = byId('team')
if (team) {
changes.push({ fix_id: 'assist', node_id: 'team', node_title: team.data.label, field: 'max_rounds', before: team.data.config.max_rounds, after: 2,
@@ -249,7 +290,7 @@ function autofix(body, { unpublished = false, followsNever = false } = {}) {
questions: ['复核团队要换成哪一个固定编排的 Agent?它现在只有一个成员 checker,保留它的职责吗?'] }
}
const remaining = lint(graph, body.level, { followsNever })
return { graph, changes, applied, rejected, remaining: remaining.issues, assist, ok: remaining.ok, ops: [] }
return { graph, changes, applied, rejected, handoff, remaining: remaining.issues, assist, ok: remaining.ok, ops: [] }
}
// ---------------------------------------------------------------- 浏览器
@@ -261,7 +302,7 @@ const writes = []
* backend:'new'(两个接口都有)| 'old'(两个接口 404)| 'nofix'(有检查、没有 autofix)
* save:'ok' | 'fail'(保存接口 500)| 'slow'(1.5 秒后才回,看保存进行中的样子)
*/
async function open({ id = 'pf-hard', width = 1440, height = 900, backend = 'new', save = 'ok', unpublished = false } = {}) {
async function open({ id = 'pf-hard', width = 1440, height = 900, backend = 'new', save = 'ok', unpublished = false, fixDelay = 0 } = {}) {
const followsNever = id === 'pf-dup'
const ctx = await browser.newContext({ viewport: { width, height } })
opened.add(ctx)
@@ -316,6 +357,7 @@ async function open({ id = 'pf-hard', width = 1440, height = 900, backend = 'new
const body = req.postDataJSON()
state.autofixes.push(body)
if (state.backend !== 'new') return json(route, { detail: 'Not Found' }, 404)
if (fixDelay) await new Promise((r) => setTimeout(r, fixDelay))
return json(route, autofix(body, { unpublished, followsNever }))
}
if (method === 'POST' && sub === 'publish') {
@@ -793,6 +835,48 @@ await section('全图默认不会被画布弄丢:保存、发布前检查、
void first
})
await section('choice 里选「交给 Copilot」:请求带 assist、等待时说 Copilot 在修;id 叫 copilot 的报告只是普通候选', async () => {
const { page, state, errors } = await open({ id: 'pf-handoff', fixDelay: 1200 })
await openDialog(page)
const g4 = dialog(page).locator('[data-fix-choice="governed.caliber_compute_input:calc"]')
const g1 = dialog(page).locator('[data-fix-choice="governed.exit_text_source:done"]')
await g4.waitFor()
check('两个 choice 都画出来了', await g1.count() === 1)
check('没选之前,按钮不是「交给 Copilot」的样子', await g4.locator('[data-fix-handoff]').count() === 0)
await g4.getByText('它在做计算', { exact: false }).click()
const button = g4.locator('[data-fix-action="choice"]')
check('选了「交给 Copilot」那一项,按钮换成「交给 Copilot」', await button.getAttribute('data-fix-handoff') === ''
&& (await button.innerText()).includes('交给 Copilot'), await button.innerText())
await button.click()
const loading = dialog(page).locator('[data-fix-preview="loading"]')
await loading.waitFor()
check('等待时写「Copilot 正在试着修」,不是「正在生成修复预览」', (await loading.innerText()).includes('Copilot 正在试着修'), await loading.innerText())
const body = state.autofixes.at(-1)
check('请求带 assist: true,选的值原样带上', body?.assist === true && body?.choices?.['governed.caliber_compute_input:calc'] === 'copilot'
&& JSON.stringify(body?.apply) === JSON.stringify(['governed.caliber_compute_input:calc']), JSON.stringify(body))
await dialog(page).locator('[data-fix-preview="ready"], [data-fix-preview]:not([data-fix-preview="loading"])').first().waitFor()
check('Copilot 的总结摆出来了', await waitFor(page, async () => (await dialog(page).locator('[data-fix-assist]').count()) > 0))
await shoot(page, 'publish-dialog-handoff', dialog(page))
// 另一个 choice:唯一的候选是 id 叫 copilot 的报告撰写节点——普通候选,不交给 Copilot
const { page: page2, state: state2, errors: errors2 } = await open({ id: 'pf-handoff', fixDelay: 1200 })
await openDialog(page2)
const exit = dialog(page2).locator('[data-fix-choice="governed.exit_text_source:done"]')
await exit.waitFor()
await exit.locator('input[type="radio"]').first().check()
const pick = exit.locator('[data-fix-action="choice"]')
check('选了 id 叫 copilot 的报告:按钮不变成「交给 Copilot」', await pick.getAttribute('data-fix-handoff') === null
&& !(await pick.innerText()).includes('交给 Copilot'), await pick.innerText())
await pick.click()
const wait2 = dialog(page2).locator('[data-fix-preview="loading"]')
await wait2.waitFor()
check('等待时写「正在生成修复预览」', (await wait2.innerText()).includes('正在生成修复预览'), await wait2.innerText())
const body2 = state2.autofixes.at(-1)
check('请求不带 assist,选的值是 copilot(节点 id)', !body2?.assist && body2?.choices?.['governed.exit_text_source:done'] === 'copilot',
JSON.stringify(body2))
check('没有页面错误', !errors.length && !errors2.length, [...errors, ...errors2].join(' | '))
})
await section('360px 下不横向滚动', async () => {
const { page } = await open({ width: 360, height: 780 })
// 窄屏上「发布」收在「更多操作」里
+296
View File
@@ -16,6 +16,8 @@ import { chromium } from '../frontend/node_modules/playwright-core/index.mjs'
const WEB = process.env.AGENTLAB_WEB ?? 'http://localhost:5273'
const API = process.env.AGENTLAB_API ?? 'http://localhost:8000/api'
// RUNS_SHOTS=<目录>:证据页签亮暗各截几张,供人眼复核
const SHOTS = process.env.RUNS_SHOTS ?? ''
const CHROME = process.env.CHROME_PATH
?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
@@ -47,7 +49,11 @@ const check = (name, cond, detail = '') => {
* 不让一处卡住把后面的检查一起吞掉。页面是各节共用的:
* 出错那一节停在哪,下一节就从哪接着
*/
// RUNS_ONLY=证据页签 只跑段名里含这些字的段(逗号分隔;改坏验证时省时间)。前面几段给后面留的数据
// (航迹那一节的时刻、工件)只在整本跑时有,单跑依赖它们的段会报「中途出错」;check-all 不传它
const ONLY = (process.env.RUNS_ONLY ?? '').split(',').filter(Boolean)
async function section(name, fn) {
if (ONLY.length && !ONLY.some((k) => name.includes(k)) && name !== '收尾') return
console.log(`\n=== ${name} ===`)
try {
await fn()
@@ -1698,6 +1704,296 @@ await section('屏幕矮、节点多:读数区不被航迹坞压住', async ()
fakes.delete('GET /api/approvals')
})
// ------------------------------------------------------------------ 证据页签(可点击证据三期)
// 夹具是后端真跑出来的(compose_doc、guess_sources、api/evidence.py 的审计函数),只用通用名
const fxe = JSON.parse(readFileSync(new URL('../frontend/src/run/__tests__/evidence-entity.json', import.meta.url), 'utf8'))
const EV = 'fake0evidence0000000000000000'
const EV_LEGACY = 'fake0evlegacy0000000000000000'
const EV_NONE = 'fake0evnone000000000000000000'
const EV_OLD = 'fake0evoldback000000000000000'
const evGraph = { nodes: [
{ id: 'in', type: 'input', position: { x: 0, y: 0 }, data: { label: '输入', config: {} } },
{ id: 'fetch', type: 'agent', position: { x: 200, y: 0 }, data: { label: '取数', config: { tools: ['db_query__shop'] } } },
{ id: 'manual', type: 'retrieve', position: { x: 200, y: 150 }, data: { label: '查手册', config: {} } },
{ id: 'write', type: 'report', position: { x: 400, y: 0 }, data: { label: '写周报', config: {} } },
{ id: 'out', type: 'output', position: { x: 600, y: 0 }, data: { label: '成果', config: {} } },
], edges: [{ source: 'in', target: 'fetch' }, { source: 'fetch', target: 'write' }, { source: 'manual', target: 'write' },
{ source: 'write', target: 'out' }] }
const evRun = (id, output) => ({
...base, id, workflow_id: null, workflow_name: '证据检查', status: 'succeeded', run_class: 'formal',
version: 3, version_hash: null, manifest_hash: 'f'.repeat(64), manifest_seq: 88, error: null, error_node_id: null,
input: { week: '2026-W37' }, output, usage: { input_tokens: 10, output_tokens: 10, cost_usd: 0, wall_ms: 4000, active_ms: 4000, wait_ms: 0 },
created_at: new Date(Date.now() - 7200e3).toISOString(), started_at: new Date(Date.now() - 7200e3).toISOString(),
finished_at: new Date(Date.now() - 7196e3).toISOString(),
})
const evEvents = (output, report = true) => {
const t0 = Date.now() / 1000 - 7200
return [
{ seq: 1, type: 'run.started', node_id: null, ts: t0, data: { nodes: 5 } },
{ seq: 2, type: 'node.started', node_id: 'write', ts: t0 + 1, data: { node_type: 'report', label: '写周报' } },
...(report ? [{ seq: 3, type: 'report.checked', node_id: 'write', ts: t0 + 3, data: fxe.report_checked }] : []),
{ seq: 4, type: 'node.finished', node_id: 'write', ts: t0 + 3.1, data: { duration_ms: 2100 } },
{ seq: 5, type: 'run.finished', node_id: null, ts: t0 + 4, data: { output, usage: {}, timing: { wall_ms: 4000, active_ms: 4000, wait_ms: 0 } } },
]
}
/** 证据相关的请求(审计、导出、片段)记下来:导出发出的请求要带对 format 和 groups */
const evRequests = []
page.on('request', (r) => {
const u = new URL(r.url())
if (/\/api\/runs\/fake0ev[^/]*\/evidence/.test(u.pathname)) evRequests.push(`${u.pathname}${u.search}`)
})
const auditFake = (body, csv) => (url) => {
const format = url.searchParams.get('format')
const groups = url.searchParams.get('groups')?.split(',')
const pick = groups ? { ...body, groups: body.groups.filter((g) => groups.includes(g.key)) } : body
if (format === 'csv') {
return { status: 200, body: csv, headers: { 'Content-Type': 'text/csv; charset=utf-8',
'Content-Disposition': `attachment; filename="evidence-${body.run_id.slice(0, 8)}.csv"` } }
}
if (format === 'json') {
return { status: 200, body: JSON.stringify(pick), headers: { 'Content-Type': 'application/json',
'Content-Disposition': `attachment; filename="evidence-${body.run_id.slice(0, 8)}.json"` } }
}
return { status: 200, json: pick }
}
const evFakes = (id, { output, graph, audit, csv, report = true }) => {
fakes.set(`GET /api/runs/${id}`, () => ({ status: 200, json: evRun(id, output) }))
fakes.set(`GET /api/runs/${id}/events`, () => ({ status: 200, json: evEvents(output, report) }))
fakes.set(`GET /api/runs/${id}/graph`, () => ({ status: 200, json: { graph: evGraph, workflow_id: null, version: 3 } }))
fakes.set(`GET /api/runs/${id}/artifacts`, () => ({ status: 200, json: [] }))
fakes.set(`GET /api/runs/${id}/evidence`, () => ({ status: 200, json: { ...graph, run_id: id } }))
fakes.set(`GET /api/runs/${id}/evidence/audit`, audit ? auditFake({ ...audit, run_id: id }, csv ?? '')
: () => ({ status: 404, json: { detail: 'Not Found' } }))
}
const openEvidence = async (id) => {
await page.goto(`${WEB}/runs/${id}?view=evidence`, { waitUntil: 'networkidle' })
await page.locator('[data-view-pane=evidence] [data-evidence-pane]:not([data-evidence-pane=loading])').waitFor({ timeout: 8000 })
await page.waitForTimeout(300)
}
const auditGroups = () => page.locator('[data-audit-table] tbody[data-audit-group]').evaluateAll((els) => els.map((e) => e.getAttribute('data-audit-group')))
const auditRowsShown = () => page.locator('[data-audit-table] tr[data-audit-row]').count()
await section('证据页签:左边报告、右边常驻面板、下方审计表', async () => {
evFakes(EV, { output: fxe.output, graph: fxe.graph, audit: fxe.audit, csv: fxe.audit_csv })
fakes.set(`GET /api/artifacts/${fxe.doc_artifact}`, () => ({ status: 200, json: { id: fxe.doc_artifact, content: fxe.doc } }))
fakes.set(`GET /api/runs/${EV}/evidence/segments/`, () => ({ status: 404, json: {} }))
await page.route(new RegExp(`/api/runs/${EV}/evidence/segments/`), (r) => {
const sid = decodeURIComponent(new URL(r.request().url()).pathname.split('/').pop())
return fxe.segments[sid] ? r.fulfill({ json: fxe.segments[sid] }) : r.fulfill({ status: 404, json: { detail: '没有这个片段' } })
})
await page.goto(`${WEB}/runs/${EV}`, { waitUntil: 'networkidle' })
await page.locator('[data-run-detail]').waitFor()
check('详情多了「证据」页签(在航迹和工件之间)', await viewTab('evidence').count() === 1
&& (await page.locator('[data-run-detail] [role=tab]').evaluateAll((els) => els.map((e) => e.getAttribute('data-tab')))).join(',') === 'stream,trace,evidence,artifacts')
check('没打开证据页签之前不取证据图和审计表', !evRequests.some((u) => u.includes(EV)), evRequests.join(' '))
await viewTab('evidence').click()
await page.locator('[data-view-pane=evidence] [data-evidence-pane=cited]').waitFor({ timeout: 8000 }).catch(() => {})
await page.waitForTimeout(400)
check('证据页签能打开,地址记着 ?view=evidence', await viewTab('evidence').getAttribute('aria-selected') === 'true'
&& new URL(page.url()).searchParams.get('view') === 'evidence')
check('左边是报告(逐段可点的文档)', await page.locator('[data-evidence-report=write] [data-evidence-doc] [data-seg]').count() > 5)
check('右边是常驻面板的位置,没点片段时说怎么用', await page.locator('[data-evidence-dock] [data-evidence-dock-idle]').count() === 1)
const seal = await page.locator('[data-evidence-seal]').innerText().catch(() => '')
check('显示封存核对的结果', await page.locator('[data-evidence-seal]').getAttribute('data-evidence-seal') === 'done'
&& seal.includes('已封存 · 核对一致') && seal.includes('88'), seal)
check('……也说报告文档的哈希一致', (await page.locator('[data-evidence-doc-hash=ok]').innerText().catch(() => '')).includes('写周报'))
check('审计表按状态分组:无证据、可疑实体在前,有出处在后', (await auditGroups()).join(',') === 'none,suspicious,cited',
(await auditGroups()).join(','))
const counts = await page.locator('[data-audit-group-toggle]').allInnerTexts()
check('每组写着条数(无证据 3、可疑实体 3、有出处 10)', counts.join('|').includes('无证据\n3') || (counts[0].includes('3') && counts[1].includes('3') && counts[2].includes('10')),
counts.join(' | ').replace(/\n/g, ' '))
check('一共 16 行', await auditRowsShown() === 16, String(await auditRowsShown()))
// 这张图的出口没有出具契约:后端说「要求了,但没有契约按它判档」,不说「出具时计入缺口」。表里照后端的原话写
const claim = page.locator('[data-audit-table] tbody[data-audit-group=none] tr[data-audit-row]', { hasText: '另外参考了' })
const claimNote = fxe.audit.groups.find((g) => g.key === 'none')?.rows.find((r) => r.kind === 'claim')?.note ?? '(夹具里没有结论句那行)'
check('没挂依据的结论句也列在无证据里,原因照后端的原话(claims: require_citation、没有出具契约)', await claim.count() === 1
&& claimNote.includes('require_citation') && (await claim.innerText()).includes(claimNote), claimNote)
check('可疑实体那组有「可能是编造的名字」和「核对不了」', (await page.locator('[data-audit-table] tbody[data-audit-group=suspicious]').innerText())
.includes('可能是编造的名字') && (await page.locator('[data-audit-table] tbody[data-audit-group=suspicious]').innerText()).includes('核对不了'))
check('有出处的行写着在封存范围内', await page.locator('[data-audit-table] tbody[data-audit-group=cited] [data-audit-sealed=yes]').count() === 10)
check('反引号里的名字在表里不带反引号', !(await page.locator('[data-audit-table]').innerText()).includes('`'))
// 只看无证据 / 可疑实体
await page.locator('[data-audit-filter-option=problems]').click()
await page.waitForTimeout(200)
check('筛选「只看无证据 / 可疑实体」:只剩这两组', (await auditGroups()).join(',') === 'none,suspicious' && await auditRowsShown() === 6,
`${(await auditGroups()).join(',')} ${await auditRowsShown()}`)
check('筛选是一组单选(radio),选中的那项 aria-checked', await page.locator('[data-audit-filter-option=problems]').getAttribute('aria-checked') === 'true')
// 导出:发出的请求要带对 format,筛选了就带 groups
evRequests.length = 0
const dl1 = page.waitForEvent('download', { timeout: 5000 }).catch(() => null)
await page.locator('[data-audit-export=csv]').click()
const d1 = await dl1
check('导出 CSV:请求 /evidence/audit?format=csv,只要筛出来的两组',
evRequests.some((u) => u === `/api/runs/${EV}/evidence/audit?format=csv&groups=none%2Csuspicious`), evRequests.join(' '))
check('……下载的文件名是后端给的', d1?.suggestedFilename() === `evidence-${EV.slice(0, 8)}.csv`, d1?.suggestedFilename() ?? '没有下载')
await page.locator('[data-audit-filter-option=all]').click()
evRequests.length = 0
const dl2 = page.waitForEvent('download', { timeout: 5000 }).catch(() => null)
await page.locator('[data-audit-export=json]').click()
const d2 = await dl2
check('导出 JSON:请求 ?format=json,不筛就不带 groups', evRequests.some((u) => u === `/api/runs/${EV}/evidence/audit?format=json`),
evRequests.join(' '))
check('……下载了 .json', d2?.suggestedFilename()?.endsWith('.json'), d2?.suggestedFilename() ?? '没有下载')
// 键盘:整张表一个 Tab 位,↑/↓ 逐行走完每一行,回车在右边打开
const focusables = await page.locator('[data-audit-table] [data-audit-focus]').evaluateAll((els) => els.map((e) => e.tabIndex))
check('表里只有一个 Tab 位(roving)', focusables.filter((t) => t === 0).length === 1 && focusables.length === 16, focusables.join(','))
await page.locator('[data-audit-table] [data-audit-focus][tabindex="0"]').focus()
const seen = [await page.evaluate(() => document.activeElement?.getAttribute('data-audit-focus'))]
for (let i = 0; i < 20; i++) {
await page.keyboard.press('ArrowDown')
seen.push(await page.evaluate(() => document.activeElement?.getAttribute('data-audit-focus')))
}
const uniq = [...new Set(seen.filter(Boolean))]
check('↓ 能逐行走完全部 16 行(包括没挂依据的结论句这种打不开的行)', uniq.length === 16, `${uniq.length} 行`)
check('走到底停住,不首尾相接', seen[seen.length - 1] === seen[seen.length - 2])
await page.keyboard.press('Home')
const home = await page.evaluate(() => document.activeElement?.getAttribute('data-audit-focus'))
await page.keyboard.press('End')
const end = await page.evaluate(() => document.activeElement?.getAttribute('data-audit-focus'))
check('Home / End 到第一行、最后一行', home === uniq[0] && end === uniq[uniq.length - 1], `${home} / ${end}`)
// 找到「orders.week」那一行,回车打开
const target = await page.locator('[data-audit-table] [data-audit-open]', { hasText: /^orders\.week$/ }).getAttribute('data-audit-focus')
await page.keyboard.press('Home')
for (let i = 0; i < 20; i++) {
if (await page.evaluate(() => document.activeElement?.getAttribute('data-audit-focus')) === target) break
await page.keyboard.press('ArrowDown')
}
await page.keyboard.press('Enter')
await page.locator('[data-evidence-dock] [data-evidence-panel=dock] [data-ev-entity-type]').waitFor({ timeout: 5000 }).catch(() => {})
check('回车在右边的常驻面板里打开这一段:实体步骤、字段类型', (await page.locator('[data-evidence-dock] [data-evidence-panel] h3').innerText().catch(() => '')) === 'orders.week'
&& (await page.locator('[data-evidence-dock] [data-ev-entity-type]').innerText().catch(() => '')).includes('VARCHAR'))
check('打开之后焦点还在表里(接着往下走)', await page.evaluate(() => document.activeElement?.getAttribute('data-audit-focus')) === target)
check('面板开着时空位提示收起', await page.locator('[data-evidence-dock] [data-evidence-dock-idle]').count() === 0)
check('正文里对应的片段标着展开', await page.locator('[data-evidence-report=write] [data-seg][aria-expanded=true]').innerText().catch(() => '') === 'orders.week')
// 点正文里的片段:面板跟着换
await page.locator('[data-evidence-report=write] [data-seg]', { hasText: '退款金额以财务确认日为准' }).click()
await page.locator('[data-evidence-dock] [data-ev-quote-hit]').waitFor({ timeout: 5000 }).catch(() => {})
check('点正文里的引文:右边换成引文步骤,原文里高亮', (await page.locator('[data-evidence-dock] [data-ev-quote-hit]').innerText().catch(() => ''))
.includes('退款金额以财务确认日为准'))
if (SHOTS) {
for (const theme of ['dark', 'light']) {
await page.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
await page.waitForTimeout(250)
await page.screenshot({ path: `${SHOTS}/runs-evidence-${theme}.png` })
await page.locator('[data-evidence-audit]').scrollIntoViewIfNeeded()
await page.waitForTimeout(150)
await page.screenshot({ path: `${SHOTS}/runs-evidence-audit-${theme}.png` })
}
await page.evaluate(() => document.documentElement.removeAttribute('data-theme'))
}
await page.keyboard.press('Escape')
})
await section('证据页签:同一段文字里好几条同样的违规、正文里点不开的行', async () => {
// 夹具同样是后端真跑的:粗体、链接里反引号写的可疑名字只记违规、不切片段——同一段文字上两条 unknown_entity、
// 两条 unverified_entity(片段和 code 都相同),列表序号 100. 是结构片段上的裸数字。这几行正文里都点不开
const dup = fxe.dup
const EV_DUP = 'fake0evdupviol000000000000000'
evFakes(EV_DUP, { output: dup.output, graph: dup.graph, audit: dup.audit })
fakes.set(`GET /api/artifacts/${dup.doc_artifact}`, () => ({ status: 200, json: { id: dup.doc_artifact, content: dup.doc } }))
await page.route(new RegExp(`/api/runs/${EV_DUP}/evidence/segments/`), (r) => {
const sid = decodeURIComponent(new URL(r.request().url()).pathname.split('/').pop())
return dup.segments[sid] ? r.fulfill({ json: dup.segments[sid] }) : r.fulfill({ status: 404, json: { detail: '没有这个片段' } })
})
const consoleErrors = []
const onConsole = (m) => { if (m.type() === 'error') consoleErrors.push(m.text()) }
page.on('console', onConsole)
try {
await openEvidence(EV_DUP)
await page.locator('[data-audit-table]').waitFor({ timeout: 5000 }).catch(() => {})
const texts = await page.locator('[data-audit-table] [data-audit-focus]').allInnerTexts()
const keys = await page.locator('[data-audit-table] tr[data-audit-row]').evaluateAll((els) => els.map((e) => e.getAttribute('data-audit-row')))
const total = dup.audit.groups.reduce((n, g) => n + g.rows.length, 0)
check(`每条违规一行(${total} 行),同一片段同一种问题的几行键各不相同`, keys.length === total && new Set(keys).size === keys.length,
keys.join(' '))
check('React 没有报「两个子元素键相同」', !consoleErrors.some((t) => /same key/i.test(t)), consoleErrors.find((t) => /same key/i.test(t))?.slice(0, 120) ?? '')
await page.locator('[data-audit-table] [data-audit-focus][tabindex="0"]').focus()
const seen = [await page.evaluate(() => document.activeElement?.getAttribute('data-audit-focus'))]
for (let i = 0; i < total + 2; i++) {
await page.keyboard.press('ArrowDown')
seen.push(await page.evaluate(() => document.activeElement?.getAttribute('data-audit-focus')))
}
const walked = [...new Set(seen.filter(Boolean))]
check(`↓ 逐行走完全部 ${total} 行,不卡在同一片段的第一条违规上`, walked.length === total
&& seen.slice(0, total - 1).every((k, i) => k !== seen[i + 1]), `${walked.length} 行:${seen.join(' → ')}`)
const reached = await page.evaluate((ks) => ks.map((k) => document.querySelector(`[data-audit-focus="${CSS.escape(k)}"]`)?.textContent), walked)
check('……粗体、链接里的四个可疑名字都走得到', ['orders.coupon_id', 'orders.promo_code', 'campaign_tags', 'promo_rules'].every((n) => reached.includes(n)),
reached.join('、'))
// 点不开的行不画成按钮:只有有状态的片段(这里是那个有出处的数字)能在右边打开
const openers = await page.locator('[data-audit-table] [data-audit-open]').evaluateAll((els) => els.map((e) => e.getAttribute('data-audit-open')))
check('只有正文里点得开的片段画成按钮(文字片段、结构片段上的违规不是)', openers.join(',') === 's1', openers.join(',') || '一个都没有')
const hidden = page.locator('[data-audit-table] tr[data-audit-row]:has([data-audit-hidden])')
check('……点不开的五行都说清只在表里列出', await hidden.count() === 5
&& (await hidden.first().innerText()).includes('只在这里列出'), String(await hidden.count()))
const deadKey = keys.find((k, i) => texts[i] === 'orders.promo_code')
await page.locator(`[data-audit-table] [data-audit-focus="${deadKey}"]`).focus()
await page.keyboard.press('Enter')
await page.waitForTimeout(300)
check('……在点不开的行上按回车:右边不开一个空面板,也不报错', await page.locator('[data-evidence-dock] [data-evidence-dock-idle]').count() === 1)
await page.locator('[data-audit-table] [data-audit-open="s1"]').click()
await page.locator('[data-evidence-dock] [data-evidence-panel]').waitFor({ timeout: 5000 }).catch(() => {})
check('点得开的那行:右边打开这一段', (await page.locator('[data-evidence-dock] [data-evidence-panel] h3').innerText().catch(() => '')) === '45,678.5')
await page.keyboard.press('Escape')
} finally {
page.off('console', onConsole)
for (const k of [...fakes.keys()]) if (k.includes(EV_DUP)) fakes.delete(k)
fakes.delete(`GET /api/artifacts/${dup.doc_artifact}`)
}
})
await section('证据页签:没有报告的运行照实说明(none / 旧运行猜测 / 老后端)', async () => {
evFakes(EV_LEGACY, { output: fxe.legacy.output, graph: fxe.legacy.graph, audit: fxe.legacy.audit, report: false })
await openEvidence(EV_LEGACY)
check('没有契约的旧运行:mode 是 legacy_text,照实说', await page.locator('[data-evidence-pane=legacy_text]').count() === 1
&& (await page.locator('[data-evidence-mode-note=legacy_text]').innerText()).includes('没有出具契约'))
check('猜测默认收起', await page.locator('[data-evidence-legacy-text] [data-ev-guess]').getAttribute('data-open') === 'false')
check('审计表里「旧运行猜测」那组默认收起', await page.locator('tbody[data-audit-group=candidate]').getAttribute('data-audit-collapsed') === '1'
&& await page.locator('tbody[data-audit-group=candidate] tr[data-audit-row]').count() === 0)
await page.locator('[data-evidence-legacy-text] [data-ev-guess-toggle]').click()
check('展开猜测写明「猜测的来源,不能当证据」', (await page.locator('[data-evidence-legacy-text] [data-ev-guess-note]').innerText().catch(() => ''))
.includes('猜测的来源,不能当证据'))
await page.locator('[data-audit-group-toggle=candidate]').click()
check('展开那一组:有候选的 4 个数字,线型是候选那一档', await page.locator('tbody[data-audit-group=candidate] tr[data-audit-row]').count() === 4
&& (await page.locator('tbody[data-audit-group=candidate] tr[data-audit-row]').evaluateAll((els) => els.every((e) => e.getAttribute('data-audit-state') === 'candidate'))))
if (SHOTS) {
for (const theme of ['dark', 'light']) {
await page.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
await page.waitForTimeout(200)
await page.screenshot({ path: `${SHOTS}/runs-evidence-legacy-${theme}.png` })
}
await page.evaluate(() => document.documentElement.removeAttribute('data-theme'))
}
evFakes(EV_NONE, { output: { answer: '这次没有数字' }, report: false,
graph: { schema: 'agentlab.evidence/1', mode: 'none', note: '这次运行没有报告文档,也没有出具契约,没有可以展示的证据', seal: { sealed: true, ok: true },
reports: [], evidence: [], edges: [] },
audit: { schema: 'agentlab.evidence.audit/1', mode: 'none', seal: { sealed: true, ok: true }, reports: [], groups: [], counts: {}, total: 0 } })
await openEvidence(EV_NONE)
check('mode 为 none:照实说没有证据', await page.locator('[data-evidence-pane=none] [data-evidence-mode-note=none]').count() === 1
&& (await page.locator('[data-evidence-mode-note=none]').innerText()).includes('没有'))
// 老后端:审计接口不存在(404 没有机读码)——清单按页面上的报告自己拼,导出也按页面上的
evFakes(EV_OLD, { output: fxe.output, graph: fxe.graph, audit: null })
await openEvidence(EV_OLD)
await page.locator('[data-audit-fallback]').waitFor({ timeout: 5000 }).catch(() => {})
check('老后端没有审计接口:照实说,清单按页面上的报告拼', await page.locator('[data-audit-fallback=unsupported]').count() === 1
&& await auditRowsShown() > 10, String(await auditRowsShown()))
const dl = page.waitForEvent('download', { timeout: 5000 }).catch(() => null)
await page.locator('[data-audit-export=csv]').click()
const d = await dl
check('……导出退回按页面上的清单,也照实说', !!d && (await page.locator('[data-toast], [role=status], [role=alert]').allInnerTexts()).join(' ').includes('后端没有导出接口'))
for (const id of [EV, EV_LEGACY, EV_NONE, EV_OLD]) {
for (const k of [...fakes.keys()]) if (k.includes(id)) fakes.delete(k)
}
fakes.delete(`GET /api/artifacts/${fxe.doc_artifact}`)
})
await section('收尾', async () => {
// 提取模板之后会跳进画布:画布一打开就拿图去做校验、变量分析,这两个是带图的只读 POST
// (同样被探针拦下,不落库)。赶上它们发出来之前就离开了画布的话就没有
+234 -4
View File
@@ -7,6 +7,7 @@
//
// 跑之前前端得起着(./scripts/dev.sh),默认连 5273。对别的实例(比如一份沙箱拷贝)跑时
// 带上地址:AGENTLAB_WEB=http://localhost:<前端端口> node scripts/check-studio.mjs
import { readFileSync } from 'node:fs'
import { chromium } from '../frontend/node_modules/playwright-core/index.mjs'
const WEB = process.env.AGENTLAB_WEB ?? 'http://localhost:5273'
@@ -100,6 +101,19 @@ const TEAM_BOUND = {
? { ...n, data: { ...n.data, config: { ...n.data.config, tools: [...QUERY_TOOLS] } } } : n)),
}
// 可疑实体、引文、表名字段名的报告(可点击证据三期):夹具是后端真跑出来的,只用通用名
const fxe = JSON.parse(readFileSync(new URL('../frontend/src/run/__tests__/evidence-entity.json', import.meta.url), 'utf8'))
const EV_GRAPH = {
nodes: [
node('start', 'input', 0, 200, '输入', { fields: [{ name: 'week', required: true }] }),
node('fetch', 'agent', 300, 120, '取数', { prompt: '查 {{ input.week }} 的订单', tools: ['db_query__shop'], assign_to: 'rows' }),
node('manual', 'retrieve', 300, 320, '查手册', { query: '退款口径', collection: 'ops', assign_to: 'manual' }),
node('write', 'report', 640, 200, '写周报', { instructions: '写本周周报', numbers: 'strict', claims: 'require_citation' }),
node('done', 'output', 980, 200, '成果', { fields: [{ name: 'answer', value: '{{ nodes.write.text }}' }] }),
],
edges: [edge('start', 'fetch'), edge('start', 'manual'), edge('fetch', 'write'), edge('manual', 'write'), edge('write', 'done')],
}
const wf = (id, extra) => ({
id, name: extra.name, description: extra.description ?? '检查脚本伪造的工作流', graph: extra.graph ?? GRAPH,
tags: extra.tags ?? [], version: extra.version ?? 3, is_template: !!extra.is_template,
@@ -113,6 +127,7 @@ const FAKES = {
'st-tpl': wf('st-tpl', { name: '__studio_check_tpl__', is_template: true, tags: ['extracted'] }),
'st-team': wf('st-team', { name: '__studio_check_team__', graph: TEAM_BOUND, version: 2, published_version: 2, status: 'published' }),
'st-lint': wf('st-lint', { name: '__studio_check_lint__', graph: TEAM_GRAPH, version: 1 }),
'st-ev': wf('st-ev', { name: '__studio_check_ev__', graph: EV_GRAPH, version: 2 }),
}
const VERSIONS = [
{ id: 'v3', version: 3, note: '', created_at: '2026-09-26T02:00:00Z' },
@@ -168,7 +183,7 @@ async function ready(page, fn, what, { arg = null, timeout = 15000, retry = true
* only:目录里只放这几张伪造的(不混真实的),用来造「删完一张不剩」
* platform:伪装成别的平台('Windows'),看快捷键提示是不是跟着平台走
*/
async function open({ width = 1440, height = 900, path = '/studio/st-main', prefs = {}, stream, only, platform, init } = {}) {
async function open({ width = 1440, height = 900, path = '/studio/st-main', prefs = {}, stream, only, platform, init, before } = {}) {
const ctx = await browser.newContext({ viewport: { width, height } })
opened.add(ctx)
// init:[函数, 参数],在页面脚本之前跑(比如装数渲染次数的钩子)
@@ -277,6 +292,8 @@ async function open({ width = 1440, height = 900, path = '/studio/st-main', pref
input: {}, output: {}, error: '', usage: {}, created_at: '2026-09-26T02:00:00Z',
}))
// before:页面第一次加载之前再装几条路由(画布一打开就发的请求,比如报告节点卡去取最近一次运行)
if (before) await before(page)
await page.goto(`${WEB}${path}`, { waitUntil: 'networkidle' })
await ready(page, () => window.__studio?.getState().workflow != null, '画布的 store(window.__studio)')
await page.waitForTimeout(500)
@@ -1779,9 +1796,14 @@ await section('自动排版:请求在路上时画布锁了或改了,不套
const okToast = page.locator('[role="status"] > div').filter({ hasText: '已重新排版' })
const pos = () => S(page, () => JSON.stringify(window.__studio.getState().nodes.map((n) => [n.id, n.position.x, n.position.y])))
const layoutBtn = page.getByRole('button', { name: '自动排版' })
// 等排版接口真的回来再看结果:固定等 1100ms 在四道并行、后端忙的时候不够(接口本身就压了 700ms)
const laidOut = () => page.waitForResponse((r) => new URL(r.url()).pathname.endsWith('/api/copilot/layout'),
{ timeout: 15000 }).catch(() => null)
const settle = async (done) => { await done; await page.waitForTimeout(250) }
const p0 = await pos()
const past0 = (await st(page)).past
let done = laidOut()
await layoutBtn.click()
await page.waitForTimeout(150)
await page.evaluate(() => window.__studio.setState((s) => ({
@@ -1789,7 +1811,7 @@ await section('自动排版:请求在路上时画布锁了或改了,不套
input: {}, output: {}, error: '', usage: {}, created_at: '2026-09-26T02:00:00Z' },
runPhase: 'running', trace: { ...s.trace, phase: 'running', runClass: 'formal' },
})))
await page.waitForTimeout(1100)
await settle(done)
check('正式运行半路开始:排版不套用', await pos() === p0 && (await st(page)).past === past0)
check('也不报「已重新排版」(撤销按钮会撤掉别的改动)', await okToast.count() === 0)
check('说清为什么没排', await page.locator('[role="status"] > div').filter({ hasText: '正式运行进行中' }).count() === 1)
@@ -1798,17 +1820,19 @@ await section('自动排版:请求在路上时画布锁了或改了,不套
run: { ...s.run, status: 'succeeded' }, runPhase: 'succeeded', trace: { ...s.trace, phase: 'succeeded' },
})))
await page.waitForTimeout(150)
done = laidOut()
await layoutBtn.click()
await page.waitForTimeout(150)
await S(page, () => window.__studio.getState().updateNode('lookup', { label: '背景检索(排版时改的)' }))
await page.waitForTimeout(1100)
await settle(done)
const kept = await S(page, () => window.__studio.getState().nodes.find((n) => n.id === 'lookup')?.data.label)
check('排版期间又改了画布:不拿旧图的排版盖掉刚才的改动', kept === '背景检索(排版时改的)', kept)
check('说清这次排版没套用', await okToast.count() === 0
&& await page.locator('[role="status"] > div').filter({ hasText: '排版期间画布又改过了' }).count() === 1)
done = laidOut()
await layoutBtn.click()
await page.waitForTimeout(1100)
await settle(done)
check('正常情况照样排版、给撤销', await okToast.count() === 1 && await okToast.locator('button:has-text("撤销")').count() === 1)
check('没有运行时报错', errors.length === 0, errors.slice(0, 2).join(' | '))
await ctx.close()
@@ -2120,6 +2144,212 @@ await section('发起就被拒(工具不存在)给修复入口;整形节
await run.ctx.close()
})
await section('证据路径:点开报告片段时画布高亮、节点名能对准;报告卡上的章', async () => {
// 运行号用夹具里文档记着的那个:成果字段取文档时核对「是不是这次运行写的」,对不上就按普通文本画
const EV_RUN = fxe.run_id
const json = (route, body, status = 200) => route.fulfill({ status, contentType: 'application/json', body: JSON.stringify(body) })
/** 伪造这张图的「最近一次运行」:latest 为 null 时一次都没跑过;传函数时每次请求现取(中途换成新跑的那次) */
const routes = (latest) => async (page) => {
await page.route((u) => { const x = new URL(u); return x.pathname === '/api/runs' && x.searchParams.get('workflow_id') === 'st-ev' },
(r) => {
const id = typeof latest === 'function' ? latest() : latest
return json(r, id ? [{ id, workflow_id: 'st-ev', status: 'succeeded', run_class: 'exploratory' }] : [])
})
await page.route(new RegExp(`/api/runs/${fxe.run_id}/evidence$`), (r) => json(r, fxe.graph))
await page.route(new RegExp(`/api/runs/${fxe.run_id}/evidence/audit(\\?.*)?$`), (r) => json(r, fxe.audit))
await page.route(new RegExp(`/api/runs/${fxe.dup.run_id}/evidence/audit(\\?.*)?$`), (r) => json(r, fxe.dup.audit))
await page.route(new RegExp(`/api/artifacts/${fxe.doc_artifact}$`), (r) => json(r, { id: fxe.doc_artifact, content: fxe.doc }))
await page.route(new RegExp(`/api/artifacts/${fxe.dup.doc_artifact}$`), (r) => json(r, { id: fxe.dup.doc_artifact, content: fxe.dup.doc }))
await page.route(new RegExp(`/api/runs/${fxe.run_id}/evidence/segments/`), (r) => {
const sid = decodeURIComponent(new URL(r.request().url()).pathname.split('/').pop())
return fxe.segments[sid] ? json(r, fxe.segments[sid]) : json(r, { detail: '没有这个片段' }, 404)
})
}
const stamp = (page) => page.locator('.react-flow__node[data-id="write"] [data-report-stamp]')
const st = fxe.report_checked.stats
const cited = st.numbers_cited + st.values + st.entities + st.quotes
const none = (st.numbers - st.numbers_cited) + Math.max(0, st.uncited_numbers + st.unresolved - (st.numbers - st.numbers_cited))
+ st.unknown_entities + st.uncited_claims
// 另一次运行(结论句策略 off):章上的数照 stampCounts 的口径算
const sd = fxe.dup.report_checked.stats
const dupText = `引用 ${sd.numbers_cited + sd.values + (sd.entities ?? 0) + (sd.quotes ?? 0)} · 无证据 ${(sd.numbers - sd.numbers_cited)
+ Math.max(0, sd.uncited_numbers + sd.unresolved - (sd.numbers - sd.numbers_cited)) + (sd.unknown_entities ?? 0)}`
/** 画布上把运行摘下来(RunHud「清除」):等它重新去取这张图的最近一次运行(取回来、画完再读章) */
const clearAndRefetch = async (pg) => {
const refetch = pg.waitForRequest((r) => { const x = new URL(r.url()); return x.pathname === '/api/runs' && x.searchParams.get('workflow_id') === 'st-ev' },
{ timeout: 3000 }).catch(() => null)
await S(pg, () => window.__studio.getState().clearRun())
const req = await refetch
await pg.waitForLoadState('networkidle').catch(() => {})
await pg.waitForTimeout(400)
return !!req
}
// 一次都没跑过:不画章
let latestRun = null
const { page, errors } = await open({ path: '/studio/st-ev', before: routes(() => latestRun) })
await page.waitForTimeout(400)
check('这张图没有运行:报告节点卡上不画章', await stamp(page).count() === 0)
// 挂上一次运行:report.checked 落下就盖章,数字取它的统计(结论句策略为 require_citation,没挂依据的结论句计入)
await S(page, ({ id, rc, output }) => {
const s = window.__studio
const t = Date.now() / 1000 - 5
s.setState({ run: { id, workflow_id: 'st-ev', workflow_name: '__studio_check_ev__', status: 'queued', input: { week: '2026-W37' },
output: {}, error: null, usage: {}, run_class: 'exploratory', version: null } })
const list = [['run.started', null, {}], ['node.started', 'write', { label: '写周报', node_type: 'report' }],
['report.checked', 'write', rc], ['node.finished', 'write', { duration_ms: 1200 }],
['run.finished', null, { output, usage: {}, timing: { wall_ms: 1500, active_ms: 1500, wait_ms: 0 } }]]
list.forEach((e, i) => s.getState().applyEvent({ seq: i + 1, type: e[0], node_id: e[1], data: e[2], ts: t + i * 0.2 }))
}, { id: EV_RUN, rc: fxe.report_checked, output: fxe.output })
await stamp(page).waitFor({ timeout: 4000 }).catch(() => {})
const text = await stamp(page).innerText().catch(() => '')
check(`报告卡上盖章「引用 ${cited} · 无证据 ${none}」`, text === `引用 ${cited} · 无证据 ${none}`, text)
const title = await stamp(page).getAttribute('title').catch(() => '')
check('章的悬停说明写出可疑名字、没挂依据的结论句计入缺口', (title ?? '').includes('可能是编造的名字 2')
&& (title ?? '').includes('计入缺口'), (title ?? '').replace(/\n/g, ' / '))
check('有缺口的章用提醒色,不是绿的', (await stamp(page).getAttribute('class')).includes('is-degraded'))
check('别的节点卡上没有章', await page.locator('[data-report-stamp]').count() === 1)
// 右栏的报告点开片段:证据路径画到画布上(LineageLayer 的 style[data-lineage])
const doc = page.locator('[data-assistant-panel] [data-evidence-doc]')
await doc.waitFor({ timeout: 6000 }).catch(() => {})
check('右栏的成果是逐段可点的报告', await doc.locator('[data-seg]').count() > 5)
await doc.locator('[data-seg]', { hasText: /^orders$/ }).first().click()
await page.waitForSelector('[data-assistant-panel] [data-evidence-panel="inline"]', { timeout: 4000 }).catch(() => {})
await page.waitForTimeout(300)
const lineage = await page.evaluate(() => {
const el = document.querySelector('style[data-lineage]')
return el ? { var: el.getAttribute('data-lineage'), css: el.textContent } : null
})
check('点开片段:画布上画出证据路径(LineageLayer 的 data-lineage 是这段证据)', lineage?.var === '证据 orders', lineage?.var ?? '没有')
check('……产出证据的查询节点实线描边、报告节点虚线描边', !!lineage && /\[data-id="fetch"\][^{]*> \.nc \{\s*box-shadow/.test(lineage.css)
&& /\[data-id="write"\][^{]*> \.nc \{\s*outline: 1\.5px dashed/.test(lineage.css), (lineage?.css ?? '').slice(0, 160))
const state = await S(page, () => window.__studio.getState().lineage)
check('……用的是 setLineage 的原形状 {var, producers, consumers}', JSON.stringify(state) === JSON.stringify({ var: '证据 orders', producers: ['fetch'], consumers: ['write'] }),
JSON.stringify(state))
await doc.locator('[data-seg]', { hasText: '退款金额以财务确认日为准' }).first().click()
await page.waitForTimeout(300)
const quote = await S(page, () => window.__studio.getState().lineage)
check('换一段(引文):路径换成检索节点 → 报告', quote?.producers?.join(',') === 'manual' && quote?.consumers?.join(',') === 'write', JSON.stringify(quote))
// 面板里的节点名:点一下选中并对准画布上的节点
const chip = page.locator('[data-assistant-panel] [data-evidence-panel] button[data-ev-node="manual"]').first()
check('面板里的节点名是按钮,写画布上的节点名', (await chip.innerText().catch(() => '')).includes('查手册'))
await chip.click().catch(() => {})
await page.waitForTimeout(250)
const sel = await S(page, () => ({ selected: window.__studio.getState().selectedId, focus: window.__studio.getState().focusRequest?.id }))
check('点节点名:选中并对准画布上的那个节点', sel.selected === 'manual' && sel.focus === 'manual', JSON.stringify(sel))
await S(page, () => window.__studio.getState().select(null))
await page.waitForTimeout(250)
if (SHOTS) {
await doc.locator('[data-seg]', { hasText: /^orders$/ }).first().click()
await page.waitForTimeout(300)
for (const theme of ['dark', 'light']) {
await page.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
await page.waitForTimeout(250)
await page.screenshot({ path: `${SHOTS}/studio-evidence-path-${theme}.png` })
}
await page.evaluate(() => document.documentElement.setAttribute('data-theme', 'dark'))
}
// 收起面板:只收回自己画的那条路径
const back = page.locator('[data-assistant-panel] [data-evidence-panel] button', { hasText: '回到正文' })
await back.click().catch(() => {})
await page.waitForTimeout(250)
check('收起面板:画布上的证据路径一起收掉', await page.locator('style[data-lineage]').count() === 0
&& await S(page, () => window.__studio.getState().lineage) === null)
// 「清除」把刚才那次运行摘下来:打开画布时这张图还没跑过(取到的是空的),现在最近一次就是刚才那次——
// 章要跟着换,不能拿打开画布时的「没跑过」当最近一次
latestRun = EV_RUN
const refetched = await clearAndRefetch(page)
check('「清除」摘下运行:重新取这张图的最近一次运行', refetched)
check('……章取刚才那次(打开画布时还没跑过,不能照旧不画)', (await stamp(page).innerText().catch(() => '没有章')) === `引用 ${cited} · 无证据 ${none}`,
await stamp(page).innerText().catch(() => '没有章'))
check('没有运行时报错(证据路径)', errors.length === 0, errors.slice(0, 2).join(' | '))
await page.context().close()
// 没挂运行、这张图最近一次运行有报告核对:章从那次运行的证据图取
let latestNow = fxe.run_id
const latest = await open({ path: '/studio/st-ev', before: routes(() => latestNow) })
await stamp(latest.page).waitFor({ timeout: 4000 }).catch(() => {})
check('没挂运行:章取这张图最近一次运行的核对统计(和挂着运行时一样,结论句策略也算上)',
(await stamp(latest.page).innerText().catch(() => '')) === `引用 ${cited} · 无证据 ${none}`,
await stamp(latest.page).innerText().catch(() => '没有章'))
if (SHOTS) {
// 取景到报告节点(可读的缩放),截卡片连同下沿的章,四周留一圈
await S(latest.page, () => window.__studio.getState().focusNode('write'))
await latest.page.waitForTimeout(600)
for (const theme of ['dark', 'light']) {
await latest.page.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
await latest.page.waitForTimeout(250)
const box = await latest.page.locator('.react-flow__node[data-id="write"]').boundingBox()
if (box) {
await latest.page.screenshot({ path: `${SHOTS}/studio-report-stamp-${theme}.png`,
clip: { x: box.x - 40, y: box.y - 40, width: box.width + 80, height: box.height + 80 } }).catch(() => {})
}
}
}
// 在画布上又跑了一次(另一份报告),跑完「清除」:最近一次换成了这次,章不能还是打开画布时取的那份
await S(latest.page, ({ id, rc, output }) => {
const s = window.__studio
const t = Date.now() / 1000 - 3
s.setState({ run: { id, workflow_id: 'st-ev', workflow_name: '__studio_check_ev__', status: 'queued', input: {},
output: {}, error: null, usage: {}, run_class: 'exploratory', version: null } })
const list = [['run.started', null, {}], ['node.started', 'write', { label: '写周报', node_type: 'report' }],
['report.checked', 'write', rc], ['node.finished', 'write', { duration_ms: 900 }],
['run.finished', null, { output, usage: {}, timing: { wall_ms: 1000, active_ms: 1000, wait_ms: 0 } }]]
list.forEach((e, i) => s.getState().applyEvent({ seq: i + 1, type: e[0], node_id: e[1], data: e[2], ts: t + i * 0.2 }))
}, { id: fxe.dup.run_id, rc: fxe.dup.report_checked, output: fxe.dup.output })
await latest.page.waitForTimeout(300)
check(`挂上新跑的一次:章跟着它(${dupText})`, (await stamp(latest.page).innerText().catch(() => '')) === dupText,
await stamp(latest.page).innerText().catch(() => '没有章'))
latestNow = fxe.dup.run_id
const again = await clearAndRefetch(latest.page)
check('「清除」之后重新取最近一次运行(打开画布时取的那份作废)', again)
check(`……章换成新跑的那次(${dupText}),不是打开画布时的「引用 ${cited} · 无证据 ${none}」`,
(await stamp(latest.page).innerText().catch(() => '没有章')) === dupText, await stamp(latest.page).innerText().catch(() => '没有章'))
check('没有运行时报错(最近一次运行的章)', latest.errors.length === 0, latest.errors.slice(0, 2).join(' | '))
await latest.ctx.close()
// 取「最近一次运行」的请求还没回来,就在画布上跑完、清除了:先发的那次(那时还没跑过)晚回来,不能把后来
// 取到的那份盖掉。页面加载等网络静下来才算完,慢请求只能在加载后从 store 发(和报告卡发的是同一个 loadLatest)
let raceRun = null
let raceHits = 0
const race = await open({ path: '/studio/st-ev', before: async (pg) => {
await routes(() => raceRun)(pg)
await pg.route((u) => { const x = new URL(u); return x.pathname === '/api/runs' && x.searchParams.get('workflow_id') === 'st-ev' },
async (r) => {
if (raceHits++ !== 1) return r.fallback()
const body = raceRun ? [{ id: raceRun, workflow_id: 'st-ev', status: 'succeeded', run_class: 'exploratory' }] : []
await new Promise((res) => setTimeout(res, 1800))
return json(r, body).catch(() => {})
})
} })
await race.page.evaluate(async () => {
const { useEvidence } = await window.__appImport('/src/store/evidence.ts')
useEvidence.getState().dropLatest('st-ev')
void useEvidence.getState().loadLatest('st-ev')
})
await race.page.waitForTimeout(150)
await S(race.page, ({ id, rc, output }) => {
const s = window.__studio
const t = Date.now() / 1000 - 2
s.setState({ run: { id, workflow_id: 'st-ev', workflow_name: '__studio_check_ev__', status: 'queued', input: {},
output: {}, error: null, usage: {}, run_class: 'exploratory', version: null } })
const list = [['run.started', null, {}], ['report.checked', 'write', rc],
['run.finished', null, { output, usage: {}, timing: { wall_ms: 1000, active_ms: 1000, wait_ms: 0 } }]]
list.forEach((e, i) => s.getState().applyEvent({ seq: i + 1, type: e[0], node_id: e[1], data: e[2], ts: t + i * 0.2 }))
}, { id: fxe.dup.run_id, rc: fxe.dup.report_checked, output: fxe.dup.output })
raceRun = fxe.dup.run_id
await race.page.waitForTimeout(150)
await S(race.page, () => window.__studio.getState().clearRun())
await race.page.waitForTimeout(2600)
check(`先发的请求晚回来(那时还没跑过):章照旧是清除后取到的那次(${dupText}),没被盖成不画`,
raceHits >= 3 && (await stamp(race.page).innerText().catch(() => '没有章')) === dupText,
`${raceHits} 次请求,${await stamp(race.page).innerText().catch(() => '没有章')}`)
check('没有运行时报错(请求先后颠倒)', race.errors.length === 0, race.errors.slice(0, 2).join(' | '))
await race.ctx.close()
})
check('整个检查没有弹出原生 confirm / prompt', dialogs === 0, `${dialogs} 次`)
check('检查没有写库(兜底拦下的写请求)', writes.length === 0, writes.slice(0, 4).join('、'))
+22 -3
View File
@@ -289,9 +289,28 @@ await section('lib/evidence:证据状态的四通道元数据、报告节点
const eq = (name, got, want) => out.push([name, got === want, got === want ? '' : `得到 ${JSON.stringify(got)},应为 ${JSON.stringify(want)}`])
const ok = (name, cond, detail = '') => out.push([name, !!cond, cond ? '' : detail])
const codes = ev.EVIDENCE_STATES
// 方案 6.1 的八种:确定性、概率性四种、无证据、连接性、旧运行候选
ok('八种状态一种不少', ['deterministic', 'supported', 'partial', 'unsupported', 'unjudged', 'none', 'connective', 'candidate']
.every((c) => codes.includes(c)) && codes.length === 8, codes.join(','))
// 方案 6.1 的八种(确定性、概率性四种、无证据、连接性、旧运行候选),加三期无证据的两个变体:
// 可疑实体(可能是编造的名字)、核对不了(表结构快照不全)
ok('十种状态一种不少', ['deterministic', 'supported', 'partial', 'unsupported', 'unjudged', 'none', 'connective', 'candidate',
'suspect', 'unverified'].every((c) => codes.includes(c)) && codes.length === 10, codes.join(','))
eq('可疑实体:点状线(同无证据)、?!、可能是编造的名字', `${ev.EVIDENCE_STATE.suspect.line}/${ev.EVIDENCE_STATE.suspect.glyph}/${ev.EVIDENCE_STATE.suspect.label}`,
'dotted/?!/可能是编造的名字')
ok('可疑实体醒目(进 n / N),核对不了只是标注', ev.EVIDENCE_STATE.suspect.alert && !ev.EVIDENCE_STATE.unverified.alert)
eq('片段状态:issue 为 unknown_entity 的是可疑实体', ev.segmentState({ kind: 'entity', state: 'none', issue: 'unknown_entity' }), 'suspect')
eq('片段状态:[[t:编造]] 的 cite 带 unknown 也是可疑实体', ev.segmentState({ kind: 'entity', state: 'none', cite: { unknown: true } }), 'suspect')
eq('片段状态:unverified_entity 是核对不了', ev.segmentState({ kind: 'entity', state: 'none', issue: 'unverified_entity' }), 'unverified')
eq('片段状态:原话对不上的引文仍是无证据', ev.segmentState({ kind: 'quote', state: 'none', issue: 'unresolved_ref' }), 'none')
ok('实体、引文另有字形和说法,线型颜色同「有出处」', ev.EVIDENCE_KIND_STYLE.entity.line === 'solid' && ev.EVIDENCE_KIND_STYLE.quote.line === 'solid'
&& ev.EVIDENCE_KIND_STYLE.quote.glyph === '“' && ev.EVIDENCE_KIND_STYLE.entity.color === ev.EVIDENCE_STATE.deterministic.color
&& /^var\(--st-[\w-]+\)$/.test(ev.EVIDENCE_KIND_STYLE.quote.color))
eq('章的两个数:引用 = 有出处的数字、值、实体、引文;无证据含可疑实体,require_citation 时加没挂依据的结论句',
JSON.stringify(ev.stampCounts({ numbers: 4, numbers_cited: 3, values: 1, entities: 5, quotes: 1, uncited_numbers: 1, unresolved: 1,
unknown_entities: 2, uncited_claims: 1 }, 'require_citation')), JSON.stringify({ cited: 10, none: 5 }))
eq('……结论句策略是 off 时不算没挂依据的结论句', ev.stampCounts({ numbers: 4, numbers_cited: 3, uncited_numbers: 1, unresolved: 0,
uncited_claims: 3 }, 'off')?.none, 1)
eq('可疑实体的提示:目录键、{name, table} 都写成去掉前缀的名字,最多 3 个',
ev.closestNames(['c:orders.amount', { alias: 't:refunds' }, { name: 'region', table: 'orders', kind: 'column' }, 'c:x']).join(','),
'orders.amount,refunds,orders.region')
const lines = new Set(['solid', 'dotted', 'badge', 'none'])
const bad = codes.filter((c) => {
const m = ev.EVIDENCE_STATE[c]