Skip to content

feat(ui): add accessibility semantics to citation inspector (#30) - #286

Merged
kbkb628 merged 1 commit into
helsome:mainfrom
yu1128-L:feat/evidence-source-inspector
Oct 3, 2026
Merged

kbkb628 merged 1 commit into
helsome:mainfrom
yu1128-L:feat/evidence-source-inspector

Conversation

@yu1128-L

@yu1128-L yu1128-L commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

改动说明

本 PR 完成 #30 中 keyboard navigation / basic accessibility 这一验收项的一个子集:让引用 chip 和 source inspector 具备基础无障碍语义,不改动可见渲染结果。

  • CitationChip.tsx:已解析引用 chip 增加 aria-label 与 aria-haspopup="dialog";
  • SourceInspector.tsx:source 行增加 aria-current,snapshot disclosure 增加 aria-expanded / aria-controls;
  • 新增 en-US / zh-CN i18n key;
  • SourceInspector.test.tsx 增加对应 a11y 断言。

关联 Issue

Refs #30

测试报告(正式审核前必填)

环境

  • Bun:1.4.2
  • OS:Windows

实际执行命令与结果

bun test packages/ui/src/components/chat/SourceInspector.test.tsx packages/ui/src/lib/citations.test.ts
→ 14 passed / 0 failed

bun run --filter '@finagent/ui' typecheck
→ exit 0

bun run i18n:check
→ en-US / zh-CN 各 1488 keys,无缺失

已知失败 / Baseline(如有)

无。

  • 已提供实际测试命令与 pass/fail 结果
  • 已说明测试环境
  • 如果存在已知 baseline / 环境失败,已提供 main 对照或说明:无
  • 核心改动已有对应 focused test / smoke / integration 验证

UI 截图(仅可见 UI 变化时必填)

  • 本 PR 无可见 UI 变化(无需截图)

本 PR 只增加 ARIA 语义和无障碍测试,视觉结果不变。

Scope / 后续

本 PR 只覆盖 #30 的部分验收项。统一 citation UI 的 streaming 稳定性、web / structured finance evidence 两类来源、provenance / conflict 展示和真实 Copilot 回答录屏仍属 issue 后续工作,不声明 #30 整体完成。

@kbkb628 kbkb628 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我按仓库测试规范在本机独立复现并做了变异检查。结论:这个 PR 做的正是它标题说的,ARIA 用法和 i18n 都是对的,可以合,唯一建议是补一行断言。

实测(bun 1.4.2 / Windows,worktree 检出 f1a0bb49)

命令 结果
bun test packages/ui/src/components/chat/SourceInspector.test.tsx exit 0 — 8 pass / 0 fail / 31 expect
bun test --isolate packages/ui exit 0 — 323 pass / 0 fail(base 是 321,差值正好 +2)
bun scripts/i18n-check.ts exit 0 — en-US 1488 keys ≡ zh-CN 1488 keys,0 issues
bun run typecheck exit 0,5 个 workspace 全 0
bun test packages/i18n exit 0 — 25 pass / 0 fail(含 resources.test.ts)

bun test packages/ui(非 isolate)是 315 pass / 0 fail / 1 error、exit 1,但那是既有问题:base 上跑出完全相同的 315/0/1(# Unhandled error between tests / window is not defined)。CI 用的是 --isolate(pr.yml:84),所以这个文件在 CI 里确实会被执行,不用担心。

已验证为正确的部分

  • aria-haspopup="dialog" 是准确的:chip 打开的是仓库的 Dialog(radix 1.1.23),其 Content 设置 role="dialog"(react-dialog/dist/index.mjs:230),并带 FocusScope 焦点陷阱与 Escape/外部点击关闭;
  • aria-expanded + aria-controls="source-snapshot" 成对,展开时 IDREF 目标(SourceInspector.tsx:184 的 <pre id="source-snapshot">)确实存在;
  • i18n key agent.citation.openSource 在 en-US / zh-CN 同一路径、占位符一致,且 i18n-check 真的会校验占位符(把 {{id}} 去掉会报 interpolation-mismatch,exit 1);测试用的 i18n 实例加载的是真实 agent namespace(变异后渲染出的是解析后的字符串而不是裸 key);
  • 变异测试证明它守得住动态行为,不只是"属性存在":删 aria-label、把 aria-current 固定成常量、把 aria-expanded 固定成常量、去掉 {{id}} —— 全部会失败;
  • 无回归:消费方只有 TurnCard.tsx:6,85 和 AnswerContent.tsx,仓库里没有其他断言依赖被改的标记。

建议(都不阻塞,1 是唯一建议补的)

1)aria-controls 没有任何断言覆盖。 单独把 SourceInspector.tsx:175 的 aria-controls="source-snapshot" 删掉,8/8 依然全绿。建议加一行,例如:

expect(toggle.getAttribute('aria-controls')).toBe('source-snapshot');
// 展开时再断言目标存在
expect(container.querySelector('#source-snapshot')).not.toBeNull();

2)aria-current 与这个交互模式不太贴合(低)。 点击行是"切换右侧详情面板",而且行首有 ChevronDown 旋转 —— 更贴合的是 aria-expanded,或整组用 tablist / tab + aria-selected + tabpanel。另外面板内容变化目前不会被播报(没有 aria-live,行与详情之间也没有 aria-controls/aria-labelledby 关联),屏幕阅读器用户点完行不知道下方变了什么。

3)断言方式可以更"语义"(低)。 现在都用 data-testid + getAttribute 查询,没有一例按 role / accessible name 查询,所以无障碍名的计算过程没有被验证。建议至少一个用例走 getByRole('button', { name: ... })。

4)aria-label 覆盖了可见的引用编号(低,WCAG 2.5.3 label-in-name)。 CitationChip.tsx:35 的 label 现在是"打开来源 get_quote-1",它替换了可见的"1",读屏用户因此丢掉引用编号、只听到内部 tool-call id。建议把编号纳入 label(例如带上 {{index}})。

5)id="source-snapshot" 是硬编码全局 id(低)。 建议用 useId()。考虑到同一时刻只挂载一个 inspector(TurnCard.tsx:84-90),重复 id 目前只是理论风险。

6)可选: 补一个 zh-CN 用例(当前只测 en-US)。

顺带

实际 parent 是 ba5dcdf,不是描述里的 2b5b88d3(#284 合并前的一个提交);#284 不碰 packages/ui 与 packages/i18n,merge-tree 无冲突,不需要 rebase。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants