registry: an import-gated route is not a path front (#186)
Whole-branch review R1 P1-1: a front whose import gate was open (or closed by a rollback) could have its prefixes selected across boxes, dispatching before any box saw the gate, so the target served them. PathFront, the one rule the edges-file writer publishes as path_front and the edge's local front-route test calls, now also requires an empty ImportGate. No box selects across boxes for a gated front; its prefixes reach its own box, whose import gate refuses them as today. PathTarget keeps its rule: a gated target is refused by the gate on its own box. PathEligibilityCases gains gated and rollback-closed rows (the edges-file guard runs them). TestImportGateCoversPathRoutesAcrossBoxes witnesses front-box, target-box and third-box ingress plus hops, for the open and the closed gate, and the prefix crossing again after the restore. Spec rev 5.3 §5.1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+157
−12
docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md+7 −2internal/edge/path_across_import_test.go+120 −0internal/registry/pathroute.go+30 −10
diff --git a/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md b/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md| index 071926b32..11cd8ae77 100644 |
| --- a/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md |
| +++ b/docs/superpowers/specs/2026-11-19-path-routes-across-boxes-design.md |
| @@ -1,6 +1,6 @@ |
| # Path routes across boxes: a prefix whose target lives on another box |
| -Rev 5.2, 2026-11-21 (§7.2 cut by Paul during the build; §7.3 clarified). Rev 5 approved by Paul 2026-11-19. Discussion #186. Builds on the path-routing design |
| +Rev 5.3, 2026-11-21 (§7.2 cut by Paul during the build; §7.3 clarified; §5.1 import-gated fronts). Rev 5 approved by Paul 2026-11-19. Discussion #186. Builds on the path-routing design |
| (`2026-09-02-path-based-routing-design.md`, "the 09-02 design" below) and |
| changes none of its rulings except the one it was written to lift: §6's |
| "a prefix's target route must be homed on the same box as the hostname's |
| @@ -192,7 +192,12 @@ called by both sides: |
| `PathTarget` is true for a ready route of kind `instance` or `static` that is |
| not a forward, demo or sidecar route. `PathFront` is true for a route of |
| -kind `instance` or `static` that is not a forward, demo or sidecar route. |
| +kind `instance` or `static` that is not a forward, demo or sidecar route |
| +and carries no import gate (an uncommitted import, its gate open or closed |
| +by a rollback: whole-branch review R1 P1-1). So no box selects a gated |
| +front's prefixes across boxes; they reach the front's own box, whose import |
| +gate holds them closed as it does today. A gated target stays a target: the |
| +box serving it runs the import gate on the selected row. |
| Region HA does not change either answer (§5.7). A guard test walks every |
| route kind and every flag the registry carries (forward, demo, sidecar, HA, |
| replica, hibernating, static, service) and fails if the published mark and |
diff --git a/internal/edge/path_across_import_test.go b/internal/edge/path_across_import_test.go| new file mode 100644 |
| index 000000000..e8b5e4fee |
| --- /dev/null |
| +++ b/internal/edge/path_across_import_test.go |
| @@ -0,0 +1,120 @@ |
| +package edge |
| + |
| +// Path routes across boxes (#186) and the import gate (seeded-instances spec |
| +// §5.4; whole-branch review R1 P1-1). An uncommitted import is not a front |
| +// route (registry.PathFront), so no box selects its prefixes across boxes: |
| +// the front's own box keeps today's import gate over them, and every other |
| +// box sends the request there or refuses it. pathAcrossScene's boxes: the |
| +// hub (A, the gated front), the tenant (B, the prefix's target) and the |
| +// third (C, neither). |
| + |
| +import ( |
| + "net/http" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/seeds" |
| +) |
| + |
| +// gateHubAcross swaps hub.example on A for a gated import row served by app, |
| +// reloads A, and republishes A's edges-file row with the marks the shared |
| +// predicates give the stored row, exactly as the edges-file writer does |
| +// (TestEdgesFilePathMarksMatchPredicates). Returns the verify token. |
| +func (s *pathAcrossScene) gateHubAcross(t *testing.T, app *acrossApp) string { |
| + t.Helper() |
| + token, hash, err := seeds.NewVerifyToken() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + gateForImport(t, s.hub.reg, acrossHub, app.addr(), hash, false) |
| + s.republishHub(t, 6) |
| + return token |
| +} |
| + |
| +// republishHub reloads A and publishes its hub.example row as the writer |
| +// would for the row A now stores. |
| +func (s *pathAcrossScene) republishHub(t *testing.T, stamp int) { |
| + t.Helper() |
| + s.reload(t, s.hub) |
| + stored, err := s.hub.reg.Get(acrossHub) |
| + if err != nil || stored == nil { |
| + t.Fatalf("get %s: %v %v", acrossHub, stored, err) |
| + } |
| + s.publish(t, s.hub, acrossHub, acrossEntry(acrossAcct, "hub", acrossAcct, "hub", stamp, |
| + registry.PathFront(*stored), registry.PathTarget(*stored))) |
| +} |
| + |
| +// wantImportRefusal fails unless res is the import gate's 503 (Retry-After 5, |
| +// the gate's sentence), wherever it was answered. |
| +func wantImportRefusal(t *testing.T, res acrossResp, what string) { |
| + t.Helper() |
| + if res.code != http.StatusServiceUnavailable || res.header.Get("Retry-After") != "5" || res.body != gateRefusal { |
| + t.Fatalf("%s: %d retry %q %q, want the import gate's 503", what, res.code, res.header.Get("Retry-After"), res.body) |
| + } |
| +} |
| + |
| +// The gated front's prefix is closed on every box, open gate and rollback's |
| +// closed gate alike: on A by A's own gate (no dial), on B and C by the |
| +// backhaul to A (the front's home) and A's gate; and a hop for it reaching |
| +// B is refused as stale, never served from the target. Nothing reaches the |
| +// target. Once the legacy row is restored the prefix crosses again. |
| +func TestImportGateCoversPathRoutesAcrossBoxes(t *testing.T) { |
| + s := newPathAcrossScene(t) |
| + imported := newAcrossApp(t, "imported-1") |
| + token := s.gateHubAcross(t, imported) |
| + |
| + verified := 0 |
| + closed := func(when string) { |
| + t.Helper() |
| + for _, p := range []string{"/acme/x", "//acme/x", "/x/../acme/x"} { |
| + wantImportRefusal(t, s.get(t, s.hub, acrossHub, p), when+": front box "+p) |
| + wantImportRefusal(t, s.get(t, s.tenant, acrossHub, p), when+": target box "+p) |
| + wantImportRefusal(t, s.get(t, s.third, acrossHub, p), when+": third box "+p) |
| + } |
| + s.hop(t, s.tenant, acrossHub, "/acme/x", false).wantStale(t) |
| + s.hop(t, s.third, acrossHub, "/acme/x", false).wantStale(t) |
| + if n := s.dialsFrom(s.hub, acrossIPTenant); n != 0 { |
| + t.Fatalf("%s: the front box dialled the target's box %d times", when, n) |
| + } |
| + if n := s.dialsFrom(s.third, acrossIPTenant); n != 0 { |
| + t.Fatalf("%s: the third box dialled the target's box %d times", when, n) |
| + } |
| + s.tenantApp.wantSeen(t) |
| + if n := len(imported.requests()); n != verified { |
| + t.Fatalf("%s: the import's row was reached %d times, want only the %d verify requests", when, n, verified) |
| + } |
| + s.hubApp.wantSeen(t) |
| + } |
| + closed("open gate") |
| + |
| + // The verify token never opens the prefix's target: no box selects it, |
| + // so on every box the verify is the front's own request, which the |
| + // front's box admits to the import's own row and nothing else (as on |
| + // main, where a prefix naming another box's route fell through to the |
| + // host's own route). |
| + for _, be := range s.boxes() { |
| + req, err := http.NewRequest(http.MethodGet, "https://"+acrossHub+"/acme/x", nil) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + req.Header.Set(ImportVerifyHeader, token) |
| + s.do(t, be, req).want(t, http.StatusOK, "imported-1|"+acrossHub+"|/acme/x") |
| + } |
| + s.tenantApp.wantSeen(t) |
| + imported.wantSeen(t, acrossSeen{acrossHub, "/acme/x"}, acrossSeen{acrossHub, "/acme/x"}, acrossSeen{acrossHub, "/acme/x"}) |
| + verified = 3 |
| + |
| + // Rollback, step 1: the gate closes; still closed everywhere. |
| + if err := s.hub.reg.CloseImportGate(acrossHub, gateSeedID, 1); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.republishHub(t, 7) |
| + closed("closed gate") |
| + |
| + // Rollback, step 2: the legacy row is back and its prefix crosses again. |
| + if err := s.hub.reg.RestoreImportRoute(acrossHub, gateSeedID); err != nil { |
| + t.Fatal(err) |
| + } |
| + s.republishHub(t, 8) |
| + s.get(t, s.third, acrossHub, "/acme/x").want(t, http.StatusOK, "tenant-1|"+acrossHub+"|/acme/x") |
| +} |
diff --git a/internal/registry/pathroute.go b/internal/registry/pathroute.go| index 5a804e382..ad38840db 100644 |
| --- a/internal/registry/pathroute.go |
| +++ b/internal/registry/pathroute.go |
| @@ -7,21 +7,36 @@ package registry |
| // 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. |
| +// PathFront reports whether rt may front a cross-box path route: a path |
| +// route (pathRouteKind) with no import gate. Status does not matter (a |
| +// starting front still owns its hostname), and HA changes nothing. |
| +// |
| +// An uncommitted import, its gate open or closed by a rollback, is not a |
| +// front (whole-branch review R1 P1-1): its own box's import gate holds |
| +// every prefix under it closed (edge importGateAdmit), and a box that |
| +// selected one of those prefixes across boxes would dispatch before any |
| +// box could see the gate. So no box selects across boxes for it; its |
| +// prefixes reach its own box, which refuses them as it always has. |
| func PathFront(rt Route) bool { |
| - if rt.Kind != "instance" && rt.Kind != "static" { |
| - return false |
| - } |
| - return !rt.IsForward() && !rt.IsDemo() && !rt.IsSidecar() |
| + return pathRouteKind(rt) && rt.ImportGate == "" |
| } |
| // PathTarget reports whether rt may be the target of a cross-box path |
| -// route: PathFront's rule plus Status "ready". HA changes nothing. |
| +// route: a path route (pathRouteKind) with Status "ready". HA changes |
| +// nothing. An import-gated target stays a target: the box serving it runs |
| +// its import gate on the selected row, so a prefix naming it is refused |
| +// there, as on one box. |
| func PathTarget(rt Route) bool { |
| - return rt.Status == "ready" && PathFront(rt) |
| + return rt.Status == "ready" && pathRouteKind(rt) |
| +} |
| + |
| +// pathRouteKind is the kind rule both predicates share: an instance or |
| +// static route that is not a forward row, a demo or a sidecar. |
| +func pathRouteKind(rt Route) bool { |
| + if rt.Kind != "instance" && rt.Kind != "static" { |
| + return false |
| + } |
| + return !rt.IsForward() && !rt.IsDemo() && !rt.IsSidecar() |
| } |
| // PathEligibilityCase is one row of PathEligibilityCases. |
| @@ -48,4 +63,9 @@ var PathEligibilityCases = []PathEligibilityCase{ |
| {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}, |
| + // An uncommitted import (seeded-instances spec §5.4) keeps its own box's |
| + // import gate over every prefix, so it is never a front across boxes; |
| + // as a target the receiving box's gate refuses it, as on one box. |
| + {Name: "import-gated instance", Route: Route{Kind: "instance", Status: "ready", ImportGate: "gate-hash"}, Front: false, Target: true}, |
| + {Name: "rollback-closed instance", Route: Route{Kind: "instance", Status: "ready", ImportGate: ImportGateClosed}, Front: false, Target: true}, |
| } |