chore(harness): ADR-0002 + G12 立指标计算的 float64 边界

为什么:Milestone 6 引入 transient float64 用于 pivot/percentile/median
计算。G2 早已预留"统计中间过程可用 float64"的例外,但缺可机械验证
的边界。本提交把例外落地为:
- ADR-0002 记录"为什么不用 shopspring/decimal"
- G12 给出 4 条 grep 守卫(usecase float 仅限 indicator.go、
  indicator.go 不依赖 repo、不依赖 binance/postgres/pgx、entity
  仍禁 float)

代码无改动;下一 commit 开始铺 indicator.go 骨架。
This commit is contained in:
dela
2026-05-24 20:10:13 +08:00
parent 05dc2ef0e7
commit c6c25d1a45
2 changed files with 126 additions and 0 deletions

View File

@@ -193,6 +193,35 @@ grep -rn "FundingRepo\|OIRepo\|LSRepo\|TakerRepo" internal/controller
---
## G12. 指标计算的 float64 边界
**规则**`float64``internal/usecase/` 下**只允许出现在 `indicator.go` 内部**作为 transient 计算变量;进入 `entity` / 返回上层之前必须 `strconv.FormatFloat(_, 'f', -1, 64)` 转回 string。`internal/usecase/indicator.go` 同时**禁止** import `internal/repo/...` 的任何子包。
**为什么**G2 已经预留"指标计算中间过程可用 float64"的例外但没有可机械验证的边界。Milestone 6 之后会有更多指标加入,必须把例外明文化、可 grep 化,避免某天 float64 悄悄出现在 entity 字段或被 repo 持久化。决策细节见 `ai/adr/0002-indicator-numeric-boundary.md`
**怎么验证**
```bash
# usecase 下除 indicator.go 之外不得出现 float64
grep -rn --include="*.go" "float64\|float32" internal/usecase | grep -v indicator
# 期望:无输出
# indicator.go 不得 import 任何 repo 子包
grep -n "internal/repo" internal/usecase/indicator.go
# 期望:无输出
# indicator.go 不得 import binance / postgres / pgx
grep -nE "binance|postgres|pgx" internal/usecase/indicator.go
# 期望:无输出(注释中的 ADR 引用不算)
# entity 字段任何位置不得 float
grep -rn --include="*.go" "float64\|float32" internal/entity
# 期望:无输出
```
**例外**:无。如果未来某个指标输入/输出确实需要 decimal 精度(累加型大数据集),先升级 ADR-0002 再改实现。
---
## 升级守护规则的时机
同一类错误第二次出现 → 写一条新规则进来。修改本文件 = 改动了项目契约,需要在 PR 描述里说明原因并 @ 维护者。