refactor: Migrate VPC Peering API handlers to WithTx#565
Conversation
Continues the `WithTx` migration, covering both `BeginTx` sites in `vpcpeering.go` (`Create` and `Delete`). Both handlers trigger workflows and wait on `we.Get`, so they're also adopting our little `timeoutResp` pattern that has evolved over a few of these PRs. Callouts are: - `Create` and `Delete` both use `WithTx` + `timeoutResp`. `Create`'s single `vpcPeering` output would fit `WithTxResult` shape-wise, but mixing that with the outer-scope `timeoutResp` closure isn't a great fit. - Validation reads (site, VPCs, tenant accounts, tenant sites, existing peerings) were already outside the legacy tx and stay there. - Errors switched to `NewAPIError`. Signed-off-by: Chet Nichols III <chetn@nvidia.com>
Summary by CodeRabbit
WalkthroughThis PR refactors the VPC peering create and delete handlers to adopt a closure-based transaction pattern using ChangesVPC Peering Handler Transaction Refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
🔐 TruffleHog Secret Scan✅ No secrets or credentials found! Your code has been scanned for 700+ types of secrets and credentials. All clear! 🎉 🕐 Last updated: 2026-05-21 20:35:22 UTC | Commit: 667237e |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
api/pkg/api/handler/vpcpeering.go (1)
279-406: 🏗️ Heavy liftAdd regression coverage for the new
WithTx/timeout contract.These two paths now depend on subtle control flow: handler-scoped API errors returned from inside
WithTx, real commit/rollback failures winning overtimeoutResp, and best-effort post-commit work staying outside the transaction. Please pin those branches with focused handler tests before more handlers adopt the same pattern.Also applies to: 872-959
🤖 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 `@api/pkg/api/handler/vpcpeering.go` around lines 279 - 406, Add focused regression tests for the new cdb.WithTx + timeoutResp contract in the VPC Peering handler: write tests that simulate (1) a workflow timeout inside the WithTx closure causing timeoutResp to be set (use a fake Temporal client returning a TimeoutError) and assert timeoutResp() is called only after the DB transaction commit/rollback and that common.TerminateWorkflowOnTimeOut is invoked; (2) a real DB commit/rollback failure (make cdb.WithTx return a non-cutil.APIError) and assert that HandleTxError wins over timeoutResp; and (3) handler-scoped API errors returned from inside the closure (returning cutil.NewAPIError) and assert they surface unchanged and that post-commit best-effort work (the timeoutResp invocation) is not executed pre-commit; apply the same test patterns to the other handler region flagged (lines ~872-959). Use the handler entry point that constructs vpcPeering, timeoutResp, cdb.WithTx, common.TerminateWorkflowOnTimeOut, and common.HandleTxError to target the exact control-flow.
🤖 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.
Nitpick comments:
In `@api/pkg/api/handler/vpcpeering.go`:
- Around line 279-406: Add focused regression tests for the new cdb.WithTx +
timeoutResp contract in the VPC Peering handler: write tests that simulate (1) a
workflow timeout inside the WithTx closure causing timeoutResp to be set (use a
fake Temporal client returning a TimeoutError) and assert timeoutResp() is
called only after the DB transaction commit/rollback and that
common.TerminateWorkflowOnTimeOut is invoked; (2) a real DB commit/rollback
failure (make cdb.WithTx return a non-cutil.APIError) and assert that
HandleTxError wins over timeoutResp; and (3) handler-scoped API errors returned
from inside the closure (returning cutil.NewAPIError) and assert they surface
unchanged and that post-commit best-effort work (the timeoutResp invocation) is
not executed pre-commit; apply the same test patterns to the other handler
region flagged (lines ~872-959). Use the handler entry point that constructs
vpcPeering, timeoutResp, cdb.WithTx, common.TerminateWorkflowOnTimeOut, and
common.HandleTxError to target the exact control-flow.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 1efb9df9-8c94-41ac-9cc1-c786e85ba57a
📒 Files selected for processing (1)
api/pkg/api/handler/vpcpeering.go
🔍 Container Scan Summary
Per-CVE detail lives in the per-service |
Description
Continues the
WithTxmigration, covering bothBeginTxsites invpcpeering.go(CreateandDelete).Both handlers trigger workflows and wait on
we.Get, so they're also adopting our littletimeoutResppattern that has evolved over a few of these PRs.Callouts are:
CreateandDeleteboth useWithTx+timeoutResp.Create's singlevpcPeeringoutput would fitWithTxResultshape-wise, but mixing that with the outer-scopetimeoutRespclosure isn't a great fit.NewAPIError.Signed-off-by: Chet Nichols III chetn@nvidia.com
Type of Change
Services Affected
Related Issues (Optional)
Breaking Changes
Testing
Additional Notes