fix(billing): 重排任务复用钱包预留

平台额度跨窗口重排时保留任务已有的钱包预留,后续 Worker 领取复用同一幂等键,避免重复 reserve/release 事务。\n\n补齐排队任务取消后的原子结算释放,并允许任务 attempt 持久化软负载、满载原因和选择原因等有界路由快照。\n\n验证:go test ./...;go vet ./...;钱包预留复用与排队取消 PostgreSQL 集成测试。
This commit is contained in:
2026-08-03 18:09:47 +08:00
parent 13faf1d072
commit c8d04ca731
4 changed files with 147 additions and 1 deletions
@@ -36,6 +36,21 @@ func TestMinimalTaskResultDropsProviderRawCopy(t *testing.T) {
}
}
func TestMinimalTaskAttemptMetricsKeepsBoundedRoutingSnapshot(t *testing.T) {
metrics := minimalTaskAttemptMetrics(map[string]any{
"loadMetrics": map[string]any{"concurrent": map[string]any{"softRatio": 0.5}},
"fullReasons": []any{"waiting"},
"selectionReason": "full_avoided",
"requestBody": map[string]any{"secret": "must not persist"},
})
if metrics["loadMetrics"] == nil || metrics["fullReasons"] == nil || metrics["selectionReason"] != "full_avoided" {
t.Fatalf("routing snapshot was dropped: %+v", metrics)
}
if metrics["requestBody"] != nil {
t.Fatalf("unbounded attempt payload was retained: %+v", metrics)
}
}
func TestTaskEventsAreMinimalAndConsecutiveDuplicatesAreSkipped(t *testing.T) {
db := billingV2IntegrationStore(t)
ctx := context.Background()