feat(deleter): write an audit record for each checkout removed during org delete - #1839
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe deleter now lists and deletes billing checkouts during organization cleanup. It records checkout deletion events with checkout attributes, tolerates audit failures, and adds mock support and failure-path tests. ChangesCheckout deletion audit
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
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 |
fd43fb5 to
e043915
Compare
e043915 to
171e145
Compare
rohilsurana
left a comment
There was a problem hiding this comment.
The shape is right: list before delete, log after the delete succeeds, and a retry lists zero checkouts so there are no duplicate records. Two notes inline. One minor thought: as more steps get audited, a small helper for this loop would keep DeleteCustomers readable.
171e145 to
9d51491
Compare
Coverage Report for CI Build 30970637866Coverage increased (+0.03%) to 47.527%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
… org delete Org delete now hard-deletes checkout rows, and with them the local reference to the Stripe checkout sessions. Emit one audit record per removed checkout carrying the provider session id, plan/product id, state, and payment status. The audits table survives the org delete, so the sessions can still be looked up on Stripe later. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Also note that the records depend on the audit service seeded in ctx; outside the API path the logger falls back to a noop. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
9d51491 to
21b3303
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/deleter/service_test.go (1)
143-144: 🗄️ Data Integrity & Integration | 🔵 Trivial | 🏗️ Heavy liftTest the persisted audit contract.
These tests use
context.Background(), soaudit.NewLoggerfalls back to a no-op audit service. ForDeleteOrganization, add a recording audit repository, set it withaudit.SetContextWithService, and assert one persistedbilling_checkout_deletedentry per checkout with the expectedprovider_id,customer_id,plan_id,product_id,state, andpayment_statusattributes, including omission of empty values. Also add a failing audit repository case that still deletes cred and customer records. ForDeleteOrganization, assert that the recorded checkout audit entry remains after organization deletion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4ca7a7c3-3b5e-48aa-857d-312ac2523381
📒 Files selected for processing (4)
core/audit/audit.gocore/deleter/mocks/checkout_service.gocore/deleter/service.gocore/deleter/service_test.go
Stacked on #1838. Review only the last commit here; the rest is the base PR.
Problem
#1838 hard-deletes the
billing_checkoutsrows during org delete. Those rows hold the only local reference to the Stripe checkout sessions (provider_id). Once they are gone, there is no local trace of what was removed.Changes
app.billing.checkout.deleted, registered as a system event.DeleteCustomers, the deleter lists the checkouts before removing them and writes one audit record per checkout. Each record carries the provider session id, customer id, plan/product id, state, and payment status.organization.deletedevent.provider_id.Testing
core/deleter/service_test.go: the delete flow now expects the checkout list call, and a new case checks that a list failure stops the customer delete.🤖 Generated with Claude Code