carlos / platform Public

registry: PathFront and PathTarget, the shared path eligibility rule

PathFront: instance or static, not a forward, demo or sidecar. PathTarget:
PathFront plus Status "ready". HA changes neither. PathEligibilityCases is
an exported test table so the edges-file guard in another package runs the
same rows; TestPathPredicatesNameEveryKind fails until a new kind gets one.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 94cc8fc0f33f06da2794edbc51f33696530950c9 parent 1a62998
2 files changed, +86 −0
  • internal/registry/pathroute.go +51 −0
  • internal/registry/pathroute_test.go +35 −0
diff --git a/internal/registry/pathroute.go b/internal/registry/pathroute.go
new file mode 100644
index 000000000..5a804e382
--- /dev/null
+++ b/internal/registry/pathroute.go
@@ -0,0 +1,51 @@
+package registry
+
+// Path routes across boxes (#186): the eligibility rule for a path route
+// whose front and target live on different boxes. The same-box case keeps
+// the edge's own answer; these two predicates are the cross-box rule only,
+// shared by the registry's reconcile (which writes path_front/path_target
+// into the edges file) and the edge's selection, so the two can never
+// disagree about which routes take part.
+
+// PathFront reports whether rt may front a cross-box path route: an
+// instance or static route that is not a forward row, a demo or a sidecar.
+// Status does not matter (a starting front still owns its hostname), and
+// HA changes nothing.
+func PathFront(rt Route) bool {
+ if rt.Kind != "instance" && rt.Kind != "static" {
+ return false
+ }
+ return !rt.IsForward() && !rt.IsDemo() && !rt.IsSidecar()
+}
+
+// PathTarget reports whether rt may be the target of a cross-box path
+// route: PathFront's rule plus Status "ready". HA changes nothing.
+func PathTarget(rt Route) bool {
+ return rt.Status == "ready" && PathFront(rt)
+}
+
+// PathEligibilityCase is one row of PathEligibilityCases.
+type PathEligibilityCase struct {
+ Name string
+ Route Route
+ Front, Target bool
+}
+
+// PathEligibilityCases is a test table, not runtime data: the expected
+// PathFront and PathTarget answers for one route of every kind plus the
+// flags that must not change them. It lives in a non-test file so tests
+// in other packages (the edges-file equivalence guard) run the same rows.
+// Every kind named on Route.Kind, plus KindForward, needs a row here
+// (TestPathPredicatesNameEveryKind).
+var PathEligibilityCases = []PathEligibilityCase{
+ {Name: "ready instance", Route: Route{Kind: "instance", Status: "ready"}, Front: true, Target: true},
+ {Name: "ready static", Route: Route{Kind: "static", Status: "ready"}, Front: true, Target: true},
+ {Name: "starting instance", Route: Route{Kind: "instance", Status: "starting"}, Front: true, Target: false},
+ {Name: "ready service", Route: Route{Kind: "service", Status: "ready"}, Front: false, Target: false},
+ {Name: "ready sidecar", Route: Route{Kind: "sidecar", Status: "ready"}, Front: false, Target: false},
+ {Name: "ready forward", Route: Route{Kind: KindForward, Status: "ready"}, Front: false, Target: false},
+ {Name: "ready demo instance", Route: Route{Kind: "instance", Status: "ready", DemoID: "demo-1"}, Front: false, Target: false},
+ {Name: "ready HA instance", Route: Route{Kind: "instance", Status: "ready", HA: true}, Front: true, Target: true},
+ {Name: "ready replica instance", Route: Route{Kind: "instance", Status: "ready", Replica: true}, Front: true, Target: true},
+ {Name: "ready hibernating instance", Route: Route{Kind: "instance", Status: "ready", Hibernate: true}, Front: true, Target: true},
+}
diff --git a/internal/registry/pathroute_test.go b/internal/registry/pathroute_test.go
new file mode 100644
index 000000000..0472e4e8a
--- /dev/null
+++ b/internal/registry/pathroute_test.go
@@ -0,0 +1,35 @@
+package registry
+
+import "testing"
+
+// TestPathEligibility runs the shared case table through both predicates.
+func TestPathEligibility(t *testing.T) {
+ for _, c := range PathEligibilityCases {
+ t.Run(c.Name, func(t *testing.T) {
+ if got := PathFront(c.Route); got != c.Front {
+ t.Errorf("PathFront = %v, want %v", got, c.Front)
+ }
+ if got := PathTarget(c.Route); got != c.Target {
+ t.Errorf("PathTarget = %v, want %v", got, c.Target)
+ }
+ })
+ }
+}
+
+// TestPathPredicatesNameEveryKind fails when a route kind has no row in
+// PathEligibilityCases, so a new kind is classified before it can be a
+// path front or target by accident. The kinds are those named in the
+// comment on Route.Kind in registry.go, plus KindForward (forward.go); add
+// a new kind here when that comment gains one.
+func TestPathPredicatesNameEveryKind(t *testing.T) {
+ kinds := []string{"instance", "service", "static", "sidecar", KindForward}
+ seen := map[string]bool{}
+ for _, c := range PathEligibilityCases {
+ seen[c.Route.Kind] = true
+ }
+ for _, k := range kinds {
+ if !seen[k] {
+ t.Errorf("kind %q has no row in PathEligibilityCases", k)
+ }
+ }
+}