region HA P3b T1: retain closed name authority before serving
Resolve ownership before dial eligibility across edge and console readers. Keep closed routes reserved, refuse held exact names, and preserve local catch-all and certificate-only behavior. Add reconcile-to-fold witnesses, a name-class census, and HTTP/owner/asset consequences for Part A.
Co-Authored-By: GPT-6 Astra (codex) <noreply@openai.com>
internal/console/group_names_test.go+28 −0internal/edge/boxroles_test.go+1 −1internal/edge/edge.go+37 −18internal/edge/group_names_test.go+204 −0internal/edge/homemap.go+99 −86internal/edgesfile/fold.go+1 −1internal/edgesfile/homeelect.go+23 −18internal/edgesfile/nameauthority.go+120 −0internal/host/group_names_test.go+301 −0
Intent
<paseo-system version="1" kind="agent-message" source-agent-id="78223e69-0073-4772-bcd6-25641b472a31" message-id="b209e278-aee0-4b58-8e9b-42bf44fe4424" source-agent-title="Region HA P3a dev rollout (executing approved card)"> FYI only, no reply needed unless you plan dev box/infra changes: Region HA P3a dev window OPEN now (2026-11-04 ~07:50Z), executor 78223e6. Sequence: dev-only release v0.34.1 from main 38cda89 (dev boxes, then dev console), then the dev ingress NLB apply (new resources only), then CARLOS_GROUP_ADMISSION opt-in on leo then sophie with attended carlos-edge restarts (about 20-40 s of 503 + Retry-After on non-exempt tenant routes per box; the dev console is exempt but blips 1-2 s), then a short restart drill on each box. DEV CHANNEL FROZEN until I post "P3a window closed" on #421: please do not cut/promote any dev release, roll, restart carlos-edge, or edit host.env on sophie or leo until then. Log: ~/.cache/region-ha-next/p3a-log.md. Reply via paseo send 78223e6 if you have something in flight on dev. No action needed otherwise. </paseo-system>
Attributed to this commit: 6.00 g CO₂e (700,506 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-p3b-build, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/group_names_test.go b/internal/console/group_names_test.go| new file mode 100644 |
| index 000000000..64bf4dbdb |
| --- /dev/null |
| +++ b/internal/console/group_names_test.go |
| @@ -0,0 +1,28 @@ |
| +package console |
| + |
| +import ( |
| + "encoding/json" |
| + "testing" |
| + "time" |
| +) |
| + |
| +func TestGroupNameHomeElection(t *testing.T) { |
| + const host = "shop.example.com" |
| + fx, _ := assetsFixture(t, "group-name-election") |
| + for _, box := range []string{"a-closed", "z-alias"} { |
| + alias := box == "z-alias" |
| + f := map[string]any{"v": 1, "box": box, "eip": "192.0.2.1", "box_role": "serve", "admitted": alias, "drained": false, |
| + "hosts": map[string]any{host: map[string]any{"role": "home", "alias": alias, "account": box, "app": "shop", "assets": statusBlock([]string{"/assets/"}, box, time.Now())}}} |
| + body, err := json.Marshal(f) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err = fx.rel.Put(t.Context(), "control/edges/"+box+".json", body, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + blocks, split, known := fx.srv.homeAssets(t.Context(), "a-closed", "shop") |
| + if !known || len(split) != 0 || blocks[host] != nil { |
| + t.Fatalf("closed route elected foreign alias assets: %v %v %v", blocks, split, known) |
| + } |
| +} |
diff --git a/internal/edge/boxroles_test.go b/internal/edge/boxroles_test.go| index 15881adc5..76cb0a5aa 100644 |
| --- a/internal/edge/boxroles_test.go |
| +++ b/internal/edge/boxroles_test.go |
| @@ -33,7 +33,7 @@ func TestRoleHomeElection(t *testing.T) { |
| closed["box_role"] = role |
| closed["admitted"] = role != "booting" |
| closed["drained"] = false |
| - closed["hosts"] = map[string]any{wakeRoute.Host: map[string]any{"role": "home", "stamp": 99}} |
| + closed["hosts"] = map[string]any{wakeRoute.Host: map[string]any{"role": "home", "stamp": 99, "account": wakeRoute.Account, "app": wakeRoute.App}} |
| peer := wakeFile("z-peer") |
| peer["box_role"], peer["admitted"], peer["drained"] = "serve", true, false |
| bodies := map[string][]byte{edgesfile.Key("g-first"): wakeBody(t, closed), edgesfile.Key("z-peer"): wakeBody(t, peer)} |
diff --git a/internal/edge/edge.go b/internal/edge/edge.go| index 0e863a711..1268e0d72 100644 |
| --- a/internal/edge/edge.go |
| +++ b/internal/edge/edge.go |
| @@ -1994,30 +1994,49 @@ func (e *Edge) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| if e.regionalGate(w, r, host, up, ok, hopped) { |
| return |
| } |
| - // A local match through a one-label "*.<parent>" key (a route |
| - // catch-all) does not beat ANOTHER box's exact host. That is the same |
| - // precedence one box keeps (lookupIn: exact first, then the star), |
| - // extended across the deployment: without it, a parent's route |
| - // catch-all on this box would swallow a name another box serves |
| - // exactly — an instance catch-all's derived name, or any alias homed |
| - // elsewhere — for every request that landed here. An arrived hop and a |
| - // door call keep the local answer: neither may start a backhaul of its |
| - // own here. |
| - // |
| - // The far asset catch (assetcatch.go, design §5.1) runs on this path too, |
| - // just before the dial: the name is homed elsewhere, so its declared asset |
| - // paths are answered from this box's store or filled from that home. |
| - if ok && !hopped && !isDoor && !e.servesExactly(host) { |
| - if eip, box, remote := e.homes.Load().ExactHome(host); remote { |
| - if eip == "" { |
| - AdmissionResponse(w, r) |
| + // Resolve local aliases and catch-alls against peer ownership before |
| + // serving. A held exact name refuses even a signed hop; a hop or door |
| + // request can never start another backhaul here. |
| + if ok && (!e.servesExactly(host) || (up.alias && !up.platformAlias)) { |
| + name := host |
| + if !e.servesExactly(host) { |
| + if i := strings.IndexByte(host, '.'); i > 0 { |
| + name = "*" + host[i:] |
| + } |
| + } |
| + class := edgesfile.NameRoute |
| + if up.alias && !up.platformAlias { |
| + class = edgesfile.NameAlias |
| + } |
| + local := edgesfile.NameClaim{Name: name, Class: class, Account: registry.EffectiveAccount(up.route.Account), App: up.route.App, |
| + Incarnation: up.route.Incarnation, ServingSeq: up.route.ServingSeq, Eligible: true, Local: true} |
| + if class == edgesfile.NameAlias { |
| + local.TargetHost = up.route.Host |
| + } |
| + resolved := e.homes.Load().resolveName(host, []edgesfile.NameClaim{local}, false) |
| + if resolved.State == edgesfile.NameHeld { |
| + AdmissionResponse(w, r) |
| + return |
| + } |
| + if resolved.State == edgesfile.NameDialable && !resolved.Serving.Local { |
| + if hopped { |
| + e.homes.Load().staleHopRefusal(w, host) |
| + return |
| + } |
| + if isDoor { |
| + e.unknownHost(w, r) |
| return |
| } |
| - if e.serveAssetFar(w, r, host) || e.backhaulTo(w, r, host, eip, box) { |
| + if e.serveAssetFar(w, r, host) || e.backhaulTo(w, r, host, resolved.Serving.Dial, resolved.Serving.Box) { |
| return |
| } |
| + // A known remote owner must not fall through to another local app |
| + // when its mesh key or transport is unavailable. |
| + AdmissionResponse(w, r) |
| + return |
| } |
| } |
| + |
| // A regional deny entry the gate let through to the exact-home arm above |
| // (a star match whose exact name another box served) that the arm did |
| // not answer: no mesh key, or the map moved between the two reads. The |
diff --git a/internal/edge/group_names_test.go b/internal/edge/group_names_test.go| new file mode 100644 |
| index 000000000..e1ee44b2f |
| --- /dev/null |
| +++ b/internal/edge/group_names_test.go |
| @@ -0,0 +1,204 @@ |
| +package edge |
| + |
| +import ( |
| + "encoding/json" |
| + "net/http" |
| + "net/http/httptest" |
| + "slices" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/edgesfile" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +func TestGroupNamesBeforeAdmission(t *testing.T) { |
| + for _, tc := range []struct { |
| + name, key, role string |
| + alias, wildcard, localAlias bool |
| + want int |
| + }{ |
| + {name: "closed route beats peer alias", key: "a.example.com", role: "home", want: 503}, |
| + {name: "closed route beats local alias", key: "a.example.com", role: "home", localAlias: true, want: 503}, |
| + {name: "held exact beats local catchall", key: "a.example.com", role: "home", alias: true, want: 503}, |
| + {name: "cert only permits local catchall", key: "*.example.com", role: "wildcard", wildcard: true, want: 200}, |
| + {name: "closed wildcard permits local catchall", key: "*.example.com", role: "home", wildcard: true, want: 200}, |
| + } { |
| + for _, state := range []string{"booting", "drain", "platform", "unadmitted", "drained", "unknown", "malformed", "no-address", "partial-no-address", "stale"} { |
| + t.Run(tc.name+"/"+state, func(t *testing.T) { |
| + reg := openReg(t) |
| + app := e2eApp(t, "local-b") |
| + primary := "*.example.com" |
| + if tc.localAlias { |
| + primary = "local.other.net" |
| + } |
| + if err := reg.Upsert(registry.Route{Host: primary, Account: "b", App: "shop", Kind: "service", Status: "ready", Addr: app.Listener.Addr().String()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if tc.localAlias { |
| + if err := reg.UpsertAlias(registry.RouteAlias{Alias: "a.example.com", Host: primary, Account: "b", App: "shop", DNSStatus: "pointing"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + e, err := New(reg, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(e.probers.Stop) |
| + s := release.NewDirStore(t.TempDir()) |
| + f := map[string]any{"v": 1, "box": "a-closed", "eip": "192.0.2.1", "box_role": state, "admitted": false, "drained": false, "hosts": map[string]any{tc.key: map[string]any{"role": tc.role, "alias": tc.alias, "wildcard": tc.wildcard, "account": "a", "app": "shop", "target_host": "primary.a.net", "stamp": 99}}} |
| + switch state { |
| + case "unadmitted": |
| + f["box_role"] = "serve" |
| + case "malformed": |
| + f["admitted"] = "true" |
| + case "no-address": |
| + f["box_role"], f["admitted"], f["eip"] = "serve", true, "" |
| + case "partial-no-address": |
| + delete(f, "box_role") |
| + delete(f, "admitted") |
| + f["drained"], f["eip"] = true, "" |
| + case "drained": |
| + f["box_role"], f["admitted"], f["drained"] = "serve", true, true |
| + case "stale": |
| + f["box_role"] = "booting" |
| + f["generation"] = time.Now().Add(-time.Hour).UTC().Format(time.RFC3339) |
| + } |
| + b, _ := json.Marshal(f) |
| + putJSON(t, s, edgesfile.Key("a-closed"), string(b)) |
| + if tc.name == "closed route beats peer alias" { |
| + putJSON(t, s, edgesfile.Key("z-alias"), `{"v":1,"box":"z-alias","eip":"192.0.2.2","hosts":{"a.example.com":{"role":"home","alias":true,"account":"b","app":"shop","target_host":"b.other.net"}}}`) |
| + } |
| + m := newHomeMap(s, "local") |
| + refreshHomeMap(t, m) |
| + e.homes.Store(m) |
| + if tc.wildcard && !slices.Contains(m.WildcardParents(), "example.com") { |
| + t.Error("closed certificate parent lost") |
| + } |
| + if tc.key == "a.example.com" { |
| + ip, box, ok := m.ExactHome(tc.key) |
| + if !ok || ip != "" || box != "" { |
| + t.Errorf("ExactHome = %q %q %v; want held", ip, box, ok) |
| + } |
| + if _, _, _, _, ok := m.Owner(tc.key); ok { |
| + t.Error("closed owner authorized a dial") |
| + } |
| + if _, ok := m.AssetsFor(tc.key, time.Now()); ok { |
| + t.Error("closed assets authorized") |
| + } |
| + } |
| + w := httptest.NewRecorder() |
| + w.Header().Set(holderHeader, "old") |
| + e.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "https://a.example.com/", nil)) |
| + if w.Code != tc.want { |
| + t.Errorf("ServeHTTP = %d %q; want %d", w.Code, w.Body.String(), tc.want) |
| + } |
| + if tc.want == 503 && (w.Header().Get("Retry-After") != "10" || w.Header().Get(holderHeader) != "") { |
| + t.Errorf("refusal headers %v", w.Header()) |
| + } |
| + if tc.want == 200 && !strings.HasPrefix(w.Body.String(), "local-b|") { |
| + t.Errorf("wrong owner: %s", w.Body.String()) |
| + } |
| + if tc.want == 503 { |
| + key := []byte("group-name-test-key-32-bytes-long!") |
| + m.keyCurrent = key |
| + req := httptest.NewRequest(http.MethodGet, "https://a.example.com/", nil) |
| + req.Header.Set(hopHeader, "1") |
| + req.Header.Set(hopAuthHeader, signHop(key, "a.example.com", time.Now())) |
| + hopped := httptest.NewRecorder() |
| + e.ServeHTTP(hopped, req) |
| + if hopped.Code != 503 || hopped.Header().Get(holderHeader) != "" || hopped.Header().Get("Retry-After") != "10" { |
| + t.Errorf("signed hop bypassed held ownership: %d %v", hopped.Code, hopped.Header()) |
| + } |
| + } |
| + |
| + }) |
| + } |
| + } |
| + for _, tc := range []struct { |
| + name, owner, target string |
| + alias bool |
| + want bool |
| + }{ |
| + {name: "same owner supplies dial", owner: "a", want: true}, |
| + {name: "unknown path owner cannot borrow dial", want: false}, |
| + {name: "foreign owner cannot borrow dial", owner: "foreign", want: false}, |
| + {name: "same alias target supplies dial", owner: "a", target: "primary.a.net", alias: true, want: true}, |
| + {name: "different alias target cannot borrow dial", owner: "a", target: "other.a.net", alias: true, want: false}, |
| + } { |
| + t.Run(tc.name, func(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + for _, box := range []string{"a-closed", "z-open"} { |
| + closed := box == "a-closed" |
| + account, target, stamp := "a", "primary.a.net", int64(1) |
| + if closed { |
| + account, target, stamp = tc.owner, tc.target, 99 |
| + if !tc.alias { |
| + target = "" |
| + } |
| + } else if !tc.alias { |
| + target = "" |
| + } |
| + f := map[string]any{"v": 1, "box": box, "eip": "192.0.2.3", "box_role": "serve", "admitted": !closed, "drained": false, |
| + "hosts": map[string]any{"a.example.com": map[string]any{"role": "home", "account": account, "app": "shop", "alias": tc.alias, "target_host": target, "stamp": stamp}}} |
| + body, _ := json.Marshal(f) |
| + putJSON(t, s, edgesfile.Key(box), string(body)) |
| + } |
| + m := newHomeMap(s, "observer") |
| + refreshHomeMap(t, m) |
| + ip, box, exact := m.ExactHome("a.example.com") |
| + if !exact || (ip != "") != tc.want || (tc.want && box != "z-open") { |
| + t.Fatalf("ExactHome %q %q %v", ip, box, exact) |
| + } |
| + _, _, _, _, owned := m.Owner("a.example.com") |
| + if owned != tc.want { |
| + t.Fatalf("Owner eligible=%v", owned) |
| + } |
| + snap, err := edgesfile.ReadSnapshot(t.Context(), s) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + won, _, err := edgesfile.ElectHomesForEveryReader(snap.Files) |
| + if err != nil || (won["a.example.com"].Box != "") != tc.want { |
| + t.Fatalf("console election %v %v", won, err) |
| + } |
| + }) |
| + } |
| + t.Run("closed wildcard cannot mask a peer catchall", func(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + putJSON(t, s, edgesfile.Key("a-closed"), `{"v":1,"box":"a-closed","eip":"192.0.2.1","box_role":"booting","admitted":false,"drained":false,"hosts":{"*.example.com":{"role":"home","account":"a","app":"shop","stamp":99}}}`) |
| + putJSON(t, s, edgesfile.Key("z-open"), `{"v":1,"box":"z-open","eip":"192.0.2.2","hosts":{"*.example.com":{"role":"home","alias":true,"account":"b","app":"shop","target_host":"b.other.net"}}}`) |
| + m := newHomeMap(s, "observer") |
| + refreshHomeMap(t, m) |
| + acct, _, ip, box, ok := m.Owner("new.example.com") |
| + if !ok || acct != "b" || ip != "192.0.2.2" || box != "z-open" { |
| + t.Fatalf("peer catchall %s %s %s %v", acct, ip, box, ok) |
| + } |
| + }) |
| + |
| + t.Run("legacy local catchall keeps its answer", func(t *testing.T) { |
| + reg := openReg(t) |
| + app := e2eApp(t, "local-b") |
| + if err := reg.Upsert(registry.Route{Host: "*.example.com", Account: "b", App: "shop", Kind: "service", Status: "ready", Addr: app.Listener.Addr().String()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + e, err := New(reg, nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(e.probers.Stop) |
| + s := release.NewDirStore(t.TempDir()) |
| + putJSON(t, s, edgesfile.Key("peer"), `{"v":1,"box":"peer","eip":"192.0.2.2","hosts":{"*.example.com":{"role":"home","account":"a","app":"shop","stamp":99}}}`) |
| + m := newHomeMap(s, "local") |
| + refreshHomeMap(t, m) |
| + e.homes.Store(m) |
| + w := httptest.NewRecorder() |
| + e.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "https://a.example.com/", nil)) |
| + if w.Code != 200 || !strings.HasPrefix(w.Body.String(), "local-b|") { |
| + t.Fatalf("legacy catchall: %d %s", w.Code, w.Body.String()) |
| + } |
| + }) |
| + |
| +} |
diff --git a/internal/edge/homemap.go b/internal/edge/homemap.go| index 870eb8150..df7354823 100644 |
| --- a/internal/edge/homemap.go |
| +++ b/internal/edge/homemap.go |
| @@ -237,6 +237,8 @@ type edgesAssetsView struct { |
| // homeEntry is one folded answer: where to dial, and which box that is. |
| type homeEntry struct { |
| + claims []edgesfile.NameClaim |
| + routeExists bool |
| // eip is the address to dial: edgesfile.Reader.Dial's answer, the home box's |
| // private address within its region and its EIP from anywhere else. |
| eip string |
| @@ -817,37 +819,10 @@ func (m *homeMap) logPartialPoll(failed, tried int, err error) { |
| } |
| } |
| -// foldHomes turns the per-box files into one host→home map. |
| -// |
| -// Three exclusions, each of which is a request this box must never make: |
| -// |
| -// - OWN BOX. A host homed here is SERVED here; offering it as a backhaul |
| -// target would have the edge dial itself. Excluded by the file's own box |
| -// field rather than by its object name, because the field is what the |
| -// publisher stamps and what self is derived to match. |
| -// - NO DIAL ADDRESS. Task 1 publishes a box with no discoverable public IP |
| -// as eip:"" so the DR runbook still gets its hosts list. There is |
| -// nothing to dial, so it is not a target. The address is edgesfile.Reader.Dial's: |
| -// a box in this box's own region is dialled at its private address when |
| -// it publishes one (region HA spec 2 §6), every other at its EIP. |
| -// - A ROLE THIS BUILD DOES NOT KNOW. Only "home" routes. The role field |
| -// exists so read-local roles can be added later; a reader that treated |
| -// every role as a home would send traffic to a box that had declared it |
| -// serves only reads. |
| -// |
| -// Iteration is over SORTED file keys so a duplicate claim — two boxes both |
| -// saying they home one host, which is a placement bug mid-move — resolves the |
| -// same way on every edge in the deployment. Convergent-but-wrong beats |
| -// split-and-wrong: the whole fleet aiming at one box is a condition that heals |
| -// on the next publish, where half the fleet aiming at each is a condition that |
| -// looks fine from any single box. |
| -// |
| -// The dial rule and the order are shared with the console's status door |
| -// (#396): this fold dials through edgesfile.Reader.Dial with this edge's |
| -// own reader context (its box, its own file's network, its region HA |
| -// switch) and orders claims by edgesfile.HomeBeats; the door elects |
| -// through edgesfile.ElectHomesForEveryReader, the same election for every |
| -// kind of reader. |
| +// foldHomes retains every admission-aware namespace claim, including closed |
| +// and address-less entries. ResolveNameAuthority chooses ownership before |
| +// service. Certificate classes are unioned independently of that choice. |
| +// Sorted file keys preserve the existing stamp and lifetime tie order. |
| func foldHomes(files map[string]edgesFileView, self string, privateDial bool) (map[string]homeEntry, []string) { |
| keys := make([]string, 0, len(files)) |
| for k := range files { |
| @@ -863,6 +838,8 @@ func foldHomes(files map[string]edgesFileView, self string, privateDial bool) (m |
| } |
| reader := edgesfile.Reader{Box: self, Self: own.dialPoint(), SelfKnown: ownKnown, PrivateDial: privateDial} |
| hosts := make(map[string]homeEntry) |
| + claims := make(map[string][]edgesfile.NameClaim) |
| + entries := make(map[string]map[string]homeEntry) |
| for _, k := range keys { |
| f := files[k] |
| if f.Box == "" || f.Box == self { |
| @@ -873,57 +850,50 @@ func foldHomes(files map[string]edgesFileView, self string, privateDial bool) (m |
| if host == "" { |
| continue |
| } |
| - switch h.Role { |
| - case edgeRoleHome: |
| - // A dial target needs an address. A file with none (a box |
| - // with no discoverable public IP) still carries its cert |
| - // halves below; its dial halves are simply not dialable. |
| - if addr == "" { |
| - if !h.Wildcard || !strings.HasPrefix(host, "*.") { |
| - continue |
| - } |
| - h.Role = edgeRoleWildcard |
| - } |
| - case edgeRoleWildcard: |
| - // The cert-only role is defined for marked catch-all keys |
| - // alone; on an exact key it would be a KnownHost admission |
| - // with no dial behind it — refused. |
| - if !h.Wildcard || !strings.HasPrefix(host, "*.") { |
| - continue |
| - } |
| - default: |
| + if h.Role != edgeRoleHome && (h.Role != edgeRoleWildcard || !h.Wildcard || !strings.HasPrefix(host, "*.")) { |
| continue |
| } |
| - in := homeEntry{eip: addr, box: f.Box, platform: h.Platform && !h.Alias && !h.Wildcard, alias: h.Alias, wildcard: h.Wildcard, dial: h.Role == edgeRoleHome && f.HomeEligible(), |
| - account: h.Account, app: h.App, stamp: h.Stamp, incarnation: h.Incarnation, servingSeq: h.ServingSeq, targetHost: h.TargetHost, assets: h.Assets} |
| - prev, dup := hosts[host] |
| - if !dup { |
| - hosts[host] = in |
| + // Preserve address-less legacy publication behavior. Admission-aware |
| + // files retain namespace even before the first address is available. |
| + if addr == "" && len(f.BoxRole) == 0 && len(f.Admitted) == 0 && len(f.Drained) == 0 && (!h.Wildcard || !strings.HasPrefix(host, "*.")) { |
| continue |
| } |
| - // A collision merges CLASSES and picks ONE dial target: the |
| - // classes are facts about the name (a delegated parent's PEM |
| - // must load everywhere even if some other box also routes the |
| - // key), the dial target is a choice. First box in sorted order |
| - // wins the dial — except that a ROUTE beats an ALIAS whatever |
| - // the order (#287), any dial target beats none, and stamps and |
| - // then lifetime pairs order the rest (dialBeats). The owner, the |
| - // stamp, the pair and the target are part of the dial choice, |
| - // not classes: they come whole from the winner, so a route that |
| - // replaces an alias never inherits the alias's owner or pair, |
| - // even when it publishes none of its own. |
| - merged := prev |
| - merged.platform = prev.platform || in.platform |
| - merged.wildcard = prev.wildcard || in.wildcard |
| - if dialBeats(in, prev) { |
| - merged.eip, merged.box, merged.alias, merged.dial = in.eip, in.box, in.alias, true |
| - merged.account, merged.app, merged.stamp = in.account, in.app, in.stamp |
| - merged.incarnation, merged.servingSeq, merged.targetHost = in.incarnation, in.servingSeq, in.targetHost |
| - merged.assets = in.assets |
| + role := h.Role |
| + if addr == "" && len(f.BoxRole) == 0 && len(f.Admitted) == 0 && len(f.Drained) == 0 { |
| + role = edgeRoleWildcard |
| + } |
| + c := edgesfile.NameClaim{Source: k, Name: host, Class: edgesfile.NameClassOf(role, h.Alias), Account: h.Account, App: h.App, |
| + TargetHost: h.TargetHost, Stamp: h.Stamp, Incarnation: h.Incarnation, ServingSeq: h.ServingSeq, |
| + Eligible: h.Role == edgeRoleHome && f.HomeEligible() && addr != "", Dial: addr, Box: f.Box} |
| + claims[host] = append(claims[host], c) |
| + if entries[host] == nil { |
| + entries[host] = map[string]homeEntry{} |
| } |
| + entries[host][k] = homeEntry{eip: addr, box: f.Box, alias: h.Alias, account: h.Account, app: h.App, stamp: h.Stamp, |
| + incarnation: h.Incarnation, servingSeq: h.ServingSeq, targetHost: h.TargetHost, assets: h.Assets} |
| + merged := hosts[host] |
| + merged.platform = merged.platform || (h.Platform && !h.Alias && !h.Wildcard) |
| + merged.wildcard = merged.wildcard || h.Wildcard |
| hosts[host] = merged |
| } |
| } |
| + for name, cs := range claims { |
| + r := edgesfile.ResolveNameAuthority(name, nil, cs) |
| + classes := hosts[name] |
| + h := entries[name][cs[0].Source] |
| + if r.State != edgesfile.NameAbsent { |
| + h = entries[name][r.Authority.Source] |
| + } |
| + if r.State == edgesfile.NameDialable { |
| + h = entries[name][r.Serving.Source] |
| + h.dial = true |
| + } |
| + h.claims = cs |
| + h.routeExists = r.RouteExists |
| + h.platform, h.wildcard = classes.platform, classes.wildcard |
| + hosts[name] = h |
| + } |
| + |
| return hosts, tiedStamps(files) |
| } |
| @@ -1066,12 +1036,13 @@ func (m *homeMap) ExactHome(host string) (eip, box string, ok bool) { |
| if m == nil || m.self == "" { |
| return "", "", false |
| } |
| - if h, found := m.snapshot().hosts[host]; found { |
| - if !h.dial { |
| - return "", "", true |
| - } |
| + r := m.resolveName(host, nil, true) |
| + if r.State == edgesfile.NameHeld { |
| + return "", "", true |
| + } |
| + if r.State == edgesfile.NameDialable { |
| observeRegional("exact-home", host) |
| - return h.eip, h.box, true |
| + return r.Serving.Dial, r.Serving.Box, true |
| } |
| return "", "", false |
| } |
| @@ -1084,18 +1055,60 @@ func (m *homeMap) lookupHome(host string) (homeEntry, bool) { |
| return homeEntry{}, false |
| } |
| hosts := m.snapshot().hosts |
| - if h, ok := hosts[host]; ok { |
| - if !h.dial { |
| - return homeEntry{}, true |
| + r := resolveHomeName(host, nil, false, hosts) |
| + if r.State == edgesfile.NameHeld { |
| + return homeEntry{}, true |
| + } |
| + if r.State == edgesfile.NameDialable { |
| + h := hosts[r.Serving.Name] |
| + c := r.Serving |
| + if h.box != c.Box { |
| + h.assets = nil |
| } |
| + h.eip, h.box, h.dial = c.Dial, c.Box, true |
| + h.account, h.app = c.Account, c.App |
| + h.alias, h.stamp = c.Class == edgesfile.NameAlias, c.Stamp |
| + h.incarnation, h.servingSeq, h.targetHost = c.Incarnation, c.ServingSeq, c.TargetHost |
| return h, true |
| } |
| - if i := strings.IndexByte(host, '.'); i > 0 { |
| - if h, ok := hosts["*"+host[i:]]; ok && h.dial { |
| - return h, true |
| + return homeEntry{}, false |
| +} |
| + |
| +func (m *homeMap) resolveName(host string, local []edgesfile.NameClaim, exact bool) edgesfile.NameResolution { |
| + var hosts map[string]homeEntry |
| + if m != nil && m.self != "" { |
| + hosts = m.snapshot().hosts |
| + } |
| + return resolveHomeName(host, local, exact, hosts) |
| +} |
| + |
| +func resolveHomeName(host string, local []edgesfile.NameClaim, exact bool, hosts map[string]homeEntry) edgesfile.NameResolution { |
| + var peers []edgesfile.NameClaim |
| + if hosts != nil { |
| + add := func(name string) { |
| + if h, ok := hosts[name]; ok { |
| + if len(h.claims) > 0 { |
| + peers = append(peers, h.claims...) |
| + return |
| + } |
| + // Some callers assemble an immutable snapshot directly. |
| + class := edgesfile.NameCertificate |
| + if h.dial { |
| + class = edgesfile.NameClassOf(edgeRoleHome, h.alias) |
| + } |
| + peers = append(peers, edgesfile.NameClaim{Name: name, Class: class, Account: h.account, App: h.app, |
| + TargetHost: h.targetHost, Stamp: h.stamp, Incarnation: h.incarnation, ServingSeq: h.servingSeq, |
| + Eligible: h.dial, Dial: h.eip, Box: h.box}) |
| + } |
| + } |
| + add(host) |
| + if !exact { |
| + if i := strings.IndexByte(host, '.'); i > 0 { |
| + add("*" + host[i:]) |
| + } |
| } |
| } |
| - return homeEntry{}, false |
| + return edgesfile.ResolveNameAuthority(host, local, peers) |
| } |
| // Owner answers, from one read of one snapshot, both whom the edge-local |
diff --git a/internal/edgesfile/fold.go b/internal/edgesfile/fold.go| index aea71c76d..786944602 100644 |
| --- a/internal/edgesfile/fold.go |
| +++ b/internal/edgesfile/fold.go |
| @@ -191,7 +191,7 @@ func DeploymentRoutesComplete(ctx context.Context, s release.Store, now time.Tim |
| } |
| joined++ |
| for host, h := range f.Hosts { |
| - if h.Role == RoleHome && !h.Alias { |
| + if ResolveNameAuthority(host, nil, []NameClaim{{Name: host, Class: NameClassOf(h.Role, h.Alias)}}).RouteExists { |
| out[host] = true |
| } |
| } |
diff --git a/internal/edgesfile/homeelect.go b/internal/edgesfile/homeelect.go| index bfb99c58b..bf7ea6194 100644 |
| --- a/internal/edgesfile/homeelect.go |
| +++ b/internal/edgesfile/homeelect.go |
| @@ -12,7 +12,7 @@ import ( |
| // foldHomes) and the console's `carlos assets status` door both decide it |
| // here, so the status door names the box an edge dials (#396). The edge |
| // keeps its own decoder and its own fold, because the fold also merges |
| -// classes; what it shares is the rule (HomeBeats) and who may take part |
| +// classes; what it shares is name authority (ResolveNameAuthority) and who may take part |
| // for a given reader (Reader.Dial). |
| // |
| // The answer depends on the reader. An edge with region HA on, in a box's |
| @@ -174,34 +174,39 @@ func decodeForElection(files []PlacementView) ([]electFile, error) { |
| return out, nil |
| } |
| -// elect is the election for r over decoded files: only a home-role entry |
| -// of a box r can dial, other than r's own, is a claim, and claims are |
| -// ordered by HomeBeats. |
| +// elect retains closed ownership while choosing each reader's dial target. |
| +// A closed route can block a foreign alias without becoming a serving home. |
| func elect(files []electFile, r Reader) map[string]Elected { |
| - type held struct { |
| - claim HomeClaim |
| - e Elected |
| - } |
| - won := map[string]held{} |
| + claims := map[string][]NameClaim{} |
| + entries := map[string]map[string]Elected{} |
| for _, f := range files { |
| - if !f.HomeEligible() || f.box == "" || f.box == r.Box || r.Dial(f.dial) == "" { |
| + if f.box == "" || f.box == r.Box { |
| + continue |
| + } |
| + addr := r.Dial(f.dial) |
| + if addr == "" && len(f.BoxRole) == 0 && len(f.Admitted) == 0 && len(f.Drained) == 0 { |
| continue |
| } |
| for host, in := range f.hosts { |
| if host == "" || in.Role != RoleHome { |
| continue |
| } |
| - c := HomeClaim{Dial: true, Alias: in.Alias, Stamp: in.Stamp, |
| - Incarnation: in.Incarnation, ServingSeq: in.ServingSeq, TargetHost: in.TargetHost} |
| - if prev, ok := won[host]; ok && !HomeBeats(c, prev.claim) { |
| - continue |
| + c := NameClaim{Source: f.key, Name: host, Class: NameClassOf(in.Role, in.Alias), Account: in.Account, App: in.App, |
| + TargetHost: in.TargetHost, Stamp: in.Stamp, Incarnation: in.Incarnation, ServingSeq: in.ServingSeq, |
| + Eligible: f.HomeEligible() && addr != "", Dial: addr, Box: f.box} |
| + claims[host] = append(claims[host], c) |
| + if entries[host] == nil { |
| + entries[host] = map[string]Elected{} |
| } |
| - won[host] = held{claim: c, e: Elected{Box: f.box, Assets: in.Assets}} |
| + entries[host][f.key] = Elected{Box: f.box, Assets: in.Assets} |
| } |
| } |
| - out := make(map[string]Elected, len(won)) |
| - for host, h := range won { |
| - out[host] = h.e |
| + out := map[string]Elected{} |
| + for host, cs := range claims { |
| + resolved := ResolveNameAuthority(host, nil, cs) |
| + if resolved.State == NameDialable { |
| + out[host] = entries[host][resolved.Serving.Source] |
| + } |
| } |
| return out |
| } |
diff --git a/internal/edgesfile/nameauthority.go b/internal/edgesfile/nameauthority.go| new file mode 100644 |
| index 000000000..17073c1f0 |
| --- /dev/null |
| +++ b/internal/edgesfile/nameauthority.go |
| @@ -0,0 +1,120 @@ |
| +package edgesfile |
| + |
| +import "strings" |
| + |
| +type NameClass uint8 |
| + |
| +const ( |
| + NameRoute NameClass = iota |
| + NameAlias |
| + NameCertificate |
| +) |
| + |
| +type NameState uint8 |
| + |
| +const ( |
| + NameAbsent NameState = iota |
| + NameHeld |
| + NameDialable |
| +) |
| + |
| +// NameClaim keeps namespace authority separate from service eligibility. |
| +// Callers supply claims in stable file order, with local claims first. |
| +type NameClaim struct { |
| + Source string |
| + Name string |
| + Class NameClass |
| + Account, App, TargetHost string |
| + Stamp int64 |
| + Incarnation, ServingSeq uint64 |
| + Eligible bool |
| + Local bool |
| + Dial, Box string |
| +} |
| + |
| +type NameResolution struct { |
| + State NameState |
| + RouteExists bool |
| + Authority NameClaim |
| + Serving NameClaim |
| +} |
| + |
| +func (c NameClaim) order() DialOrder { |
| + return DialOrder{Alias: c.Class == NameAlias, Stamp: c.Stamp, Incarnation: c.Incarnation, ServingSeq: c.ServingSeq, TargetHost: c.TargetHost} |
| +} |
| + |
| +// NameClassOf interprets the existing wire row without changing its shape. |
| +func NameClassOf(role string, alias bool) NameClass { |
| + if role != RoleHome { |
| + return NameCertificate |
| + } |
| + if alias { |
| + return NameAlias |
| + } |
| + return NameRoute |
| +} |
| + |
| +// ResolveNameAuthority first chooses ownership, then a serving claim of that |
| +// owner and target. A closed wildcard cannot reserve a new concrete name. |
| +func ResolveNameAuthority(name string, local []NameClaim, peers []NameClaim) NameResolution { |
| + var exact, fallback []NameClaim |
| + wildcard := "" |
| + if i := strings.IndexByte(name, '.'); i > 0 { |
| + wildcard = "*" + name[i:] |
| + } |
| + for _, claims := range [][]NameClaim{local, peers} { |
| + for _, c := range claims { |
| + if c.Class == NameCertificate { |
| + continue |
| + } |
| + if c.Name == name { |
| + exact = append(exact, c) |
| + } else if c.Name == wildcard && c.Eligible { |
| + fallback = append(fallback, c) |
| + } |
| + } |
| + } |
| + claims := exact |
| + if len(claims) == 0 { |
| + claims = fallback |
| + // A concrete name already served by a local catch-all keeps that |
| + // answer. Peer wildcards only supply a fallback when local has none. |
| + for _, c := range fallback { |
| + if c.Local && c.Eligible { |
| + claims = []NameClaim{c} |
| + break |
| + } |
| + } |
| + } |
| + if len(claims) == 0 { |
| + return NameResolution{} |
| + } |
| + owner := claims[0] |
| + for _, c := range claims[1:] { |
| + if DialBeats(c.order(), owner.order()) { |
| + owner = c |
| + } |
| + } |
| + out := NameResolution{State: NameHeld, Authority: owner} |
| + for _, c := range claims { |
| + if c.Class == NameRoute { |
| + out.RouteExists = true |
| + } |
| + } |
| + same := func(c NameClaim) bool { |
| + return c.Name == owner.Name && c.Class == owner.Class && c.Account != "" && c.App != "" && |
| + c.Account == owner.Account && c.App == owner.App && c.TargetHost == owner.TargetHost |
| + } |
| + // The winning claim itself may serve without owner metadata (legacy |
| + // routes and mixed path owners). Metadata cannot authorize a substitute. |
| + for _, c := range claims { |
| + if !c.Eligible || (!c.Local && c.Dial == "") || (c != owner && !same(c)) { |
| + continue |
| + } |
| + if out.State != NameDialable || DialBeats(c.order(), out.Serving.order()) { |
| + out.State = NameDialable |
| + out.Serving = c |
| + } |
| + } |
| + return out |
| +} |
diff --git a/internal/host/group_names_test.go b/internal/host/group_names_test.go| new file mode 100644 |
| index 000000000..9d12fafc0 |
| --- /dev/null |
| +++ b/internal/host/group_names_test.go |
| @@ -0,0 +1,301 @@ |
| +package host |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/json" |
| + "fmt" |
| + "go/ast" |
| + "go/parser" |
| + "go/token" |
| + "os" |
| + "path/filepath" |
| + "reflect" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| + "github.com/carlosframework/platform/internal/edge" |
| + "github.com/carlosframework/platform/internal/edgesfile" |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/status" |
| +) |
| + |
| +type groupNameCase struct { |
| + class, name string |
| + route, alias, wildcard, replica, ambiguous bool |
| +} |
| + |
| +func groupNameCases(acct string) []groupNameCase { |
| + return []groupNameCase{ |
| + {class: "exact route", name: "shop.example.com", route: true}, |
| + {class: "platform alias", name: "shop." + acct + ".apps.test", route: true}, |
| + {class: "plain alias", name: "alias.customer.test", alias: true}, |
| + {class: "instance catchall", name: "shop.instances.test", alias: true}, |
| + {class: "delegated catchall", name: "*.customer.test", alias: true, wildcard: true}, |
| + {class: "certificate parent", name: "*.cert.test", wildcard: true}, |
| + {class: "replica", name: "replica.example.com", route: true, replica: true}, |
| + {class: "path ambiguity", name: "mixed.example.com", route: true, ambiguous: true}, |
| + {class: "sidecar", name: provision.SidecarHost("bot", "shop", acct)}, |
| + } |
| +} |
| + |
| +func TestGroupNamesBeforeAdmission(t *testing.T) { |
| + ctx := t.Context() |
| + s := release.NewDirStore(t.TempDir()) |
| + reg := edgesTestRegistry(t) |
| + now := time.Now() |
| + acct := domains.Sqid(2) |
| + put := func(key string, v any) { |
| + t.Helper() |
| + b, err := json.Marshal(v) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err = s.Put(ctx, key, b, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + put(domains.AccountManifestKey(acct), map[string]any{"id": 2, "sqid": acct, "name": "shop", "created_at": now}) |
| + if err := provision.PutManifest(ctx, s, acct, "shop", provision.Manifest{Schema: 1, App: "shop", Domain: "apps.test"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, host := range []string{"shop.example.com", "replica.example.com", "mixed.example.com"} { |
| + rec := provision.Record{Schema: 1, Host: host, Slug: "shop", App: "shop", Account: acct, Channel: "stable", CreatedAt: now} |
| + if host == "replica.example.com" { |
| + rec.Role = "replica" |
| + rec.Slug = "replica" |
| + } |
| + if host == "mixed.example.com" { |
| + rec.Slug = "mixed" |
| + } |
| + if err := provision.CreateRecord(ctx, s, rec); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if err := provision.PutSidecarManifest(ctx, s, acct, "shop", provision.SidecarManifest{Schema: 1, App: "shop", Args: []string{"run"}, Channel: "stable"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := provision.CreateSidecarRecord(ctx, s, provision.SidecarRecord{Schema: 1, Name: "bot", Host: provision.SidecarHost("bot", "shop", acct), App: "shop", Account: acct, Channel: "stable"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + admission := newFixedAdmission(func(k string) string { |
| + switch k { |
| + case "CARLOS_GROUP_ADMISSION", "CARLOS_REGION_HA": |
| + return "1" |
| + case "CARLOS_BOX_REFERENCE": |
| + return "group" |
| + } |
| + return "" |
| + }, admissionHealth()) |
| + if err := reconcileSerialized(ctx, s, reg, provision.ReconcileConfig{DataDir: t.TempDir()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if rt, err := reg.Get("shop.example.com"); err != nil || rt == nil || rt.Status != "ready" || admission.TenantAdmitted() { |
| + t.Fatalf("reconcile before hook: %+v %v", rt, err) |
| + } |
| + // The platform pass derives an alias from the reconciled instance socket. |
| + cfg := domains.Config{AppsDomain: "apps.test", Now: func() time.Time { return now }, EdgeIPs: func() []string { return []string{"192.0.2.1"} }, Resolve: func(string) ([]string, error) { return []string{"192.0.2.1"}, nil }} |
| + if err := domains.Reconcile(ctx, s, reg, cfg); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, c := range []domains.Claim{ |
| + {Schema: 1, Host: "alias.customer.test", Account: acct, App: "shop", Route: "shop.example.com"}, |
| + {Schema: 1, Host: "customer.test", Account: acct, App: "shop", Route: "shop.example.com", Wildcard: true, Catchall: true}, |
| + {Schema: 1, Host: "cert.test", Account: acct, App: "shop", Route: "shop.example.com", Wildcard: true}, |
| + {Schema: 1, Host: "instances.test", Account: acct, App: "shop"}, |
| + {Schema: 1, Host: "*.instances.test", Account: acct, App: "shop", Instances: true}, |
| + } { |
| + put(domains.ClaimKey(c.Host), c) |
| + } |
| + if err := domains.ReconcileAliases(ctx, s, reg, func() time.Time { return now }, nil, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := domains.Reconcile(ctx, s, reg, cfg); err != nil { |
| + t.Fatal(err) |
| + } |
| + aliases, err := reg.ListAliases() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, a := range aliases { |
| + if err := reg.SetAliasDNSStatus(a.Alias, "pointing", now.Unix()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + // A path owned by the other account makes remote owner authorization unknown. |
| + if err := reg.Upsert(registry.Route{Host: "other.example.net", Kind: "service", Status: "ready", Addr: "127.0.0.1:9", Account: "other", App: "other"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.UpsertPath(registry.RoutePath{Host: "mixed.example.com", Prefix: "other", Target: "other.example.net", Account: acct, App: "shop"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := status.WriteBox(ctx, s, status.Box{Label: "g-closed", GeneratedAt: now}); err != nil { |
| + t.Fatal(err) |
| + } |
| + var last []byte |
| + if err := edgesFilePass(ctx, s, reg, edgesFile{Box: "g-closed", RoleSource: admission}, "192.0.2.1", &last); err != nil { |
| + t.Fatal(err) |
| + } |
| + body, _, err := s.Get(ctx, edgesfile.Key("g-closed")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + var f edgesFile |
| + if err = json.Unmarshal(body, &f); err != nil { |
| + t.Fatal(err) |
| + } |
| + routes, complete := edgesfile.DeploymentRoutesComplete(ctx, s, now) |
| + if !complete { |
| + t.Fatal("incomplete routes") |
| + } |
| + for _, tc := range groupNameCases(acct) { |
| + t.Run(tc.class, func(t *testing.T) { |
| + h, exists := f.Hosts[tc.name] |
| + if tc.class == "sidecar" { |
| + if exists || routes[tc.name] { |
| + t.Fatal("sidecar published") |
| + } |
| + return |
| + } |
| + if !exists || h.Alias != tc.alias || h.Wildcard != tc.wildcard || h.Replica != tc.replica { |
| + t.Fatalf("publication %s = %+v (%v)", tc.name, h, exists) |
| + } |
| + if routes[tc.name] != tc.route { |
| + t.Errorf("route existence %s = %v; want %v", tc.name, routes[tc.name], tc.route) |
| + } |
| + if tc.ambiguous && (h.Account != "" || h.App != "") { |
| + t.Error("ambiguous path owner published") |
| + } |
| + // An admitted foreign alias is never authority for a real closed route. |
| + peer := []byte(fmt.Sprintf(`{"v":1,"box":"z-peer","eip":"192.0.2.2","hosts":{%q:{"role":"home","alias":true,"account":"other","app":"other","target_host":"other.example.net"}}}`, tc.name)) |
| + bodies := map[string][]byte{edgesfile.Key("g-closed"): body} |
| + if tc.route { |
| + bodies[edgesfile.Key("z-peer")] = peer |
| + } |
| + if box, ok, err := edge.FoldedHome(bodies, "observer", tc.name); err != nil || ok { |
| + t.Errorf("closed %s elected %s %v %v", tc.name, box, ok, err) |
| + } |
| + var files []edgesfile.PlacementView |
| + for key, b := range bodies { |
| + var f edgesfile.PlacementView |
| + if err := json.Unmarshal(b, &f); err != nil { |
| + t.Fatal(err) |
| + } |
| + f.Key = key |
| + files = append(files, f) |
| + } |
| + won, _, err := edgesfile.ElectHomesForEveryReader(files) |
| + if err != nil || won[tc.name].Box != "" { |
| + t.Errorf("console election: %v %v", won, err) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// Every producer is pinned as well as its schema: a new derivation must add |
| +// a behavioral row above before the producer's inventory can be renewed. |
| +func TestGroupNameClassCensus(t *testing.T) { |
| + required := []string{"exact route", "platform alias", "plain alias", "instance catchall", "delegated catchall", "certificate parent", "replica", "path ambiguity", "sidecar"} |
| + got := map[string]bool{} |
| + for _, c := range groupNameCases(domains.Sqid(2)) { |
| + if got[c.class] { |
| + t.Errorf("duplicate class %s", c.class) |
| + } |
| + got[c.class] = true |
| + } |
| + for _, name := range required { |
| + if !got[name] { |
| + t.Errorf("missing class %s", name) |
| + } |
| + } |
| + if len(got) != len(required) { |
| + t.Errorf("class inventory: %v", got) |
| + } |
| + // Discover registry name writers, including newly added source files. |
| + // A new producer cannot avoid the inventory by moving to another file. |
| + for _, dir := range []string{".", "../domains", "../provision", "../edge"} { |
| + files, err := os.ReadDir(dir) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, file := range files { |
| + if file.IsDir() || !strings.HasSuffix(file.Name(), ".go") || strings.HasSuffix(file.Name(), "_test.go") { |
| + continue |
| + } |
| + path := filepath.Join(dir, file.Name()) |
| + body, err := os.ReadFile(path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + parsed, err := parser.ParseFile(token.NewFileSet(), path, body, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + produces := false |
| + ast.Inspect(parsed, func(n ast.Node) bool { |
| + call, ok := n.(*ast.CallExpr) |
| + if !ok { |
| + return true |
| + } |
| + sel, ok := call.Fun.(*ast.SelectorExpr) |
| + if !ok { |
| + return true |
| + } |
| + switch sel.Sel.Name { |
| + case "Upsert", "UpsertAlias", "UpsertPath", "UpsertWildcardDomain": |
| + produces = true |
| + } |
| + return true |
| + }) |
| + if produces { |
| + if _, ok := groupNameProducerInventory[path]; !ok { |
| + t.Errorf("unlisted producer %s %x: add its name-class consequence and inventory row", path, sha256.Sum256(body)) |
| + } |
| + } |
| + } |
| + } |
| + for path, want := range groupNameProducerInventory { |
| + body, err := os.ReadFile(path) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if hash := fmt.Sprintf("%x", sha256.Sum256(body)); hash != want { |
| + t.Errorf("producer %s changed (%s): inventory every name derivation and add its consequence row", path, hash) |
| + } |
| + } |
| + for _, schema := range []struct { |
| + value any |
| + fields string |
| + }{ |
| + {registry.Route{}, "DemoID DemoHost DemoLifetime DemoExpiresAt ClaimOwnership WakeIncarnation Host Slug Kind Socket Addr Addrs Health Status HoldOp Incarnation ServingSeq SeedSource ImportGate AssetsOff AssetGen LastError Stateless DBPath Version PrevVersion GoodVersion GoodDigest GoodDemand ServingVersion App Pool Region Channel Environment Tunnel FleetBox FleetLabel Assigned Moved Caps Hibernate HA Runtime Gate RateLimit Canary Replication NextDue StatusNamed Backing Unit Platform Provisioned Seed Args IdleSeconds MaxRunSeconds DNSStatus DNSCheckedAt CertExpiresAt Account Steering UpdateSettings EgressAllow Size PolicyExpiresAt BuildState Replicas Replica CreatedAt"}, |
| + {provision.Record{}, "Demo Coordinator ReplicaDeploy RecordSeq Acquisition Maintenance Schema Host Slug App Account Pool Region Channel CreatedAt CreatedBy FleetBox FleetBoxAt FleetBoxMoved HA Move LastMove ActiveRun Interactive RunKeys Seed Kind Addr Unit Hibernate Runtime Environment StatusNamed Addrs Health Steering Assets AssetGen Gate Incarnation IncarnationMigrating MoveSeq Retired RateLimit Role Replicas Updates Major Pin InstallRequest"}, |
| + {edgeHost{}, "Role Platform Alias Replica Wildcard Account App Stamp Incarnation ServingSeq TargetHost Assets"}, |
| + {domains.Claim{}, "Acquisition RecordIncarnation OwnershipState Schema Host Account App Route CreatedAt CreatedBy Wildcard Catchall Paths Instances Placements Pending PendingUntil"}, |
| + {registry.RouteAlias{}, "Alias Host Account App DNSStatus DNSCheckedAt CertExpiresAt CreatedAt"}, |
| + {registry.RoutePath{}, "Host Prefix Target Account App"}, |
| + {registry.WildcardDomain{}, "Host Account App CreatedAt"}, |
| + } { |
| + typ := reflect.TypeOf(schema.value) |
| + var fields []string |
| + for i := 0; i < typ.NumField(); i++ { |
| + fields = append(fields, typ.Field(i).Name) |
| + } |
| + if strings.Join(fields, " ") != schema.fields { |
| + t.Errorf("schema %s: inventory fields %q", typ, strings.Join(fields, " ")) |
| + } |
| + } |
| +} |
| + |
| +var groupNameProducerInventory = map[string]string{ |
| + "../provision/sidecar_reconcile.go": "f6260269532e84fe27acf8c7bde6d7aaa6b463b2f978e9c315609e569fbff636", |
| + "rootinventory.go": "d5f00f6c9a01049ff4a91342a8dfb253e90a186cfbd57bd02a84f2e2e8bfcf51", |
| + "edgesfile.go": "60c4706b89b776da6a1f5830f66cd640d7c0ae0a12babfd588f2e042333a510a", |
| + "../domains/aliases.go": "ce4e04b06bb9fa0685b5f912a756178ed10e5763cfafd4843daf0b6d5702ef90", |
| + "../domains/reconcile.go": "3c0ba9ccb35b7d7623896f69b225aeecde8154845bad99a301a1186793b78a7e", |
| + "../provision/reconcile.go": "7df62fbd5589e02bd316d772c006a6543ad8ff84db349a8abb4687bdd745321b", |
| + "../edge/edge.go": "f5fee9844b67382fcb1e5efe2a56e2a52a34ba9516b0f80f182ae4a3c09c8d42", |
| + "../edge/platformalias.go": "a1124d267bd53bbf9c64f7f12dc2a5923d5e32276b2551a0001a054f84f6c1db", |
| +} |