feat: verify usage billing provider conformance - #1726
Conversation
|
Warning Review limit reached
Next review available in: 56 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthrough사용량 청구 conformance 범위를 추가합니다. 중복 replay, 부분 배치, 미터 상태, retryable·terminal 오류, 미지원 capability를 검증합니다. Capability manifest와 공개 타입을 제공하고, Polar에 미지원 usage 시나리오를 연결합니다. Changes사용량 청구 적합성 검증
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant ConformanceContract
participant BillingProviderConformanceSuite
participant UsageBillingGateway
participant ProviderManifest
ConformanceContract->>BillingProviderConformanceSuite: 사용량 fixture와 실패 시나리오 제공
BillingProviderConformanceSuite->>UsageBillingGateway: 이벤트 삽입, replay, 미터 조회
UsageBillingGateway-->>BillingProviderConformanceSuite: 영수증, 상태, 공개 Problem
BillingProviderConformanceSuite->>ProviderManifest: capability evidence와 case 목록 기록
Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 8
🤖 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 `@packages/testing/src/libs/billing-provider-conformance.ts`:
- Around line 543-552: Update UsageBillingConformanceFixtures.customerMeterState
to use Omit<CustomerMeterState, "updatedAt"> and add an optional hook for
validating updatedAt. In
packages/testing/src/libs/billing-provider-conformance.ts lines 543-552 and
597-601, compare only billingAccountId, meterId, and value for
beforeReplay/afterReplay; delegate updatedAt checks to the hook or verify only
that replay does not move it backward. Leave the empty-state assertion around
line 590 unchanged.
- Around line 271-275: Update the capability property in
BillingProviderConformanceCapabilityEvidence to use the existing
BillingProviderCapability type instead of the "usage" literal, reusing the
import already present for BillingProviderCapabilityConformanceOptions.required.
- Around line 1004-1016: Consolidate assertThrowsProblem into
assertRejectsWithProblem so one helper handles both synchronous throws and
rejected promises. Invoke the supplied callback through the async path, await
its result, and validate any caught value is a Problem before returning it.
Update callers to use assertRejectsWithProblem and remove the redundant
assertThrowsProblem helper.
- Around line 1018-1021:
packages/testing/src/libs/billing-provider-conformance.ts의
usage.partialBatch.expectedReceipts와 assertUsageReceipts를 업데이트해 receipt 구조와 상태
유니온을 재선언하지 말고 packages/billing-core/src/index.ts의 UsageBillingBatchReceipt 및
UsageBillingEventReceipt에서 타입을 파생시키십시오. 해당 upstream 타입을 기준으로 receipts와 expected의
값 타입이 연결되도록 수정하고, 두 위치(166-175, 1018-1021)의 중복 선언을 모두 제거하십시오.
- Around line 705-714: Update the default enablement check in the gate handling
around AuthProviderLiveSmokeGate so required environment variables enable live
usage billing conformance only when their values are non-empty, matching the
existing AuthProviderLiveSmokeGate rule; preserve custom gate.isEnabled behavior
unchanged.
In `@packages/testing/src/tests/ConformanceContract.spec.ts`:
- Around line 609-611: Extend the manifest immutability assertions in the
conformance suite test to verify every capability evidence object in
suite.manifest.capabilityEvidence and each nested caseNames array is frozen,
while retaining the existing top-level checks.
In `@packages/testing/src/tests/testing.spec.ts`:
- Around line 1846-1879: Update the shared failure-scenario run callbacks for
http429, http5xx, and timeout to pass the fixture’s events collection to
gateway.ingest instead of an empty array. Preserve the existing gateway
construction and failure assertions so these scenarios exercise real provider
adapters with an actual event batch.
- Around line 243-275: Update FailingUsageBillingGateway to implement
UsageBillingGateway directly instead of extending InMemoryUsageBillingGateway,
preserving its existing ingest and getCustomerMeterState failure behavior.
Narrow fixture.kind to the existing conformance contract union if available, and
replace string comparisons in createProblem with a Set-based retryable-kind
check so invalid scenario names fail type checking and retry classification
remains exhaustive.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: df26e98a-6efb-47b0-83d9-e45679a02f58
📒 Files selected for processing (8)
.changeset/usage-billing-conformance.mddocs/package-catalog.jsonpackages/billing-polar/src/tests/PolarBillingGateway.spec.tspackages/testing/src/index.tspackages/testing/src/libs/billing-provider-conformance.tspackages/testing/src/tests/ConformanceContract.spec.tspackages/testing/src/tests/testing.spec.tspublic-api-surface.snapshot.json
📊 Benchmark Results✅ All benchmarks passed
Updated: 2026-08-01T20:34:18.990Z · Commit: b280fcf |
Outcome
@croco/testingnow provides a versioned, machine-readable usage-billing conformance contract. Usage-capable providers must prove one-to-one bounded batch receipts, duplicate replay without a second meter increment, explicit empty and populated meter states, 429/5xx/timeout retry classification, invalid meter/schema terminal classification, stable public Problems, raw-response redaction, and credential-gated real-provider smoke coverage.Polar runs the same suite to certify that its unsupported usage capability fails through the public capability Problem, and provider certification metadata records that evidence.
Fixes #1527
Verification
pnpm --filter @croco/testing typecheckpnpm --filter @croco/testing test— 126 tests passed.pnpm --filter @croco/billing-polar test— 87 tests passed; 2 credential-gated live-smoke tests skipped.pnpm public-api:checkpassed.Review gates
@croco/testing; raw response samples are required redaction checks.Residual risk
The real-provider profile remains deliberately opt-in and credential-gated; ordinary CI uses the deterministic reference adapter.
Summary by CodeRabbit
새로운 기능
문서