domains: derive path rows on every box (#186)
Every box now derives route_paths rows for every claim with Paths, not only the box serving the claim's host (spec 5.1). A local host keeps its tenancy check; a local target keeps today's account and readiness checks (any kind, service included); a non-local host or target derives its row and the edge checks it at request time. Sidecar refusals, the cap and its sorted truncation are unchanged. The unresolved log now counts only local targets that are not ready and drops the same-box advice. The path block moves out of ReconcileAliasesReport into derivePaths, which takes that function under the 300-line limit; the code-health record line is dropped. BenchmarkReconcilePathSection now runs a non-local workload: 10 hosts x 10,000 prefixes, unchanged pass 44-52 ms/op.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+290
−173
.amadan/code-health.tsv+0 −1internal/console/apiroutes.go+4 −4internal/domains/aliases.go+119 −130internal/domains/aliases_paths_test.go+158 −29internal/domains/paths_cost_test.go+9 −9
diff --git a/.amadan/code-health.tsv b/.amadan/code-health.tsv| index 55fb37e44..c559e6c4c 100644 |
| --- a/.amadan/code-health.tsv |
| +++ b/.amadan/code-health.tsv |
| @@ -2186,7 +2186,6 @@ func-lines internal/console (*Store).migrate - 335 |
| func-lines internal/console TestDemoProtectionsSourceToLimitAndTakedown - 412 |
| func-lines internal/console TestDemoSourceToLiveAndUpdate - 383 |
| func-lines internal/console TestHAP2ProductionDoors - 304 |
| -func-lines internal/domains ReconcileAliasesReport - 349 |
| func-lines internal/edge (*Edge).ServeHTTP - 421 |
| func-lines internal/edge TestDemoAPIAliasBoundary - 360 |
| func-lines internal/edge TestRegionalNameNeverLeavesItsRegion - 330 |
diff --git a/internal/console/apiroutes.go b/internal/console/apiroutes.go| index e757fac50..30a8bbfb5 100644 |
| --- a/internal/console/apiroutes.go |
| +++ b/internal/console/apiroutes.go |
| @@ -202,10 +202,10 @@ func (s *Server) handleAPIRoutes(w http.ResponseWriter, r *http.Request) { |
| } else { |
| for _, p := range all { |
| // The host filter is what keeps this from listing a prefix whose |
| - // hostname is not in the answer above: the reconcile pass only |
| - // derives a row when the claim's host is a local route of the |
| - // same app and account, so in practice every row passes — but a |
| - // listing must not depend on another package's invariant. |
| + // hostname is not in the answer above: the reconcile pass derives |
| + // every path-routed host's rows on every box (path routes across |
| + // boxes, spec §5.1), including hosts this console's box does not |
| + // serve, so a row's host need not be a route here. |
| // release.RouteAccount, matching the routes filter above rather |
| // than comparing the column raw. The warning there applies here |
| // word for word: a second, private notion of "whose row is this" |
diff --git a/internal/domains/aliases.go b/internal/domains/aliases.go| index 507293ccc..9338683f0 100644 |
| --- a/internal/domains/aliases.go |
| +++ b/internal/domains/aliases.go |
| @@ -602,142 +602,14 @@ func ReconcileAliasesReport(ctx context.Context, s release.Store, reg *registry. |
| } |
| } |
| - // Path derivation (prefix routing). A claim's Paths map splits its own |
| - // hostname's traffic by leading URL segment; each entry names the |
| - // hostname of the route that serves that segment. |
| - // |
| - // Gated on the claim's host being a LOCAL route whose tenancy matches |
| - // the claim — the same per-box rule the alias half above follows, and |
| - // for the same reason: the prefix map belongs to that route, so a box |
| - // that does not serve the route derives nothing. |
| - // |
| - // The TARGET is resolved through the same local byHost, which makes |
| - // co-location a hard constraint of the feature: a prefix's target |
| - // route must be homed on the same box as the hostname's own route. |
| - // There is no backhaul equivalent for a path target — backhaul fires |
| - // on a host miss, and the host resolves fine here — so a target on |
| - // another box derives no row anywhere at all. See the unresolved log |
| - // below, and design spec §6. |
| - // |
| + // Path derivation (prefix routing), on every box (derivePaths). |
| // Ordered BEFORE the wildcard section on purpose: Paths is a third |
| // claim capability independent of Wildcard (claims.go's comment on |
| // the field), and the wildcard section below `continue`s for every |
| // non-Wildcard claim — placed after that, a Paths-only claim would |
| // never reach this block. |
| if len(c.Paths) > 0 { |
| - hostRt, ok := byHost[c.Host] |
| - if strings.HasSuffix(c.Host, sidecarSuffix) { |
| - // The alias half's refusal, for the table path-based |
| - // routing added afterwards. A route_paths row keyed on a |
| - // reserved-suffix hostname is the same mistake in a |
| - // different table: it inserts a sidecar's name into the |
| - // edge's routing map, and edge.go's Kind check never sees |
| - // it because the row it reads is a path row, not a |
| - // Kind=="sidecar" route. |
| - log.Printf("domains: paths on %s refused: reserved sidecar suffix", c.Host) |
| - } else if !ok { |
| - // The hostname's own route is not on this box; another box |
| - // derives these rows. |
| - } else if hostRt.App != c.App || release.RouteAccount(hostRt) != c.Account { |
| - log.Printf("domains: paths on %s refused: route belongs to %s/%s, claim says %s/%s", |
| - c.Host, release.RouteAccount(hostRt), hostRt.App, c.Account, c.App) |
| - } else { |
| - // Sorted so the cap below truncates DETERMINISTICALLY: every |
| - // box must derive the identical subset, or the same URL would |
| - // resolve differently depending on which edge answered. |
| - prefixes := make([]string, 0, len(c.Paths)) |
| - for p := range c.Paths { |
| - prefixes = append(prefixes, p) |
| - } |
| - sort.Strings(prefixes) |
| - if len(prefixes) > MaxPathsPerClaim { |
| - log.Printf("domains: paths on %s: %d prefixes exceeds the cap of %d, dropping %d in sorted order", |
| - c.Host, len(prefixes), MaxPathsPerClaim, len(prefixes)-MaxPathsPerClaim) |
| - prefixes = prefixes[:MaxPathsPerClaim] |
| - } |
| - // Unresolved targets are counted and named ONCE per host per |
| - // pass, not logged per prefix: this pass runs every ~2s on |
| - // every box, and a 10k-entry map whose targets are all |
| - // elsewhere would otherwise write 10k lines every two |
| - // seconds. The count is the operator's signal; the first few |
| - // names are enough to identify which map is wrong. |
| - unresolved := 0 |
| - var unresolvedEg []string |
| - for _, prefix := range prefixes { |
| - target := c.Paths[prefix] |
| - if !validPathPrefix(prefix) { |
| - log.Printf("domains: path %s/%s refused: not a bare path segment", c.Host, prefix) |
| - continue |
| - } |
| - if strings.HasSuffix(target, sidecarSuffix) { |
| - // The sharper half of the same refusal, and the one |
| - // the account check above cannot make: a sidecar is |
| - // the claim's OWN account's, so pointing a prefix at |
| - // it passes every tenancy rule this block has. It |
| - // must still be refused, because the target is the |
| - // one field here that becomes a proxied upstream — |
| - // this is the door through which an account could |
| - // dial its own undialable member. |
| - log.Printf("domains: path %s/%s refused: target %s is under the reserved sidecar suffix — nothing routes to a sidecar", |
| - c.Host, prefix, target) |
| - continue |
| - } |
| - tgtRt, ok := byHost[target] |
| - // The authorization rule this feature adds: a prefix must |
| - // never point another tenant's traffic at your backend. |
| - // Account only — an account routing between its own apps |
| - // (classic and Go ARE two apps) is the whole use case. |
| - // Checked before readiness so a cross-tenant target is |
| - // named as cross-tenant rather than swept into the |
| - // unresolved count below. |
| - if ok && release.RouteAccount(tgtRt) != c.Account { |
| - log.Printf("domains: path %s/%s refused: target %s belongs to %s, claim says %s", |
| - c.Host, prefix, target, release.RouteAccount(tgtRt), c.Account) |
| - continue |
| - } |
| - if !ok || tgtRt.Status != "ready" { |
| - // The target is not a local READY route, which has |
| - // three distinct causes with three different |
| - // remedies, and the log below cannot tell them apart |
| - // from here: |
| - // |
| - // 1. The target route does not exist anywhere — a |
| - // typo in the published map, or a route deleted |
| - // out from under it. Remedy: fix the map, or |
| - // re-create the route. |
| - // 2. The target exists but is HOMED ON ANOTHER BOX. |
| - // byHost holds this box's routes only, and there |
| - // is no backhaul equivalent for a path target |
| - // (backhaul fires on a HOST miss), so nothing |
| - // derives the row anywhere. Remedy: co-locate — |
| - // a prefix's target must be homed on the same box |
| - // as the hostname's own route (design spec §6). |
| - // 3. The target is local but not ready yet — a |
| - // route mid-provision. Self-resolving; the row |
| - // appears on the pass after it goes ready. |
| - // |
| - // No row either way, so the prefix falls through to |
| - // the host's own route — the right failure direction |
| - // for a migration: a missing destination serves the |
| - // ORIGIN, never a 404. Silent traffic is the danger |
| - // here, not broken traffic, which is why this is |
| - // logged at all. |
| - unresolved++ |
| - if len(unresolvedEg) < 3 && !slices.Contains(unresolvedEg, target) { |
| - unresolvedEg = append(unresolvedEg, target) |
| - } |
| - continue |
| - } |
| - desiredPaths.add(registry.RoutePath{ |
| - Host: c.Host, Prefix: prefix, Target: target, |
| - Account: c.Account, App: c.App, |
| - }) |
| - } |
| - if unresolved > 0 { |
| - log.Printf("domains: paths on %s: %d prefix(es) name no local ready route (e.g. %s) — the target is missing, or it is homed on another box; a path target must be homed on the SAME box as %s. Those prefixes serve %s's own route.", |
| - c.Host, unresolved, strings.Join(unresolvedEg, ", "), c.Host, c.Host) |
| - } |
| - } |
| + derivePaths(c, byHost, desiredPaths) |
| } |
| // Wildcard/catch-all derivation. A claim with Catchall but not |
| @@ -1128,3 +1000,120 @@ func deriveHAIngressAliases(c Claim, local map[string]registry.Route, deployment |
| add("*." + c.Host) |
| } |
| } |
| + |
| +// derivePaths adds a claim's route_paths rows to desired. A claim's Paths |
| +// map splits its own hostname's traffic by leading URL segment; each entry |
| +// names the hostname of the route that serves that segment. |
| +// |
| +// Every box derives every path-routed host's rows (spec §5.1), so a request |
| +// for the host on any box can select a prefix whose target is homed on any |
| +// box. Each end is checked here only where this box can see it: |
| +// |
| +// - The host: if it is a local route, its tenancy must match the claim, |
| +// the same rule the alias half follows. If it is not, the rows are |
| +// still derived; the host's route owner is checked at request time |
| +// (§5.3). |
| +// - A target: if it is a local route, today's checks stand: another |
| +// account's route is refused, and one that is not ready derives |
| +// nothing. Any kind passes, a service included; registry.PathTarget is |
| +// the cross-box rule and is never applied here (global constraints: |
| +// two eligibility rules, never mixed). A target that is not local |
| +// derives its row, and the edge checks it at request time (§5.3). |
| +// |
| +// The sidecar-suffix refusals and the cap stand on both kinds of box. |
| +func derivePaths(c Claim, byHost map[string]registry.Route, desired *pathSet) { |
| + if strings.HasSuffix(c.Host, sidecarSuffix) { |
| + // The alias half's refusal, for the table path-based |
| + // routing added afterwards. A route_paths row keyed on a |
| + // reserved-suffix hostname is the same mistake in a |
| + // different table: it inserts a sidecar's name into the |
| + // edge's routing map, and edge.go's Kind check never sees |
| + // it because the row it reads is a path row, not a |
| + // Kind=="sidecar" route. |
| + log.Printf("domains: paths on %s refused: reserved sidecar suffix", c.Host) |
| + return |
| + } |
| + if hostRt, ok := byHost[c.Host]; ok && (hostRt.App != c.App || release.RouteAccount(hostRt) != c.Account) { |
| + log.Printf("domains: paths on %s refused: route belongs to %s/%s, claim says %s/%s", |
| + c.Host, release.RouteAccount(hostRt), hostRt.App, c.Account, c.App) |
| + return |
| + } |
| + // Sorted so the cap below truncates DETERMINISTICALLY: every box |
| + // derives this host's rows, and every box must derive the identical |
| + // subset, or the same URL would resolve differently depending on which |
| + // edge answered. |
| + prefixes := make([]string, 0, len(c.Paths)) |
| + for p := range c.Paths { |
| + prefixes = append(prefixes, p) |
| + } |
| + sort.Strings(prefixes) |
| + if len(prefixes) > MaxPathsPerClaim { |
| + log.Printf("domains: paths on %s: %d prefixes exceeds the cap of %d, dropping %d in sorted order", |
| + c.Host, len(prefixes), MaxPathsPerClaim, len(prefixes)-MaxPathsPerClaim) |
| + prefixes = prefixes[:MaxPathsPerClaim] |
| + } |
| + // Unresolved targets are counted and named ONCE per host per pass, not |
| + // logged per prefix: this pass runs every ~2s on every box, and a |
| + // 10k-entry map would otherwise write 10k lines every two seconds. The |
| + // count is the operator's signal; the first few names are enough to |
| + // identify which map is wrong. |
| + unresolved := 0 |
| + var unresolvedEg []string |
| + for _, prefix := range prefixes { |
| + target := c.Paths[prefix] |
| + if !validPathPrefix(prefix) { |
| + log.Printf("domains: path %s/%s refused: not a bare path segment", c.Host, prefix) |
| + continue |
| + } |
| + if strings.HasSuffix(target, sidecarSuffix) { |
| + // The sharper half of the same refusal, and the one the |
| + // account check below cannot make: a sidecar is the claim's |
| + // OWN account's, so pointing a prefix at it passes every |
| + // tenancy rule this function has. It must still be refused, |
| + // because the target is the one field here that becomes a |
| + // proxied upstream — this is the door through which an |
| + // account could dial its own undialable member. Refused by |
| + // name, so a box that does not hold the sidecar refuses it |
| + // too. |
| + log.Printf("domains: path %s/%s refused: target %s is under the reserved sidecar suffix — nothing routes to a sidecar", |
| + c.Host, prefix, target) |
| + continue |
| + } |
| + if tgtRt, local := byHost[target]; local { |
| + // The authorization rule this feature adds: a prefix must |
| + // never point another tenant's traffic at your backend. |
| + // Account only — an account routing between its own apps |
| + // (classic and Go ARE two apps) is the whole use case. |
| + // Checked before readiness so a cross-tenant target is named |
| + // as cross-tenant rather than swept into the unresolved count |
| + // below. |
| + if release.RouteAccount(tgtRt) != c.Account { |
| + log.Printf("domains: path %s/%s refused: target %s belongs to %s, claim says %s", |
| + c.Host, prefix, target, release.RouteAccount(tgtRt), c.Account) |
| + continue |
| + } |
| + if tgtRt.Status != "ready" { |
| + // A local route mid-provision. Self-resolving: the row |
| + // appears on the pass after it goes ready. Until then the |
| + // prefix falls through to the host's own route — the right |
| + // failure direction for a migration: a missing destination |
| + // serves the ORIGIN, never a 404. Silent traffic is the |
| + // danger here, not broken traffic, which is why this is |
| + // logged at all. |
| + unresolved++ |
| + if len(unresolvedEg) < 3 && !slices.Contains(unresolvedEg, target) { |
| + unresolvedEg = append(unresolvedEg, target) |
| + } |
| + continue |
| + } |
| + } |
| + desired.add(registry.RoutePath{ |
| + Host: c.Host, Prefix: prefix, Target: target, |
| + Account: c.Account, App: c.App, |
| + }) |
| + } |
| + if unresolved > 0 { |
| + log.Printf("domains: paths on %s: %d prefix(es) name a local route that is not ready (e.g. %s). Those prefixes serve %s's own route.", |
| + c.Host, unresolved, strings.Join(unresolvedEg, ", "), c.Host) |
| + } |
| +} |
diff --git a/internal/domains/aliases_paths_test.go b/internal/domains/aliases_paths_test.go| index 8cc76afb1..923a3849e 100644 |
| --- a/internal/domains/aliases_paths_test.go |
| +++ b/internal/domains/aliases_paths_test.go |
| @@ -108,11 +108,12 @@ func TestReconcileRefusesCrossTenantTarget(t *testing.T) { |
| } |
| } |
| -// TestReconcileSkipsUnknownTarget: a target that is not a local route yields |
| -// no row, so the prefix falls through to the host's own route. That is the |
| -// correct failure direction for a migration — a missing Go route serves |
| -// classic rather than 404ing. |
| -func TestReconcileSkipsUnknownTarget(t *testing.T) { |
| +// TestReconcileDerivesNonLocalTarget: a target that is not a route on this |
| +// box still derives its row (spec §5.1). The target may be homed on another |
| +// box, and the edge checks it at request time (§5.3): a target that turns out |
| +// to exist nowhere, or not to be eligible, falls through to the host's own |
| +// route there, the same failure direction as before. |
| +func TestReconcileDerivesNonLocalTarget(t *testing.T) { |
| ctx := context.Background() |
| s := release.NewDirStore(t.TempDir()) |
| reg := aliasRegWith(t) |
| @@ -126,30 +127,98 @@ func TestReconcileSkipsUnknownTarget(t *testing.T) { |
| if err := ReconcileAliases(ctx, s, reg, aliasNow(), nil, nil); err != nil { |
| t.Fatal(err) |
| } |
| - if got := pathsByPrefix(t, reg, "ti.to"); len(got) != 0 { |
| - t.Fatalf("route_paths = %v, want no row for a target that is not a local route", got) |
| + if got := pathsByPrefix(t, reg, "ti.to"); len(got) != 1 || got["paulca"] != "not-deployed-here.example" { |
| + t.Fatalf("route_paths = %v, want paulca -> not-deployed-here.example", got) |
| } |
| } |
| -// TestReconcileSkipsWhenClaimHostIsNotALocalRoute: the prefix map belongs to |
| -// the hostname's own route. If that route lives on another box, this box |
| -// derives nothing — the same per-box rule the alias half already follows. |
| -func TestReconcileSkipsWhenClaimHostIsNotALocalRoute(t *testing.T) { |
| +// TestReconcileDerivesRowsForNonLocalHost: every box derives the rows for |
| +// every path-routed host, not only the box serving the host (spec §5.1), so |
| +// a request for the host on any box can select its prefix. The rows carry |
| +// the claim's account and app; the host's route owner is checked at request |
| +// time (§5.3). A local target in the same claim still passes today's checks. |
| +func TestReconcileDerivesRowsForNonLocalHost(t *testing.T) { |
| ctx := context.Background() |
| s := release.NewDirStore(t.TempDir()) |
| reg := aliasRegWith(t) |
| - addRoute(t, reg, "go.tito.io", "tito", "classic") |
| + addRoute(t, reg, "go.tito.io", "tito", "go") |
| putClaim(t, s, Claim{ |
| Host: "ti.to", Account: "tito", App: "classic", Route: "ti.to", |
| CreatedAt: "2026-09-03T00:00:00Z", |
| - Paths: map[string]string{"paulca": "go.tito.io"}, |
| + Paths: map[string]string{"paulca": "go.tito.io", "bigcorp": "elsewhere.example"}, |
| }) |
| if err := ReconcileAliases(ctx, s, reg, aliasNow(), nil, nil); err != nil { |
| t.Fatal(err) |
| } |
| - if got := pathsByPrefix(t, reg, "ti.to"); len(got) != 0 { |
| - t.Fatalf("route_paths = %v, want nothing — ti.to is not a route on this box", got) |
| + rows, err := reg.ListPaths() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + want := map[string]string{"bigcorp": "elsewhere.example", "paulca": "go.tito.io"} |
| + if len(rows) != len(want) { |
| + t.Fatalf("route_paths = %+v, want %v on ti.to", rows, want) |
| + } |
| + for _, p := range rows { |
| + if p.Host != "ti.to" || want[p.Prefix] != p.Target || p.Account != "tito" || p.App != "classic" { |
| + t.Fatalf("route_paths row %+v, want host ti.to, %v, account tito, app classic", p, want) |
| + } |
| + } |
| +} |
| + |
| +// TestReconcileNonLocalHostKeepsLocalTargetChecks: deriving for a host this |
| +// box does not serve does not relax the checks on a target it does serve. A |
| +// local target of another account is refused and a local target that is not |
| +// ready derives nothing, exactly as for a local host. |
| +func TestReconcileNonLocalHostKeepsLocalTargetChecks(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + reg := aliasRegWith(t) |
| + addRoute(t, reg, "victim.example", "someone-else", "their-app") |
| + if err := reg.Upsert(registry.Route{ |
| + Host: "go.tito.io", App: "go", Account: "tito", Kind: "instance", Status: "provisioning", |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + putClaim(t, s, Claim{ |
| + Host: "ti.to", Account: "tito", App: "classic", Route: "ti.to", |
| + CreatedAt: "2026-09-03T00:00:00Z", |
| + Paths: map[string]string{"evil": "victim.example", "paulca": "go.tito.io", "acme": "elsewhere.example"}, |
| + }) |
| + |
| + if err := ReconcileAliases(ctx, s, reg, aliasNow(), nil, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := pathsByPrefix(t, reg, "ti.to"); len(got) != 1 || got["acme"] != "elsewhere.example" { |
| + t.Fatalf("route_paths = %v, want only acme -> elsewhere.example: a local target keeps its account and readiness checks", got) |
| + } |
| +} |
| + |
| +// TestReconcileKeepsLocalServiceTarget: the local target checks are today's, |
| +// kind-blind ones, not registry.PathTarget's. A ready same-account route of |
| +// any kind, a service included, keeps its row (global constraints: two |
| +// eligibility rules, never mixed). |
| +func TestReconcileKeepsLocalServiceTarget(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + reg := aliasRegWith(t) |
| + addRoute(t, reg, "ti.to", "tito", "classic") |
| + if err := reg.Upsert(registry.Route{ |
| + Host: "api.tito.io", App: "api", Account: "tito", Kind: "service", Status: "ready", |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + putClaim(t, s, Claim{ |
| + Host: "ti.to", Account: "tito", App: "classic", Route: "ti.to", |
| + CreatedAt: "2026-09-03T00:00:00Z", |
| + Paths: map[string]string{"api": "api.tito.io"}, |
| + }) |
| + |
| + if err := ReconcileAliases(ctx, s, reg, aliasNow(), nil, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := pathsByPrefix(t, reg, "ti.to"); got["api"] != "api.tito.io" { |
| + t.Fatalf("route_paths = %v, want api -> api.tito.io: a ready local service target keeps working", got) |
| } |
| } |
| @@ -196,6 +265,51 @@ func TestReconcileCapsPathRows(t *testing.T) { |
| } |
| } |
| +// TestReconcileCapIdenticalForNonLocalHost: every box now derives every |
| +// host's rows, so every box must truncate an over-cap map to the SAME |
| +// subset whether or not it serves the host or the targets. A box serving |
| +// both and a box serving neither derive identical rows. |
| +func TestReconcileCapIdenticalForNonLocalHost(t *testing.T) { |
| + ctx := context.Background() |
| + big := make(map[string]string, MaxPathsPerClaim+10) |
| + for i := 0; i < MaxPathsPerClaim+10; i++ { |
| + big["acct"+strconv.Itoa(i)] = "go.tito.io" |
| + } |
| + derive := func(local bool) []registry.RoutePath { |
| + s := release.NewDirStore(t.TempDir()) |
| + reg := aliasRegWith(t) |
| + if local { |
| + addRoute(t, reg, "ti.to", "tito", "classic") |
| + addRoute(t, reg, "go.tito.io", "tito", "go") |
| + } |
| + putClaim(t, s, Claim{ |
| + Host: "ti.to", Account: "tito", App: "classic", Route: "ti.to", |
| + CreatedAt: "2026-09-03T00:00:00Z", |
| + Paths: big, |
| + }) |
| + if err := ReconcileAliases(ctx, s, reg, aliasNow(), nil, nil); err != nil { |
| + t.Fatal(err) |
| + } |
| + rows, err := reg.ListPaths() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return rows |
| + } |
| + local, remote := derive(true), derive(false) |
| + if len(remote) != MaxPathsPerClaim { |
| + t.Fatalf("box serving neither end derived %d rows, want the cap of %d", len(remote), MaxPathsPerClaim) |
| + } |
| + if len(local) != len(remote) { |
| + t.Fatalf("box serving both ends derived %d rows, box serving neither %d: every box must truncate identically", len(local), len(remote)) |
| + } |
| + for i := range local { |
| + if local[i] != remote[i] { |
| + t.Fatalf("row %d differs: serving box %+v, other box %+v; every box must truncate identically", i, local[i], remote[i]) |
| + } |
| + } |
| +} |
| + |
| // TestReconcileSkipsUnreadyTarget: a target route that exists on this box but |
| // is not ready yet contributes no row (design spec §4, "a target that is not |
| // a local READY route contributes no row"). The edge filters unready routes |
| @@ -227,25 +341,33 @@ func TestReconcileSkipsUnreadyTarget(t *testing.T) { |
| } |
| } |
| -// TestReconcileLogsUnresolvedTargetsOncePerHost is the critical-silence fix. |
| -// A target homed on ANOTHER BOX is the likeliest real-world refusal in this |
| -// feature — `ti.to` and `go.tito.io` are two very different apps — and it |
| -// used to be the ONLY refusal in the path block that said nothing at all, so |
| -// a migration could be published, accepted, and never route, forever, with |
| -// no signal. It must log; and because this pass runs every ~2s against a map |
| -// that may hold 10k entries, it must log ONE line per host per pass. |
| +// TestReconcileLogsUnresolvedTargetsOncePerHost: a prefix whose target is a |
| +// local route that is not ready yet serves the host's own route, silently, |
| +// so it must log; and because this pass runs every ~2s against a map that |
| +// may hold 10k entries, it must log ONE line per host per pass. A target |
| +// that is not local is no longer unresolved here (spec §5.1): it derives its |
| +// row and the edge checks it, so it is neither counted nor named, and the |
| +// old "must be homed on the SAME box" advice is gone. |
| func TestReconcileLogsUnresolvedTargetsOncePerHost(t *testing.T) { |
| ctx := context.Background() |
| s := release.NewDirStore(t.TempDir()) |
| reg := aliasRegWith(t) |
| addRoute(t, reg, "ti.to", "tito", "classic") |
| + for _, h := range []string{"go.tito.io", "beta.tito.io"} { |
| + if err := reg.Upsert(registry.Route{ |
| + Host: h, App: "go", Account: "tito", Kind: "instance", Status: "provisioning", |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| putClaim(t, s, Claim{ |
| Host: "ti.to", Account: "tito", App: "classic", Route: "ti.to", |
| CreatedAt: "2026-09-03T00:00:00Z", |
| Paths: map[string]string{ |
| - "paulca": "elsewhere.example", |
| - "bigcorp": "elsewhere.example", |
| - "acme": "also-elsewhere.example", |
| + "paulca": "go.tito.io", |
| + "bigcorp": "go.tito.io", |
| + "acme": "beta.tito.io", |
| + "remote": "elsewhere.example", |
| }, |
| }) |
| @@ -259,14 +381,21 @@ func TestReconcileLogsUnresolvedTargetsOncePerHost(t *testing.T) { |
| log.SetOutput(old) |
| out := buf.String() |
| - if n := strings.Count(out, "name no local ready route"); n != 1 { |
| + if n := strings.Count(out, "name a local route that is not ready"); n != 1 { |
| t.Fatalf("logged the unresolved-target line %d times, want exactly one per host per pass:\n%s", n, out) |
| } |
| - for _, want := range []string{"ti.to", "3 prefix(es)", "elsewhere.example", "homed on another box"} { |
| - if !strings.Contains(out, want) { |
| - t.Fatalf("unresolved-target log is missing %q:\n%s", want, out) |
| + want := "domains: paths on ti.to: 3 prefix(es) name a local route that is not ready (e.g. beta.tito.io, go.tito.io). Those prefixes serve ti.to's own route." |
| + if !strings.Contains(out, want) { |
| + t.Fatalf("unresolved-target log, want the line %q:\n%s", want, out) |
| + } |
| + for _, gone := range []string{"elsewhere.example", "SAME box", "homed on another box"} { |
| + if strings.Contains(out, gone) { |
| + t.Fatalf("unresolved-target log still carries %q:\n%s", gone, out) |
| } |
| } |
| + if got := pathsByPrefix(t, reg, "ti.to"); len(got) != 1 || got["remote"] != "elsewhere.example" { |
| + t.Fatalf("route_paths = %v, want only remote -> elsewhere.example", got) |
| + } |
| } |
| // --- the reserved sidecar suffix, at path routing's own door ---------------- |
diff --git a/internal/domains/paths_cost_test.go b/internal/domains/paths_cost_test.go| index 2f4d6625e..23a031de8 100644 |
| --- a/internal/domains/paths_cost_test.go |
| +++ b/internal/domains/paths_cost_test.go |
| @@ -142,19 +142,18 @@ const pathCostPrefixes = 10_000 |
| // spread over, round-robin. |
| const pathCostTargets = 10 |
| -// pathCostLocal is the placement the benchmarks run with. Until Task 3 the |
| -// reconcile pass derives rows only for a front route and ready targets on |
| -// this box, so the workload must be local to survive the code under test; |
| -// Task 3 flips this to false. |
| -const pathCostLocal = true |
| +// pathCostLocal is the placement the benchmarks run with. Every box derives |
| +// every path-routed host's rows (spec §5.1), and the box serving neither the |
| +// fronts nor the targets is the common case once every box holds every map, |
| +// so the workload is non-local. |
| +const pathCostLocal = false |
| func pathCostFront(i int) string { return fmt.Sprintf("front-%d.example.com", i) } |
| func pathCostTarget(i, j int) string { return fmt.Sprintf("target-%d-%d.example.com", i, j) } |
| // pathCostRoutes writes the route rows of a hosts-wide workload into reg. |
| // With local false it writes none: the fronts and targets are homed on other |
| -// boxes, and the task that switches the workload supplies whatever marks them |
| -// served elsewhere. |
| +// boxes, and the reconcile pass derives their rows without seeing them. |
| func pathCostRoutes(tb testing.TB, reg *registry.Registry, hosts int, local bool) { |
| tb.Helper() |
| if !local { |
| @@ -243,8 +242,9 @@ func pathCostWantRows(b *testing.B, reg *registry.Registry, hosts int) { |
| // table. |
| func BenchmarkReconcilePathSection(b *testing.B) { |
| ctx := context.Background() |
| - // The pass logs one line per front host per pass ("a real route owns |
| - // that host"); at five passes per run that is noise, not signal. |
| + // With a local workload the pass logs one line per front host per pass |
| + // ("a real route owns that host"); at five passes per run that is |
| + // noise, not signal. |
| prev := log.Writer() |
| log.SetOutput(io.Discard) |
| b.Cleanup(func() { log.SetOutput(prev) }) |