console: slice 3 CI guards and regressions
- The fleet seeds door is declared to the claim guards: the three
routes join testdata/claim-routes.txt, and each has a claim refusal
fixture. On a host-claim console the door answers the seed doors'
claim sentence (409) after its owner gate, so every other caller
still gets the identical 404.
- The linked-app walk lists the three routes with the replica doors as
box-only {app} routes: no person reaches them, so a linked app's
caller keeps the door's 404.
- The claims-off legacy retire reads through the judged reader
(observeRecord), as the lifetimes audit requires.
- Test doubles: hookStore forwards conditional deletes with its delete
hooks and failures, and the dispatch test pauses the legacy detach's
now-conditional delete.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9 files changed,
+123
−10
internal/console/apifleetseeds.go+10 −0internal/console/apilinks_test.go+3 −0internal/console/claim_invariant_fixtures_test.go+5 −0internal/console/claim_invariant_seeds_test.go+69 −0internal/console/hostclaimops.go+10 −8internal/console/lifetimes_create_test.go+3 −1internal/console/temphook_test.go+16 −0internal/console/testdata/claim-routes.txt+3 −0internal/provision/fleet_seeded_create_3_census_test.go+4 −1
CI passed — run details
diff --git a/internal/console/apifleetseeds.go b/internal/console/apifleetseeds.go| index 23b3ff52d..1e7996e16 100644 |
| --- a/internal/console/apifleetseeds.go |
| +++ b/internal/console/apifleetseeds.go |
| @@ -183,6 +183,16 @@ func (s *Server) fleetSeedDoor(w http.ResponseWriter, r *http.Request, op string |
| http.NotFound(w, r) |
| return |
| } |
| + // A claim console admits no seed (seedFleetReady refuses it first, plan |
| + // R3-1), and neither sweeps nor finishes one, so it records no seed's |
| + // transition either: the claim sentence, after the owner gate so any |
| + // other caller still gets the identical 404, and before anything is |
| + // read or written. |
| + if s.cfg.HostClaim { |
| + ref := seedClaimConsoleRefusal() |
| + jsonError(w, ref.Status, ref.Msg) |
| + return |
| + } |
| var body fleetSeedReport |
| if !replicaPayload(r, &body) || !fleetSeedReportValid(op, r.PathValue("host"), body) { |
| http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) |
diff --git a/internal/console/apilinks_test.go b/internal/console/apilinks_test.go| index ca9782901..15c5dcf88 100644 |
| --- a/internal/console/apilinks_test.go |
| +++ b/internal/console/apilinks_test.go |
| @@ -698,6 +698,9 @@ var linkedWalkBoxDoors = map[string]bool{ |
| "POST /api/fleet/replicas/{account}/{app}/{host}/coordinator": true, |
| "POST /api/fleet/replicas/{account}/{app}/{host}/release": true, |
| "POST /api/fleet/replicas/{account}/{app}/{host}/deploy": true, |
| + "POST /api/fleet/seeds/{account}/{app}/{host}/placed": true, |
| + "POST /api/fleet/seeds/{account}/{app}/{host}/failed": true, |
| + "POST /api/fleet/seeds/{account}/{app}/{host}/rolledback": true, |
| } |
| // worldSnapshot is what a refused request must not change: every console |
diff --git a/internal/console/claim_invariant_fixtures_test.go b/internal/console/claim_invariant_fixtures_test.go| index ccddbe955..5e1f2324b 100644 |
| --- a/internal/console/claim_invariant_fixtures_test.go |
| +++ b/internal/console/claim_invariant_fixtures_test.go |
| @@ -747,6 +747,11 @@ var claimFixtures = map[string]claimFixture{ |
| "route POST /api/fleet/replicas/{account}/{app}/{host}/coordinator": {door: claimReplicaDoor("coordinator")}, |
| "route POST /api/fleet/replicas/{account}/{app}/{host}/release": {door: claimReplicaDoor("release")}, |
| "route POST /api/fleet/replicas/{account}/{app}/{host}/deploy": {door: claimReplicaDoor("deploy")}, |
| + // The fleet seeds door (apifleetseeds.go): refused on a host-claim |
| + // console, which admits no seed (claim_invariant_seeds_test.go). |
| + "route POST /api/fleet/seeds/{account}/{app}/{host}/placed": {refused: claimSeedsDoorRefusal("placed")}, |
| + "route POST /api/fleet/seeds/{account}/{app}/{host}/failed": {refused: claimSeedsDoorRefusal("failed")}, |
| + "route POST /api/fleet/seeds/{account}/{app}/{host}/rolledback": {refused: claimSeedsDoorRefusal("rolledback")}, |
| "route GET /accounts": claimRead("renders only the signed-in person’s account memberships"), |
| // ---- methodless routes (the handler checks r.Method itself) ---- |
| "route /api/economics/backhaul": claimRead("operator backhaul report (GET only) computed from the economics view; writes nothing"), |
diff --git a/internal/console/claim_invariant_seeds_test.go b/internal/console/claim_invariant_seeds_test.go| new file mode 100644 |
| index 000000000..7365d806e |
| --- /dev/null |
| +++ b/internal/console/claim_invariant_seeds_test.go |
| @@ -0,0 +1,69 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "net/http" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/seeds" |
| +) |
| + |
| +// claimSeedsDoorRefusal is the fleet seeds door's claim fixture: an owning |
| +// box's valid report, which a host-claim console refuses with the seed |
| +// doors' claim sentence after its owner gate and before it reads or writes |
| +// anything. No seed is ever admitted on such a console (seedFleetReady |
| +// refuses it first), so the setup writes the record a fleet's create would |
| +// have. |
| +func claimSeedsDoorRefusal(operation string) *claimRefusalFixture { |
| + const host = "seeded.shop.example.com" |
| + return &claimRefusalFixture{ |
| + apps: claimRefs("bab/titogo"), |
| + setup: func(t *testing.T, cx *claimCase) { |
| + cx.fleet(t) |
| + token, hash, err := mintFleetToken() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + reg, err := openRegistry(cx.srv.cfg.Registry) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := reg.AddFleetBox(registry.FleetBox{Fleet: "pi", Label: "pi-1", TokenHash: hash}); err != nil { |
| + t.Fatal(err) |
| + } |
| + id, err := seeds.NewID() |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + now := time.Now().UTC() |
| + rec := provision.Record{Schema: 1, Account: "bab", App: "titogo", Host: host, Slug: "seeded", Region: "fleet/pi", |
| + FleetBox: "pi-1", Channel: "stable", CreatedAt: now, |
| + Seed: &provision.SeedSource{ID: id, Kind: seeds.KindFile, State: seeds.StateReady, SHA256: strings.Repeat("a", 64), |
| + Bytes: 4, By: "paul@keymail.dev", At: now}} |
| + if err := provision.CreateRecord(context.Background(), cx.rel, rec); err != nil { |
| + t.Fatal(err) |
| + } |
| + cx.vars["seed-token"], cx.vars["seed-id"] = token, id |
| + }, |
| + do: func(t *testing.T, cx *claimCase) (int, string) { |
| + body := map[string]string{"id": cx.vars["seed-id"]} |
| + if operation == provision.FleetSeedFailed { |
| + body["code"] = provision.SeedCodeMismatch |
| + } |
| + raw, err := json.Marshal(body) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + status, _, out := rawReqHeader(t, http.MethodPost, cx.ts.URL+"/api/fleet/seeds/bab/titogo/"+host+"/"+operation, |
| + cx.vars["seed-token"], string(raw), map[string]string{"Carlos-Tunnel-Name": "pi/pi-1"}) |
| + return status, out |
| + }, |
| + status: http.StatusConflict, |
| + msg: seedClaimConsoleRefusal().Msg, |
| + } |
| +} |
diff --git a/internal/console/hostclaimops.go b/internal/console/hostclaimops.go| index a48137cb8..b8c56ba31 100644 |
| --- a/internal/console/hostclaimops.go |
| +++ b/internal/console/hostclaimops.go |
| @@ -57,18 +57,20 @@ func (s *Server) retireHostRecord(ctx context.Context, ref provision.RetireRef) |
| // done, as lifetimes on answers it. A body whose region and seed cannot be |
| // read is refused (fleetSeedHoldRaw fails closed, slice 3 review P3-1). |
| func (s *Server) retireLegacyInstanceRecord(ctx context.Context, ref provision.RetireRef) error { |
| - key := provision.RecordKey(ref.Account, ref.App, ref.Host) |
| - raw, etag, err := s.cfg.Releases.Get(ctx, key) |
| - if errors.Is(err, os.ErrNotExist) { |
| + // The read is the judged reader's (observeRecord): with lifetimes off it |
| + // is the plain read, with the stored bytes and their etag. |
| + obs := s.observeRecord(ctx, ref.Account, ref.App, ref.Host) |
| + switch { |
| + case obs.Verdict == provision.LifetimeUnreadable: |
| + return obs.Err |
| + case !obs.Present: |
| return nil |
| } |
| - if err != nil { |
| + if err := fleetSeedHoldRaw(ref.Host, obs.Raw); err != nil { |
| return err |
| } |
| - if err := fleetSeedHoldRaw(ref.Host, raw); err != nil { |
| - return err |
| - } |
| - if err := release.DeleteIfMatch(ctx, s.cfg.Releases, key, etag); err != nil && !errors.Is(err, os.ErrNotExist) { |
| + key := provision.RecordKey(ref.Account, ref.App, ref.Host) |
| + if err := release.DeleteIfMatch(ctx, s.cfg.Releases, key, obs.ETag); err != nil && !errors.Is(err, os.ErrNotExist) { |
| return err |
| } |
| return nil |
diff --git a/internal/console/lifetimes_create_test.go b/internal/console/lifetimes_create_test.go| index db8d30b28..a8adae82f 100644 |
| --- a/internal/console/lifetimes_create_test.go |
| +++ b/internal/console/lifetimes_create_test.go |
| @@ -2248,7 +2248,9 @@ func TestDispatchFollowsTheUnit(t *testing.T) { |
| l.fx.srv.cfg.Releases = bucket |
| createGate, createHook := pauseNth(t, "put", recKey(ltApp, ltOne), 1) |
| deleteGate, deleteHook := pauseNth(t, "delete-if-match", recKey(ltApp, ltOld), 1) // deleteRead's conditional delete |
| - detachGate, detachHook := pauseNth(t, "delete", recKey(ltApp, ltDomain), 1) |
| + // The legacy detach's delete is bound to its read (the fleet seed hold, |
| + // retireLegacyInstanceRecord), so it is a conditional delete too. |
| + detachGate, detachHook := pauseNth(t, "delete-if-match", recKey(ltApp, ltDomain), 1) |
| bucket.setHook(chain(createHook, deleteHook, detachHook)) |
| // Three units admitted before the marker, each held inside its door. |
| answers := make(chan string, 3) |
diff --git a/internal/console/temphook_test.go b/internal/console/temphook_test.go| index 96e0d4074..c6139c3c9 100644 |
| --- a/internal/console/temphook_test.go |
| +++ b/internal/console/temphook_test.go |
| @@ -52,6 +52,22 @@ func (h *hookStore) Put(ctx context.Context, key string, body []byte, ifMatch st |
| return h.Store.Put(ctx, key, body, ifMatch) |
| } |
| +// DeleteIfMatch is Delete's hooks and failures for the conditional delete |
| +// (the delete door's deleteRead, and the claims-off legacy retire, bound to |
| +// the read the fleet seed hold was asked of), passed to the store below. |
| +func (h *hookStore) DeleteIfMatch(ctx context.Context, key, etag string) error { |
| + if h.onDelete != nil { |
| + h.onDelete(key) |
| + } |
| + if h.fails(h.failDelete, key) { |
| + return errors.New("hookStore: delete refused") |
| + } |
| + h.mu.Lock() |
| + h.deletes = append(h.deletes, key) |
| + h.mu.Unlock() |
| + return release.DeleteIfMatch(ctx, h.Store, key, etag) |
| +} |
| + |
| func (h *hookStore) Delete(ctx context.Context, key string) error { |
| if h.onDelete != nil { |
| h.onDelete(key) |
diff --git a/internal/console/testdata/claim-routes.txt b/internal/console/testdata/claim-routes.txt| index 1b4bb0fa8..ccd8272a9 100644 |
| --- a/internal/console/testdata/claim-routes.txt |
| +++ b/internal/console/testdata/claim-routes.txt |
| @@ -388,6 +388,9 @@ route POST /api/fleet/enrol |
| route POST /api/fleet/replicas/{account}/{app}/{host}/coordinator |
| route POST /api/fleet/replicas/{account}/{app}/{host}/release |
| route POST /api/fleet/replicas/{account}/{app}/{host}/deploy |
| +route POST /api/fleet/seeds/{account}/{app}/{host}/placed |
| +route POST /api/fleet/seeds/{account}/{app}/{host}/failed |
| +route POST /api/fleet/seeds/{account}/{app}/{host}/rolledback |
| route POST /api/link/publications |
| route POST /api/link/rotate |
| route POST /api/ses/events |
diff --git a/internal/provision/fleet_seeded_create_3_census_test.go b/internal/provision/fleet_seeded_create_3_census_test.go| index edb85cd18..f04a893bb 100644 |
| --- a/internal/provision/fleet_seeded_create_3_census_test.go |
| +++ b/internal/provision/fleet_seeded_create_3_census_test.go |
| @@ -71,6 +71,9 @@ package provision |
| // stored body (fleetSeedHoldRaw: its region and seed alone), so a body |
| // the full decode rejects is still held, and one carrying a seed the |
| // hold cannot read is refused. No site changes. |
| +// - Slice 3 CI: retireLegacyInstanceRecord reads through the judged |
| +// reader (observeRecord) the lifetimes audit requires, in place of a |
| +// raw Get of RecordKey; the bound delete is unchanged. |
| // |
| // Not in the inventory, because they write no record: seedFleetReady, |
| // fleetSeedSnapshots (the sweep's fleet listing; the sweep's own record |
| @@ -107,7 +110,7 @@ func fleetSeededCreate3WriteCensusInventory() []censusEntry { |
| } |
| } |
| return append(entries, |
| - censusEntry{"internal/console/hostclaimops.go", "Server.retireLegacyInstanceRecord", "key-site", "key:RecordKey", "75be7b7a2b460bb3edf1f4b5e94b9a67475690d9a7c7f7e64c9044f6c3b4b649"}, |
| + censusEntry{"internal/console/hostclaimops.go", "Server.retireLegacyInstanceRecord", "key-site", "key:RecordKey", "c6a7984498ee546052b3220e766cbb1a75ca7df69c60fd73cbf3b7f3baf21e3c"}, |
| censusEntry{"internal/console/apifleetseeds.go", "Server.fleetSeedTransition", "record-writer", "key:SetRecordSeed", "44b66548aa5c3cafd85d240edbd4bd48e7f3ccd66dfce76facd5d20561738265"}, |
| ) |
| } |