Repository navigation
Conversation
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4933423 to
5ce5021
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
service/task_billing_test.go (1)
118-126: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake batch-update mode explicit in the test fixture.
UpdateUserUsedQuotaandUpdateChannelUsedQuotaswitch between direct database writes and queued batch records usingcommon.BatchUpdateEnabled. These tests read the database immediately after the service call. UnlesstruncateorTestMainsets and flushes this state, the assertions depend on ambient global state. Set the mode explicitly and add a separate batch-mode test with an explicit flush.As per coding guidelines, backend test fixtures must initialize settings explicitly.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@service/task_billing_test.go` around lines 118 - 126, Update the task billing test fixtures around seedUsageAccounting and the related service-call tests to set common.BatchUpdateEnabled explicitly instead of relying on ambient state. Preserve direct-update coverage, add a separate batch-mode test that enables batching and explicitly flushes queued updates before database assertions, and restore the setting after each test to prevent global-state leakage.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@model/user.go`:
- Around line 1347-1353: Update UpdateUserUsedQuota and updateUserUsedQuota to
return and propagate a persistence error, treating zero affected rows as failure
instead of only logging database errors. Make the BatchUpdateEnabled path
retryable or durable by returning an equivalent result, then update the refund
and recalculation flows in task billing to handle failures and keep the task
marker pending until both user and channel usage updates succeed.
In `@service/task_billing.go`:
- Around line 249-251: Update the settlement flow at
service/task_billing.go:249-251 to atomically commit actualQuota with both user
and channel usage deltas, or make failed usage updates safely replayable. Also
update the refund/pending-marker transition at service/task_billing.go:181-185
so refund deltas are committed together with the state change and retries cannot
reapply -quota; use the existing task billing transition symbols and preserve
signed delta semantics.
---
Nitpick comments:
In `@service/task_billing_test.go`:
- Around line 118-126: Update the task billing test fixtures around
seedUsageAccounting and the related service-call tests to set
common.BatchUpdateEnabled explicitly instead of relying on ambient state.
Preserve direct-update coverage, add a separate batch-mode test that enables
batching and explicitly flushes queued updates before database assertions, and
restore the setting after each test to prevent global-state leakage.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 332644a5-3a46-46e5-8234-8545368daf63
📒 Files selected for processing (4)
model/user.gomodel/user_update_test.goservice/task_billing.goservice/task_billing_test.go
51fdfc5 to
2b6f1df
Compare
Important
📝 变更描述 / Description
异步任务提交时会将预扣额度计入用户和渠道累计用量。任务失败或实际费用低于预扣额度时,现有逻辑只恢复余额、订阅及令牌额度,没有同步回减累计用量,导致用户总额度虚增。
本次修改让失败退款和差额结算同步调整用户及渠道累计用量;结算阶段只修正最终用量,不再重复增加请求次数。同时补充全额退款、正负差额、退款失败和批量更新场景的回归测试。
与 #4323 相比,本 PR 基于当前
main,并补充了正差额结算请求次数和自动化测试覆盖。本次修改由 AI 辅助实现,提交者已逐行审查并完成本地验证。
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
📸 运行证明 / Proof of Work
go test ./service ./model -count=1go vet ./service ./modelgit diff --check以上命令均通过。
Summary by CodeRabbit