carlos / platform Public

tests: classify platform-host, rank the account lock, census re-pins

CI on 06b65594 failed four tests; this fixes them.

- submissiongate: POST .../platform-host is an ungated serve door, as the
  domains doors are. It builds a Kind static create body itself and
  refuses a non-static head, so the route it mints runs no process; the
  create handler it delegates to still calls judgeServing under the app
  lock, and that judgement passes a static record.
- lock checker: lockAccount now emits lock events (Task 9). The checker
  ranks platform, account, app, host and fails a wait for a lower rank
  under a higher one; the create, --from and migration assertions read
  the app and host locks only, still app then hostname.
- record-write census: platformAccounts1WriteCensusInventory removes
  MintAccount (its loop moved to mint), adds mint and
  RenameAccountManifest (account manifest Puts, nonrecord) and capLabel
  (a cap id, key-site), and re-pins instanceManifest, linkedPolicies and
  routeDecls. No record write added.
- root-read census: make census-propose NAME=design-platform-accounts
  with an empty claims file re-pins the envelopes of ., internal/domains
  and internal/svcrole. No unit changed and no root read was added; the
  card awaits the reviewer in Task 15.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d23dab9eb1c982d77e7969221782c44dd240cef4 parent c0796e3
8 files changed, +147 −10
  • docs/superpowers/notes/census-proposal-design-platform-accounts.md +11 −0
  • internal/console/lifetimes_create_test.go +34 −8
  • internal/console/lifetimes_migrate_test.go +1 −1
  • internal/console/submissiongate.go +4 −0
  • internal/provision/plan9_b8_census_test.go +1 −1
  • internal/provision/platform_accounts_1_census_test.go +90 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −0
  • internal/provision/testdata/plan14-root-reads-design-platform-accounts.tsv +5 −0
diff --git a/docs/superpowers/notes/census-proposal-design-platform-accounts.md b/docs/superpowers/notes/census-proposal-design-platform-accounts.md
new file mode 100644
index 000000000..062a6f323
--- /dev/null
+++ b/docs/superpowers/notes/census-proposal-design-platform-accounts.md
@@ -0,0 +1,11 @@
+# Census approval: design-platform-accounts
+
+Ruling `census-ruling-design-platform-accounts`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+
+Envelopes re-pinned: `.`, `internal/domains`, `internal/svcrole`.
+
+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. Reject 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. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
+
+Seal: `5d4a5eea79394145fdd59aa5eb87115cc1ee396e02e0ab4b21decd2b3a10e3b4` → `5d4a5eea79394145fdd59aa5eb87115cc1ee396e02e0ab4b21decd2b3a10e3b4`.
+
+Overlay: `internal/provision/testdata/plan14-root-reads-design-platform-accounts.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/console/lifetimes_create_test.go b/internal/console/lifetimes_create_test.go
index d3bd42975..db8d30b28 100644
--- a/internal/console/lifetimes_create_test.go
+++ b/internal/console/lifetimes_create_test.go
@@ -2323,16 +2323,26 @@ func TestDispatchFollowsTheUnit(t *testing.T) {
// ---- the lock order -------------------------------------------------------------
-// lockChecker sees every app and hostname lock through lifetimeLockHook and
-// records an inversion (an app lock waited for under a hostname lock) or a
-// hostname lock waited for under another.
+// lockChecker sees every lock through lifetimeLockHook and records an
+// inversion: any lock waited for under a hostname lock, or a lock earlier in
+// hostLockRank waited for under a later one (an account lock under an app
+// lock, say).
type lockChecker struct {
mu sync.Mutex
held map[string][]string // goroutine -> held locks, in order
- seq []string // every lock as it is held: "<goroutine> app|host <key>"
+ seq []string // every lock as it is held: "<goroutine> <kind> <key>"
errs []string
}
+// hostLockRank is the documented order down to the hostname: platform
+// lifecycle, then account/plan (lockPlatformLifecycle, lockAccount), then
+// the app lock, then the hostname (lockApp, withHostname). Nothing may wait
+// for a lock of a lower rank while it holds one of a higher rank. (lockRank,
+// TestLockOrderLifecycleAccountBilling's, is the order down to billing.)
+var hostLockRank = map[string]int{"platform": 0, "account": 1, "app": 2, "host": 3}
+
+func lockKind(lock string) string { return strings.SplitN(lock, " ", 2)[0] }
+
func ltGoroutine() string {
var buf [64]byte
n := runtime.Stack(buf[:], false)
@@ -2350,7 +2360,9 @@ func installLockChecker(t *testing.T) *lockChecker {
switch event {
case lockWaiting:
for _, h := range c.held[g] {
- if strings.HasPrefix(h, "host ") {
+ hr, hok := hostLockRank[lockKind(h)]
+ wr, wok := hostLockRank[kind]
+ if strings.HasPrefix(h, "host ") || (hok && wok && hr > wr) {
c.errs = append(c.errs, fmt.Sprintf("%s waited for while %s is held", lock, h))
}
}
@@ -2372,7 +2384,8 @@ func installLockChecker(t *testing.T) *lockChecker {
return c
}
-// order is the locks taken by the goroutine that took first, in order.
+// taken is every lock held whose "<kind> <key>" starts with prefix, in
+// the order they were taken.
func (c *lockChecker) taken(prefix string) []string {
c.mu.Lock()
defer c.mu.Unlock()
@@ -2386,6 +2399,19 @@ func (c *lockChecker) taken(prefix string) []string {
return out
}
+// appAndHost is the app and hostname locks taken, in order. A capped door
+// takes the account lock (planLock) before the app lock, as hostLockRank
+// allows; check catches it taken out of order.
+func (c *lockChecker) appAndHost() []string {
+ var out []string
+ for _, l := range c.taken("") {
+ if k := lockKind(l); k == "app" || k == "host" {
+ out = append(out, l)
+ }
+ }
+ return out
+}
+
func (c *lockChecker) check(t *testing.T) {
t.Helper()
c.mu.Lock()
@@ -2407,7 +2433,7 @@ func TestLockOrderIsRespected(t *testing.T) {
t.Fatalf("--from create = %d %v", code, out)
}
f.fx.srv.seedCopies.Wait()
- if got := c.taken(""); len(got) < 2 || got[0] != "app bab/"+fromApp || got[1] != "host "+host {
+ if got := c.appAndHost(); len(got) < 2 || got[0] != "app bab/"+fromApp || got[1] != "host "+host {
t.Fatalf("the --from create took %v, want the app lock then the hostname", got)
}
code, out := beginImport(t, f, importHost, importSHA, 4096)
@@ -2426,7 +2452,7 @@ func testLockOrderOfTheDoors(t *testing.T) {
if code, body := l.create(t, ltOne); code != http.StatusCreated {
t.Fatalf("create = %d %s", code, body)
}
- if got := c.taken(""); len(got) < 2 || got[0] != "app bab/shop" || got[1] != "host "+ltOne {
+ if got := c.appAndHost(); len(got) < 2 || got[0] != "app bab/shop" || got[1] != "host "+ltOne {
t.Fatalf("the create took %v, want the app lock then the hostname", got)
}
// A create under shop retiring web's orphan slot takes no lock of web.
diff --git a/internal/console/lifetimes_migrate_test.go b/internal/console/lifetimes_migrate_test.go
index c9786bd78..6fb892d98 100644
--- a/internal/console/lifetimes_migrate_test.go
+++ b/internal/console/lifetimes_migrate_test.go
@@ -961,7 +961,7 @@ func TestMigrationTakesTheAppLockThenTheHostname(t *testing.T) {
if !l.fx.srv.incarnationMigrationIteration(context.Background()) {
t.Fatal("the migration pass did not run with lifetimes on")
}
- if got := c.taken(""); len(got) < 2 || got[0] != "app bab/"+ltApp || got[1] != "host "+ltOne {
+ if got := c.appAndHost(); len(got) < 2 || got[0] != "app bab/"+ltApp || got[1] != "host "+ltOne {
t.Fatalf("the pass took %v, want the app lock then the hostname", got)
}
oneMig(t, l.fx.st, ltOne, lifetimeCommitted)
diff --git a/internal/console/submissiongate.go b/internal/console/submissiongate.go
index 08840cc34..be388b102 100644
--- a/internal/console/submissiongate.go
+++ b/internal/console/submissiongate.go
@@ -92,6 +92,10 @@ var submissionUngatedServeDoors = map[string]string{
"no process, so no build it serves can send mail",
"POST /api/cli/apps/{account}/{app}/domains": "a first route it declares is Kind static, which runs " +
"no process, so no build it serves can send mail",
+ "POST /api/cli/apps/{account}/{app}/platform-host": "it builds the create body itself with Kind static " +
+ "and refuses a channel whose head is not a static site, so the route it mints runs no process and " +
+ "no build it serves can send mail; its write is the instance-create handler's, which still calls " +
+ "judgeServing under the app lock, and that judgement passes a static record (servingRecord)",
}
// Not serve doors, and so in neither list (the guard finds none of them
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index 8b06d91df..1c372800e 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -366,7 +366,7 @@ func TestPlan9B8RecordWriteCensus(t *testing.T) {
if len(got) < 100 {
t.Fatalf("census found only %d units under %s; the walk is broken", len(got), root)
}
- inventory := staticcheckSA4006WriteCensusInventory()
+ inventory := platformAccounts1WriteCensusInventory()
problems := append(censusDiff(inventory, got), censusPolicy(inventory)...)
if len(problems) > 0 {
t.Fatalf("record-write census rejected %d site(s); update the explicit inventory only after reviewing the source:\n %s", len(problems), strings.Join(problems, "\n "))
diff --git a/internal/provision/platform_accounts_1_census_test.go b/internal/provision/platform_accounts_1_census_test.go
new file mode 100644
index 000000000..d75b878b1
--- /dev/null
+++ b/internal/provision/platform_accounts_1_census_test.go
@@ -0,0 +1,90 @@
+package provision
+
+// platformAccounts1WriteCensusInventory is the platform accounts slice 1
+// review of the record-write census (branch design-platform-accounts),
+// layered on staticcheckSA4006WriteCensusInventory. No record write is
+// added, moved or reclassified. The account manifest's create-only mint
+// moves into a shared helper, a rename of the manifest is added, and three
+// declaration lists and one handler change.
+//
+// Removed:
+// - MintAccount (internal/domains/mint.go): its allocation loop moved,
+// unchanged in what it writes, into mint (below), which it now calls
+// with an unlinked template. It has no write site of its own.
+//
+// Added (nonrecord, the account manifest, accounts/<sqid>/account.json):
+// - mint (internal/domains/mint.go): the create-only Put of an account
+// manifest at domains.AccountManifestKey, the loop MintAccount held,
+// shared with MintLinkedAccount. It writes the template with its ID,
+// Sqid and CreatedAt filled in; with a match function it first returns
+// a live manifest carrying the same platform and mint id, writing
+// nothing; free, when set, may refuse the id before the write. Never a
+// record key. nonrecord / sel:Put, as MintAccount was.
+// - RenameAccountManifest (internal/domains/mint.go): a CAS overwrite of
+// an account manifest's name, every other field kept, one retry on a
+// lost race, nothing written when the name is unchanged. Same key and
+// shape as TombstoneAccount. nonrecord / sel:Put.
+// - capLabel (platform_cli.go): the plan-cap id "sidecars" in a switch
+// that picks a cap's display label in the `carlos platform` customer
+// views. A cap id, not a record path; nothing is written. key-site /
+// lit:sidecars, as plangrace.go's cap ids.
+//
+// Re-pinned (no class or kind changes):
+// - Server.instanceManifest (internal/console/apiinstances.go): on an
+// absent manifest, answers the platform-host door's in-memory default
+// manifest through admitDefaultManifest when the request carries one,
+// before the existing 409. A read only; the manifest is never written,
+// and the instances literal is unchanged. key-site / lit:instances.
+// - var linkedPolicies (internal/console/linkedpolicy.go): one row,
+// POST .../platform-host refused for a linked app as the instances
+// create it delegates to is. A map of patterns, no record path built
+// from it. key-site / lit:instances,lit:sidecars.
+// - var routeDecls (internal/console/routedecls.go): Publish added to the
+// instance list's roles; the platform-host door; the five platform
+// customer and credential doors; the three platform grant doors; and
+// two comments. Declarations only, no record path; each handler's own
+// writes are listed under the handler. key-site /
+// lit:instances,lit:sidecars.
+func platformAccounts1WriteCensusInventory() []censusEntry {
+ entries := append([]censusEntry(nil), staticcheckSA4006WriteCensusInventory()...)
+ removed := []struct{ file, unit string }{
+ {"internal/domains/mint.go", "MintAccount"},
+ }
+ for _, r := range removed {
+ found := false
+ for i, e := range entries {
+ if e.File == r.file && e.Unit == r.unit {
+ entries = append(entries[:i], entries[i+1:]...)
+ found = true
+ break
+ }
+ }
+ if !found {
+ panic("platform-accounts-1 census: removal of an unlisted unit " + r.file + ":" + r.unit)
+ }
+ }
+ repins := []censusEntry{
+ {"internal/console/apiinstances.go", "Server.instanceManifest", "key-site", "lit:instances", "b4a490bed99214b21615cbb3341e2a5915107f46244594f853c5679605619789"},
+ {"internal/console/linkedpolicy.go", "var linkedPolicies", "key-site", "lit:instances,lit:sidecars", "f7dbce0994af2170bdf2078bf5ca374a5d966a3777bd2df2c5f71b2d5e2fd971"},
+ {"internal/console/routedecls.go", "var routeDecls", "key-site", "lit:instances,lit:sidecars", "79970031041fda38a5e40fc88531d371c9df23c8c9a788f76a2697a8e5e94bdc"},
+ }
+ for _, r := range repins {
+ found := false
+ for i, e := range entries {
+ if e.File == r.File && e.Unit == r.Unit {
+ if e.Class != r.Class || e.Kinds != r.Kinds {
+ panic("platform-accounts-1 census: classification changed for " + r.File + ":" + r.Unit)
+ }
+ entries[i], found = r, true
+ }
+ }
+ if !found {
+ panic("platform-accounts-1 census: re-pin of an unlisted unit " + r.File + ":" + r.Unit)
+ }
+ }
+ return append(entries,
+ censusEntry{"internal/domains/mint.go", "mint", "nonrecord", "sel:Put", "0d4ffeaea33b710ee54077a4c8d9b2612f6bad6486e970e13dfbefb7259ea5ac"},
+ censusEntry{"internal/domains/mint.go", "RenameAccountManifest", "nonrecord", "sel:Put", "12f16b7e914868897ee0b63ffe42292c9cebbe3eb2a05fda5b5afec12feaa986"},
+ censusEntry{"platform_cli.go", "capLabel", "key-site", "lit:sidecars", "f221788a1492a131570821c9c915d1fec42df1eaefeb5f421c5345ad69bd3cc0"},
+ )
+}
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index db17bb86b..ed5e2eff1 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -253,3 +253,4 @@ plan14-root-reads-staticcheck-sa1019.tsv f9be26c06eb1c844b91a75f65faa51997048cb2
plan14-root-reads-small-fixes-1246-1248.tsv c6d366dcf2211b714977b7a69180289555b362dfe5f36a5780af90b5ece82998
plan14-root-reads-edge-ppv2-idle.tsv 5d4a5eea79394145fdd59aa5eb87115cc1ee396e02e0ab4b21decd2b3a10e3b4
plan14-root-reads-flake-lease-teardown.tsv 5d4a5eea79394145fdd59aa5eb87115cc1ee396e02e0ab4b21decd2b3a10e3b4
+plan14-root-reads-design-platform-accounts.tsv 5d4a5eea79394145fdd59aa5eb87115cc1ee396e02e0ab4b21decd2b3a10e3b4
diff --git a/internal/provision/testdata/plan14-root-reads-design-platform-accounts.tsv b/internal/provision/testdata/plan14-root-reads-design-platform-accounts.tsv
new file mode 100644
index 000000000..d2f919f9a
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-design-platform-accounts.tsv
@@ -0,0 +1,5 @@
+# Census overlay design-platform-accounts, written by census-propose (#369). census-ruling-design-platform-accounts, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-design-platform-accounts.md.
+# 0 body, 0 sites, 3 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+@coverage . 3d455e1942ff419bd6f7d6128b5f7583de7de7963ba993bbf4ffc092efe28239
+@coverage internal/domains 7a54788493b1f0c89412d24604eaec2b5dee6d9ce078717cb9301e4468efab90
+@coverage internal/svcrole 5d5177f2446a75afb22c4fe4f8c75464b5c433af928ad1c96fa7a160e2a01bb9