carlos / platform Public

region labels: export the everywhere-class predicates and the C23 code list (plan 1 task 1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 8ee54063a632a10533f239f16dd4243b5c1b9f6d parent a2e3aaa
4 files changed, +88 −0
  • internal/geo/awsregions.go +10 −0
  • internal/geo/awsregions_test.go +14 −0
  • internal/provision/servedeverywhere.go +14 −0
  • internal/provision/servedeverywhere_test.go +50 −0
diff --git a/internal/geo/awsregions.go b/internal/geo/awsregions.go
index 8fc5671ac..044888d16 100644
--- a/internal/geo/awsregions.go
+++ b/internal/geo/awsregions.go
@@ -1,5 +1,10 @@
package geo
+import (
+ "maps"
+ "slices"
+)
+
// AWSRegion is one AWS commercial region's metro-area point and the place
// name every surface shows for it (spec §14, copy C23 as approved in the
// nearest-region copy record).
@@ -57,6 +62,11 @@ func LookupAWSRegion(code string) (AWSRegion, bool) {
return r, ok
}
+// AWSRegionCodes is every AWS region the table knows, sorted.
+func AWSRegionCodes() []string {
+ return slices.Sorted(maps.Keys(awsRegions))
+}
+
func tablePoint(code string) (Point, bool) {
r, ok := awsRegions[code]
return r.Point, ok
diff --git a/internal/geo/awsregions_test.go b/internal/geo/awsregions_test.go
index 0cecda3d6..541c00b98 100644
--- a/internal/geo/awsregions_test.go
+++ b/internal/geo/awsregions_test.go
@@ -4,6 +4,7 @@ import (
"encoding/json"
"os"
"regexp"
+ "slices"
"strings"
"testing"
)
@@ -93,3 +94,16 @@ func TestPlaceNamesMatchApprovedRecord(t *testing.T) {
t.Errorf("%d C23 entries in the record, want 34", len(seen))
}
}
+
+func TestAWSRegionCodesIsTheTable(t *testing.T) {
+ t.Parallel()
+ codes := AWSRegionCodes()
+ if len(codes) != len(awsRegions) || !slices.IsSorted(codes) {
+ t.Fatalf("AWSRegionCodes = %v: want every one of the table's %d codes, sorted", codes, len(awsRegions))
+ }
+ for _, c := range codes {
+ if _, ok := LookupAWSRegion(c); !ok {
+ t.Errorf("%s is listed but not in the table", c)
+ }
+ }
+}
diff --git a/internal/provision/servedeverywhere.go b/internal/provision/servedeverywhere.go
new file mode 100644
index 000000000..875787c95
--- /dev/null
+++ b/internal/provision/servedeverywhere.go
@@ -0,0 +1,14 @@
+package provision
+
+import "github.com/carlosframework/platform/internal/registry"
+
+// ServedEverywhere reports whether every platform box serves rec's class:
+// everywhereClass, exported so the region labels and the reconciler answer
+// from one predicate (region labels spec §3.1). It answers the class
+// question only. A fleet placement or a pool is the caller's to apply
+// first, as inScope does.
+func ServedEverywhere(rec Record) bool { return everywhereClass(rec) }
+
+// RouteServedEverywhere is everywhereRoute: the same question asked of a
+// registry row that has no record in hand.
+func RouteServedEverywhere(rt registry.Route) bool { return everywhereRoute(rt) }
diff --git a/internal/provision/servedeverywhere_test.go b/internal/provision/servedeverywhere_test.go
new file mode 100644
index 000000000..1781d48c9
--- /dev/null
+++ b/internal/provision/servedeverywhere_test.go
@@ -0,0 +1,50 @@
+package provision
+
+import "testing"
+
+// TestServedEverywhereIsTheClassRule: the exported predicates are the
+// reconciler's own, over the shapes reconcile_test.go's agreement test
+// uses (region labels spec §10), so a label can never disagree with what
+// the boxes mint.
+func TestServedEverywhereIsTheClassRule(t *testing.T) {
+ t.Parallel()
+ off := false
+ base := func(host string) Record {
+ return Record{Schema: 1, Host: host, Slug: "s", App: "shop", Account: "bab",
+ Pool: "shop", Region: "ie", Channel: "stable"}
+ }
+ with := func(host string, mut func(*Record)) Record {
+ rec := base(host)
+ mut(&rec)
+ return rec
+ }
+ recs := []Record{
+ base("exec.shop.example.com"),
+ with("site.shop.example.com", func(r *Record) { r.Kind = "static" }),
+ with("pub.shop.example.com", func(r *Record) { r.Kind, r.Addr = "service", "203.0.113.10:443" }),
+ with("pubs.shop.example.com", func(r *Record) {
+ r.Kind, r.Addrs = "service", []string{"203.0.113.11:443", "198.51.100.7:443"}
+ }),
+ with("awake.shop.example.com", func(r *Record) { r.Kind, r.Addr, r.Hibernate = "service", "203.0.113.13:443", &off }),
+ with("loop.shop.example.com", func(r *Record) { r.Kind, r.Addr = "service", "127.0.0.1:8090" }),
+ with("priv.shop.example.com", func(r *Record) { r.Kind, r.Addrs = "service", []string{"10.0.0.5:3000"} }),
+ with("named.shop.example.com", func(r *Record) { r.Kind, r.Addr = "service", "backend.example.com:443" }),
+ with("unit.shop.example.com", func(r *Record) { r.Addr, r.Unit = "203.0.113.20:8090", "shop.service" }),
+ with("fleet-site.shop.example.com", func(r *Record) { r.Kind, r.Region = "static", "fleet/private" }),
+ }
+ for _, rec := range recs {
+ if err := ValidateShape(rec); err != nil {
+ t.Fatalf("%s: not a shape the pass ever sees: %v", rec.Host, err)
+ }
+ if got, want := ServedEverywhere(rec), everywhereClass(rec); got != want {
+ t.Errorf("%s: ServedEverywhere = %v, everywhereClass = %v", rec.Host, got, want)
+ }
+ rt := RouteFor(rec, "/data", `["seed"]`, false, nil)
+ if got, want := RouteServedEverywhere(rt), everywhereRoute(rt); got != want {
+ t.Errorf("%s: RouteServedEverywhere = %v, everywhereRoute = %v", rec.Host, got, want)
+ }
+ }
+ if !ServedEverywhere(recs[1]) || ServedEverywhere(recs[0]) {
+ t.Fatal("a static record is served everywhere and a socket-backed one is not")
+ }
+}