fix: jurisdiction fallback prefers default cluster · Entire

fix: jurisdiction fallback prefers default cluster

c8d80aa→main·

evisdren·1w ago·2 files·+25 added/-3 removed

When multiple clusters exist in a jurisdiction, the jurisdiction fallback now picks the one with IsDefault=true, matching the auth layer's resolution. Previously first-seen won, which could resolve a non-default cell API URL.

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

Sessions

01KWZVAENTM99YV06N3REHZGQXView transcript

[?
Fix Code Search across Mirror PlacementsClaude Code·Opus 4.6·1 step](/content/gh/entireio/cli/session/049ddfe6-94db-4012-a48d-d8e512970d53#timeline-01KWZVAENTM99YV06N3REHZGQX/index.html)

Changes

2

140 unmodified lines

141
142
143
144
145
144
145
146
147
148
148
149
150
151
152
153

140 unmodified lines

byJurisdiction := make(map[string]coreapi.Cluster, len(clusters.Clusters))
    for _, cl := range clusters.Clusters {
        bySlug[strings.ToLower(strings.TrimSpace(cl.Slug))] = cl
        // First cluster per jurisdiction wins — used as fallback when a
        // placement-derived group has no cluster slug.
        // Prefer the default cluster per jurisdiction — matches the auth
        // layer's resolution when routing by jurisdiction alone. A non-default
        // cluster is kept only when no default has been seen yet.
        j := strings.ToLower(strings.TrimSpace(cl.Jurisdiction))
        if j != "" {
            if _, exists := byJurisdiction[j]; !exists {
                existing, exists := byJurisdiction[j]
                if !exists || (cl.IsDefault && !existing.IsDefault) {
                    byJurisdiction[j] = cl
                }
            }
        }

Mcmd/entire/cli/cell_fanout.go+5/-3

185 unmodified lines

186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

185 unmodified lines

}

// TestResolveCellBaseURLs_JurisdictionFallbackPrefersDefault verifies that
// when multiple clusters exist in a jurisdiction, the fallback picks the one
// with IsDefault=true — matching the auth layer's resolution.
func TestResolveCellBaseURLs_JurisdictionFallbackPrefersDefault(t *testing.T) {

t.Parallel()
cells := []cellGroup{
    {cell: "aws-eu-central-1", clusterSlug: "", jurisdiction: "eu"},
}
fake := &fakeCellCore{clusters: []coreapi.Cluster{
    // Non-default listed first — must not win.
    {Slug: "eu-staging", Jurisdiction: "eu", ApiUrl: coreapi.NewOptString("https://eu-staging.api.entire.io")},
    // Default cluster — should be preferred.
    {Slug: "eu-prod", Jurisdiction: "eu", IsDefault: true, ApiUrl: coreapi.NewOptString("https://aws-eu-central-1.api.entire.io")},
}}
resolveCellBaseURLs(context.Background(), fake, cells)
if cells[0].baseURL != "https://aws-eu-central-1.api.entire.io" {

t.Fatalf("eu baseURL = %q, want default cluster's URL", cells[0].baseURL)
}
}

func TestResolveCellBaseURLs_CatalogErrorLeavesJurisdictionRouting(t *testing.T) {

t.Parallel()
cells := []cellGroup{{cell: euWestCell, clusterSlug: "eu-prod", jurisdiction: "eu"}}

Mcmd/entire/cli/cell_fanout_test.go+20