fix(alerts): 组合资产归零时触发完整回撤提醒 - #151
Merged
Merged
Conversation
wxrbyte
marked this pull request as ready for review
September 20, 2026 14:14
helsome
approved these changes
Sep 21, 2026
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 #150
启用 portfolio_drawdown(阈值 10%),先观测 totalAssets = 1000 建立峰值,再明确返回 totalAssets = 0。预期产生 100% 回撤提醒,原实现返回 null,既不通知也不保存事件;1000 → 100 的 90% 回撤则正常。
根因:evaluateDrawdown 把 totalAssets <= 0 全部过滤掉,但回撤计算的分母是历史正数峰值,当前资产为 0 仍是有效终点。
修改范围
仅修改回撤评估器和对应测试,无可见 UI 变化;不改出入金语义、冷却规则、其他提醒或持久化格式,不夹带基线修复。
验证
环境:Windows / Bun 1.4.2(744846f84),基于 main 1c1f6cd。
先添加完整回归测试、保留旧实现:
修复后:
上述集成使用模拟 portfolio.summary 能力和真实临时文件持久化,不调用券商或外部模型。未在本地执行全仓 bun test --isolate、桌面 E2E;全仓测试由远端 PR checks 提供。远端 PR checks:Typecheck / Focused tests / Secret scan / Full unit tests (advisory) 均为 SUCCESS;仅用于 main push 的 Full unit tests 按工作流条件跳过。