fix(reconcile): 修好漂移不再算失败

`-counters` 的职责就是修。修到了说明它起作用了,不是失败。
旧实现把 `fixed > 0` 并进 `failed`,于是"修好 3 条"与"连不上库"返回同一个退出码。
定时任务因此天天告警,告警本身失去意义。
现在只有 `err != nil` 才 `exit 1`。修复条数走日志的 `fixed=N`。
`-verify` 保持不变:它是只读检查,有漂移就是 `exit 1`。

验证:go test -count=1 ./cmd/reconcile/ 全绿;实跑 -counters 修好 1 条返回 exit 0
This commit is contained in:
2026-11-01 16:25:14 +08:00
parent 9d9fdb91e5
commit d542968ed4
2 changed files with 50 additions and 2 deletions

View File

@@ -0,0 +1,31 @@
package main
import (
"errors"
"testing"
)
// -counters 的职责就是修漂移:修到了说明巡检起作用了,不是失败。
//
// 旧实现把 fixed > 0 也并进 failed,于是"修好 3 条漂移"与"连不上数据库"
// 返回同一个退出码,cron 告警永远响。
func TestCountersResult_RepairedDriftIsNotFailure(t *testing.T) {
boom := errors.New("db down")
cases := []struct {
name string
in countersResult
want bool
}{
{name: "没有漂移", in: countersResult{checked: 5, fixed: 0}, want: false},
{name: "修好了漂移", in: countersResult{checked: 5, fixed: 3}, want: false},
{name: "查询失败", in: countersResult{checked: 0, fixed: 0, err: boom}, want: true},
{name: "修到一半失败", in: countersResult{checked: 3, fixed: 2, err: boom}, want: true},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
if got := c.in.failed(); got != c.want {
t.Fatalf("failed() = %v, want %v(%+v)", got, c.want, c.in)
}
})
}
}