Skip to content

fix(dashboards): remove fabricated trend deltas from CRM/Sales/Service tiles - #608

Merged
os-zhuang merged 1 commit into
mainfrom
claude/issue-587-fabricated-trends
Aug 2, 2026
Merged

os-zhuang merged 1 commit into
mainfrom
claude/issue-587-fabricated-trends

Conversation

@os-zhuang

@os-zhuang os-zhuang commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #587

Description

CRM、Sales、Service 三个看板的 12 个 KPI 卡片各自携带一个写死的环比涨跌幅,例如
trend: { value: 12.5, direction: 'up', label: 'vs last month' }。这些数字不是任何查询算出来的,
也没有任何东西会重算它们:无论哪个租户、哪份数据集,哪怕是一个刚初始化、一条记录都没有的数据库,
卡片都照样宣称 “+12.5% vs last month”,方向朝上还是朝下也纯属手写时的选择。

环比涨跌幅本质上是一次测量——它只能来自“本期结果对比上期结果”的真实比较查询。在控制台能为
dataset metric 跑这个比较(widget compareTo)之前,卡片只展示它真正测到的那个数字,不多展示任何东西。
Executive 看板在 #500 已经按同样的理由删掉了自己那批伪造百分比,本 PR 让其余三个看板与它保持一致,
不再是“一个诚实、三个编造”的半吊子修复。

顺带删掉了 CRM 看板上 avgDealSizeMetricWidget 已经空掉的 override:trend 去掉之后,它只是把工厂
自己声明的 options: { icon: 'bar-chart' } 原样再传一遍,什么也没说。

三个看板的文件头注释各补了一段说明,写清楚“为什么这里没有 trend”以及未来重新引入时的正确来源,
避免下一个作者(或下一个 AI)把它当成遗漏再补回来。

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • CI/CD update

Related Issues

Fixes #587
Related to #500

Changes Made

  • src/dashboards/crm.dashboard.ts:删除 4 处写死的 trend;avgDealSizeMetricWidget 的空 override 一并删除;文件头注释更新。
  • src/dashboards/sales.dashboard.ts:删除 4 处写死的 trend;文件头注释补充理由。
  • src/dashboards/service.dashboard.ts:删除 4 处写死的 trend;文件头注释补充理由。
  • test/analytics-integrity.test.ts:新增 pin test —— 遍历每个看板 widget,任意嵌套层级下只要出现携带字面数字的 trend(trend: 12.5 或 trend: { value: 12.5, … })即失败。先在修复前跑过,确认它准确抓出全部 12 处;修复后转绿。
  • .changeset/no-fabricated-dashboard-trends.md:patch 版本变更说明。

验收条件已满足:grep -rn "trend:" src/dashboards/ 现在零命中。

Testing

  • Unit tests pass (npm test)
  • Linting passes (npm run lint)
  • Build succeeds (npm run build)
  • Manual testing completed
  • New tests added (if applicable)
pnpm validate   → exit 0
pnpm typecheck  → exit 0
pnpm lint       → exit 0
pnpm hygiene    → ✓ source hygiene clean
pnpm build      → exit 0
pnpm test       → Test Files  34 passed (34)
                  Tests  647 passed | 1 skipped (648)

pin test 在修复之前的输出(证明它确实咬得住,而不是空转):

- Expected  []
+ Received
+   "crm_overview_dashboard/total_revenue.options.trend = {"value":12.5,"direction":"up","label":"vs last month"}",
+   "sales_dashboard/total_pipeline_value.options.trend = {"value":8.4,"direction":"up","label":"vs last quarter"}",
+   "service_dashboard/open_cases.options.trend = {"value":6.2,"direction":"down","label":"vs last week"}",
+   … 12 条全部命中

Screenshots

无 UI 截图:本 PR 只做删除。受影响的卡片仍然渲染同一个实测数值,只是下方那行伪造的涨跌幅消失了。

Checklist

  • I have added a changeset (pnpm changeset) — required on every PR, or the skip-changeset label is applied
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

为什么 guard 放在元数据层而不是源码 grep。 验收里写的是 grep -rn "trend:" src/dashboards/,
但 pin test 遍历的是 objectstack.config.ts 注册后的看板对象树。这样更严格:它不关心写法(对象字面量、
工厂函数、spread、helper 拼装都一样抓),只关心最终发布出去的元数据里有没有这个字面数字——
“声明即生效”的那一面。同时它对嵌套深度不敏感,因为控制台把 options 当自由字段包读,
手写的 trend 可以从任意深度冒出来。

文档漂移(不在本 PR 范围)。 content/docs/analytics/dashboards.mdx 描述的看板卡片与实际元数据
大面积对不上,已按 Prime Directive #10 另开 issue #610 记录,未在本 PR 内顺手改。

🤖 Generated with Claude Code

https://claude.ai/code/session_019SS7C5SXpniKeCApxgARyf

…e tiles

Twelve KPI tiles across the CRM, Sales and Service dashboards carried a
hardcoded period-over-period delta (`trend: { value: 12.5, direction: 'up',
label: 'vs last month' }` and eleven siblings). No query produced those
numbers and nothing recomputed them: every tenant, every dataset and an
empty database all rendered the same "+12.5% vs last month".

A period-over-period delta is a measurement — it can only come from
comparing this period's result against the previous period's. Until the
console can run that comparison for dataset metrics (widget `compareTo`),
a tile shows the number it actually measured and nothing else. The
executive dashboard already dropped its own on this reasoning (#500);
this makes the other three consistent with it.

Also drops the now-empty `avgDealSizeMetricWidget` override on the CRM
dashboard — with the trend gone it only re-passed the factory's own
`options: { icon: 'bar-chart' }`.

Guarded by a new assertion in `test/analytics-integrity.test.ts`, which
walks every dashboard widget and fails on a `trend` carrying a literal
number at any nesting depth, so hand-typed deltas cannot creep back into
metadata.

Fixes #587

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019SS7C5SXpniKeCApxgARyf
@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
hotcrm Ignored Ignored Aug 2, 2026 11:09am

Request Review

@github-actions github-actions Bot added ci/cd CI plumbing and the verification pipeline metadata Declarative metadata — schema, security posture, UI surfaces labels Aug 2, 2026
@os-zhuang
os-zhuang marked this pull request as ready for review August 2, 2026 11:13
@os-zhuang
os-zhuang added this pull request to the merge queue Aug 2, 2026
Merged via the queue into main with commit 183b10d Aug 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci/cd CI plumbing and the verification pipeline metadata Declarative metadata — schema, security posture, UI surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove fabricated trend values from crm/sales/service dashboards (executive already did, with rationale)

2 participants