Repository navigation
fix(dashboard): Buddy 积分看板冷启动空态整页崩溃(issue #72) - #74
Merged
Merged
Conversation
冷启动无账号凭证/快照不足两天时,workbuddy_usage_official_all 与 workbuddy_usage_fallback 经命令桥 200 下发 {status:'empty'} 空态(无 summary/daily 字段),类型别名按 main 口径未建模联合,消费端三处 TypeError 致整页 ErrorBoundary 崩溃:
- Dashboard KPI 今日消耗:?. 只保护第一层,summary 须可选链
- adapters wbOfficialAllToPoints:r.daily 判空提前返回
- adapters wbFallbackToPoints:fb.daily 判空(issue 报告方案遗漏点)
验证:tsc --noEmit 通过;vitest 61/61;empty 态全消费点(Dashboard/CreditsTab/adapters 共 21 处)逐一核验均有防护。
Fixes #72
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #72
问题
Web 版(docker_main)积分看板冷启动阶段(后端官网会话未就绪/无账号凭证、本地快照不足两天)进入 Buddy → 积分看板页签时整页 ErrorBoundary 崩溃:
复现路径与现象详见 issue #72。
根因
workbuddy_usage_official_all(无账号凭证)与workbuddy_usage_fallback(快照 < 2 天)冷启动时返回 200 空态{"status":"empty","reason":...}(空态非错误,避免命令桥映射 500;证据:crates/aiwork-core/src/commands/workbuddy/credits.rs:387-393、923-929,命令桥cmd_bridge.rs将Ok→ 200、Err→ 500);export type WbUsageOfficialAll = WbUsageOfficialAllComplete/WbUsageFallback = WbUsageFallbackComplete把联合类型别名掉了,TS 不强制消费端判别status;?.只保护第一层:wbOfficial为 empty 对象(truthy)时wbOfficial?.summary→ undefined,(undefined).usage_today抛 TypeError,且??的 fallback 回退被短路;adapters的daily.map同理。修复(2 文件,+8/-4)
wbOfficial?.summary.usage_today→wbOfficial?.summary?.usage_today(wbFallback同理),empty 态经??链安全回落到 0 或快照差分wbOfficialAllToPoints(L53)if (!r)→if (!r || !r.daily),empty 态提前返回[]wbFallbackToPoints(L82)if (!fb)→if (!fb || !fb.daily)—— issue 报告方案遗漏的第三处:快照不足两天时 fallback 同样返回 empty 形状,仅按报告 diff 修复仍会在趋势图处二次崩溃审查与验证
tsc --noEmit通过;vitest61/61 通过;models/snapshot_days/stale/note等均已有可选链或逻辑守卫);workbuddy_usage_official_all共 5 种出口(empty/实时/缓存/stale complete/Err,empty 不落缓存)、workbuddy_usage_fallback共 2 种 Ok 出口(empty/snapshot、无 Err);看板消费的其余 Buddy 命令(积分/签到/快照/网关用量)Ok 形状稳定,无同类「Ok 但缺字段」风险。备注(非阻塞观察,不在本 PR 范围)
WbUsageEmpty纳入联合(types.ts:755、852),运行时安全目前依赖手写判空;根治可改为真实联合类型并在消费端收窄(对比WbCreditsTrend已建模联合),属于独立重构;Dashboard.tsx:452-458consumedHint 在 empty 态不显示「快照差分推导」提示文案(外观层小瑕疵,不崩溃)。