Merge remote-tracking branch 'origin/main' into claims-cleanup-r2
# Conflicts: # internal/provision/plan9_b8_census_test.go # internal/provision/testdata/plan14-root-reads-chain.tsv
32 files changed,
+681
−109
docs/superpowers/notes/census-proposal-claims-cleanup-r1.md+23 −0docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md+68 −0internal/console/apidbforward.go+1 −2internal/console/apiinstancemove.go+2 −1internal/console/apiinstancemove_offline.go+9 −6internal/console/apiinstancemove_offline_absence.go+74 −0internal/console/apiinstancemove_offline_absence_test.go+154 −0internal/console/apiruns.go+1 −2internal/dbreads/agent.go+1 −2internal/dbreads/fixture_test.go+1 −2internal/host/agent.go+7 −2internal/host/boxreference.go+16 −3internal/host/claimsoff_golden_test.go+34 −0internal/host/movesoffline.go+11 −11internal/host/movesoffline_seal.go+2 −2internal/host/movessources.go+2 −1internal/host/runexec.go+1 −2internal/hostclaim/claim.go+8 −11internal/instancectl/claimunit.go+3 −6internal/instancectl/names.go+10 −0internal/instancectl/rununit_golden_test.go+14 −0internal/park/region_names.go+3 −2internal/provision/claims_cleanup_r1_census_test.go+30 −0internal/provision/claims_cleanup_r2_census_test.go+2 −1internal/provision/incarnation.go+32 −0internal/provision/incarnation_golden_test.go+66 −0internal/provision/testdata/plan14-root-reads-chain.tsv+1 −1internal/provision/testdata/plan14-root-reads-claims-cleanup-r1.tsv+16 −0internal/provision/testdata/plan14-root-reads-claims-cleanup-r2.tsv+0 −51internal/regionname/region.go+8 −0internal/regionname/region_golden_test.go+80 −0internal/runs/runs.go+1 −1
diff --git a/docs/superpowers/notes/census-proposal-claims-cleanup-r1.md b/docs/superpowers/notes/census-proposal-claims-cleanup-r1.md| new file mode 100644 |
| index 000000000..d188f4665 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-claims-cleanup-r1.md |
| @@ -0,0 +1,23 @@ |
| +# Census approval: claims-cleanup-r1 |
| + |
| +Ruling `census-ruling-claims-cleanup-r1`. Every change below keeps the disposition it already has, so it needs an approval, not a decision. |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/console/apiinstancemove_offline.go` `Server.offlineClaimEvidence` | body | unchanged (1) | claims cleanup R1: the admission and backfill reads use the console's own keys and a local copy of hostops.BackfillPlan (same store Gets, same refusals) instead of hostops.AdmissionKey and CheckCreateFreeze; the host claim is still read through hostclaim.Read; no read added, the one scanned read (hostclaim.Read) unchanged | |
| +| `internal/console/apiruns.go` `Server.handleAPIRunCreate` | body | unchanged (1) | claims cleanup R1: the request's incarnation comes from provision.Incarnation, hostclaim.Incarnation's body moved unchanged (golden vectors); no read added or changed | |
| +| `internal/host/agent.go` `runAdoptUnderRootRelease` | body | unchanged (4) | claims cleanup R1: the claims shutdown timeout is the host constant claimsShutdownLimit (120s) instead of hostbox.RequestLimit (120s); no read added or changed | |
| + |
| +Envelopes re-pinned: `internal/console`, `internal/dbreads`, `internal/host`, `internal/hostclaim`, `internal/instancectl`, `internal/park`, `internal/provision`, `internal/regionname`, `internal/runs`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Escalate if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. An escalation goes to the census owner as a decision. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/console/apiinstancemove_offline.go` `Server.offlineClaimEvidence`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-moves-offline;basis=root-input (J4, as main's moves units); the console (cmd/console serve under console.service, user carlos-console): new, reads the host claim, the record's acquisition, a domains claim and the app's admission only to refuse an offline start (MV-O29, MV-O20); a failed read refuses with a 502, never reads as absence; deny-only |
| +- `internal/console/apiruns.go` `Server.handleAPIRunCreate`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the console (cmd/console serve under console.service, user carlos-console): the run create door reads the record, and rereads it after an unknown admit, through readRecord, judged under a unit admitted on and unjudged before; read sites unchanged, offsets moved |
| +- `internal/host/agent.go` `runAdoptUnderRootRelease`: authority, task B3,E1,E2,E3. Basis: rev3=census-ruling-self-serve-moves-1;basis=root claim/adopt/update controller uid 0: builds root's lifetime judge once from the host-claim switch and hands it to both productionRestartRequestPass calls; read sites unchanged, offsets moved; the preceding B3,E1,E2,E3 classification retained |
| + |
| +Seal: `a864cf31b6bf2c30b5aa8c2647835efdc456f34f4945eea12751daab2457728e` → `9cef5e93a1e3520e02efe66455bf70c1170d380b6d6a72ede02036ce3dd41924`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-claims-cleanup-r1.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md b/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md| new file mode 100644 |
| index 000000000..9f713f0e6 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md |
| @@ -0,0 +1,68 @@ |
| +# Claims cleanup R1: move the live slices out of the claim packages |
| + |
| +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| + |
| +**Goal:** No claims-off production caller imports a claim package (hostclaim, park, hostops, hostbox, hostactors) for live behaviour, with no behaviour change. One dependency stays on purpose: the offline door's host claim check keeps `hostclaim.Read`, because telling a malformed claim (502) from a valid one needs hostclaim's full decode and `Validate`. It goes when R6 removes the claim objects' writers. |
| + |
| +**Architecture:** Each live slice gets a neutral home (`provision`, `regionname`, `console`, `host`, `instancectl`). Claim packages that still use a symbol keep it as a thin delegate to the new home, or as a test-pinned twin where the import direction forbids delegation. Golden vectors land first and must pass unchanged after every move. |
| + |
| +**Tech Stack:** Go. |
| + |
| +**Spec:** `docs/superpowers/notes/claims-inventory.md` (on design-live-moves-ha) §2.4, §3, §4 row R1; `docs/superpowers/plans/2026-10-25-claims-cleanup.md` row R1. |
| + |
| +## Global Constraints |
| + |
| +- Claims-off behaviour byte-identical: Incarnation bytes (legacy and created forms), placement codes, offline-door statuses and messages. |
| +- Targeted tests only locally (`nice -n 19 go test ./internal/<pkg>/ -run <X>`); `go build ./...` plus `GOOS=darwin` and `GOOS=windows` before the push; `go vet` on touched packages. |
| +- Census: `make census-card`, CLAIMS file, `make census-propose NAME=claims-cleanup-r1`. A refused class (`removed`, `new`, `reads`, `other`) stops the branch for a report. |
| + |
| +## Review Focus |
| + |
| +- A present-but-malformed `control/hosts/<host>.json` stays a 502: the claim object is still read through `hostclaim.Read`, because only the claim schema can tell a malformed object from a claim. Pinned by `TestOfflineDoorAbsenceChecksRefuseAndFail`. The admission and backfill checks are console-local. |
| +- A backfill plan at phase `done` must still be allowed; the console-local verify must re-encode canonically, so the local plan type copies `hostops.BackfillPlan`'s shape exactly (pinned by a test that signs a `hostops.BackfillPlan` and reads it locally). |
| +- An invalid host or account shape must still give 502 on the claim and admission checks. |
| +- `hostclaim.Incarnation` must keep returning `hostclaim.ErrMalformed` for its claim callers. |
| + |
| +--- |
| + |
| +### Task 1: Golden vectors |
| + |
| +**Files:** Test: `internal/provision/incarnation_test.go`, `internal/regionname/region_golden_test.go`, `internal/host/boxreference_golden_test.go` |
| + |
| +- [ ] Pin `hostclaim.Incarnation` today for one legacy (zero time) and one created (`2026-10-01T12:34:56.789Z`) record, plus one malformed account, as literal hex strings (computed from main before any move). |
| +- [ ] Pin `HomePlacementCode`, `PlacementRegion`, `SameRegion`, `PlacementMatches` over a table (home "", "ie"; codes "", "ie", "uk", "@home", "Bad", 17 chars) through `park.*`. |
| +- [ ] Pin `hostactors.GroupBoxReference("123456789012", "i-0a61f580df1acfa65")` and `hostbox.RequestLimit == 120s`. |
| +- [ ] Run; commit. |
| + |
| +### Task 2: Incarnation into provision |
| + |
| +- [ ] `provision.Incarnation(account, app, host string, created time.Time) (string, error)` in `internal/provision/incarnation.go`; `provision.ErrIncarnation`. |
| +- [ ] Golden test runs against `provision.Incarnation` too; `hostclaim.Incarnation` delegates and maps errors to `ErrMalformed`. |
| +- [ ] Switch `dbreads/agent.go`, `host/runexec.go`, `console/apidbforward.go`, `console/apiruns.go`, the `runs/runs.go` comment. |
| +- [ ] Run dbreads, runs, host `-run Run`, console `-run 'DBRead|Run'`; commit. |
| + |
| +### Task 3: Placement helpers into regionname |
| + |
| +- [ ] `regionname.PlacementMatches(home, code, engine string) bool`; `park.PlacementMatches` delegates. |
| +- [ ] Golden table runs against `regionname.*` too. |
| +- [ ] Switch `console/apiinstancemove.go` `homePlacementCode`, `host/movesoffline.go`, `host/movesoffline_seal.go`, `host/movessources.go` `parkRegion`. |
| +- [ ] Run host `-run Offline`, console `-run 'Offline|Region|InstanceCreate'`; commit. |
| + |
| +### Task 4: The offline door's checks, console-local; dead sentinels |
| + |
| +- [ ] `offlineClaimEvidence` reads `apps/<acct>/<app>/admission.json` and `control/hosts-backfill.json` itself (`offlineAdmissionKey`, `offlineBackfillKey`, `offlineBackfillPlan` mirroring `hostops.BackfillPlan`). The host claim `control/hosts/<host>.json` stays on `hostclaim.Read` (see the goal). |
| +- [ ] Tests: keys equal hostops'; a signed `hostops.BackfillPlan` reads locally; a malformed host claim gives 502, as on main; an unreadable object gives 502. |
| +- [ ] ~~Delete the `hostops.ErrPending`/`ErrContract` comparisons at `domainattach.go`, `apidomains.go`, `apisystem.go`, `scandeliver.go`.~~ Not done: each never matches claims off (the sources are `domains`/`provision`/`objstore`/`appconfig` on an ungated store), but each does match claims on, and `TestClaimScanCallbackContentionAndSettlement` and `TestClaimScanMasterRotationSkipsBusyApp` pin two of them. Deleting them changes claims-on behaviour, so they go with R6, when their sources do. |
| +- [ ] Run console `-run 'Offline|Domain|Scan|System'`; commit. |
| + |
| +### Task 5: RequestLimit, GroupBoxReference, the unit control group |
| + |
| +- [ ] `host.claimsShutdownLimit = 120 * time.Second` replaces `hostbox.RequestLimit` in `agent.go`; `host.groupBoxReference` replaces `hostactors.GroupBoxReference` in `boxreference.go`; golden tests pin both against the claim twins. |
| +- [ ] `instancectl.RunUnitControlGroup` in `names.go`; the offline round calls it; `ClaimUnitControlGroup` stays as a delegate for its ~25 claim callers (renaming them all would edit census authority units for no live gain). Golden test pins the path. |
| +- [ ] Run host `-run 'BoxReference|Joining|Group'`, instancectl, activator `-run RoleLaunch`; commit. |
| + |
| +### Task 6: Census, builds, push |
| + |
| +- [ ] `make census-card`; CLAIMS; `make census-propose NAME=claims-cleanup-r1 CLAIMS=<file>`; `TestPlan14RootReadCensus`, `TestPlan14RootInputInventoryCoverage`. |
| +- [ ] `go build ./...`, darwin, windows; `go vet` touched packages; `gofmt -l`. |
| +- [ ] Commit, push, `amadan ci status carlos/platform -branch claims-cleanup-r1`. |
diff --git a/internal/console/apidbforward.go b/internal/console/apidbforward.go| index 3b6a66777..2d4d9ccc8 100644 |
| --- a/internal/console/apidbforward.go |
| +++ b/internal/console/apidbforward.go |
| @@ -25,7 +25,6 @@ import ( |
| "github.com/carlosframework/platform/internal/dbdoor" |
| "github.com/carlosframework/platform/internal/dbquery" |
| "github.com/carlosframework/platform/internal/dbreads" |
| - "github.com/carlosframework/platform/internal/hostclaim" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -412,7 +411,7 @@ func (s *Server) admitDBRead(w http.ResponseWriter, r *http.Request) (dbReadAdmi |
| if err != nil { |
| return fail("mint id", err) |
| } |
| - inc, err := hostclaim.Incarnation(acct.Sqid, app, host, rec.CreatedAt) |
| + inc, err := provision.Incarnation(acct.Sqid, app, host, rec.CreatedAt) |
| if err != nil { |
| return fail("incarnation", err) |
| } |
diff --git a/internal/console/apiinstancemove.go b/internal/console/apiinstancemove.go| index 2ac1ca6b4..95fda4da5 100644 |
| --- a/internal/console/apiinstancemove.go |
| +++ b/internal/console/apiinstancemove.go |
| @@ -8,6 +8,7 @@ import ( |
| "errors" |
| "fmt" |
| "github.com/carlosframework/platform/internal/park" |
| + "github.com/carlosframework/platform/internal/regionname" |
| "log" |
| "net/http" |
| "os" |
| @@ -316,7 +317,7 @@ func (s *Server) homeRegionIn(region string) string { |
| // home named nothing is the home. claimMoveRosterPlaces reads roster |
| // regions through it too, so the door and the API translate home one way. |
| func homePlacementCode(home, region string) string { |
| - return park.HomePlacementCode(home, region) |
| + return regionname.HomePlacementCode(home, region) |
| } |
| func (s *Server) homeRegionOut(region string) string { |
diff --git a/internal/console/apiinstancemove_offline.go b/internal/console/apiinstancemove_offline.go| index 103ac3927..1739c1776 100644 |
| --- a/internal/console/apiinstancemove_offline.go |
| +++ b/internal/console/apiinstancemove_offline.go |
| @@ -18,7 +18,6 @@ import ( |
| "github.com/carlosframework/platform/internal/domains" |
| "github.com/carlosframework/platform/internal/hostclaim" |
| - "github.com/carlosframework/platform/internal/hostops" |
| "github.com/carlosframework/platform/internal/moves" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -438,6 +437,10 @@ func (s *Server) offlineClaimEvidence(ctx context.Context, d offlineDoor) *offli |
| if d.rec.Acquisition != "" { |
| return has |
| } |
| + // The claim object is still read through hostclaim: an object that is |
| + // present but does not decode and validate as a claim is a 502, and |
| + // only the claim schema can say which it is (claims cleanup R1 keeps |
| + // this one read where it was). |
| obs, err := hostclaim.Read(ctx, s.cfg.Releases, d.host) |
| if err != nil { |
| log.Printf("console: offline move %s: claim read: %v", d.host, err) |
| @@ -452,9 +455,9 @@ func (s *Server) offlineClaimEvidence(ctx context.Context, d offlineDoor) *offli |
| log.Printf("console: offline move %s: domains claim read: %v", d.host, err) |
| return unreadable |
| } |
| - key, err := hostops.AdmissionKey(d.acct.Sqid, d.app) |
| - if err != nil { |
| - log.Printf("console: offline move %s: admission key: %v", d.host, err) |
| + key, ok := offlineAdmissionKey(d.acct.Sqid, d.app) |
| + if !ok { |
| + log.Printf("console: offline move %s: admission key: invalid account or app", d.host) |
| return unreadable |
| } |
| if _, _, err := s.cfg.Releases.Get(ctx, key); err == nil { |
| @@ -465,9 +468,9 @@ func (s *Server) offlineClaimEvidence(ctx context.Context, d offlineDoor) *offli |
| } |
| // A plan at done is allowed; one that has begun, or that cannot be |
| // verified, is not. |
| - switch err := hostops.CheckCreateFreeze(ctx, s.cfg.Releases, s.cfg.ReleasePub); { |
| + switch err := offlineBackfillFreeze(ctx, s.cfg.Releases, s.cfg.ReleasePub); { |
| case err == nil: |
| - case errors.Is(err, hostops.ErrPending), errors.Is(err, hostops.ErrIdentity): |
| + case errors.Is(err, errOfflineBackfillBegun): |
| return &offlineRefusal{status: http.StatusConflict, msg: "offline moves are not available while host claims or Phase 1 moves are on"} |
| default: |
| log.Printf("console: offline move %s: backfill plan read: %v", d.host, err) |
diff --git a/internal/console/apiinstancemove_offline_absence.go b/internal/console/apiinstancemove_offline_absence.go| new file mode 100644 |
| index 000000000..1338bf80a |
| --- /dev/null |
| +++ b/internal/console/apiinstancemove_offline_absence.go |
| @@ -0,0 +1,74 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "crypto/ed25519" |
| + "errors" |
| + "os" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/controlname" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The offline move door's admission and backfill checks (MV-O20, MV-O29), |
| +// read here and not through hostops since claims cleanup R1: host claims |
| +// are off everywhere and hostops is going, but a deployment that ever wrote |
| +// one of these objects must still be refused. Each key is hostops' own |
| +// (TestOfflineAbsenceKeysAreTheClaimKeys). The claim object itself is still |
| +// read through hostclaim (offlineClaimEvidence). |
| + |
| +// offlineBackfillKey is the host-claim backfill plan (hostops.BackfillKey). |
| +const offlineBackfillKey = "control/hosts-backfill.json" |
| + |
| +// offlineAdmissionKey is an app's claim admission (hostops.AdmissionKey); |
| +// false for an account or app that is not well formed. |
| +func offlineAdmissionKey(account, app string) (string, bool) { |
| + if !controlname.ValidAccount(account) || !controlname.ValidApp(app) { |
| + return "", false |
| + } |
| + return "apps/" + account + "/" + app + "/admission.json", true |
| +} |
| + |
| +// offlineBackfillPlan and offlineBackfillHost are hostops.BackfillPlan and |
| +// hostops.BackfillHost field for field: the plan is a signed root envelope |
| +// whose payload must re-encode byte for byte, so the shapes cannot differ |
| +// (TestOfflineBackfillPlanReadsTheClaimPlan). |
| +type offlineBackfillHost struct { |
| + Key string `json:"key"` |
| + ETag string `json:"etag"` |
| + Acquisition string `json:"acq"` |
| + Region string `json:"region"` |
| + Box string `json:"box"` |
| +} |
| +type offlineBackfillPlan struct { |
| + V int `json:"v"` |
| + ID string `json:"id"` |
| + Phase string `json:"phase"` |
| + DirectoryRevision uint64 `json:"directory_revision"` |
| + CreatedAt time.Time `json:"created_at"` |
| + Reports map[string]string `json:"reports"` |
| + Hosts map[string]offlineBackfillHost `json:"hosts"` |
| +} |
| + |
| +// errOfflineBackfillBegun is a backfill plan that has begun, or that does |
| +// not verify under the release key (hostops.ErrPending, hostops.ErrIdentity). |
| +var errOfflineBackfillBegun = errors.New("console: the host-claim backfill has begun") |
| + |
| +// offlineBackfillFreeze is hostops.CheckCreateFreeze: nil with no plan or a |
| +// verified plan at done, errOfflineBackfillBegun for any other plan, and the |
| +// read's own error when the plan cannot be read. |
| +func offlineBackfillFreeze(ctx context.Context, s release.Store, pub ed25519.PublicKey) error { |
| + raw, _, err := s.Get(ctx, offlineBackfillKey) |
| + if errors.Is(err, os.ErrNotExist) { |
| + return nil |
| + } |
| + if err != nil { |
| + return err |
| + } |
| + var plan offlineBackfillPlan |
| + if release.VerifyRootEnvelope(pub, raw, &plan) != nil || plan.V != 1 || plan.ID == "" || plan.Phase != "done" { |
| + return errOfflineBackfillBegun |
| + } |
| + return nil |
| +} |
diff --git a/internal/console/apiinstancemove_offline_absence_test.go b/internal/console/apiinstancemove_offline_absence_test.go| new file mode 100644 |
| index 000000000..a45536537 |
| --- /dev/null |
| +++ b/internal/console/apiinstancemove_offline_absence_test.go |
| @@ -0,0 +1,154 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "net/http" |
| + "reflect" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/hostclaim" |
| + "github.com/carlosframework/platform/internal/hostops" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The console-local keys are the claim packages' keys, for well-formed and |
| +// malformed inputs alike. The hostclaim and hostops halves go when those |
| +// packages are deleted; the literals stay. |
| +func TestOfflineAbsenceKeysAreTheClaimKeys(t *testing.T) { |
| + for _, want := range []string{"control/hosts-backfill.json", hostops.BackfillKey} { |
| + if offlineBackfillKey != want { |
| + t.Fatalf("backfill key = %q, want %q", offlineBackfillKey, want) |
| + } |
| + } |
| + for _, c := range []struct{ acct, app string }{{"bab", "shop"}, {"BAB", "shop"}, {"bab", ""}, {"", "shop"}, {"bab", "../x"}} { |
| + got, ok := offlineAdmissionKey(c.acct, c.app) |
| + want, err := hostops.AdmissionKey(c.acct, c.app) |
| + if ok != (err == nil) || got != want { |
| + t.Errorf("admission key %q/%q = %q %v; hostops.AdmissionKey = %q %v", c.acct, c.app, got, ok, want, err) |
| + } |
| + if ok && got != "apps/"+c.acct+"/"+c.app+"/admission.json" { |
| + t.Errorf("admission key %q/%q = %q", c.acct, c.app, got) |
| + } |
| + } |
| +} |
| + |
| +// The local plan type is hostops.BackfillPlan field for field, and the |
| +// local freeze check classifies every plan as hostops.CheckCreateFreeze |
| +// does: nil, begun (ErrPending or ErrIdentity), or the read's own error. |
| +func TestOfflineBackfillPlanReadsTheClaimPlan(t *testing.T) { |
| + sameShape(t, reflect.TypeOf(offlineBackfillPlan{}), reflect.TypeOf(hostops.BackfillPlan{})) |
| + fx, _ := instanceFixture(t, "code-offline-backfill") |
| + signed := func(p hostops.BackfillPlan) []byte { |
| + t.Helper() |
| + raw, err := release.SignRootEnvelope(release.RootSigner(fx.priv), p) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return raw |
| + } |
| + full := hostops.BackfillPlan{V: 1, ID: "plan-1", Phase: "done", DirectoryRevision: 7, CreatedAt: time.Date(2026, 10, 1, 12, 0, 0, 5, time.UTC), |
| + Reports: map[string]string{"ie-box": "sha"}, Hosts: map[string]hostops.BackfillHost{offlineHost: {Key: "k", ETag: "e", Acquisition: "a", Region: "ie", Box: "ie-box"}}} |
| + variant := func(f func(*hostops.BackfillPlan)) []byte { p := full; f(&p); return signed(p) } |
| + cases := map[string][]byte{ |
| + "done, full": signed(full), |
| + "done, minimal": signed(hostops.BackfillPlan{V: 1, ID: "plan-1", Phase: "done"}), |
| + "collecting": variant(func(p *hostops.BackfillPlan) { p.Phase = "collecting" }), |
| + "adopting": variant(func(p *hostops.BackfillPlan) { p.Phase = "adopting" }), |
| + "version 2": variant(func(p *hostops.BackfillPlan) { p.V = 2 }), |
| + "no id": variant(func(p *hostops.BackfillPlan) { p.ID = "" }), |
| + "not an envelope": []byte("not an envelope"), |
| + } |
| + ctx := context.Background() |
| + for name, raw := range cases { |
| + offlinePut(t, fx.rel, offlineBackfillKey, raw) |
| + local := offlineBackfillFreeze(ctx, fx.rel, fx.srv.cfg.ReleasePub) |
| + claim := hostops.CheckCreateFreeze(ctx, fx.rel, fx.srv.cfg.ReleasePub) |
| + begun := errors.Is(claim, hostops.ErrPending) || errors.Is(claim, hostops.ErrIdentity) |
| + if (local == nil) != (claim == nil) || errors.Is(local, errOfflineBackfillBegun) != begun { |
| + t.Errorf("%s: local %v, hostops %v", name, local, claim) |
| + } |
| + } |
| + if err := fx.rel.Delete(ctx, offlineBackfillKey); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := offlineBackfillFreeze(ctx, fx.rel, fx.srv.cfg.ReleasePub); err != nil { |
| + t.Fatalf("no plan = %v", err) |
| + } |
| + boom := errors.New("boom") |
| + if err := offlineBackfillFreeze(ctx, offlineFaultStore{fx.rel, offlineBackfillKey, boom}, fx.srv.cfg.ReleasePub); !errors.Is(err, boom) || errors.Is(err, errOfflineBackfillBegun) { |
| + t.Fatalf("unreadable plan = %v", err) |
| + } |
| +} |
| + |
| +func sameShape(t *testing.T, a, b reflect.Type) { |
| + t.Helper() |
| + if a.Kind() != b.Kind() { |
| + t.Fatalf("%v is a %v, %v a %v", a, a.Kind(), b, b.Kind()) |
| + } |
| + switch a.Kind() { |
| + case reflect.Struct: |
| + if a.NumField() != b.NumField() { |
| + t.Fatalf("%v has %d fields, %v %d", a, a.NumField(), b, b.NumField()) |
| + } |
| + for i := 0; i < a.NumField(); i++ { |
| + fa, fb := a.Field(i), b.Field(i) |
| + if fa.Name != fb.Name || fa.Tag != fb.Tag { |
| + t.Fatalf("%v field %d = %s %q, %v's = %s %q", a, i, fa.Name, fa.Tag, b, fb.Name, fb.Tag) |
| + } |
| + sameShape(t, fa.Type, fb.Type) |
| + } |
| + case reflect.Map: |
| + sameShape(t, a.Key(), b.Key()) |
| + sameShape(t, a.Elem(), b.Elem()) |
| + default: |
| + if a != b { |
| + t.Fatalf("%v != %v", a, b) |
| + } |
| + } |
| +} |
| + |
| +// offlineFaultStore fails every Get of one key. |
| +type offlineFaultStore struct { |
| + release.Store |
| + key string |
| + err error |
| +} |
| + |
| +func (s offlineFaultStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if key == s.key { |
| + return nil, "", s.err |
| + } |
| + return s.Store.Get(ctx, key) |
| +} |
| + |
| +// A claim object that is present but does not decode and validate as a |
| +// claim is a 502, as it was before claims cleanup R1 (a valid one is a 409: |
| +// TestOfflineStartRefusals); any failed read of the three objects is a 502 |
| +// and never an absence. Nothing is written either way. |
| +func TestOfflineDoorAbsenceChecksRefuseAndFail(t *testing.T) { |
| + const body = `{"region":"uk"}` |
| + claimKey, err := hostclaim.Key(offlineHost) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + w := newOfflineWorld(t, oneEach...) |
| + for _, raw := range []string{"not json", `{}`, `{"v":1,"host":"other.example.com"}`} { |
| + offlinePut(t, w.fx.rel, claimKey, []byte(raw)) |
| + w.refused(http.MethodPost, "", body, http.StatusBadGateway, "could not read the host claim") |
| + w.refused(http.MethodPost, "/stage", body, http.StatusBadGateway, "could not read the host claim") |
| + } |
| + if err := w.fx.rel.Delete(context.Background(), claimKey); err != nil { |
| + t.Fatal(err) |
| + } |
| + admission, _ := offlineAdmissionKey("bab", "shop") |
| + real := w.fx.srv.cfg.Releases |
| + for _, key := range []string{claimKey, admission, offlineBackfillKey} { |
| + w.fx.srv.cfg.Releases = offlineFaultStore{real, key, errors.New("boom")} |
| + w.refused(http.MethodPost, "", body, http.StatusBadGateway, "could not read the host claim") |
| + w.refused(http.MethodPost, "/stage", body, http.StatusBadGateway, "could not read the host claim") |
| + } |
| + w.fx.srv.cfg.Releases = real |
| + w.start() |
| +} |
diff --git a/internal/console/apiruns.go b/internal/console/apiruns.go| index b60d6a9a7..b9d61437c 100644 |
| --- a/internal/console/apiruns.go |
| +++ b/internal/console/apiruns.go |
| @@ -15,7 +15,6 @@ import ( |
| "os" |
| "time" |
| - "github.com/carlosframework/platform/internal/hostclaim" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -534,7 +533,7 @@ func (s *Server) handleAPIRunCreate(w http.ResponseWriter, r *http.Request) { |
| jsonErrorCode(w, http.StatusBadGateway, runCodeRecordFailed, runRecordFailedMsg) |
| return |
| } |
| - inc, err := hostclaim.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| + inc, err := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| if err != nil { |
| jsonErrorCode(w, http.StatusBadGateway, runCodeRecordFailed, runRecordFailedMsg) |
| return |
diff --git a/internal/dbreads/agent.go b/internal/dbreads/agent.go| index 78ac62fee..6d7abe273 100644 |
| --- a/internal/dbreads/agent.go |
| +++ b/internal/dbreads/agent.go |
| @@ -17,7 +17,6 @@ import ( |
| mrand "math/rand/v2" |
| "github.com/carlosframework/platform/internal/dbdoor" |
| - "github.com/carlosframework/platform/internal/hostclaim" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -215,7 +214,7 @@ func (a *Agent) check(ctx context.Context, req Request) (provision.Record, strin |
| if err != nil { |
| return provision.Record{}, "", err |
| } |
| - inc, ierr := hostclaim.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| + inc, ierr := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| _, fleet := registry.FleetPlacement(rec.Region) |
| switch { |
| case ierr != nil, inc != req.Incarnation, rec.Account != req.Account, rec.App != req.App, |
diff --git a/internal/dbreads/fixture_test.go b/internal/dbreads/fixture_test.go| index c4a481a30..b6388798e 100644 |
| --- a/internal/dbreads/fixture_test.go |
| +++ b/internal/dbreads/fixture_test.go |
| @@ -22,7 +22,6 @@ import ( |
| "github.com/carlosframework/platform/internal/dbdoor" |
| "github.com/carlosframework/platform/internal/dbdoor/dbdoortest" |
| - "github.com/carlosframework/platform/internal/hostclaim" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -182,7 +181,7 @@ func (fx *fixture) record() provision.Record { |
| func (fx *fixture) request(sqlText, at string) Request { |
| fx.t.Helper() |
| rec := fx.record() |
| - inc, err := hostclaim.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| + inc, err := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| if err != nil { |
| fx.t.Fatal(err) |
| } |
diff --git a/internal/host/agent.go b/internal/host/agent.go| index 42dbceabd..3245308c3 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -188,7 +188,6 @@ import ( |
| "github.com/carlosframework/platform/internal/edge" |
| "github.com/carlosframework/platform/internal/edgesfile" |
| "github.com/carlosframework/platform/internal/fleetapi" |
| - "github.com/carlosframework/platform/internal/hostbox" |
| "github.com/carlosframework/platform/internal/hostwrite" |
| "github.com/carlosframework/platform/internal/instancectl" |
| "github.com/carlosframework/platform/internal/instancefs" |
| @@ -4960,7 +4959,7 @@ func runAdoptUnderRootRelease(args []string, buildClaims ClaimFactory, ensureUni |
| } |
| } |
| defer func() { |
| - ctx, cancel := context.WithTimeout(context.Background(), hostbox.RequestLimit) |
| + ctx, cancel := context.WithTimeout(context.Background(), claimsShutdownLimit) |
| defer cancel() |
| if err := claims.close(ctx); err != nil { |
| log.Printf("adopt: host claims shutdown: %v", err) |
| @@ -5268,3 +5267,9 @@ func runAdoptUnderRootRelease(args []string, buildClaims ClaimFactory, ensureUni |
| } |
| return passErr |
| } |
| + |
| +// claimsShutdownLimit bounds the adopt pass's host-claim shutdown. It is |
| +// hostbox.RequestLimit's value (two minutes), kept here since claims |
| +// cleanup R1 so the agent no longer imports hostbox for it |
| +// (TestClaimsShutdownLimitGolden). |
| +const claimsShutdownLimit = 120 * time.Second |
diff --git a/internal/host/boxreference.go b/internal/host/boxreference.go| index 47bbf843f..7dce6ce52 100644 |
| --- a/internal/host/boxreference.go |
| +++ b/internal/host/boxreference.go |
| @@ -2,7 +2,9 @@ package host |
| import ( |
| "context" |
| + "crypto/sha256" |
| "encoding/base64" |
| + "encoding/hex" |
| "encoding/json" |
| "errors" |
| "fmt" |
| @@ -11,7 +13,6 @@ import ( |
| "sync" |
| "time" |
| - "github.com/carlosframework/platform/internal/hostactors" |
| "github.com/carlosframework/platform/internal/hostenv" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -19,7 +20,7 @@ import ( |
| ) |
| // A box its region's group launched is referenced by its group reference |
| -// (census ruling region-ha-2b): hostactors.GroupBoxReference of its account |
| +// (census ruling region-ha-2b): groupReferenceOf its account |
| // and instance, "g-" and 20 hex digits. Its host.env says so: |
| // carlos system host-env write adds CARLOS_BOX_REFERENCE=group. Status |
| // labels come from 1,600 values and identity records are never deleted, so |
| @@ -83,10 +84,22 @@ func resolveGroupBoxReference() (string, error) { |
| if err != nil { |
| return "", err |
| } |
| - groupRef.ref = hostactors.GroupBoxReference(account, instance) |
| + groupRef.ref = groupReferenceOf(account, instance) |
| return groupRef.ref, nil |
| } |
| +// groupReferenceOf is the reference of a box its region's group launched: |
| +// "g-" and the first 20 hex digits of |
| +// sha256("carlos-box-ref-v1|" + account + "|" + instance). It is |
| +// hostactors.GroupBoxReference, which the console's claim activation |
| +// derives again from the instance it proved; it moved here in claims |
| +// cleanup R1 so the agent no longer imports hostactors, and |
| +// TestGroupBoxReferenceGolden holds the two to one vector. |
| +func groupReferenceOf(account, instance string) string { |
| + sum := sha256.Sum256([]byte("carlos-box-ref-v1|" + account + "|" + instance)) |
| + return "g-" + hex.EncodeToString(sum[:])[:20] |
| +} |
| + |
| // errNoGroupReference is a tick of a group box whose reference has not |
| // resolved: it publishes nothing. |
| var errNoGroupReference = errors.New("this group box's reference could not be read, so it publishes no status report this tick") |
diff --git a/internal/host/claimsoff_golden_test.go b/internal/host/claimsoff_golden_test.go| new file mode 100644 |
| index 000000000..e7c5a3a50 |
| --- /dev/null |
| +++ b/internal/host/claimsoff_golden_test.go |
| @@ -0,0 +1,34 @@ |
| +package host |
| + |
| +import ( |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/hostactors" |
| + "github.com/carlosframework/platform/internal/hostbox" |
| +) |
| + |
| +// Golden vectors for the two claim-package values the claims-off agent |
| +// uses (claims cleanup R1). The group reference was derived independently: |
| +// "g-" + the first 20 hex digits of |
| +// sha256("carlos-box-ref-v1|123456789012|i-0a61f580df1acfa65"). |
| +func TestGroupBoxReferenceGolden(t *testing.T) { |
| + impls := map[string]func(string, string) string{ |
| + "groupReferenceOf": groupReferenceOf, |
| + // The claim activation's twin, until claims cleanup deletes hostactors. |
| + "hostactors.GroupBoxReference": hostactors.GroupBoxReference, |
| + } |
| + for name, f := range impls { |
| + if got := f("123456789012", "i-0a61f580df1acfa65"); got != "g-c48ba25b2d17574d23d9" { |
| + t.Errorf("%s = %q, want g-c48ba25b2d17574d23d9", name, got) |
| + } |
| + } |
| +} |
| + |
| +func TestClaimsShutdownLimitGolden(t *testing.T) { |
| + for name, d := range map[string]time.Duration{"claimsShutdownLimit": claimsShutdownLimit, "hostbox.RequestLimit": hostbox.RequestLimit} { |
| + if d != 120*time.Second { |
| + t.Errorf("%s = %v, want 2m0s", name, d) |
| + } |
| + } |
| +} |
diff --git a/internal/host/movesoffline.go b/internal/host/movesoffline.go| index 3052233d5..0859e78b7 100644 |
| --- a/internal/host/movesoffline.go |
| +++ b/internal/host/movesoffline.go |
| @@ -22,8 +22,8 @@ import ( |
| "github.com/carlosframework/platform/internal/layout" |
| "github.com/carlosframework/platform/internal/lease" |
| "github.com/carlosframework/platform/internal/moves" |
| - "github.com/carlosframework/platform/internal/park" |
| "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/regionname" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -87,7 +87,7 @@ func offlineFenceOwner(id string) string { return "offline:" + id } |
| // offline-landed. offline-open is the target's to release (Task 5). |
| // |
| // Placements are compared as movesNamesBox compares them, by |
| -// park.PlacementMatches under the verified home binding, so the home's "" |
| +// regionname.PlacementMatches under the verified home binding, so the home's "" |
| // and its roster name are one. |
| func offlineHold(box moveCfg) func(rec provision.Record) (status, op string, ok bool) { |
| home, here := box.ParkHomeRegion, box.parkRegion() |
| @@ -98,11 +98,11 @@ func offlineHold(box moveCfg) func(rec provision.Record) (status, op string, ok |
| } |
| switch m.State { |
| case provision.OfflineStopping, provision.OfflineSealing, provision.OfflineSealed: |
| - if park.PlacementMatches(home, m.From, here) { |
| + if regionname.PlacementMatches(home, m.From, here) { |
| return "moving", m.ID, true |
| } |
| case provision.OfflineLanding, provision.OfflineLanded: |
| - if rec.Region == m.To && park.PlacementMatches(home, m.To, here) { |
| + if rec.Region == m.To && regionname.PlacementMatches(home, m.To, here) { |
| return "landing", m.ID, true |
| } |
| } |
| @@ -222,10 +222,10 @@ func (v *offlineView) keep(host string) bool { |
| if !ok || v.region == "" { |
| return false |
| } |
| - if park.PlacementMatches(v.home, m.To, v.region) { |
| + if regionname.PlacementMatches(v.home, m.To, v.region) { |
| return true |
| } |
| - if park.PlacementMatches(v.home, m.From, v.region) { |
| + if regionname.PlacementMatches(v.home, m.From, v.region) { |
| return m.State != provision.OfflineFinishing |
| } |
| return false |
| @@ -250,7 +250,7 @@ func (v *offlineView) elsewhere(host string) bool { |
| case provision.OfflineLanding, provision.OfflineLanded, provision.OfflineOpen, provision.OfflineFinishing: |
| region = m.To |
| } |
| - return !park.PlacementMatches(v.home, region, v.region) |
| + return !regionname.PlacementMatches(v.home, region, v.region) |
| } |
| // refreshOfflineView reads the record list once, outside a moves pass: at |
| @@ -403,7 +403,7 @@ func fenceAsWith(svc *activator.Service) func(ctx context.Context, host string, |
| // systemd slice under cgroupRoot (the cgroup v2 mount): every role and |
| // generation unit of the host runs in it. |
| func hostSliceCgroup(cgroupRoot, host string) string { |
| - return filepath.Join(cgroupRoot, filepath.FromSlash(path.Dir(instancectl.ClaimUnitControlGroup(host)))) |
| + return filepath.Join(cgroupRoot, filepath.FromSlash(path.Dir(instancectl.RunUnitControlGroup(host)))) |
| } |
| // offlineRound is the moves pass's round for a record with an offline move, |
| @@ -420,8 +420,8 @@ func (w *movesWorker) offlineRound(ctx context.Context, s release.Store, rec pro |
| return nil |
| } |
| here := cfg.parkRegion() |
| - source := here != "" && park.PlacementMatches(cfg.ParkHomeRegion, m.From, here) |
| - target := here != "" && park.PlacementMatches(cfg.ParkHomeRegion, m.To, here) |
| + source := here != "" && regionname.PlacementMatches(cfg.ParkHomeRegion, m.From, here) |
| + target := here != "" && regionname.PlacementMatches(cfg.ParkHomeRegion, m.To, here) |
| sealer := cfg.Box != "" && cfg.Box == m.Sealer |
| if !cfg.OfflineCapable { |
| if source || target || sealer { |
| @@ -498,7 +498,7 @@ func (w *movesWorker) offlineReassert(ctx context.Context, s release.Store) int |
| } |
| here := cfg.parkRegion() |
| roles := func(m *provision.MoveState) (bool, bool) { |
| - source := here != "" && park.PlacementMatches(cfg.ParkHomeRegion, m.From, here) |
| + source := here != "" && regionname.PlacementMatches(cfg.ParkHomeRegion, m.From, here) |
| return offlineReassertRoles(m, source, m.Sealer == cfg.Box) |
| } |
| var hosts []string |
diff --git a/internal/host/movesoffline_seal.go b/internal/host/movesoffline_seal.go| index f72f38d61..f98559c24 100644 |
| --- a/internal/host/movesoffline_seal.go |
| +++ b/internal/host/movesoffline_seal.go |
| @@ -26,8 +26,8 @@ import ( |
| "github.com/carlosframework/platform/internal/lease" |
| "github.com/carlosframework/platform/internal/moves" |
| "github.com/carlosframework/platform/internal/moves/archive" |
| - "github.com/carlosframework/platform/internal/park" |
| "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/regionname" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -214,7 +214,7 @@ func (w *movesWorker) offlineTarget(ctx context.Context, s release.Store, m *pro |
| } |
| sort.Strings(codes) |
| for _, code := range codes { |
| - if park.PlacementMatches(w.cfg.ParkHomeRegion, m.To, park.PlacementRegion(code)) { |
| + if regionname.PlacementMatches(w.cfg.ParkHomeRegion, m.To, regionname.PlacementRegion(code)) { |
| return fleet.targets[code], nil |
| } |
| } |
diff --git a/internal/host/movessources.go b/internal/host/movessources.go| index 3b8a8ed1c..0a4178935 100644 |
| --- a/internal/host/movessources.go |
| +++ b/internal/host/movessources.go |
| @@ -56,6 +56,7 @@ import ( |
| "github.com/carlosframework/platform/internal/moves" |
| "github.com/carlosframework/platform/internal/park" |
| "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/regionname" |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| @@ -73,7 +74,7 @@ const movesNoLiveRegion = "@none" |
| // for or queues in its own region, and the region its claim's engine must |
| // have go through it. An invalid code maps to "", which arms nothing and |
| // which every engine entry refuses. |
| -func (c moveCfg) parkRegion() string { return park.PlacementRegion(c.Region) } |
| +func (c moveCfg) parkRegion() string { return regionname.PlacementRegion(c.Region) } |
| // movesBoxRegion refuses a placement that disagrees with the verified roster. |
| // productionRosterRegion maps home only after checking the signed designation. |
diff --git a/internal/host/runexec.go b/internal/host/runexec.go| index 5266f47af..8168142a6 100644 |
| --- a/internal/host/runexec.go |
| +++ b/internal/host/runexec.go |
| @@ -11,7 +11,6 @@ import ( |
| "time" |
| "github.com/carlosframework/platform/internal/activator" |
| - "github.com/carlosframework/platform/internal/hostclaim" |
| "github.com/carlosframework/platform/internal/instancectl" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/registry" |
| @@ -100,7 +99,7 @@ func runResultForLaunch(err error) runs.Result { |
| // recordIncarnation is the incarnation request.json must carry for rec; |
| // "" when it cannot be computed, which matches no request. |
| func recordIncarnation(rec provision.Record) string { |
| - inc, err := hostclaim.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| + inc, err := provision.Incarnation(rec.Account, rec.App, rec.Host, rec.CreatedAt) |
| if err != nil { |
| return "" |
| } |
diff --git a/internal/hostclaim/claim.go b/internal/hostclaim/claim.go| index ee4caffcd..e917d2dc5 100644 |
| --- a/internal/hostclaim/claim.go |
| +++ b/internal/hostclaim/claim.go |
| @@ -7,7 +7,6 @@ |
| package hostclaim |
| import ( |
| - "crypto/sha256" |
| "encoding/hex" |
| "errors" |
| "fmt" |
| @@ -15,7 +14,7 @@ import ( |
| "time" |
| "github.com/carlosframework/platform/internal/controlname" |
| - "github.com/carlosframework/platform/internal/maintenanceguard" |
| + "github.com/carlosframework/platform/internal/provision" |
| ) |
| const ( |
| @@ -187,17 +186,15 @@ func Key(host string) (string, error) { |
| return "control/hosts/" + host + ".json", nil |
| } |
| -// Incarnation is §2's identity. A record with a zero CreatedAt (written |
| -// before CreatedAt existed) gets the domain-separated legacy identity. |
| +// Incarnation is §2's identity: provision.Incarnation, which claims-off |
| +// code calls directly, with a malformed legacy identity reported as |
| +// ErrMalformed for the claim code that still calls it here. |
| func Incarnation(account, app, host string, created time.Time) (string, error) { |
| - if created.IsZero() { |
| - if !controlname.ValidAccount(account) || !controlname.ValidApp(app) || !controlname.ValidHostShape(host) { |
| - return "", ErrMalformed |
| - } |
| - sum := sha256.Sum256([]byte("carlos-legacy-incarnation-v1\x00" + account + "\x00" + app + "\x00" + host)) |
| - return hex.EncodeToString(sum[:]), nil |
| + inc, err := provision.Incarnation(account, app, host, created) |
| + if errors.Is(err, provision.ErrMalformedIncarnation) { |
| + return "", ErrMalformed |
| } |
| - return maintenanceguard.RecordIdentity(account, app, host, created) |
| + return inc, err |
| } |
| // sidecarSuffix restates provision.SidecarSuffix (no import: avoids a cycle). |
diff --git a/internal/instancectl/claimunit.go b/internal/instancectl/claimunit.go| index 5d099ab3d..5abb6eba4 100644 |
| --- a/internal/instancectl/claimunit.go |
| +++ b/internal/instancectl/claimunit.go |
| @@ -5,7 +5,6 @@ import ( |
| "errors" |
| "fmt" |
| "os" |
| - "path" |
| "path/filepath" |
| "strconv" |
| "strings" |
| @@ -58,11 +57,9 @@ var ( |
| ErrClaimUnit = errors.New("instance control: the claim unit did not start as requested") |
| ) |
| -// ClaimUnitControlGroup is the host's run unit cgroup, relative to the |
| -// cgroup root. |
| -func ClaimUnitControlGroup(host string) string { |
| - return path.Join(parentSlices, SliceName(host), UnitName(RoleRun, host)) |
| -} |
| +// ClaimUnitControlGroup is RunUnitControlGroup, under the name the claim |
| +// code calls it by. |
| +func ClaimUnitControlGroup(host string) string { return RunUnitControlGroup(host) } |
| func claimTier(n int64) (cgroup.Limit, bool) { |
| switch n { |
diff --git a/internal/instancectl/names.go b/internal/instancectl/names.go| index f2adb04f9..d22c21677 100644 |
| --- a/internal/instancectl/names.go |
| +++ b/internal/instancectl/names.go |
| @@ -15,6 +15,7 @@ package instancectl |
| import ( |
| "errors" |
| "fmt" |
| + "path" |
| "path/filepath" |
| "strconv" |
| "strings" |
| @@ -138,6 +139,15 @@ func SliceName(host string) string { |
| return "carlos-instances-" + Escape(provision.InstanceID(host)) + ".slice" |
| } |
| +// RunUnitControlGroup is the host's run unit cgroup, relative to the |
| +// cgroup root: <parentSlices>/<SliceName>/<UnitName(RoleRun)>. The offline |
| +// move round reads the host's slice from it. It was ClaimUnitControlGroup |
| +// until claims cleanup R1, which keeps that name as a delegate for the |
| +// claim code. |
| +func RunUnitControlGroup(host string) string { |
| + return path.Join(parentSlices, SliceName(host), UnitName(RoleRun, host)) |
| +} |
| + |
| // UnitPrefixGen is the generation template (zero-downtime deploys spec |
| // §7.6): one instance per spawn of a host's run role. The four templates |
| // above stay for every box and binary still running them. |
diff --git a/internal/instancectl/rununit_golden_test.go b/internal/instancectl/rununit_golden_test.go| new file mode 100644 |
| index 000000000..27a3b2fb4 |
| --- /dev/null |
| +++ b/internal/instancectl/rununit_golden_test.go |
| @@ -0,0 +1,14 @@ |
| +package instancectl |
| + |
| +import "testing" |
| + |
| +// The run unit's cgroup, relative to the cgroup root. The offline move |
| +// round finds a host's slice from it (claims cleanup R1 renamed it from |
| +// ClaimUnitControlGroup, which the claim code still calls). |
| +func TestRunUnitControlGroupGolden(t *testing.T) { |
| + host := "alpha.shop.example.com" |
| + const want = "carlos.slice/carlos-instances.slice/carlos-instances-alpha.shop.example.com.slice/carlos-instance@alpha.shop.example.com.service" |
| + if got := RunUnitControlGroup(host); got != want || got != ClaimUnitControlGroup(host) { |
| + t.Fatalf("RunUnitControlGroup = %q, ClaimUnitControlGroup = %q, want %q", got, ClaimUnitControlGroup(host), want) |
| + } |
| +} |
diff --git a/internal/park/region_names.go b/internal/park/region_names.go| index f865694db..739b2cd23 100644 |
| --- a/internal/park/region_names.go |
| +++ b/internal/park/region_names.go |
| @@ -28,9 +28,10 @@ func (e Engine) OwnsRegion(region string) bool { |
| func (v View) sameRegion(a, b string) bool { return SameRegion(v.HomeRegion, a, b) } |
| -// PlacementMatches compares a record code with a nonempty engine identity. |
| +// PlacementMatches compares a record code with a nonempty engine identity |
| +// (regionname.PlacementMatches). |
| func PlacementMatches(home, code, engine string) bool { |
| - return SameRegion(home, PlacementRegion(code), engine) |
| + return regionname.PlacementMatches(home, code, engine) |
| } |
| // BoundHome joins the verified local binding and the admitted operation's |
diff --git a/internal/provision/claims_cleanup_r1_census_test.go b/internal/provision/claims_cleanup_r1_census_test.go| new file mode 100644 |
| index 000000000..1ec2bd3ab |
| --- /dev/null |
| +++ b/internal/provision/claims_cleanup_r1_census_test.go |
| @@ -0,0 +1,30 @@ |
| +package provision |
| + |
| +// Record-write census entries for claims cleanup R1 (branch |
| +// claims-cleanup-r1: the live slices move out of the claim packages), |
| +// layered on edgeProtection2WriteCensusInventory (main's newest at |
| +// 96564cf3). Reviewed by the branch author; the census owner rules on #280 |
| +// with the root-read card. |
| +// - admitDBRead computes the request's incarnation with |
| +// provision.Incarnation instead of hostclaim.Incarnation, the same |
| +// function moved (its golden vectors are incarnation_golden_test.go). |
| +// Its writes are the same conditional creates under db-reads/ in the |
| +// deployment bucket: still nonrecord. No write site is added. |
| +func claimsCleanupR1WriteCensusInventory() []censusEntry { |
| + entries := append([]censusEntry(nil), edgeProtection2WriteCensusInventory()...) |
| + replacements := []censusEntry{ |
| + {"internal/console/apidbforward.go", "Server.admitDBRead", "nonrecord", "sel:Put", "cbdbd19a26552c186e582c80342321d7f74fc9719cd78644e6a3f42f4a41b9cd"}, |
| + } |
| + for _, r := range replacements { |
| + found := false |
| + for i, e := range entries { |
| + if e.File == r.File && e.Unit == r.Unit { |
| + entries[i], found = r, true |
| + } |
| + } |
| + if !found { |
| + entries = append(entries, r) |
| + } |
| + } |
| + return entries |
| +} |
diff --git a/internal/provision/claims_cleanup_r2_census_test.go b/internal/provision/claims_cleanup_r2_census_test.go| index 820fa4128..3fbc724be 100644 |
| --- a/internal/provision/claims_cleanup_r2_census_test.go |
| +++ b/internal/provision/claims_cleanup_r2_census_test.go |
| @@ -4,6 +4,7 @@ package provision |
| // claims cleanup R2 (amadan #404), which deletes the claim activation |
| // tooling. Removals only: each unit's file is gone from the tree, so none |
| // of these writes exists any more, and nothing is added or re-pinned. |
| +// Layered on claimsCleanupR1WriteCensusInventory (main at cb23eb51). |
| func claimsCleanupR2WriteCensusInventory() []censusEntry { |
| removed := []struct{ file, unit string }{ |
| {"internal/claimactivation/backfill.go", "Runner.backfillCollect"}, |
| @@ -11,7 +12,7 @@ func claimsCleanupR2WriteCensusInventory() []censusEntry { |
| {"internal/host/activation_artifacts_linux.go", "putAttempts.Put"}, |
| {"internal/host/activation_console_report_linux.go", "publishActivationConsoleReport"}, |
| } |
| - entries := append([]censusEntry(nil), edgeProtection2WriteCensusInventory()...) |
| + entries := append([]censusEntry(nil), claimsCleanupR1WriteCensusInventory()...) |
| for _, r := range removed { |
| found := false |
| for i, entry := range entries { |
diff --git a/internal/provision/incarnation.go b/internal/provision/incarnation.go| new file mode 100644 |
| index 000000000..83c208887 |
| --- /dev/null |
| +++ b/internal/provision/incarnation.go |
| @@ -0,0 +1,32 @@ |
| +package provision |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "errors" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/controlname" |
| + "github.com/carlosframework/platform/internal/maintenanceguard" |
| +) |
| + |
| +// ErrMalformedIncarnation is Incarnation refusing a legacy identity whose |
| +// account, app or host is not well formed. |
| +var ErrMalformedIncarnation = errors.New("provision: malformed incarnation identity") |
| + |
| +// Incarnation is an instance record's identity: what db forward and carlos |
| +// run requests carry, and what the console and the box each compute and |
| +// must agree on. A record with a zero CreatedAt (written before CreatedAt |
| +// existed) gets the domain-separated legacy identity; any other gets |
| +// maintenanceguard.RecordIdentity. It moved here from hostclaim in claims |
| +// cleanup R1 with its bytes unchanged (incarnation_golden_test.go). |
| +func Incarnation(account, app, host string, created time.Time) (string, error) { |
| + if created.IsZero() { |
| + if !controlname.ValidAccount(account) || !controlname.ValidApp(app) || !controlname.ValidHostShape(host) { |
| + return "", ErrMalformedIncarnation |
| + } |
| + sum := sha256.Sum256([]byte("carlos-legacy-incarnation-v1\x00" + account + "\x00" + app + "\x00" + host)) |
| + return hex.EncodeToString(sum[:]), nil |
| + } |
| + return maintenanceguard.RecordIdentity(account, app, host, created) |
| +} |
diff --git a/internal/provision/incarnation_golden_test.go b/internal/provision/incarnation_golden_test.go| new file mode 100644 |
| index 000000000..3b5052fe1 |
| --- /dev/null |
| +++ b/internal/provision/incarnation_golden_test.go |
| @@ -0,0 +1,66 @@ |
| +package provision_test |
| + |
| +import ( |
| + "errors" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/hostclaim" |
| + "github.com/carlosframework/platform/internal/provision" |
| +) |
| + |
| +// incarnationVectors are the identities db forward and carlos run carry |
| +// (console and box compute them apart and must agree). The hex values were |
| +// derived independently of the Go code: the legacy form is |
| +// sha256("carlos-legacy-incarnation-v1\x00" + account + "\x00" + app + "\x00" + host), |
| +// the created form maintenanceguard.RecordIdentity's length-prefixed digest |
| +// over account, app, host and the RFC 3339 nano stamp. Claims cleanup R1 |
| +// moved the function; these bytes must never move. |
| +var incarnationVectors = []struct { |
| + name string |
| + acct, app, host string |
| + at time.Time |
| + want string |
| +}{ |
| + {"legacy", "bab", "shop", "alpha.shop.example.com", time.Time{}, "b3d6855bf26845a17dcfa39fd8f94a00815ecc257aaf0540a6d5522efb1d976e"}, |
| + {"created", "bab", "shop", "alpha.shop.example.com", time.Date(2026, 10, 1, 12, 34, 56, 789000000, time.UTC), "e5250d740fc808db6befc8174112bbc3bb33033672030c9ce40472800fd0ebf6"}, |
| + {"created nanosecond", "bab", "shop", "alpha.shop.example.com", time.Date(2026, 10, 1, 12, 34, 56, 789000001, time.UTC), "a37493f256a913a376898eee3f332449ea2d96103a64c58b5e11a4c59b930c02"}, |
| + {"created non-UTC zone", "bab", "shop", "alpha.shop.example.com", time.Date(2026, 10, 1, 13, 34, 56, 789000000, time.FixedZone("x", 3600)), "e5250d740fc808db6befc8174112bbc3bb33033672030c9ce40472800fd0ebf6"}, |
| + {"legacy malformed account", "BAD", "shop", "alpha.shop.example.com", time.Time{}, ""}, |
| + {"created malformed account", "BAD", "shop", "alpha.shop.example.com", time.Date(2026, 10, 1, 12, 34, 56, 789000000, time.UTC), ""}, |
| + {"legacy malformed host", "bab", "shop", "", time.Time{}, ""}, |
| +} |
| + |
| +var incarnationImpls = map[string]func(string, string, string, time.Time) (string, error){ |
| + "provision.Incarnation": provision.Incarnation, |
| + // The claim code's delegate, until claims cleanup deletes hostclaim. |
| + "hostclaim.Incarnation": hostclaim.Incarnation, |
| +} |
| + |
| +func TestIncarnationGoldenVectors(t *testing.T) { |
| + for name, f := range incarnationImpls { |
| + for _, v := range incarnationVectors { |
| + got, err := f(v.acct, v.app, v.host, v.at) |
| + if v.want == "" { |
| + if err == nil || got != "" { |
| + t.Errorf("%s %s = %q, %v; want an error and no identity", name, v.name, got, err) |
| + } |
| + continue |
| + } |
| + if err != nil || got != v.want { |
| + t.Errorf("%s %s = %q, %v; want %q", name, v.name, got, err, v.want) |
| + } |
| + } |
| + } |
| +} |
| + |
| +// hostclaim's claim callers still see hostclaim.ErrMalformed for a malformed |
| +// legacy identity; claims-off callers see provision.ErrMalformedIncarnation. |
| +func TestIncarnationMalformedErrors(t *testing.T) { |
| + if _, err := provision.Incarnation("BAD", "shop", "alpha.shop.example.com", time.Time{}); !errors.Is(err, provision.ErrMalformedIncarnation) { |
| + t.Fatalf("provision.Incarnation error = %v", err) |
| + } |
| + if _, err := hostclaim.Incarnation("BAD", "shop", "alpha.shop.example.com", time.Time{}); !errors.Is(err, hostclaim.ErrMalformed) { |
| + t.Fatalf("hostclaim.Incarnation error = %v", err) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 5a969d7fb..789a8850a 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -43,4 +43,4 @@ plan14-root-reads-rootfs-apps-2.tsv b1b17467ff148c3a0b1dd3312b7a80498db11cc4b455 |
| plan14-root-reads-edge-protection-2-decisions.tsv 7d90eff62dcb3d2d211b9f0fa37ba1967f1f418884a11c1476cdaa50b187efd5 |
| plan14-root-reads-edge-protection-2.tsv a864cf31b6bf2c30b5aa8c2647835efdc456f34f4945eea12751daab2457728e |
| plan14-root-reads-offline-move-trim-t1.tsv a864cf31b6bf2c30b5aa8c2647835efdc456f34f4945eea12751daab2457728e |
| -plan14-root-reads-claims-cleanup-r2.tsv a864cf31b6bf2c30b5aa8c2647835efdc456f34f4945eea12751daab2457728e |
| +plan14-root-reads-claims-cleanup-r1.tsv 9cef5e93a1e3520e02efe66455bf70c1170d380b6d6a72ede02036ce3dd41924 |
diff --git a/internal/provision/testdata/plan14-root-reads-claims-cleanup-r1.tsv b/internal/provision/testdata/plan14-root-reads-claims-cleanup-r1.tsv| new file mode 100644 |
| index 000000000..1c82ae095 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-claims-cleanup-r1.tsv |
| @@ -0,0 +1,16 @@ |
| +# Census overlay claims-cleanup-r1, written by census-propose (#369). census-ruling-claims-cleanup-r1, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-claims-cleanup-r1.md. |
| +# 3 body, 0 sites, 9 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@legacy 00d2e505f623cf6cebd25ed2c8d71bd5721ad7b7c7ade9d0be49b10f71c0470b internal/console/apiinstancemove_offline.go Server.offlineClaimEvidence legacy accepted-legacy accepted-legacy;rev3=census-ruling-moves-offline;basis=root-input (J4, as main's moves units); the console (cmd/console serve under console.service, user carlos-console): new, reads the host claim, the record's acquisition, a domains claim and the app's admission only to refuse an offline start (MV-O29, MV-O20); a failed read refuses with a 502, never reads as absence; deny-only;rev3=census-ruling-claims-cleanup-r1;basis=claims cleanup R1: the admission and backfill reads use the console's own keys and a local copy of hostops.BackfillPlan (same store Gets, same refusals) instead of hostops.AdmissionKey and CheckCreateFreeze; the host claim is still read through hostclaim.Read; no read added, the one scanned read (hostclaim.Read) unchanged file:Read@645 b9c29234b8db391f37db8b898901a0380b94ff0941e24b9d8ba240f530a79390 |
| +@legacy c7c644f83c1376f5dc136a13ba4009e8178325b5b2dac71c6ff6485d97385054 internal/console/apiruns.go Server.handleAPIRunCreate legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the console (cmd/console serve under console.service, user carlos-console): the run create door reads the record, and rereads it after an unknown admit, through readRecord, judged under a unit admitted on and unjudged before; read sites unchanged, offsets moved;rev3=census-ruling-claims-cleanup-r1;basis=claims cleanup R1: the request's incarnation comes from provision.Incarnation, hostclaim.Incarnation's body moved unchanged (golden vectors); no read added or changed file:Open@2086 a45e07833e363d6c7563bd3263f400b79873a839e51cda286c9d712053dde273 |
| +internal/console/apiinstancemove_offline.go Server.offlineClaimEvidence legacy accepted-legacy accepted-legacy;rev3=census-ruling-moves-offline;basis=root-input (J4, as main's moves units); the console (cmd/console serve under console.service, user carlos-console): new, reads the host claim, the record's acquisition, a domains claim and the app's admission only to refuse an offline start (MV-O29, MV-O20); a failed read refuses with a 502, never reads as absence; deny-only;rev3=census-ruling-claims-cleanup-r1;basis=claims cleanup R1: the admission and backfill reads use the console's own keys and a local copy of hostops.BackfillPlan (same store Gets, same refusals) instead of hostops.AdmissionKey and CheckCreateFreeze; the host claim is still read through hostclaim.Read; no read added, the one scanned read (hostclaim.Read) unchanged file:Read@645 b9c29234b8db391f37db8b898901a0380b94ff0941e24b9d8ba240f530a79390 |
| +internal/console/apiruns.go Server.handleAPIRunCreate legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the console (cmd/console serve under console.service, user carlos-console): the run create door reads the record, and rereads it after an unknown admit, through readRecord, judged under a unit admitted on and unjudged before; read sites unchanged, offsets moved;rev3=census-ruling-claims-cleanup-r1;basis=claims cleanup R1: the request's incarnation comes from provision.Incarnation, hostclaim.Incarnation's body moved unchanged (golden vectors); no read added or changed file:Open@2086 a45e07833e363d6c7563bd3263f400b79873a839e51cda286c9d712053dde273 |
| +internal/host/agent.go runAdoptUnderRootRelease authority B3,E1,E2,E3 rev3=census-ruling-self-serve-moves-1;basis=root claim/adopt/update controller uid 0: builds root's lifetime judge once from the host-claim switch and hands it to both productionRestartRequestPass calls; read sites unchanged, offsets moved; the preceding B3,E1,E2,E3 classification retained;rev3=census-ruling-claims-cleanup-r1;basis=claims cleanup R1: the claims shutdown timeout is the host constant claimsShutdownLimit (120s) instead of hostbox.RequestLimit (120s); no read added or changed whole:Route@11242,whole:Route@18538,whole:Route@18574,whole:Route@8533 1916559ef754fc27b761d2d489a4b34e1870ce050e6d00352788672209e67162 |
| +@coverage internal/console cce9d2eb49af5fcbcfde38c0c6f6d151cb9165bb846478fe5869f44acb8cfa64 |
| +@coverage internal/dbreads 3435a8265f4d16964920439675e1c2f982e5424c8d41248f009f643214d59ddc |
| +@coverage internal/host bb6ea03949a8e370305881229c70fc811c4ce6c6dd5710571e0ca4d396f1f7a1 |
| +@coverage internal/hostclaim 821d6bddd4d98009253602e5f2515b4ad077d6b694308fd7a718f688d227f21e |
| +@coverage internal/instancectl b73cb1ce1f6540bb232d737a6f429147c40bb62eda90b80b4930a0c1d0954cc1 |
| +@coverage internal/park 778a86513bc64068b93e257c09972fbc307ebe401a125a61003f3ad26a28f611 |
| +@coverage internal/provision f444c473b07f7497f3e294503c3d0f8f98e9d7377856d69ae2ecae7f71fc12d8 |
| +@coverage internal/regionname 5815be8b9d786cdf646ae30a3d23350096c3f0bd8200859067db2038affc68e6 |
| +@coverage internal/runs 0b7c525299df1f91b42dbcfb62f8a660ab4cb4256f849d7302dbe9d39b0925be |
diff --git a/internal/provision/testdata/plan14-root-reads-claims-cleanup-r2.tsv b/internal/provision/testdata/plan14-root-reads-claims-cleanup-r2.tsv| deleted file mode 100644 |
| index 3b433d319..000000000 |
| --- a/internal/provision/testdata/plan14-root-reads-claims-cleanup-r2.tsv |
| +++ /dev/null |
| @@ -1,51 +0,0 @@ |
| -# Census overlay claims-cleanup-r2, written by census-propose (#369). census-ruling-claims-cleanup-r2, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-claims-cleanup-r2.md. |
| -# 2 body, 0 sites, 4 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| -# 41 removed: each unit's declaration, or each envelope's directory, is absent from the scanned tree, so its row goes, a frozen declaration is retired as absent, and an envelope is retired. |
| -system.go runSystem authority B,C,D,F,G,J4 rev3=census-ruling-self-serve-moves-1;identity=explicit operator CLI uid 0;basis=adds the lifetimes family to the system dispatch (carlos system lifetimes cutover, a console door call as the operator); every existing command branch unchanged;rev3=census-ruling-claims-cleanup-r2;basis=claims cleanup R2: drops the claims case (host.RunSystemClaims, deleted); every other branch unchanged; no read added a47de59ce41c9b6dbac6a94b52ba08b3e304cf03d4773bfb8a94296a59448587 |
| -system.go systemVerb authority B,C,D,F,G,J4 rev3=census-ruling-self-serve-moves-1;identity=explicit operator CLI uid 0;basis=adds the lifetimes family to the system dispatch (carlos system lifetimes cutover, a console door call as the operator); every existing command branch unchanged;rev3=census-ruling-claims-cleanup-r2;basis=claims cleanup R2: drops "claims" from the verb list, so it now falls to the unknown-verb message; no read added cc3f962f89b4e026b46f87cb2a985be3187bd25fc3b16aa64cd1fa7815204781 |
| -@remove internal/claimactivation/artifacts.go Runner.signPolicy |
| -@remove internal/claimactivation/artifacts.go readConsole |
| -@remove internal/claimactivation/backfill.go backfillReady |
| -@remove internal/claimactivation/runner.go Runner.Run |
| -@remove internal/claimactivation/runner.go checkedStore.Delete |
| -@remove internal/claimactivation/runner.go checkedStore.Get |
| -@remove internal/claimactivation/runner.go checkedStore.Put |
| -@remove internal/host/activation_artifacts_linux.go activationOutput.finish |
| -@remove internal/host/activation_artifacts_linux.go activationOutput.ours |
| -@remove internal/host/activation_artifacts_linux.go consoleCounter.Read |
| -@remove internal/host/activation_artifacts_linux.go consoleDigest |
| -@remove internal/host/activation_artifacts_linux.go consoleDir |
| -@remove internal/host/activation_artifacts_linux.go consoleSlotSHA |
| -@remove internal/host/activation_artifacts_linux.go installProtectedConsole |
| -@remove internal/host/activation_artifacts_linux.go readConsoleSourceFile |
| -@remove internal/host/activation_artifacts_linux.go reserveOutput |
| -@remove internal/host/activation_artifacts_linux.go upgradeProtectedConsole |
| -@remove internal/host/activation_artifacts_linux.go writeConsoleTemp |
| -@remove internal/host/activation_command.go RunSystemClaims |
| -@remove internal/host/activation_command_linux.go runSystemClaims |
| -@remove internal/host/activation_command_other.go runSystemClaims |
| -@remove internal/host/activation_console.go activationConsoleEnvironment |
| -@remove internal/host/activation_console_report_linux.go activationConsolePID |
| -@remove internal/host/activation_console_report_linux.go activationConsoleProcess |
| -@remove internal/host/activation_console_report_linux.go publishActivationConsoleReport |
| -@remove internal/host/activation_install.go activationEnvironment |
| -@remove internal/host/activation_install.go activationUnitSettings |
| -@remove internal/host/activation_install_linux.go activationDir |
| -@remove internal/host/activation_install_linux.go activationLock |
| -@remove internal/host/activation_install_linux.go activationRead |
| -@remove internal/host/activation_install_linux.go activationReadAt |
| -@remove internal/host/activation_install_linux.go installActivationConsole |
| -@remove internal/host/activation_install_linux.go installActivationControl |
| -@remove internal/host/activation_install_linux.go installActivationEvidenceKey |
| -@remove internal/host/activation_install_linux.go installActivationFenceCredentials |
| -@remove internal/hostfence/activation_credentials.go ValidateActivationCredentials |
| -@remove internal/sim/hostlife/mutate.sh external |
| -@removed internal/sim/hostlife/mutate.sh external H3 census-ruling-claims-cleanup-r2;absent;basis=deleted: declaration and sites absent from the tree |
| -@remove scripts/activation-tools-root-runner.sh external |
| -@remove scripts/plan14-console-root-runner.sh external |
| -@coverage . 2a19cafd46f2ba060d15af8e20cc27a65f84aca9c97a81c777f023b0b298c8b3 |
| -@coverage internal/host 9e2fe556a0b8a1ad243e4e7d044f44a9f929ebd1612b56f815351a4f42af6945 |
| -@coverage internal/hostfence 7645ac211dd1471c70485a34c9f5693b9fdc268f60224d3eb23ac257b1b74476 |
| -@coverage scripts 4eee7ef65e826234f20d23d0f7bce0402ad5cf7e3811e44d139306bd5b61cf75 |
| -@coverage internal/claimactivation - |
| -@coverage internal/sim/hostlife - |
diff --git a/internal/regionname/region.go b/internal/regionname/region.go| index d56e208f8..ad7fa7691 100644 |
| --- a/internal/regionname/region.go |
| +++ b/internal/regionname/region.go |
| @@ -56,3 +56,11 @@ func SameRegion(home, a, b string) bool { |
| return home != "" && PlacementRegion(home) == home && |
| ((a == home && b == HomeRegion) || (a == HomeRegion && b == home)) |
| } |
| + |
| +// PlacementMatches compares a record's placement code with a nonempty |
| +// engine identity under the verified home binding: the home's "" and its |
| +// roster name are one region. The console's doors and the box's offline |
| +// move round use it (it moved here from park in claims cleanup R1). |
| +func PlacementMatches(home, code, engine string) bool { |
| + return SameRegion(home, PlacementRegion(code), engine) |
| +} |
diff --git a/internal/regionname/region_golden_test.go b/internal/regionname/region_golden_test.go| new file mode 100644 |
| index 000000000..03d57825a |
| --- /dev/null |
| +++ b/internal/regionname/region_golden_test.go |
| @@ -0,0 +1,80 @@ |
| +package regionname_test |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "fmt" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/park" |
| + "github.com/carlosframework/platform/internal/regionname" |
| +) |
| + |
| +// The placement rules the console's create, regions and move doors and the |
| +// box's offline move round share (claims cleanup R1 moved the callers off |
| +// park). placementTable renders every rule over every combination of these |
| +// inputs; its digest is pinned, and a few rows are pinned outright so a |
| +// failure says which rule moved. |
| +var placementHomes = []string{"", "ie", "@home", "Bad"} |
| +var placementCodes = []string{"", "ie", "uk", "@home", "home", "Bad", "a-1", "abcdefghijklmnopq"} |
| + |
| +type placementRules struct { |
| + region func(string) string |
| + code func(string, string) string |
| + same func(string, string, string) bool |
| + matches func(string, string, string) bool |
| +} |
| + |
| +var placementImpls = map[string]placementRules{ |
| + "regionname": {regionname.PlacementRegion, regionname.HomePlacementCode, regionname.SameRegion, regionname.PlacementMatches}, |
| + // park's delegates, until claims cleanup deletes park. |
| + "park": {park.PlacementRegion, park.HomePlacementCode, park.SameRegion, park.PlacementMatches}, |
| +} |
| + |
| +func placementTable(r placementRules) string { |
| + var b strings.Builder |
| + for _, c := range placementCodes { |
| + fmt.Fprintf(&b, "PR %q=%q\n", c, r.region(c)) |
| + } |
| + for _, h := range placementHomes { |
| + for _, c := range placementCodes { |
| + fmt.Fprintf(&b, "HPC %q %q=%q\n", h, c, r.code(h, c)) |
| + for _, e := range placementCodes { |
| + fmt.Fprintf(&b, "SR %q %q %q=%v PM=%v\n", h, c, e, r.same(h, c, e), r.matches(h, c, e)) |
| + } |
| + } |
| + } |
| + return b.String() |
| +} |
| + |
| +const placementTableDigest = "c47389f9e56f7a07d074d825372bcf9fe858614fd52c28c4fd806cd73f922500" |
| + |
| +func TestPlacementGoldenVectors(t *testing.T) { |
| + for name, r := range placementImpls { |
| + sum := sha256.Sum256([]byte(placementTable(r))) |
| + if got := hex.EncodeToString(sum[:]); got != placementTableDigest { |
| + t.Errorf("%s: placement table digest = %s, want %s", name, got, placementTableDigest) |
| + } |
| + for _, v := range []struct { |
| + got, want string |
| + }{ |
| + {r.region(""), "@home"}, {r.region("ie"), "ie"}, {r.region("@home"), ""}, {r.region("Bad"), ""}, {r.region("abcdefghijklmnopq"), ""}, |
| + {r.code("ie", "ie"), ""}, {r.code("ie", "uk"), "uk"}, {r.code("", "ie"), "ie"}, {r.code("ie", ""), ""}, |
| + } { |
| + if v.got != v.want { |
| + t.Errorf("%s: got %q, want %q", name, v.got, v.want) |
| + } |
| + } |
| + for _, v := range []struct { |
| + got, want bool |
| + }{ |
| + {r.same("ie", "ie", "@home"), true}, {r.same("", "ie", "@home"), false}, {r.same("ie", "", ""), false}, {r.same("@home", "@home", "@home"), true}, |
| + {r.matches("ie", "", "ie"), true}, {r.matches("ie", "", "@home"), true}, {r.matches("", "", "ie"), false}, {r.matches("ie", "uk", "uk"), true}, {r.matches("ie", "Bad", "Bad"), false}, |
| + } { |
| + if v.got != v.want { |
| + t.Errorf("%s: got %v, want %v", name, v.got, v.want) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/runs/runs.go b/internal/runs/runs.go| index 227df8a47..a93e065e7 100644 |
| --- a/internal/runs/runs.go |
| +++ b/internal/runs/runs.go |
| @@ -170,7 +170,7 @@ type File struct { |
| } |
| // Request is runs/<id>/request.json (run spec §5.1). Incarnation is the |
| -// record's (hostclaim.Incarnation of account, app, host and CreatedAt). |
| +// record's (provision.Incarnation of account, app, host and CreatedAt). |
| type Request struct { |
| Schema int `json:"schema"` |
| ID string `json:"id"` |