fix(alerts): persist initial portfolio drawdown peak - #45
Merged
helsome merged 1 commit intoSep 11, 2026
Merged
Conversation
helsome
approved these changes
Sep 11, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
改动边界清晰,根因与复现路径一致;首次观测持久化 high-water mark、创新高更新、重启后继续计算 drawdown 的测试覆盖充分。该修复不改变公开类型/存储格式,适合独立合入。
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.
问题与复现
新建
portfolio_drawdown提醒后,首次组合资产值没有写入alerts-snapshots.json。例如阈值设为 10%,连续两次观测到totalAssets = 100 → 80,预期触发 20% 回撤提醒,实际没有事件。原因是
snapshot.peakValue ?? current将未初始化的峰值设为当前值,但只有current > peak才持久化。空快照下该条件永远不成立,每次检查的回撤都重新变成 0。原有测试预先填入了peakValue,因此没有覆盖新建规则的实际路径。修改
建议先修复现有提醒的峰值初始化,使新建规则即可生效,再继续扩展后台研究与通知能力。本次仅涉及现有提醒逻辑和测试,不修改 UI、公开类型或持久化格式。
验证
环境:Windows,Bun 1.4.2,基于
bf3fa0a。行情输入使用确定性测试数据;持久化测试使用真实JsonFileStore和AlertEngine.tick(),不依赖券商账户、模型 API 或 Electron UI。bun test packages/shared/src/alerts:42 passed / 0 failed。bun run typecheck:全部通过。git diff --check:通过。bun test --isolate:在相同环境中对未修改基线与本分支各运行一次,结果如下。bf3fa0a两次全量运行的 12 个失败名称完全一致,没有新增失败:7 个缺少已被 gitignore 排除的 Longbridge 账户 fixture(已有 #10 跟进);其余是 Windows 符号链接权限、kernel host 测试预期、Pi session 路径分隔符及 2 个 locale 格式预期。未将这些既有问题混入本次修复。