| index fe9990af0..8783442ad 100644 |
| --- a/docs/superpowers/plans/2026-10-30-fleet-public-routes.md |
| +++ b/docs/superpowers/plans/2026-10-30-fleet-public-routes.md |
| @@ -8,7 +8,7 @@ |
| |
| **Tech Stack:** Go; registry SQLite (`internal/registry`); the edge and its tunnel hub (`internal/edge`); the agent passes (`internal/host`, `internal/provision`, `internal/domains`); the console (`internal/console`); signed system pointers (`internal/release`). |
| |
| -**Status:** draft, for Astra plan review round 1 of 3. |
| +**Status:** rev 2, for Astra plan review round 2 of 3. Round 1 (`docs/superpowers/reviews/CODEX-FINDINGS-fleet-public-routes-plan-R1.md`, NOT READY, 3 P1 and 6 P2) and its dispositions are below. |
| |
| **Spec:** `docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md`, rev 4, APPROVED by Paul 2026-10-30 (recorded on amadan #457). Read §4.2 (the shape and the writer rule), §4.3 (the forward phase), §4.4 (the predicate) and §9 (the floor) before any task. Every section number below is the spec's. |
| |
| @@ -41,6 +41,22 @@ |
| 4. A system channel with no pointer yet, whose first publication is below the floor while a fleet is being created: whichever lands first, the other is refused. Test in Task 9 (`TestFleetFloorInterleavings`). |
| 5. A fleet app moved to another fleet of the same account while a binding from the old fleet's box is in flight: the old binding must change nothing. Test in Task 1 (`TestStaleBindingCannotStampTheNewPlacement`). |
| |
| +## Review dispositions (Astra plan R1) |
| + |
| +Every finding taken, with the controller's rulings (platform-39). |
| + |
| +| finding | disposition | where | |
| +|---|---|---| |
| +| P1-1 `SetFleetBox` callers and fixtures | Task 1 migrates every caller: `registry_test.go:2066-2145` (`TestSetFleetBoxRoundTrips`, `TestSetFleetBoxUnknownHostErrors`, `TestUpsertPreservesFleetBox`), `fleets_test.go:395-420` (`TestFingerprintChangesOnFleetBoxRestamp`), `remote_dispatch.go:293`; the positive binding tests in `fleetbind_test.go` (`:251`, `:340`, `:411`) gain an active `fleet_boxes` membership. Two contracts are retired with their reason: clearing by `SetFleetBox(host, "")` (no production caller; a forward row's `FleetBox` is cleared by `PutForward` on a `Region` change, spec §4.2) and the unknown-host error (a binding whose row is gone is "no longer applies", spec §4.5) | Task 1 | |
| +| P1-2 package-private interfaces | The race test moves into `package host` on a real store-door fixture (`newFSKWorld`'s shape, `internal/host/fleet_secrets_key_test.go:57`). Task 13 is in-process through production constructors plus one exported seam, `host.BoxProvisionConfig`, which both production loops call after Task 12 and which is claimed in the census. A subprocess harness of the real agents was rejected: an unprivileged agent cannot run an instance, because staging relays to root (`carlos-stage.path`, `internal/host/stagerelay.go`) and processes run under systemd; faking root would be worse than one production-used export | Tasks 1, 12, 13 | |
| +| P1-3 corruption removed by the fixture | Corruption is injected by raw SQL after `PutForward`, read back to prove it persisted, then `Reload` | Task 4 (and Tasks 6, 7 per field) | |
| +| P2-4 registry source for `FleetOwners` | `boxProvisionConfig` becomes `BoxProvisionConfig(reg, getenv, judge, configure)`; `fastConvergeLoop` and `instancesLoop` pass their `reg`; the source pins in `policycache_wiring_test.go:31,47,59` and the callers in `lifetime_gating_test.go:513`, `sizestatus_test.go:251,259`, `hawake_wiring_test.go:20` are updated; units listed for the census | Task 12 | |
| +| P2-5 transactional side effects | Per-writer fixtures; the whole database (every table) compared before and after; `RetireClaimRows`'s archive callback is a spy that must never fire; forward-valued restore inputs at absent hosts | Task 3 | |
| +| P2-6 inventory completeness | The inventory test walks `Exec`/`ExecContext`/`Query*`/`Prepare*` call sites, resolves the SQL argument with the type checker's constant value, and requires every unresolved expression to be classified in an explicit table; the mutation splits an existing literal | Task 3 | |
| +| P2-7 the barrier's mutation | Case (a) kept as the re-judgment witness; case (c) proves fleet create stays blocked between a successful judgment and the publication; the early-unlock mutation is shown against (c) | Task 9 | |
| +| P2-8 spec witnesses | Table-driven over the forbidden class for sanitisation (Task 2), serving (Task 4), publication (Task 6) and egress (Task 7); a live forward source mints no platform name (Task 7); multipart through the real fleet gate (Task 4) | Tasks 2, 4, 6, 7 | |
| +| P2-9 rollout deliverables | Task 14 adds a read-only inventory of fleet-placed non-forward rows on dev and the flagship; Task 15 adds the release-notes paragraph through the release's Luna pass; any removal is per row with Paul's approval | Tasks 14, 15 | |
| + |
| ## Plan rulings (choices the spec leaves open, with cost if wrong) |
| |
| - P-1. The floor's version: `v0.32.0`, the next minor after v0.31.0 (live on dev). Task 13's release step re-pins it if the cut is numbered otherwise. Cost if wrong: one constant and its pinning test. |
| @@ -53,10 +69,11 @@ |
| |
| | path | responsibility | |
| |---|---| |
| -| `internal/registry/forward.go` (new) | `KindForward`, `IsForward`, `InertForward`, `ErrForwardRow`, `ErrHostHeld`, `PutForward`, `DeleteForward`, `SetFleetBoxIf`, `forwardShape` (the class table the tests read) | |
| +| `internal/registry/forward.go` (new) | `KindForward`, `IsForward`, `InertForward`, `ErrForwardRow`, `ErrHostHeld`, `PutForward`, `DeleteForward`, `SetFleetBoxIf`, `ForwardForbidden` (the forbidden class, field and column, which `PutForward` writes and the tests iterate) | |
| | `internal/registry/registry.go`, `routecas.go`, `claimhold.go`, `claimrows.go`, `coldhandover.go`, `recoveryhandover.go`, `importjournal.go`, `aliassocket.go` | the writer guard (§4.2 inventory) | |
| | `internal/registry/remote_dispatch.go` | the three new remote cases; `SetFleetBox` gone | |
| | `internal/host/hub.go` (new) | `hubArmed`, `hubFleetOwners` | |
| +| `internal/host/agent.go` | `BoxProvisionConfig` (exported, Task 12) | |
| | `internal/host/fleetbind.go` | key check, `SetFleetBoxIf` | |
| | `internal/edge/fleetforward.go` (new) | `FleetServeEligible` | |
| | `internal/edge/edge.go`, `ratelimit.go`, `planthrottle.go`, `assetcatch.go` | dispatch, login branch, caches, request policy | |
| @@ -107,27 +124,30 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| ### Task 1: Bindings bind only their own fleet, at write time (pre-existing hole) |
| |
| **Files:** |
| -- Create: `internal/registry/forward.go` (this task adds only `SetFleetBoxIf`), `internal/registry/fleetbox_if_test.go`, `internal/host/hub.go` |
| -- Modify: `internal/registry/registry.go:2750-2775` (remove `SetFleetBox`), `internal/registry/remote_dispatch.go:293` and its request fields, `internal/host/fleetbind.go:210-270`, `internal/host/agent.go:3860-3898` (`instancesLoop`), `internal/edge/fleetapi_e2e_test.go` |
| +- Create: `internal/registry/forward.go` (this task adds only `SetFleetBoxIf`), `internal/registry/fleetbox_if_test.go`, `internal/host/hub.go`, `internal/host/fleetbind_door_test.go` |
| +- Modify: `internal/registry/registry.go:2750-2775` (remove `SetFleetBox`), `internal/registry/remote_dispatch.go:293` and its request fields, `internal/host/fleetbind.go:210-270`, `internal/host/agent.go:3849-3898` (`instancesLoop`) |
| +- Migrate: `internal/registry/registry_test.go:2066-2145`, `internal/registry/fleets_test.go:395-420`, `internal/host/fleetbind_test.go:251-440` |
| |
| **Interfaces:** |
| - Produces: |
| - - `func (r *Registry) SetFleetBoxIf(host, fleet, label string) (bool, error)`: one statement, §4.5 step 2's SQL (`WHERE host = ? AND region = 'fleet/' || ? AND kind <> 'sidecar' AND EXISTS (SELECT 1 FROM fleet_boxes WHERE fleet = ? AND label = ? AND status = 'active')`); returns whether a row changed; no row is not an error. Remote case `"SetFleetBoxIf"`. |
| + - `func (r *Registry) SetFleetBoxIf(host, fleet, label string) (bool, error)`: one statement, spec §4.5 step 2's SQL (`WHERE host = ? AND region = 'fleet/' || ? AND kind <> 'sidecar' AND EXISTS (SELECT 1 FROM fleet_boxes WHERE fleet = ? AND label = ? AND status = 'active')`); returns whether a row changed; no row is not an error. Remote case `"SetFleetBoxIf"`. |
| - `func hubArmed(getenv func(string) string) bool`: `CARLOS_TUNNEL_HOST` non-empty after `TrimSpace` and `CARLOS_FLEET` empty. |
| - - `func ReconcileFleetBindings(ctx context.Context, s release.Store, reg *registry.Registry) error` keeps its signature; applies a binding only when `key == fleetBindingKey(b.Fleet, b.Host)`, then calls `SetFleetBoxIf(b.Host, b.Fleet, b.Box)`. Its existing pre-checks stay as a filter. |
| + - `ReconcileFleetBindings(ctx context.Context, s release.Store, reg *registry.Registry) error` keeps its signature; applies a binding only when `key == fleetBindingKey(b.Fleet, b.Host)`, then calls `SetFleetBoxIf(b.Host, b.Fleet, b.Box)`; its existing pre-checks stay as a filter. |
| - `instancesLoop` runs it only when `hubArmed(os.Getenv)`. |
| -- Test seam: `var bindingsAfterChecks func(host string)` in `fleetbind.go`, nil in production, called between the pre-checks and `SetFleetBoxIf`. |
| - |
| -- [ ] **Step 1: Write failing tests.** |
| - - `internal/registry`: `TestSetFleetBoxIfBindsPlacementKindAndMembership`: fleets `home` (boxes `box-1` active, `box-2` detached) and `away` (`box-1` active); a row `shop.example.com` placed `fleet/home`. `SetFleetBoxIf(host, "home", "box-1")` = true and the row reads `box-1`; `(host, "away", "box-1")` = false; `(host, "home", "box-2")` = false; `(host, "home", "box-9")` = false; a sidecar row placed `fleet/home`: false; unknown host: `false, nil`. `TestSetFleetBoxIfOverRemote`: the same first two cases through the remote fixture the fleet remote tests use. |
| - - `internal/host`: `TestHubArmed`: table over the two variables (`"tunnel.example.com"`/`""` -> true; set/`"home"` -> false; `""`/`""` -> false; `" "`/`""` -> false). |
| - - `internal/edge/fleetapi_e2e_test.go` (package `edge_test`, `newFleetDoorWorld`, `fapiStore`): `TestForgedBindingsChangeNothing`: account `bab` owns `home`, `k3x` owns `away`; `away`'s `box-1` PUTs through its door `fleets/away/bindings/<home's host>.json` naming fleet `home`, box `box-1`, and `fleets/away/bindings/<away's host>.json` naming box `box-7`; `host.ReconcileFleetBindings` leaves both rows' `FleetBox` empty. `TestStaleBindingCannotStampTheNewPlacement`: `bab` owns `home` and `away`; `home`'s `box-1` PUTs a correct binding; `bindingsAfterChecks` moves the row to `fleet/away` (as `PutForward` will, here with `SetPlacement` and `FleetBox` cleared) and returns; the stored row's `FleetBox` is empty after the pass. |
| - - Mutations to show: compare against the body's fleet instead of the key (forged test fails); use the old `UPDATE ... WHERE host` (stale test fails). |
| -- [ ] **Step 2: Run** `TMPDIR=/tmp/g nice -n 19 go test ./internal/registry/ ./internal/host/ ./internal/edge/ -run 'TestSetFleetBoxIf|TestHubArmed|TestForgedBindingsChangeNothing|TestStaleBindingCannotStampTheNewPlacement|TestReconcileFleetBindings|TestFleetBoxConvergesWithoutBucketCredentials' -count=1`. Expected: FAIL on the new tests (undefined `SetFleetBoxIf`, `hubArmed`). |
| -- [ ] **Step 3: Implement** as the Interfaces block says. |
| -- [ ] **Step 4: Run** the Step 2 command. Expected: PASS, the existing `TestReconcileFleetBindings*` and `TestFleetBoxConvergesWithoutBucketCredentials` included. |
| -- [ ] **Step 5: Census.** `make census-card`; expect `ReconcileFleetBindings` (body), `SetFleetBox` (removed), `SetFleetBoxIf` (new, if the card sees a site), `dispatchRemote`, `instancesLoop`, `hubArmed`; reconcile with §7. |
| -- [ ] **Step 6: Commit.** |
| + - Test seam, package-private and nil in production: `var bindingsAfterChecks func(host string)` in `fleetbind.go`, called between the pre-checks and `SetFleetBoxIf`. |
| +- Retired contracts, each with the test that pinned it: clearing by `SetFleetBox(host, "")` (`TestSetFleetBoxRoundTrips`'s second half, `TestUpsertPreservesFleetBox`'s last block): no production caller ever cleared; a forward row's `FleetBox` is cleared by `PutForward` on a `Region` change (Task 2), and a hand row's is never cleared by a pass, as today. The unknown-host error (`TestSetFleetBoxUnknownHostErrors`): `SetFleetBoxIf` answers `false, nil`, because a binding whose row is gone simply no longer applies (spec §4.5). |
| + |
| +- [ ] **Step 1: Migrate the existing tests**, so the package compiles once `SetFleetBox` is gone: `TestSetFleetBoxRoundTrips` becomes `TestSetFleetBoxIfRoundTrips` (fleet `home` with active `box-1`, row placed `fleet/home`; stamp; no clear); `TestSetFleetBoxUnknownHostErrors` becomes `TestSetFleetBoxIfUnknownHostIsNoChange` (`false, nil`); `TestUpsertPreservesFleetBox` stamps with `SetFleetBoxIf` and drops its clearing block; `TestFingerprintChangesOnFleetBoxRestamp` registers `box-a` and `box-b` active on fleet `pi` and restamps with `SetFleetBoxIf`; `fleetbind_test.go`'s positive cases (`TestReconcileFleetBindingsStampsMatchingRoute`, `...AppliesMatchingFleetPlacement`, `...Idempotent`) add `UpsertFleet` and an active `AddFleetBox` for the binding's label. `internal/edge`'s door e2e (`fleetapi_e2e_test.go:131`) and `fleet_e2e_test.go` already register their boxes active. |
| +- [ ] **Step 2: Write failing tests.** |
| + - `internal/registry`: `TestSetFleetBoxIfBindsPlacementKindAndMembership`: fleets `home` (`box-1` active, `box-2` detached) and `away` (`box-1` active), a row `shop.example.com` placed `fleet/home`: `(host, "home", "box-1")` true and the row reads `box-1`; `(host, "away", "box-1")`, `(host, "home", "box-2")`, `(host, "home", "box-9")` false; a sidecar row placed `fleet/home` false; unknown host `false, nil`. `TestSetFleetBoxIfOverRemote`: the first two cases through the remote fixture. |
| + - `internal/host`: `TestHubArmed`: (`"tunnel.example.com"`, `""`) true; (`"tunnel.example.com"`, `"home"`) false; (`""`, `""`) false; (`" "`, `""`) false. |
| + - `internal/host/fleetbind_door_test.go`, on a door fixture built as `newFSKWorld` builds one (`edge.New`, `EnableStatic`, `EnableTunnels`, a box store from `fleetapi.New(srvURL, "<fleet>/box-1", token)`): `TestForgedBindingsChangeNothing` (account `bab` owns `home`, `k3x` owns `away`; `away`'s `box-1` PUTs through its door `fleets/away/bindings/<home's host>.json` naming fleet `home` and box `box-1`, and `fleets/away/bindings/<away's host>.json` naming box `box-7`; after `ReconcileFleetBindings` both rows' `FleetBox` is empty). `TestStaleBindingCannotStampTheNewPlacement`: `bab` owns `home` and `away`, both with an active `box-1`; `home`'s `box-1` PUTs a correct binding through the door; `bindingsAfterChecks` moves the row to `fleet/away` with `SetPlacement` and sets `FleetBox` empty by raw SQL; after the pass the row's `FleetBox` is empty. |
| + - Mutations to show: compare the body's fleet instead of the key (the forged test fails); the old hostname-only `UPDATE` (the stale test fails). |
| +- [ ] **Step 3: Run** `TMPDIR=/tmp/g nice -n 19 go test ./internal/registry/ ./internal/host/ -run 'TestSetFleetBoxIf|TestHubArmed|TestForgedBindings|TestStaleBinding|TestReconcileFleetBindings|TestUpsertPreservesFleetBox|TestFingerprintChangesOnFleetBox' -count=1`. Expected: FAIL on the new tests only (undefined `SetFleetBoxIf`, `hubArmed`). |
| +- [ ] **Step 4: Implement** as the Interfaces block says. |
| +- [ ] **Step 5: Run** Step 3, plus `TMPDIR=/tmp/g nice -n 19 go test ./internal/edge/ -run 'TestFleetBoxConvergesWithoutBucketCredentials|TestTwoBoxFleetEndToEnd' -count=1`. Expected: PASS. |
| +- [ ] **Step 6: Census.** `make census-card`; expect `ReconcileFleetBindings` (body), `SetFleetBox` (removed), `SetFleetBoxIf` (new), `dispatchRemote`, `instancesLoop`, `hubArmed`; reconcile with spec §7. |
| +- [ ] **Step 7: Commit.** |
| |
| ### Task 2: The forward kind and its persisted shape |
| |
| @@ -144,11 +164,13 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| - `func (r *Registry) PutForward(rt Route) error`: refuses `rt` that is not `IsForward()` with an error; one transaction; an existing non-forward row: `ErrHostHeld`, nothing written; else the declared columns from `rt`, the observational ones and `CreatedAt` kept, `FleetBox` kept iff `Region` unchanged, every forbidden column written zero. |
| - `func (r *Registry) DeleteForward(host string) (bool, error)`: `DELETE FROM routes WHERE host = ? AND kind = 'forward'`. |
| - `var forwardShape = map[string]string{...}`: every persisted `Route` field name (and `ClaimOwnership`'s) to `"declared" | "binding" | "observational" | "forbidden"`, the Global Constraints table verbatim. `WakeIncarnation` is not persisted and not listed. |
| + - `type ForwardColumn struct{ Field, Column string }` and `var ForwardForbidden []ForwardColumn`: the forbidden class with each field's SQL column, derived from `forwardShape` and the registry's column list at init. `PutForward` writes zero to exactly these columns (production use); the per-field tests in Tasks 2, 4, 6 and 7 iterate it. |
| |
| - [ ] **Step 1: Write failing tests.** |
| - `TestForwardShapeClassesEveryField`: reflect over `registry.Route` (descending into the embedded `ClaimOwnership`), skip fields tagged `json:"-"`; every field is a key of `forwardShape`, and every key is a field. |
| - `TestInertForwardChecksEachForbiddenField`: for each `forbidden` field, a copy of a valid forward row with only that field set to a non-zero value of its type: `InertForward()` false. A valid row: true. A non-forward row: false. |
| - `TestPutForwardWritesTheExactShape`: put over a forward row that already carries (written by raw SQL in the test) `tunnel='t1'`, `caps='x'`, `unit='u.service'`, `seed='s'`, `dns_status='pointing'`, `cert_expires_at=5`, `fleet_box='box-1'`; read back: forbidden zero, `DNSStatus`/`CertExpiresAt` kept, `FleetBox` kept; a second put with `Region` `fleet/away`: `FleetBox` empty. |
| + - `TestPutForwardSanitisesEachForbiddenColumn`: for each `ForwardForbidden` entry, raw SQL sets that column non-zero on a forward row (`'x'` for TEXT, `1` for INTEGER), `Get` shows it persisted, `PutForward` with a valid row, `Get` shows it zero. |
| - `TestPutForwardRefusesAHeldHost`: an instance row at the host: `errors.Is(err, ErrHostHeld)`, the row unchanged (compare `Get` before and after). |
| - `TestDeleteForwardLeavesOtherRows`: a hand row: `false, nil`, row present; a forward row: `true`. |
| - `TestForwardCallsOverRemote`: `PutForward`, `DeleteForward` through the remote fixture; `ErrHostHeld` survives `errors.Is`. |
| @@ -161,22 +183,25 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| ### Task 3: Every other writer refuses a forward row |
| |
| **Files:** |
| -- Modify: the eight files of §4.2's inventory table (`registry.go`, `routecas.go`, `claimhold.go`, `claimrows.go`, `coldhandover.go`, `recoveryhandover.go`, `importjournal.go`, `aliassocket.go`); `cli.go` (`runAdd` :197, `runRemove` :471, `runRoute` :709) |
| -- Create: `internal/registry/forward_writers_test.go`, `forward_cli_test.go` (root package) |
| +- Modify: the eight files of spec §4.2's inventory table (`registry.go`, `routecas.go`, `claimhold.go`, `claimrows.go`, `coldhandover.go`, `recoveryhandover.go`, `importjournal.go`, `aliassocket.go`); `cli.go` (`runAdd` :197, `runRemove` :471, `runRoute` :709) |
| +- Create: `internal/registry/forward_writers_test.go`, `internal/registry/forward_inventory_test.go`, `forward_cli_test.go` (root package) |
| - Modify: `approved_fleet_routes_copy_test.go` (`fleetRoutesCopyBuilt` += `FPR-C01`) |
| |
| **Interfaces:** |
| - Consumes: Task 2's `KindForward`, `ErrForwardRow`. |
| -- Produces: every writer of §4.2's inventory obeys the writer rule. A writer taking a `Route` or claim row of kind forward returns `ErrForwardRow` before any write; a transactional writer reads the target host's `kind` first inside its transaction and returns `ErrForwardRow` before its first write (`SwapForImport` before its journal row, `RetireClaimRows` before `claim_row_retirements`); every `routes` statement carries `kind <> 'forward'`. `SetDNSStatus`, `SetCertExpiresAt` unchanged. |
| +- Produces: every writer of the inventory obeys the writer rule. A writer taking a `Route`, `ClaimRow` or `ColdRows` input of kind forward returns `ErrForwardRow` before any write. A transactional writer reads the target host's `kind` first inside its transaction and returns `ErrForwardRow` before its first write: `SwapForImport` before its journal row, `RetireClaimRows` before `archive` is called and before `claim_row_retirements`, `RestoreClaimRows` and `RebindClaimRows` before `cold_handovers`, `recovery_handovers` and `recovery_rows`. Every `routes` statement carries `kind <> 'forward'`. `SetDNSStatus`, `SetCertExpiresAt` unchanged. |
| - `cli.go`: on `errors.Is(err, registry.ErrForwardRow)`, or a `Get` showing `IsForward()` before the write, print FPR-C01 (`host`, `rt.App`, the fleet from `registry.FleetPlacement(rt.Region)`) and exit 1. |
| +- Test helper (package `registry`, test file): `func dumpDB(t *testing.T, r *Registry) map[string][]string`: every table named in `sqlite_master`, each row rendered as its column values joined, sorted. |
| |
| - [ ] **Step 1: Write failing tests.** |
| - - `TestEveryRouteWriterRefusesAForwardRow`: one table, one entry per writer of §4.2's inventory (each exported writer, and the unexported `upsertRoute`, `insertRouteTx`, `carryAliasesTx` through the exported writer that calls them), each called on a seeded forward row with arguments that would change it. Assertions per entry: the row read back equals the seeded row (`reflect.DeepEqual` on `Get`); the writer returned `ErrForwardRow` or reported no change; for the transactional writers, `import_journal`, `claim_row_retirements` and the timers table have the same row count before and after. Separately `SetDNSStatus` and `SetCertExpiresAt` do stamp it. |
| - - `TestRouteWriterInventoryIsComplete`: parse `internal/registry/*.go` (not tests) with `go/ast`; every function containing a string literal with `UPDATE routes`, `DELETE FROM routes`, `INSERT INTO routes`, or the `DELETE FROM `+table pattern of `RetireClaimRows`, is a name in the first test's table or in the five exceptions. A writer added later fails here until it is classed. |
| + - `TestEveryRouteWriterRefusesAForwardRow`: one table, one entry per writer of the inventory, each entry carrying its own fixture builder (the state its writer needs to act at all: a held route for the hold helpers, a journaled import for `CommitImport`/`CloseImportGate`/`RestoreImportRoute`, claim rows and a cold handover for `RestoreClaimRows`/`RebindClaimRows`/`RetireClaimRows`, an alias for `carryAliasesTx` through `RepointPlatformSocket`, a lifetime pair for `InstallLifetimeIf`) and its call with arguments that would change a non-forward row. Per entry: run it once against a non-forward row and assert the row changed (so the fixture is live); then against the same fixture with the host a forward row: `dumpDB` before equals `dumpDB` after, and the writer returned `ErrForwardRow` or no change. `RetireClaimRows` gets an `archive` spy that fails the test if called. Separately, `SetDNSStatus` and `SetCertExpiresAt` stamp a forward row. |
| + - `TestRestoreWritersRefuseForwardInputsAtAbsentHosts`: `RestoreClaimRows`, `RebindClaimRows`, `RestoreImportRoute` (and `insertRouteTx` through its caller) given an input row of kind forward for a host with no row: `ErrForwardRow`; `dumpDB` unchanged; no row at the host. |
| + - `TestRouteWriterInventoryIsComplete` (`forward_inventory_test.go`): load `internal/registry` (non-test files) with `go/parser` and `go/types` (`importer.ForCompiler(fset, "source", nil)`); visit every call whose method is `Exec`, `ExecContext`, `Query`, `QueryContext`, `QueryRow`, `QueryRowContext`, `Prepare` or `PrepareContext`; take the SQL argument's `types.Info.Types[expr].Value` (a constant, so `"UPDATE " + "routes SET x = ?"` resolves); a resolved string matching `(?i)\b(insert(\s+or\s+\w+)?\s+into|replace\s+into|update|delete\s+from)\s+routes\b` names its enclosing function, which must be a writer of the first test's table or one of the five exceptions. An argument with no constant value must be a key of `unresolvedRouteSQL map[string]string` (`"<file>:<func>"` to its classification, e.g. `"claimrows.go:RetireClaimRows": "DELETE FROM routes|timers, guarded by the forward check before archive"`); an unclassified one fails, as does a stale key. |
| - `TestForwardHostRefusedByTheCLI` (root package, `carlosTestEnv`, scratch `cmd.Dir`): `carlos add`, `carlos route -host <h> -channel x`, `carlos remove <h>` against a registry holding a forward row print FPR-C01 and exit 1; the row is unchanged. |
| -- [ ] **Step 2: Run** `nice -n 19 go test ./internal/registry/ -run 'TestEveryRouteWriter|TestRouteWriterInventory' -count=1` and `nice -n 19 go test . -run 'TestForwardHostRefusedByTheCLI|TestFleetRoutesCopy' -count=1`. Expected: FAIL. |
| -- [ ] **Step 3: Implement** the guard, writer by writer, and the CLI mapping (FPR-C01 approved; id added to `fleetRoutesCopyBuilt`). |
| -- [ ] **Step 4: Run** Step 2, plus the registry's existing writer tests by package (`-run 'Hold|Import|Claim|Alias|Upsert|Delete|Set'`). Expected: PASS. Show the mutation: remove the guard from `InstallLifetimeIf`; the table test fails on it. |
| + - Mutations to show: remove the guard from `InstallLifetimeIf` (the writer table fails on it); split `SetStatus`'s literal into `"UPDATE " + "routes SET status = ? ..."` and drop `SetStatus` from the table (the inventory test still names it). |
| +- [ ] **Step 2: Run** `nice -n 19 go test ./internal/registry/ -run 'TestEveryRouteWriter|TestRestoreWritersRefuse|TestRouteWriterInventory' -count=1` and `nice -n 19 go test . -run 'TestForwardHostRefusedByTheCLI|TestFleetRoutesCopy' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement** the guard writer by writer, and the CLI mapping (FPR-C01 approved; id added to `fleetRoutesCopyBuilt`). |
| +- [ ] **Step 4: Run** Step 2, plus the registry's existing writer tests (`nice -n 19 go test ./internal/registry/ -run 'Hold|Import|Claim|Alias|Upsert|Delete|Set|Cold|Recovery|Lifetime' -count=1`). Expected: PASS. |
| - [ ] **Step 5: Census.** Expect every changed writer with read sites (spec §7's R3-3 list) and `runAdd`, `runRemove`, `runRoute`; reconcile. |
| - [ ] **Step 6: Commit.** |
| |
| @@ -193,15 +218,17 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| - `Reload` reads `ListFleets` (and `FleetChannelAuth`) before the routes loop when `e.tunnels != nil`, builds `owners`, and: a new first dispatch case for `t.IsForward()` (eligible: `fleetProxy`, `viaTunnel`; not: no map entry, throttled log); the existing fleet case asks the predicate (refused: no map entry). Path rows whose host is a forward row are not folded. |
| - `ServeHTTP`: `loginPost := r.Method == http.MethodPost && r.URL.Path == gate.LoginPath && !up.route.IsForward()`; `cacheable` gains `&& !up.route.IsForward()`. |
| - `localAssetCatch` returns false for `up.route.IsForward()`. |
| - - Test fixture (package `edge`, `fleetforward_test.go`), reused by Task 5: `func forwardHubAndBox(t *testing.T, hubRows, boxRows []registry.Route, boxHandler http.Handler) (hubURL string, hub, box *Edge)`: a hub `Edge` on its own registry with fleet `home` of `bab` and box `box-1` (`UpsertFleet`, `AddFleetBox`), forward rows seeded with `PutForward` (not `Upsert`, which refuses them after Task 3), tunnels enabled as `fleetTestEdge` does (`fleet_route_test.go:39`); a box `Edge` on a second registry holding `boxRows`, dialed in as `home/box-1` by `startFakeRemoteHost` (`tunnel_e2e_test.go:190`, the real `tunnelclient` loop) serving the box `Edge` itself, or `boxHandler` when non-nil. `fleetTestEdge`'s `acme`/`amadan` names are not reused. |
| + - Test fixture (package `edge`, `fleetforward_test.go`), reused by Task 5: `func forwardHubAndBox(t *testing.T, hubRows, boxRows []registry.Route, boxHandler http.Handler) (hubURL string, hub, box *Edge)`: a hub `Edge` on its own registry with fleet `home` of `bab` and box `box-1` (`UpsertFleet`, `AddFleetBox`), forward rows seeded with `PutForward` (not `Upsert`, which refuses them after Task 3), tunnels enabled as `fleetTestEdge` does (`fleet_route_test.go:39`); a box `Edge` on a second registry holding `boxRows`, dialed in as `home/box-1` by `startFakeRemoteHost` (`tunnel_e2e_test.go:190`, the real `tunnelclient` loop) serving the box `Edge` itself, or `boxHandler` when non-nil. `fleetTestEdge`'s `acme`/`amadan` names are not reused. And `func corruptRow(t *testing.T, regPath, host, column string, value any)`: opens the registry file with `database/sql` (driver `"sqlite"`, as the registry does), `UPDATE routes SET <column> = ? WHERE host = ?`, asserts one row affected, then reads the row back through `registry.Open(...).Get` to prove the value persisted. |
| |
| - [ ] **Step 1: Write failing tests** (`fleetforward_test.go`, on `forwardHubAndBox`): |
| - `TestFleetServeEligible`: table. Forward rows: hub off -> false; owner match -> true; owner mismatch, unknown fleet, empty raw account, one stray forbidden field -> false. Hand rows (`Kind` instance, placed `fleet/home`): empty raw account -> true; `Account "k3x"` with owner `bab` -> false; `Account "!!"` (invalid, `RouteAccount` gives `OpsAccount`) -> false. |
| - - `TestReloadServesOnlyEligibleForwardRows`: owners `home`->`bab`; forward rows `a.example.com` (`bab`), `b.example.com` (`k3x`), `c.example.com` (`bab`, `Tunnel "t1"`): `Allowed(a)` true, `Allowed(b)` and `Allowed(c)` false; a request to `c` never reaches a tunnel named `t1` (a static client `t1` registered in the test records nothing). |
| + - `TestReloadServesOnlyEligibleForwardRows`: owners `home`->`bab`; forward rows `a.example.com` (`bab`) and `b.example.com` (`k3x`) via `PutForward`; `c.example.com` (`bab`) via `PutForward`, then `corruptRow(..., "tunnel", "t1")`; then `Reload`: `Allowed(a)` true, `Allowed(b)` and `Allowed(c)` false; a request to `c` never reaches a static tunnel client `t1` registered in the test (it records nothing). |
| + - `TestForwardServingRefusesEachForbiddenColumn`: for each `registry.ForwardForbidden` entry, a fresh eligible forward row, `corruptRow` on that column, `Reload`: `Allowed` false and a request gets the unknown-host answer. |
| - `TestForwardResponseCarriesTheBoxVersionOnce`: the box handler sets `X-Carlos-Version: v1`; through the hub, `resp.Header.Values("X-Carlos-Version")` equals `[]string{"v1"}`. |
| - `TestForwardRowsAreNeverCached`: hub with `EnableCache`; the box answers `Cache-Control: public, max-age=300` with a body that counts calls; two GETs: the box sees two. |
| - `TestForwardRowsSkipTheAssetCache`: an armed asset policy naming the host and prefix `/assets/`: `localAssetCatch` false for the forward upstream. |
| - `TestForwardLoginBodyReachesTheFleetEdge`: the box handler records `r.ContentLength`, the body bytes and `r.Header.Get("Content-Type")`; through the hub, `POST /.carlos/gate` with `Content-Type: application/x-www-form-urlencoded`, body `password=right&next=%2Fup`: the box received exactly that body and length; the same with `password=wrong`; a `multipart/form-data` body: received byte for byte. A path row at the hub for the forward host's `/shop` prefix: the POST with `next=/shop/x` still reaches the box. |
| + - `TestForwardLoginThroughTheRealFleetGate`: the box is a real `Edge` whose own row carries a gate (`SetGate` with a bcrypt hash of `right`): through the hub, the urlencoded form with `right` gets `Set-Cookie: carlos_gate=...` and a redirect to `next`; with `wrong`, the wrong-password page (401) and no cookie; a `multipart/form-data` form with `right` gets the same answer a platform-hosted gated route gives it (compared against a second, non-forward gated row served by the hub itself). |
| - `TestUngatedLoginPostStill404s`: a non-forward ungated instance row: the login POST is 404 (today's rule kept). |
| - Mutation to show: drop `!up.route.IsForward()` from `loginPost`; the login test fails with a short body at the box. |
| - [ ] **Step 2: Run** `TMPDIR=/tmp/g nice -n 19 go test ./internal/edge/ -run 'TestFleetServeEligible|TestReloadServesOnlyEligible|TestForward|TestUngatedLoginPost|TestFleetRoute|TestExplicitTunnel|TestNonFleetRoutes' -count=1`. Expected: FAIL on the new tests. |
| @@ -243,9 +270,10 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| - [ ] **Step 1: Write failing tests.** |
| - `TestEdgesFilePublishesOnlyEligibleForwardRows`: hub on; owners `home`->`bab`; forward rows for `bab` (eligible) and `k3x` (refused), each with an alias and an instance catch-all; the written file names the eligible row, its alias and catch-all with `account`/`app`, and nothing of the refused row's; no `assets` key on the eligible entry. |
| - `TestEdgesFileOmitsForwardRowsOffTheHub`: hub off: no forward row published. |
| + - `TestEdgesFileOmitsEachCorruptForwardRow`: for each `registry.ForwardForbidden` entry, an eligible forward row with an alias, that column corrupted by raw SQL (persisted, read back): neither the host nor its alias is in the written file. |
| - `TestEdgesFileForwardGolden` (`internal/host`): the first test's written file equals `internal/edge/testdata/edges-forward-hub.json` byte for byte (on mismatch the test prints the new bytes; the file is updated by hand in the same commit). |
| - `TestSeparateIssuerAdmitsOnlyPublishedForwardNames` (`internal/edge`, package `edge`, because `deploymentHost` and `newHomeMap` are unexported and `internal/edge` cannot import `internal/host`): a `DirStore` holding that golden file at `control/edges/hub.json`, read by `newHomeMap(store, "issuer")` into a second `Edge` with no local rows; `deploymentHost` true for the eligible host and its alias, false for the refused host and its alias. |
| -- [ ] **Step 2: Run** `nice -n 19 go test ./internal/host/ ./internal/edge/ -run 'TestEdgesFilePublishesOnly|TestEdgesFileOmitsForward|TestEdgesFileForwardGolden|TestSeparateIssuer' -count=1`. Expected: FAIL. |
| +- [ ] **Step 2: Run** `nice -n 19 go test ./internal/host/ ./internal/edge/ -run 'TestEdgesFilePublishesOnly|TestEdgesFileOmitsForward|TestEdgesFileOmitsEachCorrupt|TestEdgesFileForwardGolden|TestSeparateIssuer' -count=1`. Expected: FAIL. |
| - [ ] **Step 3: Implement** the writer change and check in the golden file. |
| - [ ] **Step 4: Run** Step 2 plus `-run 'EdgesFile'`. Expected: PASS. |
| - [ ] **Step 5: Census** (`edgesFileWriteClaims`). |
| @@ -264,12 +292,14 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| - Domains whole-app trash loop: `if rt.IsForward() { keptLive = append(keptLive, rt); continue }` ahead of `DeleteIfUnchanged`. |
| |
| - [ ] **Step 1: Write failing tests.** |
| - - `TestEgressNestedWithAnInertForwardRow`: one nested managed local instance and an inert forward row: `boxWhollyNested` true. With the forward row carrying `Socket`: false, reason names the host. A row of kind `"frobnicate"`: false (today's refusal kept). Mutation: skip every forward row regardless of shape; the second arm fails. |
| + - `TestEgressNestedWithAnInertForwardRow`: one nested managed local instance and an inert forward row: `boxWhollyNested` true. A row of kind `"frobnicate"`: false (today's refusal kept). Mutation: skip every forward row regardless of shape; the next test fails. |
| + - `TestEgressRefusesEachNonInertForwardRow`: for each `registry.ForwardForbidden` entry, the same box with the forward row's column corrupted by raw SQL (persisted, read back): `boxWhollyNested` false, the reason naming the host. |
| - `TestRetentionIgnoresForwardRows`: a forward row of app `shop` with a retention record of keep 1 and three versions in the store: `retentionPass` deletes nothing for `shop` (counting store: zero `GetRetention` reads for `shop`). |
| - `TestExpiredCanariesIgnoreForwardRows`: a forward row on `canary/x`: the count is 0 and the store sees no channel read. |
| - `TestDomainsTrashLoopKeepsForwardRows` (`internal/domains`): trashed `shop` with a forward row and trashed `blog` with an instance row: after `Reconcile`, `blog`'s row gone, `shop`'s forward row present. |
| + - `TestDomainsMintsNoPlatformNameFromALiveForwardRow` (`internal/domains`): apps domain `example.com`, account `bab` materialized, a live (not trashed) forward row for `shop` and its canary channel pointer present: after `Reconcile`, no `Platform` row for `shop` exists and the registry's route count is unchanged (spec §4.11, `firstReadyUpstream` at `internal/domains/reconcile.go:823`). |
| - `TestReadersIgnoreInertForwardRows`: one table asserting false for an inert forward row from `release.Adoptable`, `release.SidecarAdoptable`, `release.CapabilityRoute`, `restartEligible`, `keepsBuildState`, `activator.ActivatorManaged`, and that `ops.FleetDBs` and the staged-version sweep's pins exclude it (spec §4.15). |
| -- [ ] **Step 2: Run** `nice -n 19 go test ./internal/host/ ./internal/domains/ -run 'TestEgressNestedWith|TestRetentionIgnores|TestExpiredCanariesIgnore|TestDomainsTrashLoopKeeps|TestReadersIgnore' -count=1`. Expected: FAIL. |
| +- [ ] **Step 2: Run** `nice -n 19 go test ./internal/host/ ./internal/domains/ -run 'TestEgressNestedWith|TestEgressRefusesEach|TestRetentionIgnores|TestExpiredCanariesIgnore|TestDomainsTrashLoopKeeps|TestDomainsMintsNoPlatformName|TestReadersIgnore' -count=1`. Expected: FAIL (the platform-name test passes at once; show it can fail by making `firstReadyUpstream` accept a forward row). |
| - [ ] **Step 3: Implement.** |
| - [ ] **Step 4: Run** Step 2 plus `-run 'Egress|Retention|Canar'` (host) and `-run 'Trash'` (domains). Expected: PASS. |
| - [ ] **Step 5: Census.** `boxWhollyNested` runs as root: its claim states that an agent-written row can only skip itself and that a non-inert forward row is refused. Also `retentionPass`, `countExpiredCanaries`, domains `Reconcile`. |
| @@ -305,7 +335,7 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| - [ ] **Step 5: Census** (`SystemPointer`, `SystemPromoteOptions`, `PrepareSystemPromotion`, `PrepareSystemRollback`, the new release declarations, `runSystemUpdate`, `runSystemRollback`; the console files are outside the scope). |
| - [ ] **Step 6: Commit.** |
| |
| -### Task 9: The fleet-create barrier and the two interleavings |
| +### Task 9: The fleet-create barrier and the three interleavings |
| |
| **Files:** |
| - Modify: `internal/console/fleetfloor.go`, `internal/console/fleets.go:176` (`handleAPIFleetNew`) and the page form's create handler, `approved_fleet_routes_copy_test.go` (+= C06, C07) |
| @@ -316,12 +346,13 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| - Produces: |
| - `func (s *Server) fleetCreateFloorRefusal(ctx context.Context) *doorRefusal`: the channels the fresh heartbeats follow (`stable` for a box naming none), as `regionalChannelRefusal` reads them (`apiplacements.go:935-978`); a pointer below the floor or unparseable: 409 C06; unreadable: 503 C07; absent: passes. |
| - Both create doors hold `s.fleetFloorMu` from `fleetCreateFloorRefusal` through the registry write. |
| - - Test hooks `fleetFloorHooks struct{ beforeLock, locked func() }` on `Server`, as `regionalFloorHooks`. |
| + - Test hooks `fleetFloorHooks struct{ beforeLock, locked, createBeforeLock func() }` on `Server`, as `regionalFloorHooks`: `beforeLock` and `locked` in `fleetFloorPublish`, `createBeforeLock` in the create doors just before they take `fleetFloorMu`. |
| |
| - [ ] **Step 1: Write failing tests.** |
| - `TestFleetCreateRefusedWhileAChannelIsBelowTheFloor`: pointer `stable` at `v0.31.0` followed by a fresh box: `carlos fleets create` answers 409 with C06 and no fleet row exists; pointer at `v0.32.0`: created; no pointer: created; pointer unreadable: 503 C07. |
| - `TestFleetFloorInterleavings`: (a) no pointer; an update to `v0.31.0` passes `systemFloorGate` with no fleet; `beforeLock` creates fleet `home` through the door (passes: no pointer); the publication then judges under `fleetFloorMu`, refuses with C03, and `GetSystemPointer` still returns not-found. (b) no pointer, no fleet; the publication of `v0.31.0` holds `fleetFloorMu` (`locked` hook) while a fleet create starts in a goroutine; after it publishes, the create returns 409 C06 and no fleet row exists. |
| - - Mutation: release `fleetFloorMu` before `publish`; (a) fails. |
| + - (c), the mutual exclusion through the write: no pointer, no fleet; the publication of `v0.31.0` judges (passes) and the `locked` hook, which runs after the judgment and before `publish`, starts a fleet create in a goroutine, waits until the create's own `beforeLock` hook reports it is about to take `fleetFloorMu`, then waits 200 ms and asserts the create has not returned and no fleet row exists; the hook returns, the pointer is published, and the create then returns 409 C06 with no fleet row. |
| + - Case (a) is the re-judgment witness and stays. The early-unlock mutation (release `fleetFloorMu` after the judgment, before `publish`) is shown against (c): the create returns 201 inside the hook's wait, and the test fails. |
| - [ ] **Step 2: Run** `nice -n 19 go test ./internal/console/ -run 'TestFleetCreateRefused|TestFleetFloorInterleavings|TestFleetFloor|TestAPIFleet' -count=1`. Expected: FAIL on the new tests. |
| - [ ] **Step 3: Implement.** |
| - [ ] **Step 4: Run** Step 2. Expected: PASS. |
| @@ -373,21 +404,26 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| ### Task 12: Switch it on at the hub, and the request budget |
| |
| **Files:** |
| -- Modify: `internal/host/hub.go` (`hubFleetOwners`), `internal/host/agent.go:3552` (`boxProvisionConfig`) |
| +- Modify: `internal/host/hub.go` (`hubFleetOwners`), `internal/host/agent.go:3552` (`boxProvisionConfig` becomes `BoxProvisionConfig`), its callers `agent.go:3261` (`fastConvergeLoop`'s `passLegs.cfg`) and `instancesLoop` (`agent.go:3849`) |
| +- Migrate: `internal/host/policycache_wiring_test.go:31,47,59`, `lifetime_gating_test.go:513`, `sizestatus_test.go:251,259`, `hawake_wiring_test.go:20` |
| - Test: `internal/host/fleet_forward_budget_test.go` |
| |
| **Interfaces:** |
| -- Consumes: Task 1's `hubArmed`, Task 10's `FleetOwners`. |
| -- Produces: `func hubFleetOwners(reg *registry.Registry) func() (map[string]string, error)` (fleet name -> account from `ListFleets`); `boxProvisionConfig` sets `cfg.FleetOwners` when `hubArmed(os.Getenv)`. This is the switch-on. |
| - |
| -- [ ] **Step 1: Write failing tests.** |
| - - `TestBoxProvisionConfigArmsForwardingOnTheHubOnly`: env with `CARLOS_TUNNEL_HOST`: `FleetOwners` non-nil and returns the registry's fleets; with `CARLOS_FLEET` also set, or neither: nil. |
| - - `TestForwardRequestBudget`: §6's comparative test. One `DirStore` wrapped in a counting store keyed by object prefix; one registry; the production functions the loops call (`reconcileSerialized` with `boxProvisionConfig`'s config, `telemetryPass`, `plansPass` with plans on, `retentionPass`, `bs.refreshAll`, `ReconcileFleetBindings`, `edgesFilePass`, `countExpiredCanaries`, `domains.Reconcile` with an apps domain, `aliasPassReporting` with the box's judge) run once over a baseline, then over the baseline plus `shop` of `bab` on `fleet/home` on channel `canary/x` with its forward row. Assert the difference per prefix: one tombstone GET; the telemetry and limits reads of §6 (`A = 1`, `C = 1`); zero manifest, seed, policy, retention and channel-pointer reads for `shop`. Case two: attach an instance catch-all claim for `shop`: exactly one more `List` of `apps/bab/shop/instances/`. Case three: two `shop` instances sharing a label: their two lifetime observations more (record and slot GETs). |
| -- [ ] **Step 2: Run** `nice -n 19 go test ./internal/host/ -run 'TestBoxProvisionConfigArmsForwarding|TestForwardRequestBudget' -count=1`. Expected: FAIL. |
| -- [ ] **Step 3: Implement.** |
| -- [ ] **Step 4: Run** Step 2. Expected: PASS. If the budget test shows a read §6 does not list, stop and update spec §6 (with the reason) in this commit rather than loosening the assertion. |
| -- [ ] **Step 5: Census** (`boxProvisionConfig`, `hubFleetOwners`). |
| -- [ ] **Step 6: Commit.** |
| +- Consumes: Task 1's `hubArmed`; Task 10's `FleetOwners`. |
| +- Produces: |
| + - `func hubFleetOwners(reg *registry.Registry) func() (map[string]string, error)`: fleet name to account, from `reg.ListFleets()` on each call. |
| + - `func BoxProvisionConfig(reg *registry.Registry, getenv func(string) string, judge *provision.LifetimeJudge, configure []func(*provision.ReconcileConfig)) provision.ReconcileConfig`: today's body with `provisionTickConfig(getenv)` in place of `os.Getenv`, plus `cfg.FleetOwners = hubFleetOwners(reg)` when `hubArmed(getenv)`. Exported because Task 13's witness, in the root package, builds the hub's and the box's pass config with it; it is the function both production loops call, so the export is production-used. Callers: `BoxProvisionConfig(reg, os.Getenv, judge, configure)` in both loops (each already has `reg` in scope). |
| + - The source pins in `policycache_wiring_test.go` count `BoxProvisionConfig(reg, os.Getenv, judge, configure)` (2, one per loop); `configuredClaimProvision(provisionTickConfig(` stays at 1. This is the switch-on. |
| + |
| +- [ ] **Step 1: Migrate** the pinning tests and the four callers in tests to the new name and arguments (a test registry from `openTestRegistry`-equivalent in `internal/host`, `func(string) string { return "" }`). |
| +- [ ] **Step 2: Write failing tests.** |
| + - `TestBoxProvisionConfigArmsForwardingOnTheHubOnly`: getenv with `CARLOS_TUNNEL_HOST`: `FleetOwners` non-nil and returns the registry's fleets (`home`->`bab`); with `CARLOS_FLEET` also set, or neither: nil. |
| + - `TestForwardRequestBudget`: spec §6's comparative test. One `DirStore` wrapped in a counting store keyed by object prefix; one registry; the production functions the loops call (`provision.Reconcile` with `BoxProvisionConfig`'s config, `telemetryPass`, `plansPass` with plans on, `retentionPass`, `bs.refreshAll`, `ReconcileFleetBindings`, `edgesFilePass`, `countExpiredCanaries`, `domains.Reconcile` with an apps domain, `aliasPassReporting` with the box's judge) run once over a baseline, then over the baseline plus `shop` of `bab` on `fleet/home` on channel `canary/x` with its forward row. Assert the difference per prefix: one tombstone GET; the telemetry and limits reads of §6 (`A = 1`, `C = 1`); zero manifest, seed, policy, retention and channel-pointer reads for `shop`. Case two: attach an instance catch-all claim for `shop`: exactly one more `List` of `apps/bab/shop/instances/`. Case three: two `shop` instances sharing a label: their two lifetime observations more (record and slot GETs). |
| +- [ ] **Step 3: Run** `nice -n 19 go test ./internal/host/ -run 'TestBoxProvisionConfigArmsForwarding|TestForwardRequestBudget|TestPolicyCache|TestLifetimeGating|TestSizeStatus|TestHAWake' -count=1`. Expected: FAIL on the new tests only. |
| +- [ ] **Step 4: Implement.** |
| +- [ ] **Step 5: Run** Step 3. Expected: PASS. If the budget test shows a read §6 does not list, update spec §6 with the reason in this commit rather than loosening the assertion. |
| +- [ ] **Step 6: Census** (`BoxProvisionConfig` replacing `boxProvisionConfig`, `fastConvergeLoop`, `instancesLoop`, `hubFleetOwners`). |
| +- [ ] **Step 7: Commit.** |
| |
| ### Task 13: The production-wired witness |
| |
| @@ -395,28 +431,32 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| - Create: `fleet_public_routes_e2e_test.go` (root package) |
| |
| **Interfaces:** |
| -- Consumes: everything above, through production constructors only: `console.NewServer` over a temp registry and a `release.DirStore`; the hub `Edge` armed by `enableTunnelsFromEnv` (`CARLOS_TUNNEL_HOST` in the test env) on the same registry; the hub's instance pass through the change-index leg's function with `boxProvisionConfig`'s config; the box: a second `Edge` on its own registry, its instance pass with `CARLOS_FLEET=home`, `CARLOS_REGION=fleet/home`, serving over `tunnelclient.Loop` with the token `fleets add-box` printed; a real process bound at the derived socket answering `/up` with `v1` (the binary instance kind; the tests' existing tiny server binary). |
| +- Consumes, all exported and used in production, nothing exported for the test alone: `console.NewServer` over a temp registry and a `release.DirStore` (as `deploy_region_e2e_test.go` runs the console); the `carlos` CLI built by `buildCarlos` (`auth_e2e_test.go:34`) for every member action; the hub `Edge` from `edge.New`, armed with `EnableStatic` and `EnableTunnels(edge.NewTunnelHub(host, nil))` (the calls `enableTunnelsFromEnv` makes) on the console's registry file, served by `httptest.NewTLSServer`; the hub's pass as `provision.Reconcile(ctx, store, reg, host.BoxProvisionConfig(reg, hubEnv, nil, nil))` with `hubEnv` naming `CARLOS_TUNNEL_HOST`; the box: a second `Edge` on its own registry, its pass `provision.Reconcile(ctx, boxStore, boxReg, host.BoxProvisionConfig(boxReg, boxEnv, nil, nil))` with `CARLOS_FLEET=home`, `CARLOS_REGION=fleet/home` over a `fleetapi.New` store (the door), its release staged and stamped by `release.Pass(ctx, boxReg, boxStore, pub, optDir, nil)` (the root adopt pass) into a temp `optDir`, the staged binary (the tiny server the console tests ship) started by the test at the row's socket as its unit would start it, and the box dialed in with `tunnelclient.Loop` using the token `fleets add-box` printed. |
| +- Why in-process: an unprivileged `carlos agent` cannot stage (the agent relays a blocked stage to root, `internal/host/stagerelay.go`) or run an instance unit, so a subprocess harness of the agents would have to fake root; the one export it costs, `BoxProvisionConfig`, is the production loops' own function (Task 12). |
| |
| -- [ ] **Step 1: Write the test** `TestFleetAppServesThroughTheHub`, no hand rows, no fabricated records, every step through the console's HTTP API as the CLI calls it: |
| - 1. Create account `bab`, fleet `home`, box `box-1`; app `shop` with `--place fleet/home`; set a password gate and a rate limit of 5 per window; ship and promote `v1`; create the instance `shop.bab.example.com`. |
| - 2. Through the hub's TLS listener (test certificate): `GET /up` is the fleet edge's login form; the form posted back as a browser sends it with a wrong password: the wrong-password page, no cookie; with the right one: the cookie; `GET /up` with it: 200 and `Header.Values("X-Carlos-Version") == []string{"v1"}`; without it: the form again. |
| +- [ ] **Step 1: Write** `TestFleetAppServesThroughTheHub`, no hand rows, no fabricated records, every member step through the CLI: |
| + 1. Account `bab`, fleet `home`, box `box-1`; app `shop` with `--place fleet/home`; a password gate and a rate limit of 5 per window; ship and promote `v1`; instance `shop.bab.example.com`. Run both passes and the box's adopt pass. |
| + 2. Through the hub's TLS listener: `GET /up` is the fleet edge's login form; the form posted back as a browser sends it with a wrong password: the wrong-password page, no cookie; with the right one: the cookie; `GET /up` with it: 200 and `Header.Values("X-Carlos-Version") == []string{"v1"}`; without it: the form again. |
| 3. Requests over the limit: 429 from the hub. |
| 4. Attach a custom parent with an instance catch-all: `<slug>.<parent>` serves 200. |
| - 5. Detach `box-1`: 503 with `Retry-After`; re-add it (new token, box redials): 200. |
| - 6. Trash `shop` (not production): after the hub's next pass the forward row is gone and the hub refuses the name's TLS handshake. |
| + 5. `fleets detach-box`: 503 with `Retry-After`; `fleets add-box` again and redial with the new token: 200. |
| + 6. Trash `shop` (not production): after the hub's pass the forward row is gone and the hub's TLS handshake for the name fails. |
| 7. Account `k3x` writes a record placed on `fleet/home` directly to the store: after a pass, no row at its host and no entry in the hub's edges file. |
| -- [ ] **Step 2: Run** `TMPDIR=/tmp/g nice -n 19 go test . -run 'TestFleetAppServesThroughTheHub' -count=1 -v` (sandbox off). Expected: PASS. Show it can fail: set `FleetOwners` nil in the test's config; step 2 fails with a TLS refusal. |
| -- [ ] **Step 3: Commit.** |
| +- [ ] **Step 2: Run** `TMPDIR=/tmp/g nice -n 19 go test . -run 'TestFleetAppServesThroughTheHub' -count=1 -v` (sandbox off). Expected: PASS. Show it can fail: give the hub `hubEnv` without `CARLOS_TUNNEL_HOST`; step 2 fails with a TLS refusal. |
| +- [ ] **Step 3: Census** (none expected: a test file; confirm the card is unchanged). |
| +- [ ] **Step 4: Commit.** |
| |
| -### Task 14: Census, whole-branch review, merge |
| +### Task 14: Legacy rows inventory, census, whole-branch review, merge |
| |
| -- [ ] **Step 1:** `make census-card`; reconcile every unit against spec §7 (no difference left unexplained); write CLAIMS from §7's per-unit text; `make census-propose NAME=fleet-public-routes CLAIMS=<file>`. |
| -- [ ] **Step 2:** Brief Astra from `REVIEW-BRIEF-TEMPLATE.md` for the census and the whole branch (one review, three rounds, stopping rules); focus: the writer guard, the predicate's two callers, `boxWhollyNested`, the floor's mutex. |
| -- [ ] **Step 3:** Push to amadan; `amadan ci status carlos/platform -branch design-fleet-public-routes` green on the tip; record the census verdict on #280; `amadan branch describe`. |
| -- [ ] **Step 4:** Paul's merge go, then `amadan branch merge carlos/platform design-fleet-public-routes -squash -expect <full tip> -message "..."`. |
| +- [ ] **Step 1: Read-only inventory of fleet-placed rows that are not forward rows**, on dev and on the flagship, through the existing read path only (no SSM, no box access, no change): for each account that owns a fleet (`carlos fleets ls --account <sqid> --console <origin>`), and for each app the fleet page lists as placed, `carlos routes --app <app> --account <sqid> --console <origin>`; a row whose REGION names a fleet and whose KIND is not `forward` is a hand row or a legacy placed row that will keep its host (spec §4.7). Dev: `--console https://platform.dev.carlosframework.com`; the flagship: its console origin. Post the list on #457. Removing any row later needs Paul's approval per row. |
| +- [ ] **Step 2:** `make census-card`; reconcile every unit against spec §7 (no unexplained difference); CLAIMS from §7's per-unit text; `make census-propose NAME=fleet-public-routes CLAIMS=<file>`. |
| +- [ ] **Step 3:** Brief Astra from `REVIEW-BRIEF-TEMPLATE.md` for the census and the whole branch (one review, three rounds, stopping rules); focus: the writer guard, the predicate's two callers, `boxWhollyNested`, the floor's mutex. |
| +- [ ] **Step 4:** Push to amadan; `amadan ci status carlos/platform -branch design-fleet-public-routes` green on the tip; the census verdict on #280; `amadan branch describe`. |
| +- [ ] **Step 5:** Paul's merge go, then `amadan branch merge carlos/platform design-fleet-public-routes -squash -expect <full tip> -message "..."`. |
| |
| ### Task 15: Live on dev |
| |
| +- [ ] **Step 0: Release notes.** A paragraph for the release that carries this, through the release's Luna pass: fleet-placed apps get public routes on the hub; an existing route at a fleet app's host keeps it (name the Task 14 inventory's count, no hostnames); the new floor (`v0.32.0`) and what `--allow-below-fleet-forward-floor` costs. |
| - [ ] **Step 1:** A release containing the merge, numbered `v0.32.0` (or Task 8's constant and its pin re-set to the cut's number on a follow-up branch before the cut), rolled to dev: dev boxes, then the dev console (sophie, the hub), the CLI on DOCS-T1. |
| - [ ] **Step 2:** From DOCS-T1: `curl -sI https://shop.bab.dev.oncarlos.com/up` answers `200` with exactly one `x-carlos-version: v1`. |
| - [ ] **Step 3:** The same through leo: `curl -sI --resolve shop.bab.dev.oncarlos.com:443:18.200.150.210 https://shop.bab.dev.oncarlos.com/up`: 200, one `v1`. |
| @@ -427,8 +467,8 @@ Forward rows exist only once the hub's pass is given `FleetOwners` (Task 12). Un |
| |
| ## Self-review |
| |
| -1. **Spec coverage.** §4.2 shape: Task 2; writer rule and inventory: Task 3. §4.3 forward phase, trash, prefetch, order, ownership: Task 10; switch-on: Task 12. §4.4 predicate: Task 4 (serving), Task 6 (publication). §4.5 bindings: Task 1. §4.6 retirement table: Task 10 tests, Task 13 steps 5-6. §4.7 rows already there, `apps place`: Tasks 10, 11. §4.8 request policy: Task 5; gate and caches: Task 4. §4.9 certs: Tasks 4, 6. §4.10 backhaul: Task 15 step 3. §4.11 catch-alls: Task 6, Task 13 step 4; no platform names: Task 7's domains test leaves `firstReadyUpstream` untouched (no change needed, §4.11). §4.12 headers: Task 4. §4.13 hibernation: no change (Task 7's readers table pins `ActivatorManaged`). §4.15 readers: Task 7; console readers: Task 11. §6 budget: Task 12. §7 census: every task's census step, Task 14. §8 tests: distributed as above; the witness: Task 13. §9 floor: Tasks 8, 9; rollout: Task 15. |
| +1. **Spec coverage.** §4.2 shape: Task 2; writer rule and inventory: Task 3. §4.3 forward phase, trash, prefetch, order, ownership: Task 10; switch-on: Task 12. §4.4 predicate: Task 4 (serving), Task 6 (publication). §4.5 bindings: Task 1. §4.6 retirement table: Task 10 tests, Task 13 steps 5-6. §4.7 rows already there, `apps place`: Tasks 10, 11, and Task 14's inventory. §4.8 request policy: Task 5; gate and caches: Task 4. §4.9 certs: Tasks 4, 6. §4.10 backhaul: Task 15 step 3. §4.11 catch-alls: Task 6, Task 13 step 4; no platform names: Task 7's domains test leaves `firstReadyUpstream` untouched (no change needed, §4.11). §4.12 headers: Task 4. §4.13 hibernation: no change (Task 7's readers table pins `ActivatorManaged`). §4.15 readers: Task 7; console readers: Task 11. §6 budget: Task 12. §7 census: every task's census step, Task 14. §8 tests: distributed as above; the witness: Task 13. §9 floor: Tasks 8, 9; rollout and release notes: Task 15. |
| 2. **Step scan.** No step says "handle" or "as appropriate" without a named rule; code appears only as signatures, the SQL the spec fixes, and the copy table. |
| -3. **Type consistency.** `SetFleetBoxIf(host, fleet, label string) (bool, error)` (Tasks 1, 2's remote case, 10 never calls it); `DeleteForward(host string) (bool, error)`; `PutForward(rt Route) error`; `FleetServeEligible(rt registry.Route, hub bool, owners map[string]string) (bool, string)` (Tasks 4, 6); `hubArmed(getenv func(string) string) bool` (Tasks 1, 6, 12); `FleetOwners func() (map[string]string, error)` (Tasks 10, 12); `fleetFloorPublish` and `fleetForwardFloorJudge` (Tasks 8, 9). |
| +3. **Type consistency.** `SetFleetBoxIf(host, fleet, label string) (bool, error)` (Task 1); `DeleteForward(host string) (bool, error)`; `PutForward(rt Route) error`; `ForwardForbidden []ForwardColumn` (Tasks 2, 4, 6, 7); `FleetServeEligible(rt registry.Route, hub bool, owners map[string]string) (bool, string)` (Tasks 4, 6); `hubArmed(getenv func(string) string) bool` (Tasks 1, 6, 12); `FleetOwners func() (map[string]string, error)` (Tasks 10, 12); `BoxProvisionConfig(reg, getenv, judge, configure)` (Tasks 12, 13); `fleetFloorPublish` and `fleetForwardFloorJudge` (Tasks 8, 9). |
| 4. **Review focus.** Five lines, each with its test in the owning task (Tasks 1, 4, 9, 10, 11). |
| 5. **Proportion.** The plan carries signatures, test names, assertions and the spec's values; no function bodies beyond the fixed SQL. |