Fleet public routes Task 3 C01 fix round 1: C01 first, and on every write race
Astra's review of the FPR-C01 step (2 P2): - FPR-C01 takes precedence on a forward target. runAdd reads the row as soon as the host is known and refuses a forward one before addRail, the regional-domain claim read and the flag checks. runRoute opens the registry once the --host/--app selector resolves and refuses a forward target there (refuseForwardTargets), before every flag, value and row check; an --app batch is refused whole before its collection's skip diagnostics and suffixRail. - Every ErrForwardRow refusal answers FPR-C01: the single-axis writes of runRouteGrant, runRouteHibernate, runRouteBacking, runRouteUnit and runRouteReplication go through refuseForwardWrite. Tests: precedence cases in TestForwardHostRefusedByTheCLI (each a forward host plus an input another check would refuse, a stored regional claim included), and TestRouteSingleAxisWriteRaceAnswersC01 (one re-executed child per axis, the row turned forward between its read and its write). Record-write census: runRoute and runRouteHibernate re-pinned. Spec §7 lists the root units.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+315
−73
cli.go+79 −38docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md+25 −15forward_cli_race_test.go+100 −0forward_cli_test.go+96 −18internal/provision/fleet_public_routes_census_test.go+15 −2
Intent
Attributed to this commit: 23.8 g CO₂e (3,056,552 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-public-routes, 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/cli.go b/cli.go| index 213d1c230..eed6c7e8f 100644 |
| --- a/cli.go |
| +++ b/cli.go |
| @@ -129,6 +129,37 @@ func refuseForwardWrite(r *registry.Registry, host string, err error) error { |
| return err |
| } |
| +// refuseForwardTargets refuses a carlos route invocation whose target is a |
| +// forward row, before any other check: the --host row, or, for an --app |
| +// batch, every row the batch selects (app and account filter), FPR-C01 for |
| +// each forward one and the whole batch refused. |
| +func refuseForwardTargets(r *registry.Registry, host, app string, account func() string) { |
| + if host != "" { |
| + rt, err := r.Get(host) |
| + if err != nil { |
| + log.Fatal(err) |
| + } |
| + refuseForwardRoute(rt) |
| + return |
| + } |
| + routes, err := r.List() |
| + if err != nil { |
| + log.Fatal(err) |
| + } |
| + want := account() |
| + refused := false |
| + for _, rt := range routes { |
| + if rt.App != app || !rt.IsForward() || (want != "" && release.RouteAccount(rt) != want) { |
| + continue |
| + } |
| + fmt.Fprintln(os.Stderr, forwardRouteRefusal(rt)) |
| + refused = true |
| + } |
| + if refused { |
| + os.Exit(1) |
| + } |
| +} |
| + |
| // refuseForwardBatch is refuseForwardWrite for a batch write: the registry |
| // refused it whole, so FPR-C01 names whichever host is now a forward row. |
| func refuseForwardBatch(r *registry.Registry, hosts []string, err error) { |
| @@ -256,6 +287,19 @@ func runAdd(args []string) { |
| log.Fatal("usage: carlos add [flags] <host>") |
| } |
| host := fs.Arg(0) |
| + // A forward row is refused before every other check (fleet public routes |
| + // spec §4.2): FPR-C01 takes precedence on a forward target. The row read |
| + // here is also the one the checks below validate the resulting row |
| + // against. |
| + r, err := registry.Open(*reg) |
| + if err != nil { |
| + log.Fatal(err) |
| + } |
| + existing, err := r.Get(host) |
| + if err != nil { |
| + log.Fatal(err) |
| + } |
| + refuseForwardRoute(existing) |
| if err := addRail(host, *kind); err != nil { |
| log.Fatalf("add %s: %v", host, err) |
| } |
| @@ -299,23 +343,13 @@ func runAdd(args []string) { |
| log.Fatalf("add %s: --backing unit with --unit %s: a unit-backed route's process is the carlos-app@%s unit the platform derives and already restarts, "+ |
| "so a second unit name here would be two answers to one question — drop one of the two flags", host, *unit, host) |
| } |
| - // Opened here, before the default-socket and flag-combination guards |
| - // below, so both validate the ROW THAT WOULD RESULT rather than the raw |
| - // flags on this invocation: a bare re-add of an existing stamped route |
| - // (e.g. `carlos add -app relay -channel edge relay.example.com`, no |
| - // --unit) still names a unit via the existing row, and must not slip |
| - // past the guards that exist to keep a stamped row in StampShape. |
| - r, err := registry.Open(*reg) |
| - if err != nil { |
| - log.Fatal(err) |
| - } |
| - existing, err := r.Get(host) |
| - if err != nil { |
| - log.Fatal(err) |
| - } |
| - // A forward row is refused before any check that reads the row |
| - // (fleet public routes spec §4.2): FPR-C01. |
| - refuseForwardRoute(existing) |
| + // The row read at the top (existing), before the default-socket and |
| + // flag-combination guards below, so both validate the ROW THAT WOULD |
| + // RESULT rather than the raw flags on this invocation: a bare re-add of |
| + // an existing stamped route (e.g. `carlos add -app relay -channel edge |
| + // relay.example.com`, no --unit) still names a unit via the existing row, |
| + // and must not slip past the guards that exist to keep a stamped row in |
| + // StampShape. |
| effectiveUnit := *unit |
| if effectiveUnit == "" && existing != nil { |
| effectiveUnit = existing.Unit |
| @@ -833,6 +867,28 @@ func runRoute(args []string) { |
| if *host != "" && *app != "" { |
| log.Fatal("route: --host and --app are mutually exclusive — name the one route, or the app whose routes to move\n\n" + usage) |
| } |
| + r, err := registry.Open(*regPath) |
| + if err != nil { |
| + log.Fatal(err) |
| + } |
| + defer r.Close() |
| + // --account-id supersedes --account here as everywhere, including over |
| + // the "all" escape hatch: someone who names one account by its sqid |
| + // means that account, not every account, whatever --account happens to |
| + // still hold from a script's defaults. |
| + appAccount := func() string { |
| + if strings.TrimSpace(*acctIDFilter) != "" { |
| + return resolveAccount(*regPath, "", *acctIDFilter) |
| + } |
| + if !strings.EqualFold(*acctFilter, "all") { |
| + return resolveAccount(*regPath, *acctFilter, "") |
| + } |
| + return "" |
| + } |
| + // A forward target is refused before every other check, as soon as the |
| + // selector resolves (fleet public routes spec §4.2): the --host row, or |
| + // every row an --app batch selects, the whole batch refused. |
| + refuseForwardTargets(r, *host, *app, appAccount) |
| // The three single-route axes. Each is ITS OWN operation: a grant change |
| // is not a repoint, and combining two would put two unrelated writes |
| // behind two unrelated rails in one command. --channel and --environment |
| @@ -997,12 +1053,6 @@ func runRoute(args []string) { |
| resolvedTunnel = "" |
| } |
| - r, err := registry.Open(*regPath) |
| - if err != nil { |
| - log.Fatal(err) |
| - } |
| - defer r.Close() |
| - |
| // The single-route axes short-circuit here, before the channel/environment |
| // machinery below: they write one column of one row, through one narrow |
| // setter, and share none of that batch's all-or-nothing plumbing. |
| @@ -1054,16 +1104,7 @@ func runRoute(args []string) { |
| if err != nil { |
| log.Fatal(err) |
| } |
| - // --account-id supersedes --account here as everywhere, including |
| - // over the "all" escape hatch: someone who names one account by |
| - // its sqid means that account, not every account, whatever --account |
| - // happens to still hold from a script's defaults. |
| - var wantAcct string |
| - if strings.TrimSpace(*acctIDFilter) != "" { |
| - wantAcct = resolveAccount(*regPath, "", *acctIDFilter) |
| - } else if !strings.EqualFold(*acctFilter, "all") { |
| - wantAcct = resolveAccount(*regPath, *acctFilter, "") |
| - } |
| + wantAcct := appAccount() |
| var forward []registry.Route |
| for _, rt := range routes { |
| if rt.App != *app { |
| @@ -1552,7 +1593,7 @@ func runRouteGrant(r *registry.Registry, rt registry.Route, grantTok, revokeTok |
| // losing a race against another operator's grant/revoke refuses with |
| // the current value rather than merging a stale read over it. |
| if err := r.SetCaps(rt.Host, rt.Caps, next); err != nil { |
| - log.Fatalf("route: write: %v", err) |
| + log.Fatalf("route: write: %v", refuseForwardWrite(r, rt.Host, err)) |
| } |
| } |
| verb := "granted" |
| @@ -1781,7 +1822,7 @@ func runRouteHibernate(r *registry.Registry, rt registry.Route, on, dryRun bool) |
| } |
| if !dryRun { |
| if err := r.SetHibernate(rt.Host, on); err != nil { |
| - log.Fatalf("route: write: %v", err) |
| + log.Fatalf("route: write: %v", refuseForwardWrite(r, rt.Host, err)) |
| } |
| } |
| fmt.Printf("%s%s: hibernate %v -> %v\n", prefix, rt.Host, rt.Hibernate, on) |
| @@ -1843,7 +1884,7 @@ func runRouteBacking(r *registry.Registry, rt registry.Route, backing string, dr |
| } |
| if !dryRun { |
| if err := r.SetBacking(rt.Host, backing); err != nil { |
| - log.Fatalf("route: write: %v", err) |
| + log.Fatalf("route: write: %v", refuseForwardWrite(r, rt.Host, err)) |
| } |
| } |
| fmt.Printf("%s%s: backing %s -> %s\n", prefix, rt.Host, backingWord(rt.Backing), backingWord(backing)) |
| @@ -1934,7 +1975,7 @@ func runRouteUnit(r *registry.Registry, rt registry.Route, unit string, dryRun b |
| } |
| if !dryRun { |
| if err := r.SetUnit(rt.Host, unit); err != nil { |
| - log.Fatalf("route: write: %v", err) |
| + log.Fatalf("route: write: %v", refuseForwardWrite(r, rt.Host, err)) |
| } |
| } |
| fmt.Printf("%s%s: unit %s -> %s\n", prefix, rt.Host, unitWord(rt.Unit), unitWord(unit)) |
| @@ -2040,7 +2081,7 @@ func runRouteReplication(r *registry.Registry, rt registry.Route, class string, |
| } |
| if !dryRun { |
| if err := r.SetReplication(rt.Host, class); err != nil { |
| - log.Fatalf("route: write: %v", err) |
| + log.Fatalf("route: write: %v", refuseForwardWrite(r, rt.Host, err)) |
| } |
| } |
| fmt.Printf("%s%s: replication %s -> %s\n", prefix, rt.Host, replicationWord(rt.Replication), replicationWord(class)) |
diff --git a/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md b/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md| index d5494548d..6e1d0dde3 100644 |
| --- a/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md |
| +++ b/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md |
| @@ -894,20 +894,28 @@ Units, by file (N = new, R = removed, otherwise a changed body or sites): |
| `forwardAt` (`forward.go`, N, `+file:QueryRow`) is a new unit the list |
| did not name: the one `SELECT kind` every guarded writer uses. |
| `noRoute` (`forward.go`) has no read site and moves only the envelope. |
| - The root package (Task 3's FPR-C01 step, after copy approval): `runAdd` |
| - (`sites`, `+whole:Route`: the forward check on the row it read, first |
| - of every check on that row), `runRemove` (`reads`, `+whole:Route`: a |
| - `Get` and the forward check before `Delete`), `runRoute` (`sites`, |
| - `+registry:Host`, `+whole:Route` x9: the check first on both `--host` |
| - branches, before `suffixRail` and the record-owned channel rail, and an |
| - `--app` batch holding a forward row refused whole before any rail or |
| - write); three new units in `cli.go`: `forwardRouteRefusal` (N, |
| - `+registry:App`, `+registry:Host`, `+registry:Region`: FPR-C01's |
| - three values), `refuseForwardRoute` (N, `+whole:Route` x2) and |
| - `refuseForwardWrite` (N, `+whole:Route`: a write the registry refused |
| - with `ErrForwardRow` reads the row again for FPR-C01). |
| - `refuseForwardBatch` has no read site. The root envelope `.` re-pins. |
| - All of these only read an agent-written row to refuse; none writes. |
| + The root package (Task 3's FPR-C01 step and its fix round 1): FPR-C01 |
| + takes precedence on a forward target. `runAdd` (`sites`, |
| + `+whole:Route`: it reads the row as soon as the host is known and |
| + refuses a forward one before every other check, the regional-domain |
| + claim read and the flag checks included); `runRemove` (`reads`, |
| + `+whole:Route`: a `Get` and the forward check before `Delete`); |
| + `runRoute` (`sites`, `+registry:Host`, `+whole:Route` x9: it opens the |
| + registry once the `--host`/`--app` selector resolves and calls |
| + `refuseForwardTargets` before every flag, value and row check, the |
| + `--app` batch's collection, skip diagnostics and `suffixRail` |
| + included); `runRouteGrant`, `runRouteHibernate`, `runRouteBacking`, |
| + `runRouteUnit`, `runRouteReplication` (`sites`, `+registry:Host` each: |
| + the write error goes through `refuseForwardWrite`, so a forward row |
| + that took the host after the read also answers FPR-C01). New units in |
| + `cli.go`: `forwardRouteRefusal` (N, `+registry:App`, `+registry:Host`, |
| + `+registry:Region`: FPR-C01's three values), `refuseForwardRoute` (N, |
| + `+whole:Route` x2), `refuseForwardWrite` (N, `+whole:Route`: reads the |
| + row again for FPR-C01) and `refuseForwardTargets` (N, `+registry:App`, |
| + `+whole:Route` x4: the `--host` row or every row the `--app` batch |
| + selects). `refuseForwardBatch` has no read site. The root envelope `.` |
| + re-pins. All of these only read an agent-written row to refuse; none |
| + writes. |
| - `internal/registry/forward.go` (a new file; the plan puts the forward |
| row's writers here rather than in `registry.go`): `Registry.SetFleetBoxIf` |
| (N, Task 1). Task 1's card shows it with `+file:Exec`, |
| @@ -1038,7 +1046,9 @@ They are not outside the record-write census, which pins by digest |
| `key:RecordKey`, class and kinds unchanged: the forward refusals; the |
| journal row and its record key are written as before). Task 3's C01 |
| step re-pins `cli.go` `runRoute` there (key-site, `lit:instances`, |
| -unchanged: FPR-C01 first; `runAdd` and `runRemove` are not 9B8 units); Task 10 `reconcile.go` `Reconcile`; |
| +unchanged: FPR-C01 first; `runAdd` and `runRemove` are not 9B8 units), |
| +and its fix round 1 re-pins `runRoute` again and `runRouteHibernate` |
| +(key-site, `key:SidecarManifestKey`, unchanged: the write-race mapping); Task 10 `reconcile.go` `Reconcile`; |
| Task 11 `fleets.go` `Server.placeAppTarget` and `apiinstances.go` |
| `Server.handleAPIInstanceList`. |
diff --git a/forward_cli_race_test.go b/forward_cli_race_test.go| new file mode 100644 |
| index 000000000..55ad068b5 |
| --- /dev/null |
| +++ b/forward_cli_race_test.go |
| @@ -0,0 +1,100 @@ |
| +package main |
| + |
| +import ( |
| + "errors" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/registry" |
| +) |
| + |
| +// carlos route's single-row axes read the row, run their own checks on it, |
| +// then write. If the hub's forward phase replaces the row with a forward row |
| +// in between, the registry refuses the write with ErrForwardRow, and the |
| +// verb answers FPR-C01 like every other refusal of a forward host (fleet |
| +// public routes spec §4.2). One child per axis helper, each re-executing |
| +// this test binary because the refusal exits the process: the child reads |
| +// the ordinary row, the race turns the host forward, and the helper runs on |
| +// the row it read. |
| +func TestRouteSingleAxisWriteRaceAnswersC01(t *testing.T) { |
| + const host = "shop.example.com" |
| + want := fleetRoutesC01(t, host, "shop", "home") |
| + for _, axis := range []string{"grant", "hibernate", "backing", "unit", "replication"} { |
| + t.Run(axis, func(t *testing.T) { |
| + regPath := filepath.Join(t.TempDir(), "registry.db") |
| + cmd := exec.Command(os.Args[0], "-test.run=^TestRouteAxisRaceHelper$") |
| + cmd.Env = carlosTestEnv(t, "CARLOS_ROUTE_RACE_AXIS="+axis, "CARLOS_ROUTE_RACE_REGISTRY="+regPath, |
| + "CARLOS_DATA_DIR="+t.TempDir()) |
| + cmd.Dir = t.TempDir() |
| + out, err := cmd.CombinedOutput() |
| + var exit *exec.ExitError |
| + if !errors.As(err, &exit) || exit.ExitCode() != 1 { |
| + t.Fatalf("route --%s raced by a forward row: err %v, want exit 1\n%s", axis, err, out) |
| + } |
| + if !strings.Contains(string(out), want) { |
| + t.Fatalf("route --%s raced by a forward row did not answer FPR-C01 %q:\n%s", axis, want, out) |
| + } |
| + reg, err := registry.Open(regPath) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + defer reg.Close() |
| + if got, err := reg.Get(host); err != nil || got == nil || !got.InertForward() { |
| + t.Fatalf("the forward row after the refused write: %+v, %v", got, err) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// TestRouteAxisRaceHelper is the child of TestRouteSingleAxisWriteRaceAnswersC01. |
| +func TestRouteAxisRaceHelper(t *testing.T) { |
| + axis, regPath := os.Getenv("CARLOS_ROUTE_RACE_AXIS"), os.Getenv("CARLOS_ROUTE_RACE_REGISTRY") |
| + if axis == "" { |
| + t.Skip("the child of TestRouteSingleAxisWriteRaceAnswersC01") |
| + } |
| + r, err := registry.Open(regPath) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + const host = "shop.example.com" |
| + // An ordinary row the axis below writes: a unit-backed instance holding |
| + // a grant and hibernating, with a database path; --unit wants an |
| + // always-on addr-backed row that is not unit-backed. |
| + row := registry.Route{Host: host, Kind: "instance", App: "shop", Account: "bah", |
| + Addr: "127.0.0.1:9000", Backing: registry.BackingUnit, Caps: "doc-engine", Hibernate: true, |
| + DBPath: "/data/" + host + ".db", Status: "ready"} |
| + if axis == "unit" { |
| + row.Backing, row.Hibernate, row.Caps = "", false, "" |
| + } |
| + if err := r.Upsert(row); err != nil { |
| + t.Fatal(err) |
| + } |
| + rt, err := r.Get(host) |
| + if err != nil || rt == nil { |
| + t.Fatalf("Get = %+v, %v", rt, err) |
| + } |
| + // The race: the host becomes a forward row after the verb read it. |
| + if err := r.Delete(host); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := r.PutForward(registry.Route{Host: host, Kind: registry.KindForward, Slug: "shop", App: "shop", |
| + Account: "bah", Region: registry.PlacementTarget("home"), Channel: "stable"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + switch axis { |
| + case "grant": |
| + runRouteGrant(r, *rt, "", "doc-engine", false) |
| + case "hibernate": |
| + runRouteHibernate(r, *rt, false, false) |
| + case "backing": |
| + runRouteBacking(r, *rt, "", false) |
| + case "unit": |
| + runRouteUnit(r, *rt, "shop.service", false) |
| + case "replication": |
| + runRouteReplication(r, *rt, registry.ReplicationDaily, false) |
| + } |
| + t.Fatalf("route --%s returned instead of refusing", axis) |
| +} |
diff --git a/forward_cli_test.go b/forward_cli_test.go| index e1105b264..d118e6d5b 100644 |
| --- a/forward_cli_test.go |
| +++ b/forward_cli_test.go |
| @@ -1,6 +1,7 @@ |
| package main |
| import ( |
| + "context" |
| "errors" |
| "fmt" |
| "os/exec" |
| @@ -8,7 +9,9 @@ import ( |
| "strings" |
| "testing" |
| + "github.com/carlosframework/platform/internal/domains" |
| "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| ) |
| // A forward row is the hub's forward phase's (fleet public routes spec §4.2): |
| @@ -24,10 +27,16 @@ func TestForwardHostRefusedByTheCLI(t *testing.T) { |
| bin := buildCarlos(t) |
| regPath := filepath.Join(t.TempDir(), "registry.db") |
| scratch := t.TempDir() |
| + var runEnv []string |
| run := func(args ...string) (string, int) { |
| t.Helper() |
| cmd := exec.Command(bin, args...) |
| - cmd.Env = carlosTestEnv(t) |
| + // carlosTestEnv inherits the operator's shell; the deployment |
| + // variables are cleared first, and runEnv (the regional case's |
| + // store) is set after them. |
| + cmd.Env = carlosTestEnv(t, append([]string{ |
| + "CARLOS_DEPLOYMENT_BUCKET=", "CARLOS_DEPLOYMENT_DIR=", "CARLOS_RELEASE_PUBKEY=", |
| + }, runEnv...)...) |
| // pick() walks cwd ancestors for .carlos/config, so the subprocess must not run from the real checkout. |
| cmd.Dir = scratch |
| out, err := cmd.CombinedOutput() |
| @@ -80,17 +89,7 @@ func TestForwardHostRefusedByTheCLI(t *testing.T) { |
| } |
| } |
| - // FPR-C01, as the deck approved it, for the forward host. |
| - var c01 string |
| - for _, row := range mustParseFleetRoutesRecord(t) { |
| - if row.ID == "FPR-C01" { |
| - c01 = fleetRoutesAppliedText(row.Text) |
| - } |
| - } |
| - if c01 == "" { |
| - t.Fatal("the deck has no FPR-C01") |
| - } |
| - want := fmt.Sprintf(c01, host, "shop", "home") |
| + want := fleetRoutesC01(t, host, "shop", "home") |
| // The --app batch: an ordinary row of app shop rides with the forward |
| // one, and an app with no forward row (blog) shows the batch path runs |
| @@ -110,13 +109,43 @@ func TestForwardHostRefusedByTheCLI(t *testing.T) { |
| t.Fatalf("batch of app blog: exit %d, want 1 at the channel check, not C01\n%s", code, out) |
| } |
| - channel := []string{"route", "-registry", regPath, "-host", host, "-channel", "x"} |
| - batch := []string{"route", "-registry", regPath, "-app", "shop", "-account", "all", "-channel", "x"} |
| - // add's unit rail would refuse this flag pair with its own words; the |
| - // forward check comes before it. |
| - unitAdd := []string{"add", "-registry", regPath, "-app", "shop", "-unit", "shop.service", "-socket", "/run/shop.sock", host} |
| - for _, args := range append(verbs(host), channel, batch, unitAdd) { |
| + // A platform-minted row of app shop: the batch's collection would print |
| + // a "skipped" diagnostic for it, and must not before C01. |
| + if err := reg.Upsert(registry.Route{Host: "shop.bah.apps.example.com", Kind: "instance", App: "shop", |
| + Account: "bah", Platform: true, Socket: "/run/carlos/shop-b.example.com.sock"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + |
| + // C01 takes precedence on a forward target: each invocation below also |
| + // carries an input another check would refuse in its own words (named |
| + // beside it), and C01 must come first, with that other refusal absent. |
| + r := func(a ...string) []string { return append([]string{a[0], "-registry", regPath}, a[1:]...) } |
| + cases := []struct { |
| + args []string |
| + other string // the other check's words, which must not appear |
| + }{ |
| + {verbs(host)[0], ""}, |
| + {verbs(host)[1], ""}, |
| + {verbs(host)[2], ""}, |
| + {r("route", "-host", host, "-channel", "x"), "provisioned route"}, |
| + {r("route", "-app", "shop", "-account", "all", "-channel", "x"), "skipped"}, |
| + {r("add", "-app", "shop", "-unit", "shop.service", "-socket", "/run/shop.sock", host), "needs --addr"}, |
| + {r("add", "-app", "shop", "-backing", "bogus", host), "want \"\""}, |
| + {r("add", "-app", "shop", "-kind", "sidecar", host), "does not mint sidecars"}, |
| + {r("route", "-host", host, "-channel", "Not A Channel"), "is not a valid channel"}, |
| + {r("route", "-host", host, "-environment", "default"), "--environment default is refused"}, |
| + {r("route", "-host", host, "-grant", "doc-engine", "-revoke", "doc-engine"), "mutually exclusive"}, |
| + {r("route", "-app", "shop", "-account", "all", "-channel", "Not A Channel"), "is not a valid channel"}, |
| + } |
| + for _, c := range cases { |
| + args := c.args |
| out, code := run(args...) |
| + if c.other != "" && strings.Contains(out, c.other) { |
| + t.Errorf("carlos %v over a forward row: another check (%q) answered before FPR-C01:\n%s", args, c.other, out) |
| + } |
| + if strings.Contains(out, "skipped") { |
| + t.Errorf("carlos %v over a forward row printed a skip diagnostic before FPR-C01:\n%s", args, out) |
| + } |
| if code != 1 { |
| t.Errorf("carlos %v over a forward row: exit %d, want 1\n%s", args, code, out) |
| } |
| @@ -131,4 +160,53 @@ func TestForwardHostRefusedByTheCLI(t *testing.T) { |
| t.Fatalf("carlos %v changed the batch's ordinary row: %+v, %v", args, got, err) |
| } |
| } |
| + |
| + // The regional-domain check reads a stored claim; C01 comes before it. |
| + storeDir := t.TempDir() |
| + _, pubB64, err := release.GenerateKey() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := domains.SetClaimPlacements(context.Background(), release.NewDirStore(storeDir), domains.Claim{ |
| + Schema: 2, Host: host, Account: "bah", App: "shop", Route: "shop-ie.example.net", |
| + CreatedAt: "2026-10-29T00:00:00Z", CreatedBy: "owner@example.com", |
| + Placements: []domains.Placement{{Region: "", Host: "shop-ie.example.net"}, {Region: "uk", Host: "shop-uk.example.net"}}, |
| + }, nil, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + runEnv = []string{"CARLOS_DEPLOYMENT_DIR=" + storeDir, "CARLOS_RELEASE_PUBKEY=" + pubB64} |
| + // Control: an ordinary host under a claim of its own meets the regional |
| + // refusal, so the store is read. |
| + if out, code := run("add", "-registry", regPath, "-app", "shop", "shop-c.example.com"); code != 0 || strings.Contains(out, "regional") { |
| + t.Fatalf("control add without a claim: exit %d\n%s", code, out) |
| + } |
| + if _, err := domains.SetClaimPlacements(context.Background(), release.NewDirStore(storeDir), domains.Claim{ |
| + Schema: 2, Host: "shop-d.example.com", Account: "bah", App: "shop", Route: "shop-ie.example.net", |
| + CreatedAt: "2026-10-29T00:00:00Z", CreatedBy: "owner@example.com", |
| + Placements: []domains.Placement{{Region: "", Host: "shop-ie.example.net"}, {Region: "uk", Host: "shop-uk.example.net"}}, |
| + }, nil, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if out, _ := run("add", "-registry", regPath, "-app", "shop", "shop-d.example.com"); !strings.Contains(out, "belongs to a regional domain") { |
| + t.Fatalf("control: the regional check did not answer for a claimed ordinary host:\n%s", out) |
| + } |
| + out, code := run("add", "-registry", regPath, "-app", "shop", host) |
| + if code != 1 || !strings.Contains(out, want) || strings.Contains(out, "regional") { |
| + t.Errorf("carlos add over a forward row under a regional claim: exit %d, want 1 with FPR-C01 and no regional refusal:\n%s", code, out) |
| + } |
| + if after, err := reg.Get(host); err != nil || after == nil || *after != *before { |
| + t.Fatalf("the regional case changed the forward row: %+v, %v", after, err) |
| + } |
| +} |
| + |
| +// fleetRoutesC01 is FPR-C01 as the deck approved it, filled. |
| +func fleetRoutesC01(t *testing.T, host, app, fleet string) string { |
| + t.Helper() |
| + for _, row := range mustParseFleetRoutesRecord(t) { |
| + if row.ID == "FPR-C01" { |
| + return fmt.Sprintf(fleetRoutesAppliedText(row.Text), host, app, fleet) |
| + } |
| + } |
| + t.Fatal("the deck has no FPR-C01") |
| + return "" |
| } |
diff --git a/internal/provision/fleet_public_routes_census_test.go b/internal/provision/fleet_public_routes_census_test.go| index 971d0a0bc..80c655f18 100644 |
| --- a/internal/provision/fleet_public_routes_census_test.go |
| +++ b/internal/provision/fleet_public_routes_census_test.go |
| @@ -22,13 +22,26 @@ package provision |
| // holds one (the whole batch, before any write); a write the registry |
| // refuses with ErrForwardRow is answered with FPR-C01 too. The instance |
| // record path it names (lit:instances) is unchanged. |
| +// |
| +// Task 3's C01 fix round 1, two re-pins, no new unit: |
| +// - cli.go runRoute (key-site): the forward check moves to the moment the |
| +// selector resolves (refuseForwardTargets), before every flag and value |
| +// check and before the --app batch's collection; the account filter is |
| +// one closure (appAccount) the check and the batch share. The record path |
| +// literal is unchanged. |
| +// - cli.go runRouteHibernate (key-site, key:SidecarManifestKey): its write |
| +// error goes through refuseForwardWrite (FPR-C01 when a forward row took |
| +// the host after the read). The sidecar manifest key it names is |
| +// unchanged. |
| func fleetPublicRoutesWriteCensusInventory() []censusEntry { |
| entries := append([]censusEntry(nil), rootfsFleetFollowupsWriteCensusInventory()...) |
| repins := []censusEntry{ |
| // Task 3: the forward-row refusals; the same journal row and record key. |
| {"internal/registry/importjournal.go", "Registry.SwapForImport", "key-site", "key:RecordKey", "ce455c5e25b3534423b4a7113c8429ce8f57057b04a298abe8f8ca839ccd0162"}, |
| - // Task 3, FPR-C01: the forward refusal first; the same record path literal. |
| - {"cli.go", "runRoute", "key-site", "lit:instances", "2c95f72274284129671cf93653341c33aed1f9b826b6995b0ba7dacbf9b24ac8"}, |
| + // Task 3, FPR-C01 (C01 fix round 1: at the selector, before every check); the same record path literal. |
| + {"cli.go", "runRoute", "key-site", "lit:instances", "1dbcc1f1b43bb4b38d5095de12b72f65e07e1d1ac2cc5035291bced93807c910"}, |
| + // Task 3, C01 fix round 1: the write-race mapping; the same manifest key. |
| + {"cli.go", "runRouteHibernate", "key-site", "key:SidecarManifestKey", "51c9d6fada4fccba3ea62e8df01444cc2945442f298dccb3e805557567b6c820"}, |
| } |
| for _, r := range repins { |
| found := false |