You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: keep feature flag overrides when upgrading (#4934)
Currently any plan change results in the override of the plan flags to
the default values of the new plan. Any override that was set is
discarded. (ie: an enabled flag or a manually increased limit will be
lost)
This PR is ensuring flags aren't reset if more generous that the new
plan default when upgrading or migrating. Downgrading always results in
applying default flags for new plan.
<!-- Summary by @propel-code-bot -->
---
**Preserve feature-flag overrides on plan upgrades/migrations**
Adds logic so that when a team upgrades or migrates to a different
billing plan, any flag that was previously overridden to a *more
generous* value is retained. A full reset to new-plan defaults still
happens on downgrades.
Key pieces are the new `mergeFlags` helper in
`packages/shared/lib/services/plans/plans.ts` and the
downgrade-detection utility `isPotentialDowngrade` in
`packages/shared/lib/services/plans/definitions.ts`.
`handlePlanChanged()` now calls `mergeFlags` and applies the merged set
instead of blindly spreading `newPlan.flags`. A comprehensive Vitest
suite validates merge behaviour across upgrade, migration and downgrade
scenarios.
<details>
<summary><strong>Key Changes</strong></summary>
• Introduced `mergeFlags` to combine `currentPlan` and
`newPlanDefinition.flags` while preserving overrides when appropriate
• Injected `mergedFlags` into `updatePlanByTeam()` inside
`handlePlanChanged()` instead of raw `newPlan.flags`
• Added downgrade detection via `isPotentialDowngrade` with an explicit
downgrade matrix
• Exposed helper `getPlanDefinition` for tests and internal lookup
• Added 100+ line unit test `plans.unit.test.ts` covering downgrade,
upgrade and migration paths
• Minor type additions (`PlanDefinition`) and import adjustments
</details>
<details>
<summary><strong>Affected Areas</strong></summary>
• `packages/shared/lib/services/plans/plans.ts` (plan update flow)
• `packages/shared/lib/services/plans/definitions.ts` (plan metadata
helpers)
• `packages/shared/lib/services/plans/plans.unit.test.ts` (new tests)
</details>
---
*This summary was automatically generated by @propel-code-bot*
0 commit comments