Repository navigation
Conversation
📝 WalkthroughWalkthroughThe Stripe adapter now receives a dedicated webhook secret service. The secret service removes in-memory caching and locking. Application wiring and Stripe tests now provide and verify the separate webhook secret dependency. ChangesStripe webhook secret handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 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 |
| func (c Config) Validate() error { | ||
| var errs []error | ||
|
|
||
| if c.Adapter == nil { | ||
| errs = append(errs, errors.New("adapter is required")) | ||
| } | ||
|
|
||
| if c.CacheSize < 0 { | ||
| errs = append(errs, fmt.Errorf("cache size must not be negative: %d", c.CacheSize)) | ||
| } | ||
|
|
||
| if c.CacheTTL < 0 { | ||
| errs = append(errs, fmt.Errorf("cache ttl must not be negative: %s", c.CacheTTL)) | ||
| return errors.New("adapter cannot be null") | ||
| } |
There was a problem hiding this comment.
Preserve structured validation errors
Config.Validate now returns a plain error for a nil adapter instead of the repository-standard GenericValidationError, preventing callers from classifying this constructor failure with models.IsGenericValidationError and dropping consistent validation context.
Context Used: AGENTS.md (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: openmeter/secret/service/service.go
Line: 19-22
Comment:
**Preserve structured validation errors**
`Config.Validate` now returns a plain error for a nil adapter instead of the repository-standard `GenericValidationError`, preventing callers from classifying this constructor failure with `models.IsGenericValidationError` and dropping consistent validation context.
**Context Used:** AGENTS.md ([source](https://github.com/openmeterio/openmeter/blob/main/AGENTS.md))
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
test/app/stripe/app_test.go (1)
67-69: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
t.Context()for the webhook-secret test.The caller passes a parent context, and
TestGetWebhookSecretaccepts and uses it instead of the subtest context. Uset.Context()so fixture setup and webhook lookup follow the subtest lifecycle.
test/app/stripe/app_test.go#L67-L69: remove thectxargument from the helper call.test/app/stripe/appstripe.go#L807-L838: remove thectxparameter and uset.Context()for both operations.As per coding guidelines, use
t.Context()whenever atesting.Tortesting.TBis available.🤖 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 `@test/app/stripe/app_test.go` around lines 67 - 69, Update test/app/stripe/app_test.go lines 67-69 to call TestGetWebhookSecret without the parent ctx argument. In test/app/stripe/appstripe.go lines 807-838, remove the helper’s ctx parameter and use t.Context() for both fixture setup and webhook lookup operations.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 `@openmeter/secret/service/service.go`:
- Around line 19-24: Update Config.Validate to collect validation errors in an
errs slice, wrapping the missing Adapter error with its field context, and
return models.NewNillableGenericValidationError(errors.Join(errs...)) instead of
a plain errors.New result. Preserve the nil result when no validation errors
exist.
---
Nitpick comments:
In `@test/app/stripe/app_test.go`:
- Around line 67-69: Update test/app/stripe/app_test.go lines 67-69 to call
TestGetWebhookSecret without the parent ctx argument. In
test/app/stripe/appstripe.go lines 807-838, remove the helper’s ctx parameter
and use t.Context() for both fixture setup and webhook lookup operations.
🪄 Autofix (Beta)
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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: b541b367-eb90-447e-9a81-e5daf223a4a3
📒 Files selected for processing (16)
app/common/app.goapp/common/secret.gocmd/billing-worker/wire_gen.gocmd/jobs/internal/wire_gen.gocmd/server/wire_gen.goopenmeter/app/stripe/adapter.goopenmeter/app/stripe/adapter/adapter.goopenmeter/app/stripe/adapter/stripe.goopenmeter/secret/service/secret.goopenmeter/secret/service/secret_test.goopenmeter/secret/service/service.gotest/app/stripe/app_test.gotest/app/stripe/appstripe.gotest/app/stripe/invoice_test.gotest/app/stripe/testenv.gotest/app/testenv.go
💤 Files with no reviewable changes (1)
- openmeter/secret/service/secret_test.go
| func (c Config) Validate() error { | ||
| var errs []error | ||
|
|
||
| if c.Adapter == nil { | ||
| errs = append(errs, errors.New("adapter is required")) | ||
| } | ||
|
|
||
| if c.CacheSize < 0 { | ||
| errs = append(errs, fmt.Errorf("cache size must not be negative: %d", c.CacheSize)) | ||
| } | ||
|
|
||
| if c.CacheTTL < 0 { | ||
| errs = append(errs, fmt.Errorf("cache ttl must not be negative: %s", c.CacheTTL)) | ||
| return errors.New("adapter cannot be null") | ||
| } | ||
|
|
||
| return models.NewNillableGenericValidationError(errors.Join(errs...)) | ||
| return nil |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Use the standard Validate error contract.
Collect the adapter error with field context. Return models.NewNillableGenericValidationError(errors.Join(errs...)).
The current plain error loses the standard structured validation result. As per coding guidelines, “For Validate() error, collect field errors and return models.NewNillableGenericValidationError(errors.Join(errs...)), preserving field context with wrapped errors.”
🤖 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 `@openmeter/secret/service/service.go` around lines 19 - 24, Update
Config.Validate to collect validation errors in an errs slice, wrapping the
missing Adapter error with its field context, and return
models.NewNillableGenericValidationError(errors.Join(errs...)) instead of a
plain errors.New result. Preserve the nil result when no validation errors
exist.
Source: Coding guidelines
5d1c8b2
into
fix/stripe-webhook-app-not-found-500
Summary
Stacked on #4828.
WebhookSecretServicedependency for Stripe webhook verificationsecret.ServiceWhy
Caching policy belongs to the deployment that owns the backing secret store. Cloud already has a cache wrapper and can now inject it specifically for the high-volume webhook path without making all OpenMeter secret reads cached.
The adapter dependency is required so deployments cannot silently fall back to an unintended uncached webhook path.
Validation
make generatego test -tags=dynamic ./openmeter/secret/service ./openmeter/app/stripe/adapter ./app/commongo test -tags=dynamic ./test/app/stripe -run '^$'go test -tags=dynamic ./cmd/server ./cmd/billing-worker ./cmd/jobs/internal -run '^$'go vet -tags=dynamic ./openmeter/app/stripe/... ./openmeter/secret/... ./app/common ./test/app/stripe ./test/appThe PostgreSQL-backed webhook dependency test compiles, but could not be executed locally because PostgreSQL was not available on
127.0.0.1:5432.Summary by CodeRabbit
New Features
Bug Fixes
Tests
Greptile Summary
The PR separates Stripe webhook-signing-secret reads from general secret operations so deployments can inject a specialized read service.
WebhookSecretServicedependency in the Stripe adapter.Confidence Score: 4/5
The PR appears safe to merge, with one non-blocking validation-error consistency issue.
The new webhook dependency is supplied across the discovered production and test construction paths and preserves the existing secret lookup contract; only the secret-service constructor's validation error classification needs cleanup.
Files Needing Attention: openmeter/secret/service/service.go
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart LR W[Stripe webhook handler] --> S[Stripe app service] S --> A[Stripe adapter] A --> D[(Stripe app database row)] A --> H[WebhookSecretService] H --> X[Secret adapter] A -. general secret operations .-> G[secret.Service] G --> XPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "refactor(app/stripe): inject webhook sec..." | Re-trigger Greptile
Context used (7)