mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-16 21:32:00 +00:00
正文给被反方审过的句子挂句末标记,「质询」图标平时的对比度提到 3:1 以上:EvidenceDoc 按证据图 reports[].challenge_verdicts 给被审句子挂标记(被推翻、被削弱带字醒目,经受住、无法判断只有淡色图标),已有裁判徽标的并在同一枚徽标里,点开是整句面板,没有可点片段、没开裁判的句子也打得开;有运行就取一次证据图(同一次运行只取一回,不逐句请求),只认工件 id 对得上的那份报告;证据页挂载时手里那份证据图是运行收尾前取的(没封存)就重取。句末「质询」图标平时改用暗字色压到 70%,深浅两套、页面底色和面板底色上都在 3.3 以上,不撑开排版。check-evidence 补标记、整句面板、未能反查的说法和平时对比度的断言,probe 改在打开页面之前挂路由(证据图一挂上就取)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import type { JSX } from 'react'
|
||||
import { EvidenceDoc } from '../../run/EvidenceDoc'
|
||||
import type { EvidenceDocData } from '../../types'
|
||||
import judge from '../../run/__tests__/evidence-judge.json'
|
||||
|
||||
/**
|
||||
* 报告正文句末「质询」图标(审批质询)平时的样子,scripts/check-evidence.mjs 按它量平时状态的对比度:
|
||||
* - ?syn=evidence-ask:同一份没开裁判的周报(run/__tests__/evidence-judge.json 的 plain,后端 compose_doc 真跑出来的,
|
||||
* 内容虚构)摆两份,都给了质询入口:一份在页面底色上(同审批卡里展开的报告),一份在面板底色上(同运行详情的证据页)
|
||||
*
|
||||
* 证据图、片段接口由检查脚本伪造;不点「质询」,提问框不挂
|
||||
*/
|
||||
const DOC = judge.plain.doc as unknown as EvidenceDocData
|
||||
const ACCESS = { approvalId: 'ap-evidence-ask', host: 'evidence-ask' }
|
||||
|
||||
export const cases: Record<string, () => JSX.Element> = {
|
||||
'evidence-ask': () => (
|
||||
<div className="flex max-w-3xl flex-col gap-3 p-4" data-fixture="evidence-ask">
|
||||
<div className="rounded-lg border bg-bg p-3" data-ask-on="bg">
|
||||
<EvidenceDoc doc={DOC} artifact={judge.plain.doc_artifact} runId={judge.plain.run_id} label="周报" inquiry={ACCESS} />
|
||||
</div>
|
||||
<div className="rounded-lg border bg-panel p-3" data-ask-on="panel">
|
||||
<EvidenceDoc doc={DOC} artifact={judge.plain.doc_artifact} runId={judge.plain.run_id} label="周报" inquiry={ACCESS} />
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
}
|
||||
@@ -49,9 +49,17 @@ export function EvidencePane({ run, output, labelOf, refreshKey }: {
|
||||
const reloadGraph = useEvidence((s) => s.reloadGraph)
|
||||
const first = useRef(true)
|
||||
useEffect(() => {
|
||||
if (first.current) { first.current = false; void loadGraph(run.id); return }
|
||||
if (first.current) {
|
||||
first.current = false
|
||||
// 报告正文(成果区、审批卡里展开的那份)有运行就先取过证据图,取的时候运行可能还停在审批上、刚收尾还没封存:
|
||||
// 运行已经结束、手里那份却说没封存时重取一次,不然这一页顶上一直写着尚未封存(之后没有新事件,refreshKey 不再变)
|
||||
const held = useEvidence.getState().graphs[run.id]
|
||||
if (held?.status === 'ok' && SETTLED.has(run.status) && !held.data?.seal?.sealed) void reloadGraph(run.id)
|
||||
else void loadGraph(run.id)
|
||||
return
|
||||
}
|
||||
void reloadGraph(run.id)
|
||||
}, [run.id, refreshKey, loadGraph, reloadGraph])
|
||||
}, [run.id, run.status, refreshKey, loadGraph, reloadGraph])
|
||||
const audit = useAudit(run.id, refreshKey)
|
||||
const graph = graphSlot?.data
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ import {
|
||||
type KeyboardEvent as ReactKeyboardEvent, type MouseEvent as ReactMouseEvent, type RefObject,
|
||||
} from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { ListChecks, MessageCircleQuestion } from 'lucide-react'
|
||||
import {
|
||||
ListChecks, MessageCircleQuestion, ShieldAlert, ShieldCheck, ShieldMinus, ShieldQuestion, ShieldX, type LucideIcon,
|
||||
} from 'lucide-react'
|
||||
import clsx from 'clsx'
|
||||
import { rovingTarget } from '../components/ui'
|
||||
import {
|
||||
@@ -13,9 +15,12 @@ import {
|
||||
type EvidenceStateCode, type EvidenceTally as Tally,
|
||||
} from '../lib/evidence'
|
||||
import { formatNumber } from '../lib/format'
|
||||
import { EVIDENCE_STATE_LABEL, EVIDENCE_TEXT, INQUIRY_TEXT, JUDGE_TEXT, claimTally, evidenceTally, type ClaimTallyCounts } from '../lib/terms'
|
||||
import {
|
||||
CHALLENGE_TEXT, EVIDENCE_STATE_LABEL, EVIDENCE_TEXT, INQUIRY_TEXT, JUDGE_TEXT, claimTally, evidenceTally,
|
||||
type ClaimTallyCounts,
|
||||
} from '../lib/terms'
|
||||
import { useEvidence, useVerdicts } from '../store/evidence'
|
||||
import type { EvidenceBlock, EvidenceDocData, EvidenceSegment, EvidenceUnit, EvidenceVerdict } from '../types'
|
||||
import type { ChallengeVerdict, EvidenceBlock, EvidenceDocData, EvidenceSegment, EvidenceUnit, EvidenceVerdict } from '../types'
|
||||
import { EvidencePanel, type PanelMode, type PanelView } from './EvidencePanel'
|
||||
import { askAbout, type InquiryAccess } from './Inquiry'
|
||||
import { BlockView, Markdown, StyledSlice, inlineStyles, numericColumns, type InlineStyles } from './Markdown'
|
||||
@@ -30,6 +35,8 @@ import { BlockView, Markdown, StyledSlice, inlineStyles, numericColumns, type In
|
||||
*
|
||||
* 结论句的判定(四期)只在句末挂一枚小徽标(◆ ◇ ! ○ ?),整句不画线;证据相矛盾(和旧的证据不支持)的整句
|
||||
* 铺一层浅底。徽标也是按钮:点开是这一句的「模型的解释」。判定是模型给的,颜色一律不用确定性的绿。
|
||||
* 被反方审过的句子(期 4,证据图的 reports[].challenge_verdicts)同样在句末挂标记:被推翻、被削弱带字、醒目,经受住、
|
||||
* 无法判断只有淡色图标;有判定的句子并在同一枚徽标里。点开都是整句面板,没有可点片段的句子也打得开。
|
||||
*
|
||||
* 键盘:整份报告只占一个 Tab 位(roving tabindex)。←/→ 在有状态的片段、句末徽标间走,↑/↓ 按
|
||||
* 句子走(表格里按列走到上一行 / 下一行,出了表格接着按句子走),n / N 跳到下一处 /
|
||||
@@ -69,7 +76,15 @@ const unitOfAsk = (key: string) => (key.startsWith('ask:') ? key.slice(4) : null
|
||||
const askable = (unit: EvidenceUnit, block: EvidenceBlock) =>
|
||||
(unit.kind ? unit.kind === 'claim' : !!unitText(unit).trim()) && !['heading', 'code', 'hr', 'table'].includes(block.type)
|
||||
|
||||
interface Badge { unit: EvidenceUnit; block: number; verdict: EvidenceVerdict; state: EvidenceStateCode }
|
||||
/**
|
||||
* 句末徽标:结论句裁判的判定(verdict、state),和 / 或反方审稿的判断(challenge)。两样都有的并在一个徽标里,不挂两个;
|
||||
* 只被反方审过的句子(没开裁判的报告、裁判没送的句子)只有 challenge
|
||||
*/
|
||||
interface Badge {
|
||||
unit: EvidenceUnit; block: number
|
||||
verdict?: EvidenceVerdict; state?: EvidenceStateCode
|
||||
challenge?: string
|
||||
}
|
||||
|
||||
interface Model {
|
||||
/** 可点的片段和句末徽标,按正文顺序 */
|
||||
@@ -98,7 +113,8 @@ interface Model {
|
||||
grid: Map<string, string>
|
||||
}
|
||||
|
||||
function buildModel(blocks: EvidenceBlock[], overlay?: Record<string, EvidenceVerdict>, ask = false): Model {
|
||||
function buildModel(blocks: EvidenceBlock[], overlay?: Record<string, EvidenceVerdict>, ask = false,
|
||||
marks?: Record<string, string>): Model {
|
||||
const order: string[] = []
|
||||
const index = new Map<string, number>()
|
||||
const seg = new Map<string, { seg: EvidenceSegment; unit: EvidenceUnit; block: number }>()
|
||||
@@ -132,12 +148,15 @@ function buildModel(blocks: EvidenceBlock[], overlay?: Record<string, EvidenceVe
|
||||
if (!grid.has(key)) grid.set(key, s.id)
|
||||
}
|
||||
}
|
||||
// 句末徽标排在这一句的片段后面:←/→ 走到句尾就是它,证据相矛盾、部分有依据、证据不足的也进 n / N
|
||||
// 句末徽标排在这一句的片段后面:←/→ 走到句尾就是它,证据相矛盾、部分有依据、证据不足的也进 n / N。被反方审过的
|
||||
// 句子同样挂(和裁判的判定并在一个徽标里):没有可点的片段、也没有判定的句子靠它才打开得了整句面板。n / N 只按
|
||||
// 裁判的判定走——横幅、证据条的「定位下一处」只数证据和判定的问题,反方的判断在面板和审批卡里看
|
||||
const verdict = unitVerdict(unit, overlay)
|
||||
const state = verdictState(verdict)
|
||||
if (verdict && state) {
|
||||
const challenge = marks?.[unit.id]
|
||||
if ((verdict && state) || challenge) {
|
||||
const key = badgeKey(unit.id)
|
||||
badge.set(key, { unit, block: b, verdict, state })
|
||||
badge.set(key, { unit, block: b, ...(verdict && state ? { verdict, state } : {}), ...(challenge ? { challenge } : {}) })
|
||||
index.set(key, order.length)
|
||||
order.push(key)
|
||||
if (first) { unitFirst.push(key); first = false }
|
||||
@@ -198,6 +217,46 @@ function verticalTarget(model: Model, id: string, down: boolean): string | null
|
||||
return model.unitFirst[(u + (down ? 1 : -1) + n) % n] ?? null
|
||||
}
|
||||
|
||||
/**
|
||||
* 这份报告里被反方审过的句子 → 判断(证据图 reports[].challenge_verdicts)。只认证据图里这份报告、而且封存的就是正文
|
||||
* 这一份(工件 id 对得上)的那一项:证据图说的是这个报告节点最后写的那一稿,正文是另一稿时同一个句子编号说的可能是别的话。
|
||||
* 没有运行、证据图还没取到(或取不到)、一句都没审、老服务端都是 undefined
|
||||
*/
|
||||
function useChallengeMarks(runId: string | undefined, report: string | undefined, artifact: string | undefined):
|
||||
Record<string, string> | undefined {
|
||||
const graph = useEvidence((s) => (runId ? s.graphs[runId]?.data : undefined))
|
||||
return useMemo(() => {
|
||||
const hit = (graph?.reports ?? []).find((r) => (!report || !r?.node_id || r.node_id === report)
|
||||
&& (!artifact || r?.doc_artifact === artifact))
|
||||
const raw: unknown = hit?.challenge_verdicts
|
||||
if (!raw || typeof raw !== 'object') return undefined
|
||||
const marks = Object.fromEntries(Object.entries(raw as Record<string, unknown>)
|
||||
.filter((e): e is [string, string] => !!e[0] && typeof e[1] === 'string' && !!e[1]))
|
||||
return Object.keys(marks).length ? marks : undefined
|
||||
}, [graph, report, artifact])
|
||||
}
|
||||
|
||||
/** 句末标记读屏念的那一句:截到 40 字(同 lib/evidence 的 claimLabel) */
|
||||
const markSentence = (unit: EvidenceUnit) => {
|
||||
const text = unitText(unit).trim()
|
||||
return text.length > 40 ? `${text.slice(0, 39)}…` : text
|
||||
}
|
||||
|
||||
/** 反方审稿判断的叫法:认不出的照写原值(同审批卡) */
|
||||
const challengeLabel = (v: string) => (Object.hasOwn(CHALLENGE_TEXT.verdict, v)
|
||||
? CHALLENGE_TEXT.verdict[v as keyof typeof CHALLENGE_TEXT.verdict] : CHALLENGE_TEXT.verdictUnknown(v))
|
||||
|
||||
/**
|
||||
* 句末徽标的读屏名:有判定的照裁判的说法(claimLabel),被反方审过的接着说反方审稿的判断;只被反方审过的
|
||||
* 说「结论句「…」,反方审稿:被推翻」
|
||||
*/
|
||||
function badgeLabel(badge: Badge): string {
|
||||
const said = badge.challenge ? CHALLENGE_TEXT.markLabel(challengeLabel(badge.challenge)) : ''
|
||||
if (!badge.verdict) return JUDGE_TEXT.badgeLabel(markSentence(badge.unit), said, false)
|
||||
const judged = claimLabel(badge.unit, badge.verdict)
|
||||
return said ? `${judged},${said}` : judged
|
||||
}
|
||||
|
||||
/** 片段的外观:线型走 data 属性(CSS 里只管线型),颜色写成变量交给 index.css(引文前的引号用 --ev-glyph) */
|
||||
function segStyle(state: EvidenceStateCode): CSSProperties {
|
||||
const meta = EVIDENCE_STATE[state]
|
||||
@@ -257,14 +316,16 @@ export const EvidenceDoc = forwardRef<EvidenceDocHandle, {
|
||||
const ask = !!inquiry && !!runId && !!report
|
||||
// 封存之后按需追加的判定:盖过文档里的「未裁判 · 按需」。只换句末徽标,封存的文档一个字不改
|
||||
const overlay = useVerdicts(runId, report)
|
||||
const model = useMemo(() => buildModel(blocks, overlay, ask), [blocks, overlay, ask])
|
||||
// 被反方审过的句子:句末挂标记(和裁判的判定并在一个徽标里),点开是整句面板
|
||||
const marks = useChallengeMarks(runId, report, artifact)
|
||||
const model = useMemo(() => buildModel(blocks, overlay, ask, marks), [blocks, overlay, ask, marks])
|
||||
const counts = useMemo(() => docTally(doc), [doc])
|
||||
const claims = useMemo(() => claimCounts(doc, overlay), [doc, overlay])
|
||||
// 探索运行的报告(开了裁判的按需文档,或调用方说了是探索运行):证据图带着这次运行里之前按需判过的句子
|
||||
// (reports[].post_seal_verdicts),取一次,重新打开页面时徽标还在。别的报告不多发这个请求
|
||||
// 有运行就取一次这次运行的证据图(同一次运行只取一次,不逐句请求):它带着被反方审过的句子(reports[].challenge_verdicts,
|
||||
// 正式、探索运行都可能有,反方审稿在报告写完之后才审,文档里没有这份记录),探索运行的报告还带着之前按需判过的句子
|
||||
// (reports[].post_seal_verdicts),重新打开页面时标记、徽标都还在
|
||||
const loadGraph = useEvidence((s) => s.loadGraph)
|
||||
const lateOnes = doc.judge?.mode === 'on_demand' || (runClass === 'exploratory' && doc.judge?.mode !== 'inline')
|
||||
useEffect(() => { if (lateOnes && runId) void loadGraph(runId) }, [lateOnes, runId, loadGraph])
|
||||
useEffect(() => { if (runId) void loadGraph(runId) }, [runId, loadGraph])
|
||||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
const instance = useId()
|
||||
const panelId = `${instance}-panel`
|
||||
@@ -341,7 +402,7 @@ export const EvidenceDoc = forwardRef<EvidenceDocHandle, {
|
||||
if (badge) {
|
||||
claim(instance)
|
||||
setView({ kind: 'unit', id: badge.unit.id })
|
||||
setAnnounce(`${JUDGE_TEXT.section}:${claimLabel(badge.unit, badge.verdict)}`)
|
||||
setAnnounce(`${badge.verdict ? JUDGE_TEXT.section : CHALLENGE_TEXT.claimTitle}:${badgeLabel(badge)}`)
|
||||
return
|
||||
}
|
||||
const hit = model.seg.get(id)
|
||||
@@ -860,10 +921,42 @@ const DocBlock = memo(function DocBlock({ block, dense, doc, visual, current, ac
|
||||
}
|
||||
})
|
||||
|
||||
/** 反方审稿的判断在句末徽标里的样子 */
|
||||
interface MarkLook { icon: LucideIcon; color: string; soft: string; loud: boolean }
|
||||
|
||||
/**
|
||||
* 被推翻、被削弱醒目:盾牌图标加判断两个字,用失败色、提醒色;经受住、无法判断低调:只有淡色的盾牌图标(悬停、读屏照样
|
||||
* 说得出是哪一种)。四种图标各不相同,去掉颜色也分得开;判断是反方模型给的,经受住也不用确定性的绿。认不出的判断按低调画
|
||||
*/
|
||||
const MARK_LOOK: Record<ChallengeVerdict, MarkLook> = {
|
||||
refuted: { icon: ShieldX, color: 'var(--st-failed)', soft: 'var(--st-failed-soft)', loud: true },
|
||||
weakened: { icon: ShieldMinus, color: 'var(--st-waiting)', soft: 'var(--st-waiting-soft)', loud: true },
|
||||
stands: { icon: ShieldCheck, color: 'var(--text-faint)', soft: 'var(--st-idle-soft)', loud: false },
|
||||
inconclusive: { icon: ShieldQuestion, color: 'var(--text-faint)', soft: 'var(--st-idle-soft)', loud: false },
|
||||
}
|
||||
const markLook = (verdict: string): MarkLook => (Object.hasOwn(MARK_LOOK, verdict) ? MARK_LOOK[verdict as ChallengeVerdict]
|
||||
: { icon: ShieldAlert, color: 'var(--text-faint)', soft: 'var(--st-idle-soft)', loud: false })
|
||||
|
||||
/**
|
||||
* 句末徽标里反方审稿的那一截。和裁判的字形并在一个徽标里时跟在字形后面(after)。醒目的那两种连字一起写:字号定成
|
||||
* 10px(同句末的「无证据」小标签),窄栏里 0.72em 的上标只有 8px,汉字认不清
|
||||
*/
|
||||
function ChallengeMark({ verdict, look, after }: { verdict: string; look: MarkLook; after: boolean }) {
|
||||
const Icon = look.icon
|
||||
return (
|
||||
<span aria-hidden="true" className={clsx('inline-flex items-center gap-px whitespace-nowrap', after && 'ml-0.5')}
|
||||
style={{ color: look.color }} data-ev-challenge-look={look.loud ? 'loud' : 'quiet'}>
|
||||
<Icon size={10} strokeWidth={2.25} className="shrink-0" />
|
||||
{look.loud && <span className="text-[10px]">{challengeLabel(verdict)}</span>}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 一句话:文字按行内 Markdown 渲染(整句算一次样式,跨片段的 `code`、**粗体** 不会
|
||||
* 被切坏),有状态的片段包成按钮。含无证据片段的句子末尾挂「? 无证据」;有判定的结论句末尾挂
|
||||
* 一枚徽标(也是按钮),证据相矛盾(和旧的证据不支持)的整句铺浅底——字本身不画线
|
||||
* 一枚徽标(也是按钮),证据相矛盾(和旧的证据不支持)的整句铺浅底——字本身不画线。被反方审过的
|
||||
* 句子同样挂徽标(和判定并在一起),点开都是整句面板
|
||||
*/
|
||||
function UnitView({ unit, doc, current, active, panelId, code, tag, badge, ask }: {
|
||||
unit: EvidenceUnit; doc: EvidenceDocData; current: string | null; active: string | null; panelId: string
|
||||
@@ -911,8 +1004,18 @@ function UnitView({ unit, doc, current, active, panelId, code, tag, badge, ask }
|
||||
)
|
||||
})
|
||||
const key = badge ? badgeKey(unit.id) : ''
|
||||
const meta = badge ? EVIDENCE_STATE[badge.state] : null
|
||||
const meta = badge?.state ? EVIDENCE_STATE[badge.state] : null
|
||||
const open = !!badge && active === key
|
||||
const verdict = badge?.verdict
|
||||
// 模型判过的写明谁判的、非确定(证据不足的接着写缺什么);模型没判过的(按需还没点、到上限、没跑成)只说
|
||||
// 这是什么状态——到上限没判的也记着裁判模型,但不能写成「(模型 · 非确定)」,像是它判过一样
|
||||
const judgedTitle = !verdict || !meta ? ''
|
||||
: isJudged(verdict)
|
||||
? `${meta.label}${verdict.post_seal ? ` · ${JUDGE_TEXT.postSeal}` : ''}(${verdict.judge || JUDGE_TEXT.judgeModel} · 非确定)${
|
||||
verdictMissing(verdict) ? `。${JUDGE_TEXT.missing(verdictMissing(verdict))}` : ''}`
|
||||
: limitOf(verdict) ? `${meta.label}:${JUDGE_TEXT.limitNotJudged}` : `${meta.label}:${meta.hint}`
|
||||
const challengeTitle = badge?.challenge ? CHALLENGE_TEXT.markTitle(challengeLabel(badge.challenge)) : ''
|
||||
const look = badge?.challenge ? markLook(badge.challenge) : null
|
||||
const body = (
|
||||
<>
|
||||
{conflicting(badge?.state)
|
||||
@@ -924,32 +1027,33 @@ function UnitView({ unit, doc, current, active, panelId, code, tag, badge, ask }
|
||||
{EVIDENCE_STATE[state].glyph}{TAG_TEXT[state]}
|
||||
</span>
|
||||
))}
|
||||
{badge && meta && (
|
||||
{badge && (meta || look) && (
|
||||
<button
|
||||
type="button"
|
||||
className="ev-badge"
|
||||
data-ev-claim={unit.id}
|
||||
data-ev-verdict={badge.state}
|
||||
data-ev-post-seal={badge.verdict.post_seal ? '' : undefined}
|
||||
data-ev-post-seal={verdict?.post_seal ? '' : undefined}
|
||||
data-ev-challenge-mark={badge.challenge}
|
||||
tabIndex={current === key ? 0 : -1}
|
||||
aria-label={claimLabel(unit, badge.verdict)}
|
||||
aria-label={badgeLabel(badge)}
|
||||
aria-expanded={open}
|
||||
aria-controls={open ? panelId : undefined}
|
||||
// 模型判过的写明谁判的、非确定(证据不足的接着写缺什么);模型没判过的(按需还没点、到上限、没跑成)只说
|
||||
// 这是什么状态——到上限没判的也记着裁判模型,但不能写成「(模型 · 非确定)」,像是它判过一样
|
||||
title={isJudged(badge.verdict)
|
||||
? `${meta.label}${badge.verdict.post_seal ? ` · ${JUDGE_TEXT.postSeal}` : ''}(${badge.verdict.judge || JUDGE_TEXT.judgeModel} · 非确定)${
|
||||
verdictMissing(badge.verdict) ? `。${JUDGE_TEXT.missing(verdictMissing(badge.verdict))}` : ''}`
|
||||
: limitOf(badge.verdict) ? `${meta.label}:${JUDGE_TEXT.limitNotJudged}` : `${meta.label}:${meta.hint}`}
|
||||
style={segStyle(badge.state)}
|
||||
title={[judgedTitle, challengeTitle].filter(Boolean).join('。')}
|
||||
// 字形的颜色照裁判的判定;只被反方审过的照反方的判断(悬停的浅底同理)
|
||||
style={meta ? segStyle(badge.state!) : { '--ev-glyph': look!.color, '--ev-soft': look!.soft } as CSSProperties}
|
||||
>
|
||||
<span aria-hidden="true">{meta.glyph}</span>
|
||||
{meta && <span aria-hidden="true">{meta.glyph}</span>}
|
||||
{look && <ChallengeMark verdict={badge.challenge!} look={look} after={!!meta} />}
|
||||
</button>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
if (!ask) return body
|
||||
// 「质询」跟在句末,是一个固定宽度的小图标:平时淡淡的,悬停这一句、焦点落在这一句上时显出来(强调色、描边)。
|
||||
// 平时也得看得清它是个可点的东西(WCAG 1.4.11 要求界面组件对背景 ≥ 3:1):最淡的字色再压到 60% 不透明,深色约 2.75、
|
||||
// 浅色约 2.33,看不出来。改用次一级的暗字色压到 70%:深浅两套、报告摆在页面底色或面板底色上都在 3.3 以上,仍比正文
|
||||
// 淡得多;不透明度留在 0.75 以下,和悬停、聚焦时显出来(不透明、强调色)分得开。
|
||||
// 显没显出来只换颜色,宽度一直是那么宽——悬停时撑开的话,后面的字整体右移,鼠标底下的数字跟着挪走,点不到。
|
||||
// 触屏没有悬停,一直显出来,并写上「质询」两个字。
|
||||
// 跟随的那种只在焦点在这一句上时进 Tab 顺序,整份报告不因此多出一串 Tab 位
|
||||
@@ -961,7 +1065,7 @@ function UnitView({ unit, doc, current, active, panelId, code, tag, badge, ask }
|
||||
<button type="button" data-inquiry-ask={unit.id} tabIndex={here ? 0 : -1}
|
||||
aria-label={INQUIRY_TEXT.askUnit(unitText(unit).trim())} title={INQUIRY_TEXT.askTitle}
|
||||
className={'ml-1 inline-flex select-none items-center gap-0.5 whitespace-nowrap rounded border border-transparent px-[3px] '
|
||||
+ 'align-middle text-[10px] font-medium leading-[1.4] text-faint opacity-60 outline-none '
|
||||
+ 'align-middle text-[10px] font-medium leading-[1.4] text-dim opacity-70 outline-none '
|
||||
+ 'hover:bg-hover group-hover/evu:border-[color:var(--border)] group-hover/evu:text-[color:var(--accent)] group-hover/evu:opacity-100 '
|
||||
+ 'group-focus-within/evu:border-[color:var(--border)] group-focus-within/evu:text-[color:var(--accent)] group-focus-within/evu:opacity-100 '
|
||||
+ 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-[color:var(--accent)] '
|
||||
|
||||
+236
-13
@@ -87,8 +87,11 @@ function judgeReply(set, body) {
|
||||
* 三节都不画,只看 DOM 的断言不论前端发没发请求都会过。推断来源夹具的运行按 provenance[<片段>] 作答,其余一律回
|
||||
* 可识别的哨兵(418,harness_unexpected_provenance),界面会画出「未能获取推断的来源」。prov 给了就由它改答复
|
||||
* (prov(运行, 片段, 默认答复) → {status?, json} 或它的 Promise:延迟、出错、老服务端)
|
||||
*
|
||||
* 期 4:graph 给了就由它改四期夹具(结论句裁判那几份)的证据图答复(graph(夹具, 证据图拷贝) → 证据图),并把每次请求
|
||||
* 记成 graph:<运行>(数得出同一次运行取了几回);不给时照夹具答、不记
|
||||
*/
|
||||
async function routed(page, { judge = null, segPatch = null, prov = null } = {}) {
|
||||
async function routed(page, { judge = null, segPatch = null, prov = null, graph = null } = {}) {
|
||||
const hits = []
|
||||
const judged = new Set()
|
||||
await page.route((u) => new URL(u).pathname.startsWith('/api/'), async (r) => {
|
||||
@@ -152,7 +155,11 @@ async function routed(page, { judge = null, segPatch = null, prov = null } = {})
|
||||
return body ? r.fulfill({ json: body })
|
||||
: r.fulfill({ status: 404, json: { detail: '报告中没有这个片段', code: 'evidence_segment_not_found' } })
|
||||
}
|
||||
if (/\/evidence$/.test(url.pathname)) return r.fulfill({ json: jset.graph })
|
||||
if (/\/evidence$/.test(url.pathname)) {
|
||||
if (!graph) return r.fulfill({ json: jset.graph })
|
||||
hits.push(`graph:${jset.run_id}`)
|
||||
return r.fulfill({ json: graph(jset, structuredClone(jset.graph)) })
|
||||
}
|
||||
if (url.pathname.endsWith(`/runs/${jset.run_id}`)) {
|
||||
hits.push(`run:${jset.run_id}`)
|
||||
return r.fulfill({ json: { id: jset.run_id, run_class: jset.run_class, status: 'succeeded' } })
|
||||
@@ -182,14 +189,17 @@ async function routed(page, { judge = null, segPatch = null, prov = null } = {})
|
||||
return hits
|
||||
}
|
||||
|
||||
async function open(url, { w = 1280, h = 1000, reduced = false, patchQuery = null, judge = null, segPatch = null, prov = null } = {}) {
|
||||
async function open(url, { w = 1280, h = 1000, reduced = false, patchQuery = null, judge = null, segPatch = null, prov = null,
|
||||
graph = null, before = null } = {}) {
|
||||
const ctx = await browser.newContext({ viewport: { width: w, height: h }, ...(reduced ? { reducedMotion: 'reduce' } : {}) })
|
||||
const page = await ctx.newPage()
|
||||
// 找不到元素时 8 秒就报,不等默认的 30 秒:改坏验证时一节里十几处都找不到
|
||||
page.setDefaultTimeout(8000)
|
||||
const errors = []
|
||||
page.on('pageerror', (e) => errors.push(e.message))
|
||||
const hits = await routed(page, { judge, segPatch, prov })
|
||||
const hits = await routed(page, { judge, segPatch, prov, graph })
|
||||
// 打开页面之前再挂的路由(排在 routed 前面,认不出的交回 routed):报告一挂上就取这次运行的证据图,换答复得赶在那之前
|
||||
if (before) await before(page)
|
||||
// 预览页直接 import 第二期夹具(vite 把 JSON 当模块给):要一份改过的文档时把那个模块换掉
|
||||
if (patchQuery) {
|
||||
await page.route((u) => new URL(u).pathname.endsWith('/run/__tests__/evidence-query.json'), (r) =>
|
||||
@@ -580,16 +590,15 @@ await section('integrity', '证据接口复核出问题:醒目写出来,不
|
||||
})
|
||||
|
||||
/**
|
||||
* 组件预览页,片段接口按 answer(segId, 夹具里那一份的拷贝) 回:返回对象就当 200,返回数字
|
||||
* 就当那个状态码。证据图按 graph(夹具拷贝) 回
|
||||
* 组件预览页,一期夹具那份报告(#evidence-wide)的片段接口按 answer(segId, 夹具里那一份的拷贝) 回:返回对象就当 200,
|
||||
* 返回数字就当那个状态码。它的证据图按 graph(夹具拷贝) 回。在打开页面之前挂上:报告一挂上就会取证据图(期 4 起正文
|
||||
* 要它带的反方审稿标记),换答复晚了,取回来缓存住的就是换之前那一份。别的请求照 routed 答
|
||||
*/
|
||||
async function probe(answer, { graph = (g) => g } = {}) {
|
||||
const r = await open('/ui-harness.html?evidence=1')
|
||||
await r.page.unroute((u) => new URL(u).pathname.startsWith('/api/'))
|
||||
await r.page.route((u) => new URL(u).pathname.startsWith('/api/'), (route) => {
|
||||
return open('/ui-harness.html?evidence=1', { before: (page) => page.route((u) => new URL(u).pathname.startsWith('/api/'), (route) => {
|
||||
const req = route.request()
|
||||
if (req.method() !== 'GET') return route.abort()
|
||||
const path = new URL(req.url()).pathname
|
||||
if (req.method() !== 'GET' || !path.startsWith(`/api/runs/${fx.run_id}/`)) return route.fallback()
|
||||
const m = path.match(/\/evidence\/segments\/([^/]+)$/)
|
||||
if (m) {
|
||||
const body = answer(m[1], structuredClone(fx.segments[m[1]] ?? {}))
|
||||
@@ -598,9 +607,8 @@ async function probe(answer, { graph = (g) => g } = {}) {
|
||||
: route.fulfill({ json: body })
|
||||
}
|
||||
if (/\/evidence$/.test(path)) return route.fulfill({ json: graph(structuredClone(fx.graph)) })
|
||||
return route.continue()
|
||||
})
|
||||
return r
|
||||
return route.fallback()
|
||||
}) })
|
||||
}
|
||||
const sealOf = async (p) => ({
|
||||
state: await p.locator('[data-evidence-panel] [data-ev-seal-state]').getAttribute('data-ev-seal-state').catch(() => null),
|
||||
@@ -3584,6 +3592,221 @@ await section('verify', '期 4:指标步骤的双盲复算、取自遮罩列
|
||||
}
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------- 期 4:正文里被反方审过的句子
|
||||
|
||||
/**
|
||||
* 证据图带的被反方审过的句子(服务端 _challenge_verdicts,{句子: 判断}):没开裁判的那份挂在纯文字的结论句(u2、u4、u6
|
||||
* 一个可点的片段都没有)和带数字的句子(u3)上;正式运行那份和裁判的徽标并在一起;探索运行那份的证据图说的是另一稿
|
||||
* (工件 id 对不上),一个都不该挂
|
||||
*/
|
||||
const MARKS = {
|
||||
plain: { u2: 'refuted', u3: 'weakened', u4: 'inconclusive', u6: 'stands' },
|
||||
formal: { [fxj.formal.units.bad]: 'refuted', [fxj.formal.units.ok]: 'stands', [fxj.formal.units.limit]: 'inconclusive' },
|
||||
explore: { [fxj.explore.units.ok]: 'refuted' },
|
||||
}
|
||||
/**
|
||||
* 片段接口答的 unit.challenge 里整份报告的计数:没开裁判的那份无法判断 1 句、未能反查 1 句(无法判断的就是没反查成的);
|
||||
* 正式运行那份无法判断 2 句、未能反查 1 句(说不准是哪一句)
|
||||
*/
|
||||
const MARK_COUNTS = {
|
||||
plain: { counts: { stands: 1, weakened: 1, refuted: 1, inconclusive: 1 }, unreviewed: 1 },
|
||||
formal: { counts: { stands: 1, weakened: 0, refuted: 1, inconclusive: 2 }, unreviewed: 1 },
|
||||
}
|
||||
const markSet = (jset) => (jset === fxj.plain ? 'plain' : jset === fxj.formal ? 'formal' : jset === fxj.explore ? 'explore' : '')
|
||||
const markGraph = (jset, g) => {
|
||||
const key = markSet(jset)
|
||||
if (!key) return g
|
||||
g.reports[0].challenge_verdicts = MARKS[key]
|
||||
if (key === 'explore') g.reports[0].doc_artifact = 'e0'.repeat(32)
|
||||
return g
|
||||
}
|
||||
const markSeg = (jset, body) => {
|
||||
const key = markSet(jset)
|
||||
const verdict = MARKS[key]?.[body.unit?.id]
|
||||
if (verdict && MARK_COUNTS[key]) {
|
||||
body.unit.challenge = { verdict, node_id: 'chal', artifact: CH_ART, on_refuted: 'degrade', report_label: '写周报', ...MARK_COUNTS[key] }
|
||||
}
|
||||
return body
|
||||
}
|
||||
/** 半透明的前景叠在底色上之后的颜色(rgb 字符串),量对比度用 */
|
||||
function blendOver(fg, bg, alpha) {
|
||||
const nums = (c) => (c.match(/[\d.]+/g) ?? []).slice(0, 3).map(Number)
|
||||
const [f, b] = [nums(fg), nums(bg)]
|
||||
return `rgb(${f.map((v, i) => Math.round(v * alpha + b[i] * (1 - alpha))).join(', ')})`
|
||||
}
|
||||
|
||||
await section('marks', '期 4:被反方审过的句子在正文里挂句末标记——和裁判徽标并在一起、点开是整句面板、不逐句请求', async () => {
|
||||
const r = await open('/ui-harness.html?evidence=1', { graph: markGraph, segPatch: markSeg })
|
||||
const pg = r.page
|
||||
await pg.waitForSelector(`${JP} [data-ev-challenge-mark]`, { timeout: 5000 }).catch(() => {})
|
||||
// 正文一挂上、一处都没点:不请求片段接口;证据图每次运行只取一回(正式运行那份宽窄各摆一份也一样)
|
||||
const segHits = () => r.hits.filter((h) => h.startsWith('j:'))
|
||||
const graphs = (run) => r.hits.filter((h) => h === `graph:${run}`).length
|
||||
check('一处都没点:没有逐句请求片段接口,证据图每次运行只取一回', segHits().length === 0
|
||||
&& graphs(fxj.plain.run_id) === 1 && graphs(fxj.formal.run_id) === 1,
|
||||
`${segHits().join(',')} | ${r.hits.filter((h) => h.startsWith('graph:')).join(',')}`)
|
||||
|
||||
const look = await pg.evaluate((sel) => [...document.querySelectorAll(`${sel} [data-ev-claim]`)].map((el) => {
|
||||
const mark = el.querySelector('[data-ev-challenge-look]')
|
||||
return { unit: el.getAttribute('data-ev-claim'), verdict: el.getAttribute('data-ev-verdict'),
|
||||
mark: el.getAttribute('data-ev-challenge-mark'), look: mark?.getAttribute('data-ev-challenge-look') ?? null,
|
||||
text: el.textContent ?? '', color: mark ? getComputedStyle(mark).color : '', icon: !!mark?.querySelector('svg'),
|
||||
label: el.getAttribute('aria-label'), title: el.getAttribute('title'), tag: el.tagName, type: el.getAttribute('type') }
|
||||
}), JP)
|
||||
const by = Object.fromEntries(look.map((x) => [x.unit, x]))
|
||||
check('没开裁判的报告:被审过的四句都挂了标记(纯文字的结论句、带数字的句子都有),没被审的不挂',
|
||||
JSON.stringify(Object.keys(by).sort()) === JSON.stringify(['u2', 'u3', 'u4', 'u6'])
|
||||
&& look.every((x) => x.mark === MARKS.plain[x.unit] && x.verdict === null && x.tag === 'BUTTON' && x.type === 'button'),
|
||||
JSON.stringify(look.map((x) => [x.unit, x.mark, x.verdict])))
|
||||
const [failedC, waitingC, faintC] = await Promise.all(['--st-failed', '--st-waiting', '--text-faint'].map((t) => colorOf(pg, t)))
|
||||
check('被推翻、被削弱醒目:盾牌图标加判断两个字,失败色、提醒色', by.u2?.look === 'loud' && by.u2.text.includes('被推翻')
|
||||
&& by.u2.color === failedC && by.u2.icon && by.u3?.look === 'loud' && by.u3.text.includes('被削弱') && by.u3.color === waitingC
|
||||
&& by.u3.icon, JSON.stringify([by.u2, by.u3]))
|
||||
check('经受住、无法判断低调:只有淡色的盾牌图标,不写字', ['u4', 'u6'].every((k) => by[k]?.look === 'quiet' && by[k].icon
|
||||
&& !by[k].text.trim() && by[k].color === faintC), JSON.stringify([by.u4, by.u6]))
|
||||
check('读屏名写明句子和反方审稿的判断,悬停写明是反方模型的判断',
|
||||
by.u2?.label === '结论句「增长主要来自新客首单,老客复购持平。」,反方审稿:被推翻'
|
||||
&& by.u2?.title === '反方审稿:被推翻(反方模型的判断,并非系统核对)', `${by.u2?.label} | ${by.u2?.title}`)
|
||||
|
||||
const both = await pg.evaluate(({ sel, unit }) => {
|
||||
const els = document.querySelectorAll(`${sel} [data-ev-claim="${unit}"]`)
|
||||
const el = els[0]
|
||||
return { n: els.length, verdict: el?.getAttribute('data-ev-verdict'), mark: el?.getAttribute('data-ev-challenge-mark'),
|
||||
text: el?.textContent ?? '', label: el?.getAttribute('aria-label'), title: el?.getAttribute('title') ?? '' }
|
||||
}, { sel: J, unit: fxj.formal.units.bad })
|
||||
check('正式运行:有裁判徽标的句子并在一个徽标里,不挂两个', both.n === 1 && both.verdict === 'unsupported' && both.mark === 'refuted'
|
||||
&& both.text.startsWith('!') && both.text.includes('被推翻'), JSON.stringify(both))
|
||||
check('……读屏名、悬停说明两样都说', both.label === '结论句「增长主要来自新客首单,老客复购持平。」,模型判断:证据不支持,反方审稿:被推翻'
|
||||
&& both.title.startsWith('模型判断:证据不支持') && both.title.endsWith('反方审稿:被推翻(反方模型的判断,并非系统核对)'),
|
||||
`${both.label} | ${both.title}`)
|
||||
check('……两份报告仍各只占一个 Tab 位', await pg.locator(`${JP} [data-seg][tabindex="0"], ${JP} [data-ev-claim][tabindex="0"]`).count() === 1
|
||||
&& await pg.locator(`${J} [data-seg][tabindex="0"], ${J} [data-ev-claim][tabindex="0"]`).count() === 1)
|
||||
check('证据图说的是另一稿(工件 id 对不上):一个标记都不挂', await pg.locator(`${JX} [data-ev-challenge-mark]`).count() === 0)
|
||||
|
||||
// 键盘:没有可点片段的那句,标记就是它在键盘顺序里的位置;回车打开整句面板,Esc 回到标记
|
||||
await pg.locator(`${JP} [data-seg="s8"]`).focus()
|
||||
await pg.keyboard.press('ArrowDown')
|
||||
check('↓ 从上一句走到只有标记的那一句', await activeKey(pg) === 'claim:u2', await activeKey(pg))
|
||||
await pg.keyboard.press('Enter')
|
||||
await pg.waitForSelector('[data-evidence-panel] [data-ev-challenge]', { timeout: 4000 }).catch(() => {})
|
||||
const p = panel(pg)
|
||||
const block = p.locator('[data-ev-challenge]')
|
||||
const blockText = (await block.innerText().catch(() => '')).replace(/\s+/g, ' ')
|
||||
check('回车打开整句面板:标题是这一句,「反方审稿」一节写被推翻(单句展示)',
|
||||
(await p.locator('h3').innerText().catch(() => '')).trim() === '增长主要来自新客首单,老客复购持平。'
|
||||
&& await block.getAttribute('data-ev-challenge').catch(() => null) === 'refuted'
|
||||
&& await block.locator('[data-challenge-scope="claim"]').count() === 1, blockText)
|
||||
check('……只请求了这一句的一个片段', JSON.stringify(segHits()) === JSON.stringify(['j:s11']), segHits().join(','))
|
||||
check('……标记标着展开了面板', await pg.locator(`${JP} [data-ev-claim="u2"]`).getAttribute('aria-expanded') === 'true')
|
||||
check('……读屏从 live region 听到这一句的反方审稿判断',
|
||||
(await pg.locator(`${JP} [aria-live="polite"]`).first().innerText()).includes('反方审稿:被推翻'))
|
||||
check('……判断不是无法判断:不说未能反查', await p.locator('[data-challenge-unreviewed]').count() === 0)
|
||||
await pg.keyboard.press('Escape')
|
||||
await pg.waitForTimeout(150)
|
||||
check('Esc 关掉,焦点回到标记', await panel(pg).count() === 0 && await activeKey(pg) === 'claim:u2', await activeKey(pg))
|
||||
|
||||
// 判为无法判断的句子:这份报告无法判断的全是没反查成的,就说这一句未能反查;还有查过了、数据不够的,说可能在其中
|
||||
await pg.locator(`${JP} [data-ev-claim="u4"]`).click()
|
||||
await pg.waitForSelector('[data-evidence-panel] [data-challenge-unreviewed]', { timeout: 4000 }).catch(() => {})
|
||||
const sure = p.locator('[data-challenge-unreviewed]')
|
||||
const sureText = (await sure.innerText().catch(() => '')).replace(/\s+/g, ' ')
|
||||
check('无法判断、而无法判断的全是没反查成的:说这一句未能反查', await sure.getAttribute('data-challenge-unreviewed').catch(() => null) === 'claim'
|
||||
&& sureText.startsWith('这一句未能反查,已记为无法判断。反查没有完成'), sureText)
|
||||
await badge(pg, J, fxj.formal.units.limit).click()
|
||||
await pg.waitForSelector('[data-evidence-panel] [data-ev-challenge="inconclusive"] [data-challenge-unreviewed]', { timeout: 4000 })
|
||||
.catch(() => {})
|
||||
const maybe = p.locator('[data-challenge-unreviewed]')
|
||||
const maybeText = (await maybe.innerText().catch(() => '')).replace(/\s+/g, ' ')
|
||||
check('……无法判断的还有查过了、数据不够的:说这份报告几句未能反查、这一句可能在其中',
|
||||
await maybe.getAttribute('data-challenge-unreviewed').catch(() => null) === 'maybe'
|
||||
&& maybeText.startsWith('这份报告有 1 句未能反查,已记为无法判断,这一句可能在其中'), maybeText)
|
||||
await pg.keyboard.press('Escape')
|
||||
await pg.waitForTimeout(120)
|
||||
|
||||
for (const theme of ['light', 'dark']) {
|
||||
await pg.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
|
||||
await pg.waitForTimeout(100)
|
||||
const pairs = await pg.evaluate((sel) => [...document.querySelectorAll(`${sel} [data-ev-challenge-look]`)].map((el) => {
|
||||
const back = (node) => {
|
||||
for (let n = node; n; n = n.parentElement) {
|
||||
const c = getComputedStyle(n).backgroundColor
|
||||
if (c && !/rgba\(0, 0, 0, 0\)|transparent/.test(c)) return c
|
||||
}
|
||||
return getComputedStyle(document.body).backgroundColor
|
||||
}
|
||||
return { loud: el.getAttribute('data-ev-challenge-look') === 'loud', fg: getComputedStyle(el).color, bg: back(el) }
|
||||
}), JP)
|
||||
const worst = (loud) => Math.min(...pairs.filter((x) => x.loud === loud).map((x) => contrastOf(x.fg, x.bg)))
|
||||
check(`${theme}:醒目的标记(带字)对比度 ≥ 4.5,低调的图标 ≥ 3`, pairs.length === 4 && worst(true) >= 4.5 && worst(false) >= 3,
|
||||
`${worst(true).toFixed(2)} / ${worst(false).toFixed(2)}`)
|
||||
}
|
||||
await pg.evaluate(() => document.documentElement.removeAttribute('data-theme'))
|
||||
const narrow = await pg.evaluate(() => {
|
||||
const el = document.querySelector('#evidence-judge-narrow')
|
||||
return el ? el.scrollWidth - el.clientWidth : 99
|
||||
})
|
||||
check('360px 画布右栏那份(并在一起的徽标)不撑出横向滚动', narrow <= 0, `${narrow}px`)
|
||||
check('没有运行时报错', r.errors.length === 0, r.errors.join(' | '))
|
||||
await r.ctx.close()
|
||||
|
||||
const n = await open('/ui-harness.html?evidence=1', { graph: markGraph, segPatch: markSeg, w: 390, h: 844 })
|
||||
await n.page.waitForSelector(`${JP} [data-ev-challenge-mark]`, { timeout: 5000 }).catch(() => {})
|
||||
await n.page.locator(`${JP} [data-ev-claim="u2"]`).click()
|
||||
await n.page.waitForSelector('[data-evidence-panel] [data-ev-challenge]', { timeout: 4000 }).catch(() => {})
|
||||
const wide390 = await n.page.evaluate(() => {
|
||||
const doc = document.querySelector('#evidence-judge-plain')
|
||||
const el = document.querySelector('[data-evidence-panel]')
|
||||
return { doc: doc ? doc.scrollWidth - doc.clientWidth : 99, panel: el ? el.scrollWidth - el.clientWidth : 99 }
|
||||
})
|
||||
check('390px:带标记的报告、点开的整句面板都不横向溢出', wide390.doc <= 0 && wide390.panel <= 1, JSON.stringify(wide390))
|
||||
check('390px:没有运行时报错', n.errors.length === 0, n.errors.join(' | '))
|
||||
await n.ctx.close()
|
||||
})
|
||||
|
||||
await section('ask', '期 4:句末「质询」图标平时的对比度——深浅两套、页面底色和面板底色上都 ≥ 3:1,显出来时不撑开排版', async () => {
|
||||
// 平时是淡淡的一个小图标(字色压一层不透明度),可 WCAG 1.4.11 要求界面组件对背景 ≥ 3:1(以前最淡的字色压到 60%,深色
|
||||
// 约 2.75、浅色约 2.33)。用例 evidence-ask(dev/fixtures/evidence_ask.tsx):同一份报告摆在页面底色(同审批卡)和面板
|
||||
// 底色(同证据页)上,深浅两套各量一遍,按叠上不透明度之后的颜色算
|
||||
const r = await open('/preview.html?syn=evidence-ask')
|
||||
const pg = r.page
|
||||
await pg.waitForSelector('[data-ask-on="panel"] [data-inquiry-ask]')
|
||||
await pg.mouse.move(1, 1)
|
||||
await pg.evaluate(() => document.activeElement?.blur?.())
|
||||
for (const theme of ['dark', 'light']) {
|
||||
await pg.evaluate((t) => document.documentElement.setAttribute('data-theme', t), theme)
|
||||
await pg.waitForTimeout(120)
|
||||
for (const [on, name] of [['bg', '页面底色'], ['panel', '面板底色']]) {
|
||||
const m = await pg.evaluate((box) => [...document.querySelectorAll(`[data-ask-on="${box}"] [data-inquiry-ask]`)].map((b) => {
|
||||
const back = (node) => {
|
||||
for (let n = node; n; n = n.parentElement) {
|
||||
const c = getComputedStyle(n).backgroundColor
|
||||
if (c && !/rgba\(0, 0, 0, 0\)|transparent/.test(c)) return c
|
||||
}
|
||||
return getComputedStyle(document.body).backgroundColor
|
||||
}
|
||||
const cs = getComputedStyle(b)
|
||||
return { fg: cs.color, opacity: Number(cs.opacity), bg: back(b) }
|
||||
}), on)
|
||||
const ratios = m.map((x) => contrastOf(blendOver(x.fg, x.bg, x.opacity), x.bg))
|
||||
const worst = Math.min(...ratios)
|
||||
check(`${theme} · ${name}:平时的「质询」图标对比度 ≥ 3:1`, m.length >= 3 && worst >= 3 && m.every((x) => x.opacity < 1),
|
||||
`${worst.toFixed(2)}(${m[0]?.fg} × ${m[0]?.opacity} on ${m[0]?.bg})`)
|
||||
}
|
||||
}
|
||||
await pg.evaluate(() => document.documentElement.removeAttribute('data-theme'))
|
||||
// 悬停一句时显出来:只换颜色、描边和不透明度,宽度、位置不变
|
||||
const btn = pg.locator('[data-ask-on="panel"] [data-inquiry-ask]').first()
|
||||
const rest = await btn.boundingBox()
|
||||
await pg.locator('[data-ask-on="panel"] [data-ev-unit]').first().hover()
|
||||
await pg.waitForTimeout(150)
|
||||
const shown = await btn.boundingBox()
|
||||
const opacity = await btn.evaluate((el) => getComputedStyle(el).opacity)
|
||||
check('悬停这一句:图标显出来(不透明),宽度、位置不变,不撑开排版', opacity === '1' && !!rest && !!shown
|
||||
&& Math.abs(rest.width - shown.width) < 0.5 && Math.abs(rest.x - shown.x) < 0.5, JSON.stringify({ rest, shown, opacity }))
|
||||
check('没有运行时报错', r.errors.length === 0, r.errors.join(' | '))
|
||||
await r.ctx.close()
|
||||
})
|
||||
|
||||
check('没有运行时报错(组件预览)', harness.errors.length === 0, harness.errors.join(' | '))
|
||||
await harness.ctx.close()
|
||||
await browser.close()
|
||||
|
||||
Reference in New Issue
Block a user