Repository navigation
fix(clusters): explain the two saves a region change takes instead of failing the update #1849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
dawsontoth
wants to merge
2
commits into
claude/1275-region-removal-keeps-siblings
from
claude/1311-guide-region-swap
+202
−1
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/features/clusters/upsert/lib/describeRegionSwap.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import type { SchemaRegion } from '@/integrations/api/api.gen'; | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { describeRegionSwap, regionNamesOfPlans } from './describeRegionSwap'; | ||
|
|
||
| const swap = (currentRegionNames: string[], selectedRegionNames: string[], singleRegionTier = false) => | ||
| describeRegionSwap({ currentRegionNames, selectedRegionNames, singleRegionTier }); | ||
|
|
||
| describe('regionNamesOfPlans', () => { | ||
| const catalog = [ | ||
| { id: 'us-1', region: 'US', latencyDescription: '83ms', instanceCount: 2 }, | ||
| { id: 'eu-1', region: 'Europe', latencyDescription: '58ms', instanceCount: 2 }, | ||
| ] as SchemaRegion[]; | ||
|
|
||
| it('names each plan by its catalog region, falling back to the name the plan carries', () => { | ||
| expect(regionNamesOfPlans([ | ||
| { planId: 'shared', regionId: 'eu-1' }, | ||
| { planId: 'shared', regionId: 'retired-1', region: 'Asia' }, | ||
| ], catalog)).toEqual(['Europe', 'Asia']); | ||
| }); | ||
|
|
||
| it('skips plans with no region, such as self-hosted instances', () => { | ||
| expect(regionNamesOfPlans([{ planId: 'self-hosted-0' }], catalog)).toEqual([]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('describeRegionSwap', () => { | ||
| it('stays quiet for a new cluster, which has no current regions', () => { | ||
| expect(swap([], ['Europe'])).toBeNull(); | ||
| }); | ||
|
|
||
| it('stays quiet while any current region is kept', () => { | ||
| expect(swap(['US'], ['US'])).toBeNull(); | ||
| expect(swap(['US'], ['Europe', 'US'])).toBeNull(); | ||
| expect(swap(['US', 'Asia'], ['Asia', 'Europe'])).toBeNull(); | ||
| }); | ||
|
|
||
| it('stays quiet until a region is actually chosen', () => { | ||
| expect(swap(['US'], [])).toBeNull(); | ||
| expect(swap(['US'], [''])).toBeNull(); | ||
| }); | ||
|
|
||
| it('names the region to keep and the one to add', () => { | ||
| expect(swap(['US'], ['', 'Europe'])).toBe( | ||
| "A cluster can't move out of all its current regions in one update. Keep US, add Europe as an additional region and save, then remove US once that update has finished.", | ||
| ); | ||
| }); | ||
|
|
||
| it('asks to keep at least one of several current regions', () => { | ||
| expect(swap(['US', 'Asia', 'US'], ['Europe', 'Canada'])).toBe( | ||
| "A cluster can't move out of all its current regions in one update. Keep at least one of US and Asia, add Europe as an additional region and save, then remove the old regions that are left once that update has finished.", | ||
| ); | ||
| }); | ||
|
|
||
| it('does not suggest a second region on a tier that allows only one', () => { | ||
| expect(swap(['US'], ['Europe'], true)).toBe( | ||
| "A cluster can't move out of all its current regions in one update, and this tier allows only one region, so it can't move from US to Europe. Create a new cluster in Europe instead.", | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { SchemaRegion, SchemaRegionPlan } from '@/integrations/api/api.gen'; | ||
|
|
||
| const regionList = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' }); | ||
|
|
||
| export function regionNamesOfPlans(plans: readonly SchemaRegionPlan[], catalog: readonly SchemaRegion[]): string[] { | ||
| return plans.flatMap(plan => { | ||
| const name = catalog.find(region => region.id === plan.regionId)?.region ?? plan.region; | ||
| return name ? [name] : []; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Central manager refuses an update that leaves every region a cluster runs in while adding a new one, matching | ||
| * regions by name, so moving a cluster takes two saves. Returns guidance for a selection it would refuse, or null. | ||
| */ | ||
| export function describeRegionSwap({ currentRegionNames, selectedRegionNames, singleRegionTier }: { | ||
| currentRegionNames: readonly string[]; | ||
| selectedRegionNames: readonly string[]; | ||
| singleRegionTier: boolean; | ||
| }): string | null { | ||
| if (!currentRegionNames.length) { | ||
| return null; | ||
| } | ||
| const current = [...new Set(currentRegionNames.filter(Boolean))]; | ||
| const selected = selectedRegionNames.filter(Boolean); | ||
| if (!current.length || !selected.length || selected.some(name => current.includes(name))) { | ||
| return null; | ||
| } | ||
| const from = regionList.format(current); | ||
| const to = selected[0]; | ||
| const rule = "A cluster can't move out of all its current regions in one update"; | ||
| if (singleRegionTier) { | ||
| return `${rule}, and this tier allows only one region, so it can't move from ${from} to ${to}. Create a new cluster in ${to} instead.`; | ||
| } | ||
| return current.length === 1 | ||
| ? `${rule}. Keep ${from}, add ${to} as an additional region and save, then remove ${from} once that update has finished.` | ||
| : `${rule}. Keep at least one of ${from}, add ${to} as an additional region and save, then remove the old regions that are left once that update has finished.`; | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
selectedPlanis undefined (e.g., during initial load or if the selected deployment/performance descriptions are temporarily invalid),!selectedPlan?.priceUsdevaluates totrue. This incorrectly flags the plan as asingleRegionTier, which can display a misleading "single-region tier" error message to the user instead of a generic or no error message.We should explicitly guard this check to ensure
selectedPlanis defined before determining if it is a single-region tier.