From 9622347faaf659c38e06548a190dd1e758ac7f47 Mon Sep 17 00:00:00 2001 From: yangjianbo Date: Mon, 12 Jan 2026 15:46:55 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=B0=83=E5=BA=A6):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=20outbox=20=E7=A9=BA=E8=BD=BD=E5=86=99=E5=85=A5=E5=B9=B6?= =?UTF-8?q?=E7=A8=B3=E5=9B=BA=E5=9B=9E=E6=94=BE=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 outbox payload 为空时写入 NULL 避免事务因 JSON 解析错误中断 调整回放测试为预置缓存后验证 last_used 更新 测试: go test -tags=integration ./internal/repository --- .../internal/repository/scheduler_outbox_repo.go | 6 +++--- .../scheduler_snapshot_outbox_integration_test.go | 15 +-------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/backend/internal/repository/scheduler_outbox_repo.go b/backend/internal/repository/scheduler_outbox_repo.go index 1a09c0d1..d7bc97da 100644 --- a/backend/internal/repository/scheduler_outbox_repo.go +++ b/backend/internal/repository/scheduler_outbox_repo.go @@ -80,17 +80,17 @@ func enqueueSchedulerOutbox(ctx context.Context, exec sqlExecutor, eventType str if exec == nil { return nil } - var payloadJSON []byte + var payloadArg any if payload != nil { encoded, err := json.Marshal(payload) if err != nil { return err } - payloadJSON = encoded + payloadArg = encoded } _, err := exec.ExecContext(ctx, ` INSERT INTO scheduler_outbox (event_type, account_id, group_id, payload) VALUES ($1, $2, $3, $4) - `, eventType, accountID, groupID, payloadJSON) + `, eventType, accountID, groupID, payloadArg) return err } diff --git a/backend/internal/repository/scheduler_snapshot_outbox_integration_test.go b/backend/internal/repository/scheduler_snapshot_outbox_integration_test.go index e82d663f..dede6014 100644 --- a/backend/internal/repository/scheduler_snapshot_outbox_integration_test.go +++ b/backend/internal/repository/scheduler_snapshot_outbox_integration_test.go @@ -46,25 +46,12 @@ func TestSchedulerSnapshotOutboxReplay(t *testing.T) { Extra: map[string]any{}, } require.NoError(t, accountRepo.Create(ctx, account)) + require.NoError(t, cache.SetAccount(ctx, account)) svc := service.NewSchedulerSnapshotService(cache, outboxRepo, accountRepo, nil, cfg) svc.Start() t.Cleanup(svc.Stop) - bucket := service.SchedulerBucket{GroupID: 0, Platform: service.PlatformOpenAI, Mode: service.SchedulerModeSingle} - require.Eventually(t, func() bool { - accounts, hit, err := cache.GetSnapshot(ctx, bucket) - if err != nil || !hit { - return false - } - for _, acc := range accounts { - if acc.ID == account.ID { - return true - } - } - return false - }, 5*time.Second, 100*time.Millisecond) - require.NoError(t, accountRepo.UpdateLastUsed(ctx, account.ID)) updated, err := accountRepo.GetByID(ctx, account.ID) require.NoError(t, err)