Merge pull request #1674 from entireio/investigate-cli-cross-region-code-search-fan-out-i · Entire

Merge pull request #1674 from entireio/investigate-cli-cross-region-code-search-fan-out-i

7e3bba8→main·

Soph·1w ago·4 files·+397 added/-41 removed

fix: fan out code search across mirror placements

Changes

4

import (
    "context"
    "net/url"
    "sort"
    "strings"
    "sync"
)

// includes the jurisdiction so entries whose index row carries no cell don't
// collapse across jurisdictions into one group routed by whichever repo came
// first — they stay per-jurisdiction and route via the jurisdiction fallback.
// ...

func groupReposByCell(repos []coreapi.RepoIndexEntry) []cellGroup {
    byCell := make(map[string]*cellGroup)
    for _, r := range repos {
        id := strings.TrimSpace(r.ID)

addToGroup := func(id, cell, jurisdiction, clusterSlug string) {
            id = strings.TrimSpace(id)
            if id == "" {
                continue
                return
            }
            cell := strings.ToLower(strings.TrimSpace(r.Cell))
            jurisdiction := strings.ToLower(strings.TrimSpace(r.Jurisdiction))
            // ...
        }

for _, r := range repos {
            if len(r.Placements) > 0 {
                // ...
            } else {
                addToGroup(r.ID, r.Cell, r.Jurisdiction, r.ClusterSlug)
            }
        }
    }
    // ...
}

TestGroupReposByCell_Placements

This test verifies the grouping of repos with placements into their own cell group.

func TestGroupReposByCell_Placements(t *testing.T) {
    t.Parallel()
    repos := []coreapi.RepoIndexEntry{
        {
            ID: "01US", Cell: "aws-us-east-2", ClusterSlug: "us-prod", Jurisdiction: "us",
            Placements: []coreapi.RepoPlacement{
                {ID: "01US", Cell: "aws-us-east-2", Jurisdiction: "us"},
                {ID: "01EU", Cell: "aws-eu-central-1", Jurisdiction: "eu", Mirror: true},
            },
        },
        {
            ID: "01LEGACY", Cell: "aws-us-east-2", ClusterSlug: "us-prod", Jurisdiction: "us",
        },
    }
    cells := groupReposByCell(repos)
    if len(cells) != 2 {
        t.Fatalf("groups = %d, want 2 (one per cell): %+v", len(cells), cells)
    }
}

TestResolveCellBaseURLs_RefusesBaseURLWithoutJurisdiction

This test verifies that a concrete baseURL is only usable together with its jurisdiction.

func TestResolveCellBaseURLs_RefusesBaseURLWithoutJurisdiction(t *testing.T) {
    t.Parallel()
    cells := []cellGroup{{cell: "aws-us-east-2", clusterSlug: "us-prod", jurisdiction: "us"}}
    // ...
}