Skip to content

ui: 诊断页金融提供方行把 {{list}} 占位符原样渲染,列表被拼在第二个冒号之后 - #295

Merged
helsome merged 1 commit into
helsome:mainfrom
wxrbyte:codex/fix-diagnostics-coverage-interpolation
Oct 18, 2026
Merged

helsome merged 1 commit into
helsome:mainfrom
wxrbyte:codex/fix-diagnostics-coverage-interpolation

Conversation

@wxrbyte

@wxrbyte wxrbyte commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

问题与修复

Closes #294

设置 → 诊断页的「金融提供方」卡片把 {{list}} 占位符原样渲染给用户,并把真正的列表拼在自己的第二个冒号之后。packages/ui/src/components/settings/DiagnosticsTab.tsx:210 / :213(行号基于 3a17eca6):

{t('diagnostics.markets')}: {provider.coverage.markets.join(', ') || '—'}
{t('diagnostics.capabilities')}: {provider.coverage.capabilities.join(', ') || '—'}

两个键的文案本身已经带了占位符与分隔符(en-US 'Markets: {{list}}' / 'Capabilities: {{list}}';zh-CN '市场:{{list}}' / '能力:{{list}}'),调用点却没传插值参数,于是 i18next 保留原样占位符:

en-US: Markets: {{list}}: US, HK        Capabilities: {{list}}: market.quote, market.kline
zh-CN: 市场:{{list}}: US, HK           能力:{{list}}: market.quote
空覆盖: Markets: {{list}}: —

根因是类型把修复路径堵死了:FinancialProviderRow 把 t 的 prop 收窄成 t: (key: string) => string,而父组件传进来的是真实 TFunction(:138)。收窄后的签名不允许传第二个参数,调用点只能手工拼字符串。

修复(4 处改动):

位置 改动
DiagnosticsTab.tsx:2 新增 import type { TFunction } from 'i18next';
:202 t: (key: string) => string; → t: TFunction;
:210 {t('diagnostics.markets')}: {…join(', ') || '—'} → {t('diagnostics.markets', { list: …join(', ') || '—' })}
:213 capabilities 同上

TFunction 的用法与仓库既有写法一致(components/today/TodayView.tsx:5,42 的 formatWhen(timestamp, t: TFunction))。不改任何 locale 文案、不新增键。

为什么判定是「漏网」而不是「口径分歧」

脚本对齐两侧枚举:从 packages/i18n/src/locales/en-US/*.ts 得到 637 个键,67 个含 {{…}};在 packages/{ui,shared,core,skill-hub,pi-runtime}/src + apps/electron/src 找所有 t('字面量键')(不带第二参数)。

  • 未传插值参数却命中占位符键的调用点全仓恰好 2 处(即上面两行,在同一函数内);
  • 同一批键里正确传参的有 61 处,其中 8 处就在本文件内::239 diagnostics.summaryFolio、:244 summaryAgentRuntime、:248 summaryLlm、:252 summaryBroker、:258 summaryLongbridgeCli、:259 summarySkills、:263 summaryResources、:267 summaryRecentErrors。

同文件、同一种 {{name}} 写法,8 处对、2 处错 ⇒ 这两行是漏网。

可复现测试报告

环境:Windows 10.0.26200.9457(x64)、Bun 1.4.2、main 3a17eca6。

新增 packages/ui/src/components/settings/DiagnosticsTab.test.tsx(3 个用例:en-US 插值、空覆盖的 — 回退、zh-CN 插值)。用真实资源包(createSyncI18n)+ 真实组件渲染,只把 client.diagnostics.collect 换成固定 bundle(该 channel 的 export / restartRuntime 一并给出以匹配 DiagnosticsChannel 类型)。

修复前(把 DiagnosticsTab.tsx 还原为 3a17eca6 的原始字节后重跑):

$ bun test packages/ui/src/components/settings/DiagnosticsTab.test.tsx
 0 pass / 3 fail

  Expected to contain: "Markets: US, HK"
  Expected to contain: "Markets: —"
  Expected to contain: "市场:US, HK"

修复后:3 pass / 0 fail。

其他校验:

命令 结果
bun test packages/ui --isolate 352 pass / 0 fail(65 个文件,无失败项)
tsc --noEmit(packages/ui) exit 0
bun run i18n:check en-US 1487 keys ≡ zh-CN 1487 keys (0 issues)

说明:352 这个数字包含本 PR 新增的 3 个用例与姊妹 PR #293 新增的 7 个用例(i18n/localeRendering.test.tsx 6 个 + DiscoverView.test.tsx 1 个);两个 PR 都只动 packages/ui。

未运行:apps/electron e2e(本机无法跑,见 #223);上游 PR checks 当前 state=disabled_manually,新建 PR 不产生 check run,故以上均为本地等价命令结果,非 CI 结论。

UI 变化

诊断页「金融提供方」两行的文本变化,布局不变:

  • Markets: {{list}}: US, HK → Markets: US, HK
  • Capabilities: {{list}}: market.quote → Capabilities: market.quote
  • zh-CN:市场:{{list}}: US, HK → 市场:US, HK
  • 空覆盖:Markets: {{list}}: — → Markets: —

范围

…{list}}

The diagnostics "Financial providers" rows called t('diagnostics.markets') and
t('diagnostics.capabilities') without interpolation values, then appended the
list themselves after their own ":" separator. Both keys already carry the value
and the separator ('Markets: {{list}}' / '市场:{{list}}'), so the shipped text
was "Markets: {{list}}: US, HK" — the raw placeholder was user-visible, in both
locales, including the empty-coverage fallback ("Markets: {{list}}: —").

The row's `t` prop was narrowed to (key: string) => string, which is why the
call site could not pass options even though the parent hands over the real
TFunction. Widen it to TFunction (same shape TodayView uses for formatWhen) and
pass { list }. No locale copy changes and no new keys: i18n:check stays at
1487 ≡ 1487.

A repo-wide sweep of every t('literal') call against the 67 placeholder-bearing
keys finds exactly these 2 sites missing their values, against 61 that pass them
— 8 of those in this very file (the summary* keys). So these two lines are a
missed spot, not a difference of convention.

Add packages/ui/src/components/settings/DiagnosticsTab.test.tsx (3 cases: en-US
substitution, the em-dash fallback, zh-CN substitution), rendering the real
component against the real resource bundle. Pre-fix 0 pass / 3 fail; post-fix
3 pass / 0 fail. Whole workspace: bun test packages/ui --isolate is
352 pass / 0 fail.

Closes helsome#294

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

独立源码审查通过;精确 HEAD focused 3 pass / 0 fail。与最新 main 的本批累计组合独立验证 1831 pass / 7 skip / 0 fail,全 workspace typecheck、i18n 均通过。相关生产变更文件高信号 secret 扫描零命中;不把这些确定性回归声称为真实模型或完整桌面验收。

@helsome
helsome merged commit 1b82fe9 into helsome:main Oct 18, 2026
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.

ui: 诊断页金融提供方行把 {{list}} 占位符原样渲染,列表被拼在第二个冒号之后

2 participants