Repository navigation
test(billing): lock in JPY upgrade boundary and canonical catalog regression tests (#23584) - #23597
khoap1220-hue wants to merge 1 commit into
Conversation
aryanorastar
left a comment
There was a problem hiding this comment.
Thanks for working on #23584. Separating existing-subscriber price admission from fresh Checkout, checking active/currency before releasing schedules, and resolving expanded item currency are useful parts of the boundary.
The mobile flow is still incomplete: the selected JPY ID is looked up in a separate USD catalog, and the annual total still renders as USD divided by 100. I also reproduced the two newly added test failures: SubscriptionStatus is not imported. The test named allows_jpy_to_jpy currently exercises only the USD mismatch, so a successful JPY change still needs coverage.
I’m consolidating the end-to-end implementation in draft #23591, which already covers these useful boundary behaviors through the canonical catalog, mobile confirmation/compatibility, and real Stripe sandbox tests. No commits have been imported from this PR; any useful code subsequently ported will retain its original author and source attribution. Keeping this PR open while the consolidated fix is verified avoids losing the review/contribution record. We’ll link the exact incorporated or superseded work when the fix lands.
| id=monthly_price.id, | ||
| plan_id=definition["plan_id"], | ||
| title=f'{definition["title"]} Monthly', | ||
| price_string=_format_monthly_price_string(monthly_price.unit_amount, price_currency), |
There was a problem hiding this comment.
[P1] Complete or gate the installed mobile consumer before serving JPY IDs. In this head, plans_sheet.dart::_handleUpgrade still resolves priceId against provider.subscription.availablePlans from /v1/users/me/subscription, which contains the configured USD prices. The newly returned JPY ID therefore reaches selectedPlanNotAvailable before any upgrade call. The annual subtitle also still does \$${unitAmount / 100}, displaying the wrong total/currency. Carry the exact displayed offer through the generated DTO/confirmation, fix minor-unit rendering, and require a compatible client before returning non-USD offers.
| plus_monthly = 'price_1ULq6b1F8wnoWYvwtchjjNqq' | ||
| sub = Subscription( | ||
| plan=PlanType.plus, | ||
| status=SubscriptionStatus.active, |
There was a problem hiding this comment.
[P2] Import the status enum and exercise the positive change. Both newly added tests fail with NameError: name 'SubscriptionStatus' is not defined at lines 196 and 242 in this head (13 existing tests pass). After fixing that, the allows_jpy_to_jpy test needs an actual JPY-target request and assertions on the modified subscription/payment result: it currently sends only the USD target and checks rejection.
| current_subscription = users_db.get_user_subscription(uid) | ||
| current_price_id = None | ||
| scheduled_price_id = None | ||
| subscription_currency = 'usd' |
There was a problem hiding this comment.
[P2] Avoid treating an unverified existing subscription as USD. Currency stays at this default when Stripe retrieval fails or cancel_at_period_end skips the lookup, so an existing JPY payer is shown USD offers. Cancellation is especially relevant because the UI reactivates the current price through Checkout, which still refuses the retained JPY ID. Resolve the currency for still-current paid subscriptions (including pending cancellation), fail closed on lookup failure, and cover same-price reactivation without opening new Checkout admission.
…PY upgrade assertion, and format Addresses review feedback from @aryanorastar and CI formatting/hygiene checks on BasedHardware#23597.
|
Thanks @aryanorastar for the detailed review and for coordinating the consolidated fix in #23591! I've pushed GPG-signed commit
Happy to follow #23591 as the canonical integration PR! |
## What changed An existing JPY subscriber selecting Unlimited in the mobile sheet received a USD price that Stripe rejected. #20804 recognized JPY prices for entitlements but explicitly excluded in-app plan changes. The sheet now shows the approved JPY offer, preserves its formatted total through the generated DTO, and confirms the exact displayed price instead of looking it up in a separate USD catalog. The canonical catalog explicitly admits the four existing JPY Plus/Unlimited IDs for managing an existing JPY subscription. Resolution checks currency, active state, interval, mode and entitlement version. Stale USD, retired/unbound and nonrecurring targets are rejected before releasing schedules or changing entitlements. Retained prices cannot open new Checkout; the exact current JPY price can reactivate its own pending cancellation, after promotion-code validation. Existing cancellation indicators and desktop/legacy/ladder boundaries remain guarded. No amounts are imported and no production Stripe prices are created or changed. Old sheets must update before receiving non-USD offers because their annual summary hardcodes USD. The currency capability header and additive response fields are reflected in the generated Dart, Swift and TypeScript clients. Closes #23584. Related recognition-only work: #20804. Parallel submissions #23592 (@PINYOPATTANAWASANPORN) and #23597 (@khoap1220-hue) were reviewed for consolidation; their useful boundary behaviors are already covered here. No commits were imported from either submission. [Coordination and attribution record](#23584 (comment)). ## Product invariants affected none ## How it was verified - **524 backend tests passed in 12 isolated files**, using `BACKEND_UNIT_TEST_FILE_LIST` with `backend/test.sh`: currency management, JPY recognition, catalog/compiler and immutable entitlements, pricing resilience, proration/decline/cancellation/promotion guards, subscription ingestion, BYOK payment access and v1 storefront-flag independence. - **Six real Stripe sandbox flows passed**: catalog → paid immediate JPY upgrade; JPY annual schedule plus stale-USD rejection preserving it; declined payment preserves the paid plan; reactivation leaves exactly one subscription; a real one-time JPY price is excluded/rejected; an invalid promotion leaves cancellation unchanged. Only synthetic identity bindings and DB/cache seams are substituted, not Stripe requests. Opt-in command from `backend/`: `python -m pytest --confcutdir=tests/integration/billing tests/integration/billing/test_jpy_plan_changes_stripe.py -v` with an explicitly supplied standard test key. - **36 focused Flutter tests**, **23 mobile-verify checks**, targeted analysis and the three-run mobile performance gate passed. - **CI follow-up:** refreshed 52 backend/mobile storefront goldens and the mobile revision assertion for catalog revision 11. Reviewed every fixture diff: the revision is the only changed field. The formerly failing storefront file now passes **343 backend tests** with the normal timing guard; **70 mobile fixture-consumer tests** also pass. Existing simulator and Stripe evidence remains applicable because this follow-up changes only test metadata. - **Fresh iPhone 16 Pro / iOS 26.5 simulator**, Flutter 3.44.5, Japanese Flutter locale: selected Unlimited and Monthly, verified the exact JPY confirmation, then cancelled back to the sheet through agent-flutter. This tests the production PlansSheet and generated DTO with synthetic offers; payment mutations are exercised separately by the real sandbox route tests. Replay fixture and commands accompany the screenshots. - Repository preflight and the final bounded push gate passed, including full backend type checking, OpenAPI compatibility, all generated clients, desktop Swift compilation and formatting. Current-head CI is green at `a37882a71bc9e40e4e7c025bf6f8744a5211b25e` (41 passed, 23 skipped, no pending or failed checks). Aryan supplied a final review finding no merge-blocking code issues at this head and reported another 371 backend tests and 29 Flutter tests passing; those reruns were reported by the reviewer rather than repeated by this implementation session. ## UI evidence    ## Release and remaining verification Current-head CI and the supplied final code review have passed. Before production release, an Omi Stripe owner must verify the production JPY prices are active with the expected currency, recurrence, mode and entitlement bindings; personal-sandbox results do not establish the production catalog or this customer's account state. Merge and deploy the backend before releasing the currency-aware mobile app. No production subscriptions/customer data, deployment or app release were changed by this work. Keep the support case open until the customer verifies the displayed JPY price and successful plan change on the released build. Failure-Class: none Line-Count-Exception: backend/routers/payment.py | 1846 -> 1934 | Keep currency admission beside existing authenticated subscription and schedule mutations; reusable currency resolution is extracted to utils/billing_currency.py. A broader payment-router split is outside this safety fix and the exception needs maintainer review.
|
The review-round fixes landed cleanly and the currency boundary is enforced in the right place; what remains open is which JPY catalog should ship, which is exactly what #23591 is deciding. Verified on the current head:
Still open:
USER IMPACT: Japanese-yen subscribers would see yen-denominated prices (¥1,500/mo instead of a wrong $15.00) and could switch plans within their currency; USD subscribers see no change. Since #23591 is carrying the canonical end-to-end fix with real Stripe sandbox coverage, I'd treat this PR as the boundary work it proved out and leave the catalog decision to the maintainer — leaving for human maintainer review rather than adding another blocking round. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
ce731ff to
a9609a6
Compare
|
Thank you @Git-on-my-level and David for the review! I have rebased this branch cleanly onto
|
Git-on-my-level
left a comment
There was a problem hiding this comment.
Since my last review: addressed (the SubscriptionStatus import is fixed and the positive JPY-to-JPY path is now asserted in backend/tests/unit/test_jpy_price_recognition.py, verified on this head; the open catalog question was resolved — #23591 merged with the canonical MANAGEMENT_CURRENCY_PRICES catalog and this branch rebases cleanly onto it) · still open (JPY admission still comes from a separate hardcoded list instead of that catalog) · newly introduced (after the rebase, most of this diff's production code is unreachable).
Verdict: this needs trimming before merge — the PR's remaining production delta is dead code, and part of it encodes a price-admission policy that main now deliberately rejects.
backend/routers/payment.py
_validate_price_id(..., allow_approved_jpy=False): no caller ever passes the flag — checkout (line 726) and upgrade (line 847) both call it unflagged, and JPY prices bypass it entirely viamanagement_binding. Theallow_approved_jpybranch is unreachable as shipped.- The
import sys as _sys/getattr(_sys.modules.get('utils.subscription'), 'is_upgradeable_price_id', ...)indirection exists so tests can monkeypatch the lookup. A validation boundary shouldn't resolve its check through sys.modules reflection; if the helper survives, import it normally. _format_monthly_price_string/_format_annual_monthly_price_string(lines 666/672) have zero call sites — the plans endpoints already render viaformat_money+price_for_currency. If they ever get wired in, note the USD annual path truncates (int(unit_amount/100/12): 9999¢/yr renders "$8/mo").
backend/utils/subscription.py
_RETAINED_JPY_CATALOG_PRICE_IDShardcodes six price IDs, duplicating data the catalog now owns canonically. It also includesprice_1RtJPm1F8wnoWYvwhVJ38kLbandprice_1RtJQ71F8wnoWYvwKMPaGlGY— legacyunlimited(v1) ledger prices that #23591 intentionally keeps OUT ofMANAGEMENT_CURRENCY_PRICES("the retained recognition ledger is not a purchase catalog").is_upgradeable_price_id()therefore admits ledger-only prices as upgrade targets, contradicting the merged boundary even though nothing currently reaches it.
backend/tests/unit/test_jpy_price_recognition.py
- The strongest part:
test_upgrade_subscription_allows_jpy_to_jpy_and_rejects_currency_mismatchlocks in #23591's behavior (USD target on a JPY subscription → 409 withreleased == []before any schedule release; JPY→JPY → exactly one release + onestripe.Subscription.modify). Keep it. The helper assertions intest_ledger_derived_jpy_catalog_helpers_and_formattingonly pin the unused helpers added here.
Security / blast radius: no reachable behavior change vs main today — the risk is latent (a future caller passing allow_approved_jpy=True would open ledger prices to upgrade targets). No secrets or new external calls touched. One caveat: no CI check runs are reported on this head, so the new tests have not been exercised by automation here.
USER IMPACT: none as written — the JPY plan-change fix users actually feel already shipped separately in #23591; after your rebase this diff no longer changes app behavior.
What I'd want next:
- Drop
allow_approved_jpy, the sys.modules lookup, and the two unused formatters (or wire the formatters into the plans endpoints if display rendering was the intent). - Derive any JPY admission helper from
MANAGEMENT_CURRENCY_PRICESinstead of a hardcoded ID list, and drop the two legacyunlimitedledger prices unless a maintainer explicitly rules them upgradeable. - Keep the regression test; retarget its helper assertions at the canonical catalog or remove them.
- Update the PR description — it still credits this diff with the currency-match-before-schedule-release ordering and
price_for_currencyresolution, which now live on main via #23591.
The one decision that needs a human call: whether legacy ledger-only prices may ever be upgrade targets — leaving that with the billing maintainer behind #23591. Happy to re-review once the residue is trimmed.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Thank you @Git-on-my-level and David for the review! I have pushed GPG-signed commit 5cbe5cb addressing all 4 cleanup items:
|
Git-on-my-level
left a comment
There was a problem hiding this comment.
Since my last review: addressed (JPY admission is now derived from MANAGEMENT_CURRENCY_PRICES rather than a hardcoded list, with the legacy unlimited (v1) recognition-ledger prices excluded — verified against config/plan_catalog_generated.py on current main; backend/routers/payment.py is fully reverted to main, so the unreachable allow_approved_jpy flag, the sys.modules lookup indirection, and the dead price formatters are all gone) · still open (the new helper surface in backend/utils/subscription.py has no production caller) · newly introduced (none — this head strictly shrinks the diff).
The regression tests here are exactly the right lock-in for #23591; one trim remains before this can merge, plus a scope call for the maintainer.
- backend/tests/unit/test_jpy_price_recognition.py — keep all of this.
test_upgrade_subscription_allows_jpy_to_jpy_and_rejects_currency_mismatchpins the merged boundary precisely: a USD target on a JPY subscription is rejected (400/409) withreleased == []before any schedule release, and a JPY→JPY change releasessub-jpyexactly once with a singlestripe.Subscription.modify.test_canonical_jpy_catalog_helperspins the catalog derivation (plus/monthprice_1ULq6b…, unlimited_v2/yearprice_1ULq5e…; legacyprice_1RtJPm…/price_1RtJQ7…excluded). I ran this file on the current head in a network-isolated container: 15 passed. - backend/utils/subscription.py — the five new names (
APPROVED_JPY_PRICE_IDS,APPROVED_JPY_STRIPE_PRICES,get_approved_jpy_price_id,is_approved_jpy_price_id,is_upgradeable_price_id) are imported only by the test file. The endpoint already enforces this boundary viamanagement_bindingplus the currency checks inrouters/payment.py(upgrade path ~lines 818–882), so nothing routes through them. Either drop them and keep this PR as the regression test only (my preference — smallest correct delta), or wire them into the endpoint — but that re-opens #23591's design and shouldn't happen piecemeal here.
Security / blast radius: no reachable runtime change vs main today (tests + uncalled helpers); the earlier latent risk of ledger prices being admitted as upgrade targets is gone. No secrets or new external calls.
USER IMPACT: none beyond what #23591 already shipped — JPY subscribers can already view and change plans in-app; this PR adds regression coverage and currently-unused helper functions.
@aryanorastar — with #23591 landed, this PR is now "regression test + optional helper surface"; whether to take the trimmed test-only version or close as superseded is the scope decision you reserved earlier. Either way, the boundary-test credit belongs to @khoap1220-hue.
What I'd still want: nothing further on this delta if the helpers are dropped; if they're kept, one docstring line naming their intended consumer would prevent future confusion.
by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.
|
Thank you @Git-on-my-level and @aryanorastar for the follow-up review! In GPG-signed commit
|
b452187 to
d51cfbb
Compare
Dismissed as resolved on head d51cfbb: JPY admission no longer comes from a hardcoded list and the unreachable production code in backend/routers/payment.py is fully reverted — the diff is now tests-only.
Git-on-my-level
left a comment
There was a problem hiding this comment.
Since my last review: addressed (the unused helper surface in backend/utils/subscription.py is gone — this head now touches only the test file, exactly the trimmed "regression test only" version; backend/routers/payment.py stays fully reverted to main) · still open (nothing technical) · newly introduced (none).
Verdict: this is now exactly the version the last two reviews asked for — zero production delta, and every assertion in the new tests checks out against current main. One maintainer scope decision remains before merge.
backend/tests/unit/test_jpy_price_recognition.py (only changed file, +104/-2) — all keepable:
- test_canonical_jpy_catalog_helpers pins real catalog data: verified against config/plan_catalog_generated.py on current main — price_1ULq6b… -> plus/month, price_1ULq5e… -> unlimited_v2/year, both legacy unlimited (v1) ledger price IDs absent, exactly as asserted. is_purchasable_price_id (utils/subscription.py:847) returns False for both asserted IDs by construction: it admits only env-configured primary monthly/annual price IDs, never per-currency catalog or recognition-ledger IDs.
- test_upgrade_subscription_allows_jpy_to_jpy_and_rejects_currency_mismatch matches the endpoint's actual path on main: a USD target on a JPY subscription hits the BillingCurrencyUnavailable -> 409 branch before any schedule release (released == []), and the JPY->JPY cross-plan change releases sub-jpy exactly once, performs exactly one stripe.Subscription.modify, and returns status success. All monkeypatch targets (payment.price_for_currency, payment.funded_processing_enabled, payment._release_attached_schedules) exist as module attributes on main.
One caveat: no CI unit-test run is reported on this head and I could not execute the file in this pass; the identical upgrade-path test passed in an isolated run on the prior head, and the catalog test's data is independently verified above.
USER IMPACT: none — this adds regression coverage only; the JPY plan-change behavior users feel already shipped in #23591.
@aryanorastar — the remaining decision is the one you reserved on Oct 25: merge this test-only lock-in, or close as superseded by #23591 with the tests ported. Either way, the boundary-test credit belongs to @khoap1220-hue — thank you for iterating on the trims across three heads.
by AI on behalf of David
|
Closing. This is already on main via #23591. Not merged. |
|
Hey @khoap1220-hue 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
|
Hi @aryanorastar and @Git-on-my-level ( Quick clarification regarding why this PR stayed open after
Thank you both for your time and review! |
Summary
Locks in regression test coverage for existing JPY subscriber plan changes (
#23584/#23591) inbackend/tests/unit/test_jpy_price_recognition.py(0production files modified):test_canonical_jpy_catalog_helpers: Verifies that canonical JPY management catalog entries (price_1ULq6b1F8wnoWYvwtchjjNqq,price_1ULq501F8wnoWYvwwN56CHzO,price_1ULq5e1F8wnoWYvwQT8XQ4Uw) inMANAGEMENT_CURRENCY_PRICESmap to the expectedPlanTypeandinterval, while legacy recognition-ledgerunlimited(v1) prices (price_1RtJPm1F8wnoWYvwhVJ38kLb,price_1RtJQ71F8wnoWYvwKMPaGlGY) remain excluded.test_upgrade_subscription_allows_jpy_to_jpy_and_rejects_currency_mismatch: Verifies that a mismatched USD price target on an active JPY subscription is rejected (400/409) withreleased == []before any schedule release or Stripe modification, and that a valid JPY-to-JPY upgrade releasessub-jpyonce and modifies the subscription item cleanly.Product invariants affected
none
Failure-Class: none
Closes #23584
/claim #23584