Repository navigation
FE-2217 test(account): pin the generated billing contracts the SDK decodes - #17829
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linear FE-2217.
Why
The billing SDK core decodes generated zod schemas from
@comfyorg/ingest-types/zod, which a bot regenerates from the cloud OpenAPI whenever the backend moves. Today a regen that renames a field, drops it, or widens an enum the reducer switches on surfaces either as a typecheck error somewhere deep in the core or, worse, as a runtimeMALFORMED_RESPONSEin front of a customer mid-payment. Nothing states, in one readable place, which fields of which schema the SDK actually depends on.This adds a contract test per generated schema the core decodes. Each pins the fields the core reads and the enum members it branches on, at the type level and at parse time, so a regen that changes one of them fails a named block whose name says what broke — the parse rows under
vitest run, theexpectTypeOfexhaustiveness pins under the package typecheck. A failure here means the backend contract moved: fix the SDK, not the test.These are pins, not behaviour: reader and command behaviour stays covered by the existing
credits.test.ts,status.test.ts,capabilities.test.ts,operationState.test.ts,subscriptionCommands.test.ts, andtopup.test.ts.How
New folder
packages/account-core/src/core/billing/contracts/, one file per endpoint contract, picked up by the package's existingsrc/core/**/*.{test,spec}.tsinclude. Each file holds a canonical fixture typed asz.input<typeof schema>built by a small typed builder (no casts), parses it withsafeParse, pins the output type withexpectTypeOf, and runs oneit.forrow per enum value the SDK branches on.zBillingBalanceResponsecredits.ts(read bytopup.ts,balanceWatch.ts)amount_microsas a number; the four optional breakdown microszBillingStatusResponsestatus.ts(read byoperationLifecycle.ts,subscriptionCommands.ts,presentation.ts)billing_rail(3),pending_billing_op_id,pending_billing_op_type(2),action_url,payment_intent_client_secret,is_active,subscription_tier(7),subscription_status(3)zBillingCapabilitiesResponse,zBillingCapabilities,zBillingCapabilityScope,zBillingCapabilityRolloutDefaultscapabilities.ts(which parses the three named pieces, not the response schema)expires_atas a plain string andrevisionas a number; all seven capability booleans;resolved_for.user_id/workspace_id;expires_at;revisionas an int64 bounded to the JavaScript-safe range the reader reads it back as a number over;denied_reasonsabsent from the contract, which is whycapabilityDenials.tsdecodes it off the raw bodyzBillingOpStatusResponseoperationLifecycle.ts,operationState.tsid;status(the 4 the reducer handles);authentication_state(the 5 it reads or assigns);decline_reason(8, incl. thegenericfallback);recovery_action(4);phase(3);action_url;payment_intent_client_secret;retryableoptionalzErrorResponsebillingErrorBody.tscodeas an open string the commands match against their own closed set; a body withoutmessageyields no codezSubscribeRequest,zSubscribeResponsesubscriptionCommands.tsconfirmation_token,saved_payment_method_id(pm_prefix),idempotency_key,confirm_reactivation;billing_op_id,status(3), optionalpayment_method_urlzResubscribeResponsesubscriptionCommands.tsbilling_op_idregardless ofstatus(2)zCancelSubscriptionResponse2subscriptionCommands.tsbilling_op_idon both members of the response unionzPaymentPortalResponsesubscriptionCommands.tsurlrequired, and not https-checked by the schema, which is why the command re-checks itzPreviewSubscribeRequest,zPreviewSubscribeResponsesubscriptionCommands.tsplan_slugrequired and the three optional request fields;allowed,is_immediate,effective_at,transition_type(4), the int64 money fields and their JSON-number coercion,discounts,requires_reactivation_confirmationzCreateTopupRequest,zCreateTopupResponsetopup.tsamount_centsminimum and its int64 coercion of the JSON number the command validates but does not send;idempotency_key;billing_op_idregardless ofstatus(3)zCreateTopupCheckoutRequest,zCreateTopupCheckoutResponsetopup.tsreturn_urlURL rule, pinned by the issue path the command reads to tell the two apart;checkout_urlrequired,session_idoptionalcapabilityDenials.tsis the one billing module that decodes without a generated schema — deliberately, since a strict enum parse would lose the whole capability set the first time the server names an unfamiliar policy branch. Its absence from the generated contract is pinned inbillingCapabilities.contract.test.ts.AS-IS / TO-BE
No UI. A regenerated
zBillingOpStatusResponsethat adds a fifthstatus:terminalFromStatusinto the pending branch; the operation polls until its budget runs out and reportstimed_out.billingOpStatus.contract.test.tsfails on the regen PR, naming the reducer as what needs updating. Two gates, and which one fires depends on the pin: the enum rows (accepts the %s status) fail undervitest run, while the exhaustiveness pin atbillingOpStatus.contract.test.ts:36sits at module scope and fails as a TS2344 under the package typecheck, not in the test run.Testing
cd packages/account-core && vitest run src/core/billing/contracts— 12 files, 90 tests, all passing. The type pins are not among them: they sit at module scope and failpnpm --filter @comfyorg/account-core typecheckinstead, because nothing here runsvitest --typecheck.cd packages/account-core && tsc --noEmit— cleanpnpm typecheck— passing; verified the type pins bite by injecting a spurious enum member and watchingexpectTypeOffail with TS2344pnpm lint,pnpm format,pnpm knip— passingfallow audit --changed-since origin/main— no issues in the 13 changed filesWhere this sits in the plan
Billing SDK track FE-2210 (implementation plan V2). Hybrid model: top-up in-app, subscription management / invoices / payment methods on the hosted billing app.
@comfyorg/account-uicomposables +CheckoutStepsbilling_sdk_topup_enabledhosted_billing_destinationserver flag read by the hosthostedDestinationport on the lifecycle, value on operation state@comfyorg/account→@comfyorg/account-corerenamebilling-contractroute builder +return_toregistrycreateHostedTopupCheckoutpreviewSubscribecommandusePlans,usePaymentMethods,usePreviewSubscribe)ci-billing-web-unit.yaml)/v1entry routing + subscription / payment-method surfacesprivateoff), Platform install, billing-web live top-upneedsCustomerAttentionpredicate (from the #17665 review)BillingServerCode(from the #17656 review)useCreditsclears onSUPERSEDED(from the #17799 review)SUPERSEDED(from the #17798 review)