Skip to content

feat(leaderboard): 缓存系数列增加 tooltip 与分层上色 - #1389

Merged
ding113 merged 2 commits into
devfrom
cache-coefficient-tiering
Aug 3, 2026
Merged

feat(leaderboard): 缓存系数列增加 tooltip 与分层上色#1389
ding113 merged 2 commits into
devfrom
cache-coefficient-tiering

Conversation

@ding113

@ding113 ding113 commented Aug 3, 2026

Copy link
Copy Markdown
Owner

变更内容

  • 表头 tooltip:排行榜中「缓存系数」列(供应商成本榜 + 缓存命中榜)新增帮助图标,悬停解释字段含义:缓存系数越大,供应商切号越少,失缓现象越不明显;并标注分档阈值(0.9 优秀 / 0.8 良好)
  • 分层上色:与缓存命中率同档配色 —— ≥0.9 绿色(优秀)、≥0.8 黄色(良好)、其余橙色;无数据仍显示
  • 基础设施ColumnDef 新增 headerTooltip 字段,tooltip 触发处 stopPropagation,不影响表头排序
  • i18n:5 种语言(zh-CN / zh-TW / en / ja / ru)文案齐备
  • 测试:新增 tooltip 触发器与三档配色断言,共 4 个用例全部通过

验证

  • bun run typecheck / biome check / bun run build 通过
  • bunx vitest run tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx:4 passed
  • tests/unit/dashboard/ 全套 31 个文件 174 个用例通过
  • 真实页面截图核验(种子数据 0.95 / 0.86 / 0.50 三档):tooltip 悬停展示正常,两张榜单配色正确

Greptile Summary

The PR adds localized cache-coefficient guidance and tier-based coloring to both provider leaderboards, while preserving sorting and missing-data behavior.

  • Adds a focusable tooltip control to sortable cache-coefficient headers.
  • Applies green, yellow, and orange coefficient tiers with localized explanations in all five supported locales.
  • Adds coverage for tooltip rendering, sort-event isolation, threshold colors, and null values.
  • Truncates long identity values in the error-details summary.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported inaccessible tooltip trigger is now a native focusable button.

Important Files Changed

Filename Overview
src/app/[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx Adds reusable tooltip metadata and a keyboard-focusable button trigger that prevents its click from activating header sorting.
src/app/[locale]/dashboard/leaderboard/_components/leaderboard-view.tsx Adds shared cache-coefficient tier rendering and localized tooltip content to both applicable provider tables.
tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx Covers tooltip presence, sort isolation, exact tier boundaries, missing data, and both provider leaderboard variants.
src/app/[locale]/dashboard/logs/_components/error-details-dialog/components/SummaryTab.tsx Changes long identity links from wrapping to constrained truncation within the existing flex layout.

Reviews (2): Last reviewed commit: "fix(leaderboard,logs): address review fe..." | Re-trigger Greptile

Context used:

…nt column

- Add headerTooltip support to leaderboard table headers with a help icon
- Explain cache coefficient: higher value means fewer provider account
  switches and less noticeable cache degradation
- Tiered coloring aligned with cache hit rate: >=0.9 excellent (green),
  >=0.8 good (yellow), below 0.8 orange
- Add i18n copy for all 5 locales and unit tests
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

本次变更为排行榜增加缓存系数 Tooltip。缓存系数统一转换为两位小数,并按 0.9、0.8 阈值显示颜色。五种语言新增本地化文案。测试覆盖 Tooltip、排序交互和颜色分级。错误详情中的身份链接改为单行截断。

Changes

缓存系数排行榜展示

Layer / File(s) Summary
表头提示与本地化文案
src/app/[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx, messages/*/dashboard.json
ColumnDef<T> 新增可选的 headerTooltip。配置该字段时,表头显示帮助图标和 Tooltip。图标点击不会触发表头排序。五种语言新增缓存系数提示文案。
缓存系数格式与排行榜接入
src/app/[locale]/dashboard/leaderboard/_components/leaderboard-view.tsx
新增 renderCacheCoefficientCell。函数处理空值、数值转换、两位小数和颜色分级。两个排行榜表格复用该函数。
缓存系数展示测试
tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx
测试验证 Tooltip 触发器、帮助图标交互、排序状态,以及不同阈值和缺失值的显示样式。

身份链接布局

Layer / File(s) Summary
身份链接截断
src/app/[locale]/dashboard/logs/_components/error-details-dialog/components/SummaryTab.tsx
身份链接从任意位置换行改为单行截断,并保留悬停下划线。

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed 标题准确概括了排行榜缓存系数列新增 tooltip 和分层上色的主要变更。
Description check ✅ Passed 描述详细说明了 tooltip、分层上色、国际化、测试及相关界面调整,与变更内容一致。
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cache-coefficient-tiering

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54245ea0b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/app/[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx Outdated
Comment thread messages/en/dashboard.json

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx (1)

127-145: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

补充 Tooltip 行为和边界值测试。

当前测试在整个容器中查找 [data-slot="tooltip-trigger"]。其他 Tooltip 也可能使测试通过。请将查询范围限定到缓存系数表头。

PR 还要求点击帮助图标时不触发表头排序。请模拟点击并断言排序状态未改变。

颜色测试请增加 0.900.80null 输入。当前 0.950.860.50 未覆盖包含边界和缺失值显示。

Also applies to: 147-172

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx` around
lines 127 - 145, Extend the leaderboard view tests around the cache coefficient
column header: scope the tooltip-trigger query to that specific header instead
of the whole container, then click the help icon and assert the header sorting
state remains unchanged. Expand the color-mapping coverage to include 0.90,
0.80, and null inputs alongside the existing values, verifying the expected
boundary and missing-value displays.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/`[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx:
- Around line 252-266: Update the TooltipTrigger child in the leaderboard header
tooltip block to use a focusable button instead of the span, preserving the
existing onClick propagation stop and styling. Add an accessible label to the
button so keyboard users can identify and open the headerTooltip via Tab.

---

Nitpick comments:
In `@tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx`:
- Around line 127-145: Extend the leaderboard view tests around the cache
coefficient column header: scope the tooltip-trigger query to that specific
header instead of the whole container, then click the help icon and assert the
header sorting state remains unchanged. Expand the color-mapping coverage to
include 0.90, 0.80, and null inputs alongside the existing values, verifying the
expected boundary and missing-value displays.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8460957e-9adf-4448-905f-20133e005044

📥 Commits

Reviewing files that changed from the base of the PR and between 07fdc53 and 54245ea.

📒 Files selected for processing (8)
  • messages/en/dashboard.json
  • messages/ja/dashboard.json
  • messages/ru/dashboard.json
  • messages/zh-CN/dashboard.json
  • messages/zh-TW/dashboard.json
  • src/app/[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx
  • src/app/[locale]/dashboard/leaderboard/_components/leaderboard-view.tsx
  • tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🧪 测试结果

测试类型 状态
代码质量
单元测试
集成测试
API 测试

总体结果: ✅ 所有测试通过

@github-actions github-actions Bot added the size/S Small PR (< 200 lines) label Aug 3, 2026
Comment thread src/app/[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx Outdated
Comment thread messages/en/dashboard.json

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Summary

I found three user-visible issues in the new cache-coefficient tooltip and tiering changes that should be fixed before merge. The most important are the inaccessible tooltip trigger and the new tier colors disagreeing with the rounded values shown in the UI.

PR Size: S

  • Lines changed: 100
  • Files changed: 8

Issues Found

Category Critical High Medium Low
Logic/Bugs 0 2 0 0
Security 0 0 0 0
Error Handling 0 0 0 0
Types 0 0 0 0
Comments/Docs 0 0 1 0
Tests 0 0 0 0
Simplification 0 0 0 0

Critical Issues (Must Fix)

None.

High Priority Issues (Should Fix)

  • [High] [LOGIC-BUG] src/app/[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx:255 — the new tooltip trigger is a plain span, so keyboard users cannot focus it or open the help text.
  • [High] [LOGIC-BUG] src/app/[locale]/dashboard/leaderboard/_components/leaderboard-view.tsx:116 — color tiers are computed from the unrounded value while the UI displays toFixed(2), so values like 8999 render as 0.90 but stay yellow.
  • [Medium] [COMMENT-INACCURATE] messages/en/dashboard.json:707 — the tooltip text claims the metric means fewer provider account switches, but the underlying formula is a confidence-adjusted cache-effectiveness score and does not measure switches directly.

Review Coverage

  • Logic and correctness
  • Security (OWASP Top 10)
  • Error handling
  • Type safety
  • Documentation accuracy
  • Test coverage
  • Code clarity

Automated review by Codex AI

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Review completed for PR #1389 and size/S was applied.
  • I posted 3 inline comments on diff lines:
    • src/app/[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx:255 — tooltip trigger is not keyboard-focusable.
    • src/app/[locale]/dashboard/leaderboard/_components/leaderboard-view.tsx:116 — tier color can contradict the rounded value shown.
    • messages/en/dashboard.json:707 — tooltip copy overstates what the metric measures.
  • I also submitted the required summary review with the issue counts and coverage checklist.

If you want, I can now switch from review mode to fix mode and patch those three issues directly.

…n id

- Make header tooltip trigger a focusable button with aria-label so
  keyboard users can open the field explanation (a11y review)
- Strengthen cache coefficient tests: scope tooltip query to the column
  header, assert clicking the help icon does not toggle sorting, cover
  0.90/0.80 boundary tiers and null display
- Show Canonical Session ID on a single truncated line in the session
  info drawer; full value stays in the DOM for select-copy and the link
  navigation is unchanged

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx (2)

143-149: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

补充 Tooltip 触发器的无障碍断言。

当前断言只检查 [data-slot="tooltip-trigger"] 存在。它不能检测触发器退化为不可聚焦元素,或 aria-label 被删除。请断言触发器为 <button>,并断言 aria-label 非空。

依据 PR 目标:跟进提交要求触发器为可聚焦按钮并带有 aria-label

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx` around
lines 143 - 149, 增强 leaderboard 缓存系数测试中 coefficientHeader 的 Tooltip 触发器断言:在现有
data-slot 定位后,断言触发器元素为 button,并断言其 aria-label 属性存在且非空,保留现有触发器存在性检查。

176-183: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

验证 Tooltip 内容和本地化文案。

当前点击测试只检查 tbody 的行顺序。Tooltip 内容缺失、阈值错误或翻译键错误时,测试仍会通过。触发 Tooltip 后,请断言 role="tooltip" 出现,并使用当前 locale 的期望消息断言说明文本和两个阈值。

依据 PR 目标:Tooltip 需要提供本地化说明和阈值。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx` around
lines 176 - 183, Update the click test around the existing MouseEvent dispatch
and leaderboard ordering assertion to verify the tooltip contract as well:
assert that a role="tooltip" element appears, then check its localized
explanatory message and both expected threshold values for the current locale.
Preserve the existing default row-order assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx`:
- Around line 151-164: 在 “does not trigger column sorting when the help icon is
clicked” 相关测试中补充 scope=userCacheHitRate 的 LeaderboardView 覆盖,验证用户排行榜默认路径下缓存系数列的
Tooltip、排序隔离和分级显示行为。复用现有 providerCacheHitRate 测试的断言结构与测试数据模式,确保两种 scope 均得到验证。

---

Nitpick comments:
In `@tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx`:
- Around line 143-149: 增强 leaderboard 缓存系数测试中 coefficientHeader 的 Tooltip
触发器断言:在现有 data-slot 定位后,断言触发器元素为 button,并断言其 aria-label 属性存在且非空,保留现有触发器存在性检查。
- Around line 176-183: Update the click test around the existing MouseEvent
dispatch and leaderboard ordering assertion to verify the tooltip contract as
well: assert that a role="tooltip" element appears, then check its localized
explanatory message and both expected threshold values for the current locale.
Preserve the existing default row-order assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4b30930c-76ad-4793-9ac4-038c2fc7a11c

📥 Commits

Reviewing files that changed from the base of the PR and between 54245ea and 85b37bc.

📒 Files selected for processing (3)
  • src/app/[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx
  • src/app/[locale]/dashboard/logs/_components/error-details-dialog/components/SummaryTab.tsx
  • tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/app/[locale]/dashboard/leaderboard/_components/leaderboard-table.tsx

Comment on lines +151 to +164
it("does not trigger column sorting when the help icon is clicked", async () => {
fetchMock.mockImplementation(async (input) => {
const url = String(input);
if (url.includes("scope=providerCacheHitRate")) {
return {
ok: true,
json: async () => [
cacheHitEntry({ providerId: 1, providerName: "high-first", cacheCoefficientBp: 9500 }),
cacheHitEntry({ providerId: 2, providerName: "low-second", cacheCoefficientBp: 5000 }),
],
} as Response;
}
return { ok: true, json: async () => [] } as Response;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n 'scope=(providerCacheHitRate|userCacheHitRate)' \
  tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx

Repository: ding113/claude-code-hub

Length of output: 484


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "file_stats"
wc -l tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx

echo
echo "outline"
ast-grep outline tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx || true

echo
echo "scope/usages"
rg -n 'userCacheHitRate|providerCacheHitRate|scope=|cacheCoefficient|cacheCoefficientBp|Leaderboard' tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx

echo
echo "sections"
sed -n '1,220p' tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx

Repository: ding113/claude-code-hub

Length of output: 10217


scope=userCacheHitRate 补充 LeaderboardView 测试覆盖。

当前用例只使用 scope=providerCacheHitRate,缓存系数列的 Tooltip、排序隔离和分级显示在未指定 scope 或默认用户排行榜路径下未得到验证。请补充对应的 userCacheHitRate 测试。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/dashboard/leaderboard-view-cache-coefficient.test.tsx` around
lines 151 - 164, 在 “does not trigger column sorting when the help icon is
clicked” 相关测试中补充 scope=userCacheHitRate 的 LeaderboardView 覆盖,验证用户排行榜默认路径下缓存系数列的
Tooltip、排序隔离和分级显示行为。复用现有 providerCacheHitRate 测试的断言结构与测试数据模式,确保两种 scope 均得到验证。

@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

🧪 测试结果

测试类型 状态
代码质量
单元测试
集成测试
API 测试

总体结果: ✅ 所有测试通过

@ding113
ding113 merged commit 6421bcf into dev Aug 3, 2026
12 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Claude Code Hub Roadmap Aug 3, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR (< 200 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant