plan: platform accounts slice 1, the platform layer
Sixteen tasks for spec 2026-11-19-platform-accounts-design.md slice 1: the operator grant, the manifest link, ownerless linked accounts, the platform role and customer doors, per-customer credentials, a static site's first host from a Publish credential, linked accounts in plans, billing and notices, the end-to-end witness, and a pending copy table.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+1,068
−0
docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md+1,068 −0
diff --git a/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md b/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md| new file mode 100644 |
| index 000000000..23953892c |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md |
| @@ -0,0 +1,1068 @@ |
| +# Platform accounts, slice 1: the platform layer. Implementation Plan |
| + |
| +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| + |
| +**Goal:** An operator grants an account platform status; that account's `platform` service credential (or an owner of it) creates ownerless customer accounts linked to it, lists and changes them within the grant, mints short-lived per-customer credentials, and deploys a static site into a customer account to serving, with no person signing in. |
| + |
| +**Architecture:** The grant is a console table read on every platform request. The link is a `platform` field (plus `platform_ref`) in the customer's bucket manifest, written in the create-only mint and mirrored in two `accounts` columns that `MaterializeAccounts` fills at birth only. The platform credential is a new svcrole outside Admin's union that reaches only six new `/api/cli/platform/{account}/...` doors; per-customer credentials are a new `cli_tokens` kind that resolves to an ordinary one-account Publish or Deploy principal, but only while the link and the grant are live. |
| + |
| +**Tech Stack:** Go; the console's SQLite store (`internal/console`); `release.Store` for the bucket; the `carlos` CLI (`clireg`, `apiSession`). |
| + |
| +**Spec:** `docs/superpowers/specs/2026-11-19-platform-accounts-design.md` (approved by Paul 2026-11-19). Executors read both. Its file:line refs were taken at `ed6ae029`; every ref below was re-checked at `06603e71`. |
| + |
| +## Global Constraints |
| + |
| +House rules (from the brief, verbatim where they are rules): |
| + |
| +- Every new user-facing string (CLI human output, errors shown to people, emails) goes in one copy table in the plan, marked "pending copy review"; implementers use the table's text and the strings are reviewed before merge. No em dashes; no real tenant names in examples (use neutral ones like shop, example.com); curly quotes in copy. The table is the "Copy table" section at the end. A string not in the table is not shipped: add a row and flag it in the task report. |
| +- CLI human-readable output gets a UX pass before the copy review (AGENTS.md "Every UI change gets a UX pass"). Task 1 is that pass. |
| +- Provider-neutral core: no AWS SDK in console logic; use existing store abstractions (`release.Store`, the console `Store`). No new per-box polling. |
| +- Acceptance witness goes through production wiring (real constructors, real stores, no fabricated records). Task 14 is the one end-to-end console test: an operator grants, a platform credential creates a customer, mints a per-customer credential, deploys a static site to serving, and that credential is refused on a second customer account and after revoke. |
| +- Local verification is targeted only: `go test ./internal/<pkg>/ -run '<TestNames>'`; never full suites, -race or e2e locally (CI runs them). If socket tests fail with path-length errors, run with `TMPDIR=/tmp/g` (`mkdir -p /tmp/g` first). |
| +- Go: leave `GOCACHE` at its default. If the sandbox makes the cache read-only, run the go command with the sandbox off (AGENTS.md "Build & test"). |
| +- Max three cross-model review rounds on this plan (AGENTS.md "Stopping rules"). |
| +- Commit subjects under 80 chars; body after a blank line; end with `Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>`. |
| + |
| +From the spec and AGENTS.md: |
| + |
| +- Names: **platform account** and **customer account**. Never "managed" (taken by managed fleets). |
| +- Wire shapes are additive: a manifest written before this change parses unchanged, and an unlinked manifest marshals byte-identical to today (`platform`, `platform_ref` are `omitempty`). |
| +- The platform role is never combined with other roles, never app-bound, and reachable only through `svcrole.Exactly(svcrole.Platform)`. Admin service credentials do NOT reach platform doors (spec §12 suggestion, adopted). |
| +- Per-customer credentials: kind `platform`; role Publish (account-wide, no app) or Deploy (one app, rungs required); expiry default 1 h, at most 24 h, at least 1 minute; checked on every request against a live link and an active grant. |
| +- Revoking a grant refuses the platform credential and every per-customer credential from the next request, read doors included. Links stay; sites keep serving. |
| +- The ops account (`OpsAccountID`, `domains.ReservedAccountID`) and any linked account can never hold a grant. |
| +- A platform account is never deleted while it has a live linked customer. |
| +- Linked accounts never get a Stripe customer: `holdBilling` refuses them, domain purchase refuses them, and they do not count towards anyone's free-account cap. |
| +- Ordinary security gate order holds (AGENTS.md): session, CSRF, owner (byte-identical 404), `requireFreshAuth` last. A caller who cannot see an account gets the stdlib `404 page not found`. |
| +- Files: no Go file past 3,000 code lines and no function past 300 grows (`make code-health`). Do not add code to `internal/console/server.go`, `apimode.go`, or the bodies of `(*Store).migrate`, `runDeploy` or `handleAPIInstanceCreate`. New code goes in the new files named in each task. |
| +- Every new `carlos` command gets a `docs/site/cli.md` heading and a `parity/parity.tsv` row in this branch; run `make parity-doc` after editing either. |
| +- The root binary's sources change (`internal/domains`, `internal/svcrole`, the root package), so Task 15 runs the census card flow (AGENTS.md "The census"). |
| + |
| +## Review Focus |
| + |
| +1. **Retried creates.** A platform's server retries `customers create` with the same `ref` after a timeout, sometimes concurrently. Expect exactly one account and the same sqid in every answer (Task 8, `TestCustomerCreateConcurrentSameRefMakesOneAccount`). |
| +2. **A mint that lands in the bucket and not in the console.** The manifest write succeeds and the row insert fails. Expect the next console start to materialize it as a linked, ownerless customer that lists, counts against `max_customers`, and can be deleted (Task 5, `TestMaterializeAdoptsAStrandedLinkedMint`). |
| +3. **The expiry boundary.** A per-customer credential at exactly `expires_at` works; one second later it is refused like an unknown token (Task 10, `TestCustomerCredentialExpiryBoundary`). |
| +4. **A grant that shrinks.** The operator lowers `max_customers` below the current count or drops a plan customers are on. Expect existing customers untouched, new creates refused with the cap sentence, and a PATCH onto a dropped plan refused (Task 8 `TestCustomerCreateStopsAtMaxCustomers`, Task 9 `TestCustomerPlanChangeStaysInsideTheGrant`). |
| +5. **The platform credential at an ordinary door.** A platform credential sent to `apps list`, `deploy` or `services` on its own platform account gets the role refusal, never a widening (Task 8, `TestPlatformCredentialRefusedAtOrdinaryDoors`). |
| + |
| +--- |
| + |
| +## File structure |
| + |
| +Create: |
| + |
| +- `internal/console/platform_store.go`: grant table, link columns, linked-customer queries, linked account create/ensure/rename/delete, `migratePlatformAccounts`. |
| +- `internal/console/platform_credentials.go`: per-customer credential mint, the live-link check, kind constants. |
| +- `internal/console/apiplatformgrant.go`: the operator grant doors. |
| +- `internal/console/apiplatformcustomers.go`: the platform gate and the customer doors (create, list, show, update, delete). |
| +- `internal/console/apiplatformcredentials.go`: the per-customer credential door. |
| +- `internal/console/apiplatformhost.go`: the Publish-reachable first static host door (§6.3). |
| +- `internal/console/platformlinked.go`: linked-account policy used by billing, domain purchase, the free cap, deletion and notices. |
| +- `internal/console/platform_copy.go`: console copy, from the copy table. |
| +- Tests beside each: `platform_store_test.go`, `platform_credentials_test.go`, `apiplatformgrant_test.go`, `apiplatformcustomers_test.go`, `apiplatformhost_test.go`, `platformlinked_test.go`. |
| +- Root: `accounts_platform.go`, `platform_cli.go`, `deploy_platformhost.go`, `platform_copy.go`, with `accounts_platform_test.go`, `platform_cli_test.go`, `platform_e2e_test.go`, and in Task 15 `approved_platform_accounts_copy_test.go`. |
| + |
| +Modify (refs checked at `06603e71`): |
| + |
| +- `internal/domains/mint.go` (manifest `:26-70`, `MintAccount :219`, `TombstoneAccount :268`). |
| +- `internal/svcrole/svcrole.go` (`catalogue :83`, `Allow :125`, `Exactly :169`), its tests. |
| +- `internal/console/store.go` (`migrate :167`; the feature-migration calls `:721-793`). |
| +- `internal/console/authstore.go` (kinds `:390-395`, `CLITokensContext :861`). |
| +- `internal/console/svcprincipal.go` (`Principal :58`, `CLIPrincipalContext :112`, mint rules `:355`). |
| +- `internal/console/apicli.go` (`auditActor :118`). |
| +- `internal/console/apiservices.go` (mint refusal mapping `:256-299`), `internal/console/svcpage.go` (`servicePane :175`). |
| +- `internal/console/materialize.go` (birth `:156-199`). |
| +- `internal/console/ownership.go` (`deletionRefused :161`, `DeleteAccount :790`). |
| +- `internal/console/accountplans.go` (sources `:18-23`). |
| +- `internal/console/plancaps.go` (`checkNewFreeAccount :175`), `billinghold.go` (`holdBilling :81`, `billingOwner :94`), `planexempt.go` (`errBillingExempt :41`), `billingpage_copy.go`, `domainbuy.go` (`admitDomainBuy :39`), `plangracepass.go` (`notifyPlanOwners :222`, `planNoticeEmail :275`). |
| +- `internal/console/routedecls.go` (instances list `:613`; new declarations), `svcroutes_test.go` (`closedDoors :103`). |
| +- Root: `deploy.go` (`mintPlatformHost :1086`), `accounts.go` (`accountsUsage :33`, `accountsCommand :85`), `accounts_plan.go` (source lines `:189-196`), `commands.go` (`:149-155`), `parity/parity.tsv`, `parity/cli.tsv` and `docs/parity.md` (generated), `docs/site/cli.md`. |
| + |
| +--- |
| + |
| +### Task 1: UX pass on the CLI output |
| + |
| +No code. The output mocks below are the starting point; this task is AGENTS.md's UX pass on them, before anything is built or copy-reviewed. |
| + |
| +**Files:** |
| +- Modify: this plan (the mocks and the copy table) |
| + |
| +- [ ] **Step 1: Render each mock below at 80 columns in a terminal (scratch file under `$TMPDIR`) and check it against AGENTS.md "Every UI change gets a UX pass": state first, label/value pairs and tables, about a dozen words to understand it, problems visible as a state.** |
| + |
| +``` |
| +$ carlos accounts platform --account bcd |
| +bcd is a platform account |
| + status on |
| + customers 3 of 50 |
| + plans free, personal |
| + new accounts start on free |
| + granted by ops@example.com on 19 November 2026: agreed by email |
| + |
| +$ carlos platform customers list --platform bcd |
| +3 customer accounts, 50 allowed |
| +ACCOUNT NAME REF PLAN OWNED USAGE |
| +bdf shop 4812 free no ok |
| +bdg bakery 4813 personal no near object storage |
| +bdh florist - free no over apps and instances |
| + |
| +$ carlos platform customers show --platform bcd --customer bdg |
| +bakery (bdg) |
| + ref 4813 |
| + plan personal |
| + owned no |
| + created 19 November 2026 |
| +usage |
| + object storage 8.2 GB of 10 GB near the limit |
| + apps and instances 2 of 10 |
| + |
| +$ carlos platform customers create --platform bcd --name shop --ref 4812 |
| +created shop (bdf) on the free plan |
| + |
| +$ carlos platform credentials mint --platform bcd --customer bdf |
| +minted a publish credential for shop (bdf), valid until 19 November 2026 15:04 UTC |
| +token <the secret, shown once> |
| +use it as CARLOS_SERVICE_TOKEN with --account bdf |
| +``` |
| + |
| +- [ ] **Step 2: Fix what reads badly in the mocks and the copy table rows they use; record each change in a short "UX pass" note under this task.** Expected: every mock leads with its state line; no line needs a second read. |
| + |
| +- [ ] **Step 3: Commit** |
| + |
| +```bash |
| +git add docs/superpowers/plans/2026-11-19-platform-accounts-1-platform-layer.md |
| +git commit -m "plan: platform accounts slice 1, CLI UX pass" |
| +``` |
| + |
| +--- |
| + |
| +### Task 2: The link in the bucket manifest |
| + |
| +**Files:** |
| +- Modify: `internal/domains/mint.go` |
| +- Test: `internal/domains/mint_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: |
| + - `AccountManifest.Platform string \`json:"platform,omitempty"\`` (the platform account's sqid) and `AccountManifest.PlatformRef string \`json:"platform_ref,omitempty"\``. |
| + - `func MintLinkedAccount(ctx context.Context, s release.Store, name, platformSqid, ref string, created time.Time) (int64, string, error)`: `MintAccount`'s loop with no owner and the two link fields in the same create-only write. |
| + - `func RenameAccountManifest(ctx context.Context, s release.Store, sqid, name string) error`: CAS read-modify-write with one retry (`TombstoneAccount`'s shape), every other field kept. |
| + - `var ErrBadPlatformLink = errors.New(...)`. |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + |
| +```go |
| +func TestMintLinkedAccountWritesTheLinkInTheCreateOnlyWrite(t *testing.T) { |
| + // DirStore with ops (id 1) and bcd's manifest present. |
| + id, sqid, err := MintLinkedAccount(ctx, s, "shop", "bcd", "4812", now) |
| + // err == nil; manifest at AccountManifestKey(sqid) decodes to |
| + // Platform "bcd", PlatformRef "4812", Owner "", ID id, Name "shop". |
| +} |
| +func TestMintLinkedAccountRefusesABadLink(t *testing.T) { |
| + // platformSqid "" , "not a sqid!", Sqid(ReservedAccountID): errors.Is(err, ErrBadPlatformLink) |
| + // and s.List(ctx, "accounts/") is unchanged (nothing written). |
| +} |
| +func TestUnlinkedManifestIsByteIdentical(t *testing.T) { |
| + // json.Marshal(AccountManifest{ID:2,Sqid:"bab",Name:"a",CreatedAt:t0}) has no "platform" key; |
| + // a manifest body without the keys unmarshals with Platform == "" && PlatformRef == "". |
| +} |
| +func TestRenameAccountManifestKeepsEveryField(t *testing.T) { |
| + // linked manifest renamed "shop" -> "shop-2": Name changed; ID, Sqid, CreatedAt, Owner, |
| + // Platform, PlatformRef unchanged. A missing manifest is an error wrapping os.ErrNotExist. |
| +} |
| +func TestTombstoneKeepsThePlatformLink(t *testing.T) { |
| + // TombstoneAccount on a linked manifest: Deleted() true, Owner "", Platform still "bcd". |
| +} |
| +``` |
| + |
| +- [ ] **Step 2: Run them to verify they fail** |
| + |
| +Run: `go test ./internal/domains/ -run 'TestMintLinkedAccount|TestUnlinkedManifestIsByteIdentical|TestRenameAccountManifest|TestTombstoneKeepsThePlatformLink' -count=1` |
| +Expected: FAIL (undefined: MintLinkedAccount). |
| + |
| +- [ ] **Step 3: Implement.** Refactor `MintAccount`'s body into an unexported `mint(ctx, s, AccountManifest template, created)` that both call, so the create-only loop exists once. `MintLinkedAccount` validates before the first listing: `ValidSqid(platformSqid)` and `platformSqid != Sqid(ReservedAccountID)`, else `ErrBadPlatformLink`. The ref is validated by the console (Task 8), not here. `TombstoneAccount` needs no change: it round-trips the struct, so it keeps the new fields; the test pins that. |
| + |
| +- [ ] **Step 4: Run the tests to verify they pass** (same command). Expected: PASS. |
| + |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add internal/domains/mint.go internal/domains/mint_test.go |
| +git commit -m "domains: platform link fields in the account manifest" |
| +``` |
| + |
| +--- |
| + |
| +### Task 3: The `platform` service role |
| + |
| +**Files:** |
| +- Modify: `internal/svcrole/svcrole.go` |
| +- Test: `internal/svcrole/svcrole_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: `const Platform Role = "platform"`, inserted in `catalogue` just before `Admin`, so `All()` keeps Admin last. `Allow(Platform)` panics with a message naming `Exactly(Platform)`. `Exactly(Platform)` admits only Platform. Admin's comment becomes "every role except Run, Team and Platform". |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + |
| +```go |
| +func TestPlatformIsInTheCatalogueAndOutsideAdminsUnion(t *testing.T) { |
| + // Parse("platform") == (Platform, true); slices.Contains(All(), Platform); |
| + // Exactly(Platform).Permits(Admin) == false; Allow(Publish).Permits(Platform) == false. |
| +} |
| +func TestAllowRefusesPlatform(t *testing.T) { /* defer recover: Allow(Platform) panics, message contains "Exactly(Platform)" */ } |
| +func TestExactlyPlatformAdmitsOnlyPlatform(t *testing.T) { |
| + // for every r in All(): Exactly(Platform).Permits(r) == (r == Platform) |
| +} |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/svcrole/ -run 'TestPlatform|TestAllowRefusesPlatform|TestExactlyPlatform' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement** in `svcrole.go`, following Run's pattern exactly. Update any existing svcrole test that enumerates `All()` and asserts Admin reaches every role (`TestAdminPermitsEveryNonEmptySet` and friends) so Platform joins Run and Team as the exceptions. |
| +- [ ] **Step 4: Run** `go test ./internal/svcrole/ -run 'TestPlatform|TestAllow|TestExactly|TestAdmin|TestParse|TestRun|TestTeam' -count=1`. Expected: PASS. |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add internal/svcrole |
| +git commit -m "svcrole: platform role, outside Admin, reachable only through Exactly" |
| +``` |
| + |
| +--- |
| + |
| +### Task 4: Console store for grants and links |
| + |
| +**Files:** |
| +- Create: `internal/console/platform_store.go`, `internal/console/platform_store_test.go` |
| +- Modify: `internal/console/store.go` (`migrate`), `internal/console/ownership.go` (`DeleteAccount :790`), `internal/console/accountplans.go` |
| + |
| +**Interfaces:** |
| +- Consumes: nothing from earlier tasks (the manifest work is bucket-side). |
| +- Produces (all in `platform_store.go` unless named): |
| + |
| +```go |
| +const PlanSourcePlatform = "platform" // accountplans.go, beside the others |
| +const (PlatformGrantActive = "active"; PlatformGrantRevoked = "revoked") |
| +type PlatformGrant struct { |
| + AccountID int64 |
| + State string |
| + MaxCustomers int |
| + Plans []string // sorted, deduped; nil with no catalog |
| + DefaultPlan string // "" with no catalog |
| + Reason, GrantedBy string |
| + GrantedAt time.Time |
| + RevokedBy, RevokeReason string |
| + RevokedAt time.Time |
| +} |
| +type LinkedCustomer struct { |
| + ID int64; Sqid, Name, Ref string; CreatedAt time.Time |
| + Owners int // owner memberships; > 0 means claimed |
| +} |
| +var ( |
| + ErrNotPlatform = errors.New("console: this account is not a platform account") // no grant row, or not active |
| + ErrPlatformHasCustomers = errors.New("console: this platform account still has customer accounts") |
| + ErrCustomerClaimed = errors.New("console: someone owns this customer account") |
| + ErrCustomerHasApps = errors.New("console: this customer account still holds apps") |
| +) |
| +func (s *Store) migratePlatformAccounts() error |
| +func (s *Store) PlatformGrant(ctx context.Context, accountID int64) (*PlatformGrant, error) // nil, nil: none |
| +func (s *Store) PutPlatformGrant(ctx context.Context, g PlatformGrant, now time.Time) error // upsert, state active, revoke fields cleared |
| +func (s *Store) RevokePlatformGrant(ctx context.Context, accountID int64, by, reason string, now time.Time) (credentials int, err error) |
| +func (s *Store) AccountPlatform(ctx context.Context, accountID int64) (platformSqid, ref string, err error) // "" when unlinked or unknown |
| +func (s *Store) LinkedCustomers(ctx context.Context, platformSqid string) ([]LinkedCustomer, error) // live only, by id |
| +func (s *Store) LinkedCustomer(ctx context.Context, platformSqid, customerSqid string) (*LinkedCustomer, error) // nil when not this platform's |
| +func (s *Store) LinkedCustomerByRef(ctx context.Context, platformSqid, ref string) (*LinkedCustomer, error) |
| +func (s *Store) LinkedCustomerCount(ctx context.Context, platformSqid string) (int, error) |
| +type NewLinkedAccount struct { |
| + ID int64; Sqid, Name, Platform, Ref string |
| + Plan, PlanReason, By string // Plan "" writes no plan row |
| +} |
| +func (s *Store) CreateLinkedAccount(ctx context.Context, a NewLinkedAccount, now time.Time) error |
| +func (s *Store) EnsureLinkedAccount(id int64, sqid, name, platformSqid, ref string, created time.Time) (added bool, err error) |
| +func (s *Store) RenameAccount(ctx context.Context, accountID int64, name string) error |
| +func (s *Store) DeleteUnclaimedCustomer(ctx context.Context, customerID int64, platformSqid string, now time.Time) error |
| +``` |
| + |
| +Schema (in `migratePlatformAccounts`, idempotent, "duplicate column" forgiven like the ALTER lists): |
| + |
| +```sql |
| +CREATE TABLE IF NOT EXISTS platform_grants ( |
| + account_id INTEGER PRIMARY KEY, state TEXT NOT NULL, max_customers INTEGER NOT NULL, |
| + plans TEXT NOT NULL DEFAULT '[]', default_plan TEXT NOT NULL DEFAULT '', |
| + reason TEXT NOT NULL, granted_by TEXT NOT NULL, granted_at INTEGER NOT NULL, |
| + revoked_by TEXT NOT NULL DEFAULT '', revoked_at INTEGER NOT NULL DEFAULT 0, |
| + revoke_reason TEXT NOT NULL DEFAULT '', updated_at INTEGER NOT NULL); |
| +ALTER TABLE accounts ADD COLUMN platform TEXT NOT NULL DEFAULT ''; -- platform account sqid |
| +ALTER TABLE accounts ADD COLUMN platform_ref TEXT NOT NULL DEFAULT ''; |
| +ALTER TABLE cli_tokens ADD COLUMN platform_account_id INTEGER NOT NULL DEFAULT 0; |
| +CREATE INDEX IF NOT EXISTS accounts_platform ON accounts (platform) WHERE platform != ''; |
| +CREATE UNIQUE INDEX IF NOT EXISTS accounts_platform_ref ON accounts (platform, platform_ref) |
| + WHERE platform_ref != '' AND deleted_at = 0; |
| +CREATE INDEX IF NOT EXISTS cli_tokens_platform ON cli_tokens (platform_account_id) WHERE platform_account_id != 0; |
| +``` |
| + |
| +The link column holds the platform's sqid, not its id, so materialization (Task 5) never depends on the order accounts are listed in. |
| + |
| +- [ ] **Step 1: Write the failing tests** (`platform_store_test.go`, using `Open` on `t.TempDir()` like `store_test.go`) |
| + |
| +```go |
| +func TestPlatformGrantRoundTrip(t *testing.T) // Put, read back every field; second Put re-grants (state active, revoke fields "") |
| +func TestRevokePlatformGrantRevokesItsCredentials(t *testing.T) { |
| + // rows: kind 'platform' platform_account_id=P (2 rows), kind 'service' role 'platform' account_id=P (1), |
| + // kind 'service' role 'publish' account_id=P (1), kind 'platform' platform_account_id=Q (1). |
| + // RevokePlatformGrant(P) returns 3; only those three have revoked_at != 0; grant state "revoked". |
| +} |
| +func TestCreateLinkedAccountHasNoMembersAndAPlatformPlan(t *testing.T) { |
| + // Members(id) empty; AccountPlatform == ("bcd", "4812"); AccountPlan(id).Source == PlanSourcePlatform, |
| + // Plan == "personal", UpdatedBy == "service:bcd/cms"; no launch sponsorship row even with a rule recorded. |
| +} |
| +func TestLinkedCustomerRefIsUniquePerPlatform(t *testing.T) // same ref on bcd twice: second CreateLinkedAccount errors; same ref on bcf is fine; after DeleteUnclaimedCustomer the ref is free again |
| +func TestLinkedCustomersListsOnlyThisPlatformsLiveAccounts(t *testing.T) |
| +func TestEnsureLinkedAccountDropsAConflictingRef(t *testing.T) // a second birth with a taken ref is added with Ref "" |
| +func TestDeleteAccountRefusesAPlatformWithCustomers(t *testing.T) // errors.Is(err, ErrPlatformHasCustomers); after the customer is deleted it succeeds |
| +func TestDeleteUnclaimedCustomerRefusals(t *testing.T) { |
| + // owner membership -> ErrCustomerClaimed; an app row -> ErrCustomerHasApps; |
| + // wrong platform sqid -> ErrAccountGone; success marks deleted_at, revokes kind 'platform' rows for it. |
| +} |
| +func TestMigrateIsIdempotentWithPlatformTables(t *testing.T) // Open, Close, Open the same file: no error |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestPlatformGrantRoundTrip|TestRevokePlatformGrant|TestCreateLinkedAccount|TestLinkedCustomer|TestEnsureLinkedAccount|TestDeleteAccountRefusesAPlatform|TestDeleteUnclaimedCustomer|TestMigrateIsIdempotentWithPlatform' -count=1`. Expected: FAIL. |
| + |
| +- [ ] **Step 3: Make room in `migrate` first.** `(*Store).migrate` is 389 code lines, held by the ratchet. Replace the run of feature calls from `migrateCLIAuth` to `migrateDomains` (`store.go:721-793`) with one `migrateFeatures()` method that iterates an ordered `[]func() error{s.migrateCLIAuth, s.migrateLinks, ...}` in the same order, carrying each call's comment onto its element, and append `s.migratePlatformAccounts` last. No reordering, nothing else changed. `migrate` shrinks; nothing grows. |
| + |
| +- [ ] **Step 4: Implement the store.** Points the signatures leave open: |
| + - `CreateLinkedAccount`: one transaction: the `accounts` insert with `platform`, `platform_ref`; when `Plan != ""`, the plan row through `accountPlanUpsertSQL`/`accountPlanUpsertArgs` with `PlanSourcePlatform`. No membership. No `sponsorOnInsertTx`: a linked account's plan is its platform's (decision D9). |
| + - `EnsureLinkedAccount`: `EnsureAccount`'s body (share an unexported helper) plus the two columns; inside its transaction, a ref already held by a live account of the same platform is dropped to `""` before the insert, so the unique index can never turn a birth into an ignored insert. No sponsorship either. |
| + - `DeleteAccount` (`ownership.go:790`): inside its transaction, before the deletes, count live accounts whose `platform` is this account's sqid; non-zero is `ErrPlatformHasCustomers`. |
| + - `DeleteUnclaimedCustomer`: one transaction: the row must be live with `platform = platformSqid` (else `ErrAccountGone`); owner count 0 (else `ErrCustomerClaimed`); `apps` count 0, unfiltered like `AppCount` (else `ErrCustomerHasApps`); then the same statements as `DeleteAccount` and `UPDATE cli_tokens SET revoked_at = ? WHERE kind = 'platform' AND account_id = ? AND revoked_at = 0`. |
| + - `RevokePlatformGrant`: one transaction: grant row to revoked, then `UPDATE cli_tokens SET revoked_at = ? WHERE revoked_at = 0 AND ((kind = 'platform' AND platform_account_id = ?) OR (kind = 'service' AND role = 'platform' AND account_id = ?))`; returns rows affected. A missing grant is `ErrNotPlatform`. |
| + |
| +- [ ] **Step 5: Run** the Step 2 command, then the existing migration and deletion tests: `go test ./internal/console/ -run 'TestOpen|TestMigrate|TestDeleteAccount|TestEnsureAccount' -count=1`. Expected: PASS. |
| + |
| +- [ ] **Step 6: Commit** |
| + |
| +```bash |
| +git add internal/console/platform_store.go internal/console/platform_store_test.go internal/console/store.go internal/console/ownership.go internal/console/accountplans.go |
| +git commit -m "console: platform grants and customer links in the store" |
| +``` |
| + |
| +--- |
| + |
| +### Task 5: Materialization carries the link, at birth only |
| + |
| +**Files:** |
| +- Modify: `internal/console/materialize.go` (birth branch `:156-199`) |
| +- Test: `internal/console/materialize_test.go` (append) |
| + |
| +**Interfaces:** |
| +- Consumes: `domains.AccountManifest.Platform/PlatformRef` (Task 2), `Store.EnsureLinkedAccount` (Task 4). |
| +- Produces: nothing new; behaviour only. |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + |
| +```go |
| +func TestMaterializeCarriesThePlatformLinkAtBirth(t *testing.T) |
| + // manifest bdf {platform:"bcd", platform_ref:"4812"}, no owner -> AccountPlatform(bdf) == ("bcd","4812"), Members empty |
| +func TestMaterializeNeverLinksAnAccountAfterBirth(t *testing.T) |
| + // materialize bdf unlinked; rewrite its manifest with platform "bcd"; materialize again -> AccountPlatform(bdf) == ("", "") |
| +func TestMaterializeRefusesASelfOrOpsLink(t *testing.T) |
| + // platform == own sqid, == Sqid(1), or not ValidSqid -> materialized unlinked (row exists, AccountPlatform "") |
| +func TestMaterializeAdoptsAStrandedLinkedMint(t *testing.T) |
| + // domains.MintLinkedAccount with no console row, then MaterializeAccounts -> LinkedCustomers("bcd") contains it |
| +func TestLinkedOwnerlessAccountReachesNobody(t *testing.T) |
| + // after birth: AccountsFor(any address) never returns it; GET /a/<sqid>/ as a signed-in person is the stdlib 404 |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestMaterializeCarries|TestMaterializeNeverLinks|TestMaterializeRefusesASelf|TestMaterializeAdoptsAStranded|TestLinkedOwnerlessAccountReachesNobody' -count=1`. Expected: FAIL on the first four. |
| +- [ ] **Step 3: Implement.** In the birth branch only: when `m.Platform != ""` and it passes the same checks as `MintLinkedAccount` plus `m.Platform != m.Sqid`, call `EnsureLinkedAccount`; when it fails them, log one line naming the manifest and call `EnsureAccount` (unlinked and ownerless: unreachable, which is the safe side). The `a != nil` branch stays "settled": no link is ever adopted after birth, for the same reason `materializeOwner` runs once (its comment `:204-249` is the argument; add one sentence there saying the link follows the same rule). |
| +- [ ] **Step 4: Run** the Step 2 command plus `-run 'TestMaterialize'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add internal/console/materialize.go internal/console/materialize_test.go |
| +git commit -m "console: materialize the platform link at an account's birth only" |
| +``` |
| + |
| +--- |
| + |
| +### Task 6: The operator grant door and `carlos accounts platform` |
| + |
| +**Files:** |
| +- Create: `internal/console/apiplatformgrant.go`, `internal/console/apiplatformgrant_test.go`, `internal/console/platform_copy.go`, `accounts_platform.go`, `accounts_platform_test.go`, `platform_copy.go` |
| +- Modify: `internal/console/routedecls.go`, `internal/console/svcroutes_test.go` (`closedDoors`), `accounts.go`, `parity/parity.tsv`, `docs/site/cli.md` |
| + |
| +**Interfaces:** |
| +- Consumes: Task 4 store. |
| +- Produces: |
| + - Doors, all `Kind: kindCLI, Allow: svcrole.Set{}` (person only; added to `closedDoors`): |
| + `GET /api/cli/accounts/{account}/platform` → `handleAPIPlatformGrantGet`; |
| + `PUT /api/cli/accounts/{account}/platform` → `handleAPIPlatformGrantPut`; |
| + `POST /api/cli/accounts/{account}/platform/revoke` → `handleAPIPlatformGrantRevoke`. |
| + - Wire: `type platformGrantReply struct { Account string; Platform bool; State string; MaxCustomers, Customers int; Plans []string; DefaultPlan, Reason, GrantedBy string; GrantedAt time.Time; RevokedBy, RevokeReason string; RevokedAt time.Time }` (JSON snake_case, time fields `omitempty` via pointers); `type putPlatformGrantRequest struct { MaxCustomers int; Plans []string; DefaultPlan, Reason string }`; revoke body `{ "reason": string }`, reply `platformGrantReply` plus `"credentials_revoked": int`. |
| + - `func (s *Server) platformGrantDoor(w http.ResponseWriter, r *http.Request) (addr string, acct *Account, ok bool)`: `accountPlanDoor`'s gate (`apiaccountplan.go:45`) without the catalog requirement: `cliUser`, `IsOperator` else stdlib 404, `AccountBySqid` else 404. |
| + - CLI: `func runAccountsPlatformWithSession(ctx context.Context, sess *apiSession, args []string, out io.Writer) error`; `raw("platform", op, runAccountsPlatform)` in `accountsCommand`; session methods `platformGrant`, `putPlatformGrant`, `revokePlatformGrant` in `accounts_platform.go`. |
| + |
| +Rules the handler enforces, in order, on PUT: write budget (`allowWrite`) → reason non-empty (`grant.reason`) → `acct.ID == OpsAccountID` is 409 `grant.ops` → linked account (`AccountPlatform != ""`) is 409 `grant.linked` → `1 <= max_customers <= 10000` else 400 `grant.max` → with a catalog: `plans` non-empty, each in `cat.Plans`, `default_plan` among them, else 400 `grant.plans`; without one: `plans` and `default_plan` empty, else 400 `grant.no_catalog` → `PutPlatformGrant`, audit on the platform account (`platform-grant`, copy `audit.grant`). Revoke: reason required, no grant is 409 `grant.not_platform`, else `RevokePlatformGrant` and audit (`audit.revoke`). GET on an account with no grant answers 200 `{"platform": false}`. |
| + |
| +- [ ] **Step 1: Write the failing console tests** (`newConsoleFixture`, `planOperatorToken`, `examplePlanCatalog` from the existing tests) |
| + |
| +```go |
| +func TestPlatformGrantDoorIsOperatorOnly(t *testing.T) // owner token: GET/PUT/revoke all "404 page not found\n"; nothing written |
| +func TestPlatformGrantDoorRefusesOpsAndCustomerAccounts(t *testing.T) // 409 with platformCopy["grant.ops"], ["grant.linked"] |
| +func TestPlatformGrantValidatesPlansAgainstTheCatalog(t *testing.T) // unknown plan, default not in plans, max 0 and 10001 -> 400s |
| +func TestPlatformGrantWithoutACatalog(t *testing.T) // max only -> 200; plans set -> 400 grant.no_catalog |
| +func TestPlatformRevokeAndRegrant(t *testing.T) // revoke -> state revoked, credentials_revoked counted; PUT again -> active |
| +func TestPlatformGrantDoorsAreClosedToEveryRole(t *testing.T) // serviceToken(Admin) at each door -> the closed-door 403 |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestPlatformGrant|TestPlatformRevokeAndRegrant|TestEveryCLIDoorNamesItsRoles|TestEveryClosedDoorRefusesAServiceCredential' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement the doors** in `apiplatformgrant.go`; add the three declarations beside the plan doors (`routedecls.go:996-997`) and the three patterns to `closedDoors` with a comment: "Granting platform status is an operator's act; no credential reaches it." |
| +- [ ] **Step 4: Write the failing CLI tests** (`accounts_platform_test.go`, the `accounts_plan_test.go` pattern: an `httptest` console fake and `runAccountsPlatformWithSession`) |
| + |
| +```go |
| +func TestAccountsPlatformShowPrintsTheGrant(t *testing.T) // output lines equal the Task 1 mock with the copy constants |
| +func TestAccountsPlatformShowNotAPlatform(t *testing.T) // cliPlatformCopyNotPlatform |
| +func TestAccountsPlatformGrantSendsTheGrant(t *testing.T) // PUT body {max_customers:50, plans:["free","personal"], default_plan:"free", reason:"r"} |
| +func TestAccountsPlatformFlagRefusals(t *testing.T) // --grant with --revoke; --plans without --grant; --grant without --reason -> errors, nothing sent |
| +``` |
| + |
| +- [ ] **Step 5: Implement the CLI.** Flags: `--account` (required, `explicitStoreAccount`), `--grant`, `--revoke` (bools), `--max-customers`, `--plans` (comma list), `--default-plan`, `--reason`, `--console`. No `--grant`/`--revoke` shows. Session via `requirePlanAPISession`'s pattern with its own "needs a console" sentence (`cliPlatformCopyNeedsConsole`). Add the `plan` line's sibling to `accountsUsage`; add parity row `op-accounts-platform operator operator accounts platform The operator account pages show grants in slice 3.`; add `### carlos accounts platform` to `docs/site/cli.md` (copy table, docs rows). Run `make parity-doc`. |
| +- [ ] **Step 6: Run** `go test . -run 'TestAccountsPlatform|TestCLIProjection|TestParity' -count=1` and `go test ./internal/parity/ ./internal/docsite/ -count=1`. Expected: PASS. |
| +- [ ] **Step 7: Commit** |
| + |
| +```bash |
| +git add internal/console/apiplatformgrant*.go internal/console/platform_copy.go internal/console/routedecls.go internal/console/svcroutes_test.go accounts.go accounts_platform*.go platform_copy.go parity docs/parity.md docs/site/cli.md |
| +git commit -m "accounts platform: operator grants and revokes platform status" |
| +``` |
| + |
| +--- |
| + |
| +### Task 7: The platform credential through the services door |
| + |
| +**Files:** |
| +- Modify: `internal/console/svcprincipal.go`, `internal/console/apiservices.go`, `internal/console/svcpage.go` |
| +- Test: `internal/console/platform_credentials_test.go` (create) |
| + |
| +**Interfaces:** |
| +- Consumes: `svcrole.Platform` (Task 3), `Store.PlatformGrant` (Task 4). |
| +- Produces: |
| + - `var ErrAppScopedPlatform = errors.New("console: a platform credential is never bound to an app")`; mint returns it, and `ErrNotPlatform` when the account has no active grant (checked inside the mint transaction). |
| + - `CLIPrincipalContext` refuses a `kind='service'` row with role `platform` and a non-empty app, and refuses any row with `platform_account_id != 0` unless its kind is `platform` (Task 10 adds that kind). |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + |
| +```go |
| +func TestServicesDoorMintsAPlatformCredentialOnlyOnAGrantedAccount(t *testing.T) |
| + // owner POST /api/cli/services/<acct> {name:"cms", role:"platform"}: no grant -> 409 platformCopy["svc.not_platform"]; |
| + // grant -> 201 with role "platform" and app "". (Task 8 adds the assertion that its doors are the platform patterns.) |
| +func TestPlatformCredentialTakesNoApp(t *testing.T) // {role:"platform", app:"site"} -> 400 platformCopy["svc.platform_app"] |
| +func TestPlatformRoleRowWithAnAppDoesNotResolve(t *testing.T) // raw row kind service role platform app "x" -> CLIPrincipal ok == false |
| +func TestRowWithAPlatformAccountIDOnlyResolvesAsPlatformKind(t *testing.T) // kind service + platform_account_id 5 -> refused |
| +func TestBrowserMintFormDoesNotOfferPlatform(t *testing.T) // servicePane's ServiceRoles has no "platform" |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestServicesDoorMintsAPlatform|TestPlatformCredentialTakesNoApp|TestPlatformRoleRowWithAnApp|TestRowWithAPlatformAccountID|TestBrowserMintFormDoesNotOfferPlatform' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** In `claimRawNewServicePrincipalScoped` (`svcprincipal.go:355`), beside the Service rule: Platform with an app is `ErrAppScopedPlatform`; inside the existing transaction, a Platform mint on an account whose grant row is missing or not active is `ErrNotPlatform`. Map both in `handleAPIServiceCreate` (`apiservices.go:256-299`) to 400 and 409 with the copy rows. Add `platform_account_id` to the `CLIPrincipalContext` SELECT and the checks above. `servicePane` skips `svcrole.Platform` when building `ServiceRoles`. |
| +- [ ] **Step 4: Run** the Step 2 command plus `-run 'TestServiceCreate|TestCLIPrincipal'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add internal/console/svcprincipal.go internal/console/apiservices.go internal/console/svcpage.go internal/console/platform_credentials_test.go |
| +git commit -m "console: mint platform credentials on granted accounts only" |
| +``` |
| + |
| +--- |
| + |
| +### Task 8: The platform gate, customer create, list and show |
| + |
| +**Files:** |
| +- Create: `internal/console/apiplatformcustomers.go`, `internal/console/apiplatformcustomers_test.go` |
| +- Modify: `internal/console/routedecls.go`, `internal/console/platform_copy.go`, `internal/console/platform_store.go` (`LinkedCustomerPlans`) |
| + |
| +**Interfaces:** |
| +- Consumes: Tasks 2, 4, 7. |
| +- Produces: |
| + - Declarations, all `Kind: kindCLI, Allow: svcrole.Exactly(svcrole.Platform)`. The path segment is `{account}` (not the spec's `{platform}`) so `apiPrincipalAccount` binds it unchanged (decision D1): |
| + `POST /api/cli/platform/{account}/customers` → `handlePlatformCustomerCreate`; |
| + `GET /api/cli/platform/{account}/customers` → `handlePlatformCustomerList` (optional `?ref=`); |
| + `GET /api/cli/platform/{account}/customers/{customer}` → `handlePlatformCustomerShow`; |
| + `PATCH` and `DELETE` on the same path → Task 9; `POST .../customers/{customer}/credentials` → Task 10. |
| + - ```go |
| + type platformCaller struct { |
| + P Principal |
| + Platform *Account |
| + Grant *PlatformGrant |
| + Actor string // auditActor(P, Platform) |
| + } |
| + func (s *Server) platformGate(w http.ResponseWriter, r *http.Request) (platformCaller, bool) |
| + func (s *Server) platformCustomer(w http.ResponseWriter, r *http.Request, c platformCaller) (*LinkedCustomer, *Account, bool) |
| + type platformCustomerView struct { |
| + Account string `json:"account"` |
| + Name string `json:"name"` |
| + Ref string `json:"ref,omitempty"` |
| + Plan string `json:"plan,omitempty"` |
| + PlanSource string `json:"plan_source,omitempty"` |
| + Claimed bool `json:"claimed"` |
| + CreatedAt time.Time `json:"created_at"` |
| + Usage []platformUsageView `json:"usage"` |
| + } |
| + type platformUsageView struct { |
| + Cap string `json:"cap"` |
| + Used int64 `json:"used"` |
| + Limit int64 `json:"limit"` |
| + Level string `json:"level"` |
| + GraceEnds *time.Time `json:"grace_ends,omitempty"` |
| + } |
| + func validPlatformRef(ref string) bool // 1-64 of [A-Za-z0-9._:-] |
| + ``` |
| + - List reply `{"platform": sqid, "max_customers": n, "count": n, "customers": [...]}`; create reply 201 `{"created": true, "customer": view}` or 200 `{"created": false, "customer": view}` on a ref hit. |
| + |
| +`platformGate` order: `apiPrincipalAccount` (service binding or membership; the family's 404) → a person who is not an owner gets 403 `door.not_owner` → `PlatformGrant` missing is 403 `door.not_platform`, revoked is 403 `door.revoked`. `platformCustomer`: `LinkedCustomer(platform.Sqid, PathValue("customer"))` nil is the stdlib 404, whatever the reason. |
| + |
| +Create, in order: decode `{name, ref, plan}` → `ValidAccountName` (`create.name`) → `ref == "" || validPlatformRef` (`create.ref`) → plan: empty means `Grant.DefaultPlan`; non-empty must be in `Grant.Plans` (`create.plan`); with no catalog a named plan is `create.no_catalog_plan` → take `s.lockAccount(platform.Sqid)` → ref hit: answer 200 with it, spending nothing → `allowCreate(P)` (`create.rate`, 429) → `LinkedCustomerCount >= MaxCustomers` is 409 `create.cap` → `domains.MintLinkedAccount` → `startNewAccountAnalytics` → `CreateLinkedAccount` (plan reason `fmt.Sprintf("platform %s", platform.Sqid)`, by `Actor`) → audit on the platform account (`audit.customer_create`) and on the customer (`audit.customer_created_by`) → 201. Mint or row failures log the sqid like `mintAccount` does (`server.go:3155-3190`) and answer 502 `create.failed`. |
| + |
| +Usage: the customer's `plan_cap_state` rows whose `Period == capPeriod(Cap, now)`, in `capOrder`. The list must not run two queries per customer (up to 10000 of them on a one-connection database), so it reads both in two queries through a new store method in `platform_store.go`: |
| + |
| +```go |
| +// LinkedCustomerPlans returns every live customer's plan row and cap rows, keyed by account id, |
| +// with one query each: WHERE account_id IN (SELECT id FROM accounts WHERE platform = ? AND deleted_at = 0). |
| +func (s *Store) LinkedCustomerPlans(ctx context.Context, platformSqid string) (map[int64]AccountPlanRow, map[int64][]capState, error) |
| +``` |
| + |
| +Show uses `AccountPlanContext` and `CapStatesContext` for its one customer. |
| + |
| +- [ ] **Step 1: Write the failing tests** (fixture helpers: a `grantPlatform(t, fx, sqid, max, plans...)` and `platformToken(t, fx, platformID, "cms")` built on `serviceToken`; put them in the test file) |
| + |
| +```go |
| +func TestPlatformDoorsTakeOnlyThePlatformRole(t *testing.T) // every pattern under /api/cli/platform/ has Exactly(Platform); no other pattern permits Platform; a services-door mint of role platform answers doors == exactly those patterns |
| +func TestAdminCredentialIsRefusedAtPlatformDoors(t *testing.T) // serviceToken(Admin) on the platform account -> 403 role refusal |
| +func TestPlatformDoorRefusesANonPlatformAndARevokedGrant(t *testing.T) |
| +func TestPlatformDoorAdmitsAnOwnerNotAMember(t *testing.T) // owner person token 200; member token 403 door.not_owner; stranger 404 |
| +func TestCustomerCreateMintsALinkedOwnerlessAccount(t *testing.T) |
| + // 201; manifest Platform == platform sqid, Owner ""; Members empty; plan row source platform, plan == grant default |
| +func TestCustomerCreateIsIdempotentOnRef(t *testing.T) // second create, same ref, other name -> 200 created:false, same sqid |
| +func TestCustomerCreateConcurrentSameRefMakesOneAccount(t *testing.T) // 8 goroutines, same ref -> one sqid, LinkedCustomerCount == 1 |
| +func TestCustomerCreateRefusesAPlanOutsideTheGrant(t *testing.T) |
| +func TestCustomerCreateStopsAtMaxCustomers(t *testing.T) // max 2: third 409 create.cap; lower the grant to 1: existing two still listed |
| +func TestCustomerCreateRefusesBadNamesAndRefs(t *testing.T) // "Shop!", ref "a b", ref of 65 chars, ref "é" -> 400 |
| +func TestCustomerListAndShowCarryUsage(t *testing.T) // PutCapState a storage row at warn -> show's usage has it; an old-period row is absent |
| +func TestCustomerDoorsHideOtherPlatformsCustomers(t *testing.T) // platform A's credential on B's customer sqid -> stdlib 404, byte-identical to an unknown sqid |
| +func TestPlatformCredentialRefusedAtOrdinaryDoors(t *testing.T) // GET /api/cli/apps/<platform>, POST /api/cli/services/<platform> -> role refusal, not 200 |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestPlatformDoor|TestAdminCredentialIsRefusedAtPlatformDoors|TestCustomerCreate|TestCustomerListAndShow|TestCustomerDoorsHide|TestPlatformCredentialRefusedAtOrdinaryDoors' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement** `apiplatformcustomers.go` and the three declarations (a block after the services family, `routedecls.go:943-946`, with a comment naming spec §6.1 and that Admin is out on purpose). |
| +- [ ] **Step 4: Run** the Step 2 command plus `-run 'TestEveryCLIDoorNamesItsRoles|TestNoRoleReachesAMintFleetOrPolicyDoor|TestRouteDeclsMatchRegistrations'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add internal/console/apiplatformcustomers*.go internal/console/routedecls.go internal/console/platform_copy.go |
| +git commit -m "console: platform doors to create, list and show customer accounts" |
| +``` |
| + |
| +--- |
| + |
| +### Task 9: Customer update and delete; platform accounts keep their customers |
| + |
| +**Files:** |
| +- Modify: `internal/console/apiplatformcustomers.go`, `internal/console/routedecls.go`, `internal/console/ownership.go`, `internal/console/platformlinked.go` (create) |
| +- Test: `internal/console/apiplatformcustomers_test.go`, `internal/console/platformlinked_test.go` (create) |
| + |
| +**Interfaces:** |
| +- Consumes: Tasks 2, 4, 8. |
| +- Produces: |
| + - `PATCH /api/cli/platform/{account}/customers/{customer}` → `handlePlatformCustomerUpdate`, body `{name?, plan?, reason?}`, reply the view. |
| + - `DELETE /api/cli/platform/{account}/customers/{customer}` → `handlePlatformCustomerDelete`, reply `{"deleted": true, "account": sqid}`. |
| + - `var errPlanSetByOperator = errors.New("console: an operator set this account's plan")` in `apiplatformcustomers.go`. |
| + - `func (s *Server) applyPlatformPlan(ctx context.Context, cust *Account, plan, reason, by string, now time.Time) error`: `transitionAccountPlan` (`planlapse.go:131`) with a write closure that refuses an old row whose source is operator or sponsored (`errPlanSetByOperator`) and otherwise does what `applyAccountPlan`'s closure does with `PlanSourcePlatform`, so lapse and grace work as for an owner's change. |
| + - `platformlinked.go`: `func (s *Server) linkedPlatform(ctx context.Context, acct *Account) (*Account, error)` (nil when unlinked). |
| + |
| +Update: write budget; nothing to change is 400 `update.empty`; a name runs `ValidAccountName`, then `domains.RenameAccountManifest` (bucket first), then `RenameAccount`, audit `audit.customer_rename`; a plan must be in `Grant.Plans` (`create.plan`), then `applyPlatformPlan` (`update.operator_plan` on refusal), audit `audit.customer_plan`. Empty reason becomes `fmt.Sprintf("platform %s", platform.Sqid)`. |
| + |
| +Delete: write budget; take `s.lockAccount(customer.Sqid)` for the rest; `LinkedCustomer.Owners > 0` is 409 `delete.claimed`; `AppCount > 0` is 409 `delete.apps`; then `tombstoneAccount` (bucket first, `ownership.go:672`), `s.manifestSeen.Delete`, `DeleteUnclaimedCustomer`, `auditAccountDeleted`. A bucket failure is 502 `delete.failed` and nothing is deleted. If `DeleteUnclaimedCustomer` refuses after the tombstone (an owner added box-side by `console member` in that window), log one line naming the account and answer 409 `delete.claimed`: the same accepted hazard `deleteAccountNow` documents (`ownership.go:196-201`), and the lock is what slice 2's claim must take to close it for claims. |
| + |
| +Platform account deletion: `deletionRefused` (`ownership.go:161`) adds, before the app count, a refusal when `LinkedCustomerCount(acct.Sqid) > 0` (flash `delete.platform_has_customers`), and a refusal for a linked account deleted by a person in the browser (flash `delete.linked`): until slice 2's leave, a linked account's end is its platform's door (decision D11). |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + |
| +```go |
| +func TestCustomerRenameRewritesTheManifest(t *testing.T) // row and manifest Name both "shop-2"; Platform kept |
| +func TestCustomerPlanChangeGoesThroughTheTransition(t *testing.T) // personal -> free with a lapse cap over: MarkLapse set, plan row source platform |
| +func TestCustomerPlanChangeStaysInsideTheGrant(t *testing.T) // plan dropped from the grant -> 400 create.plan |
| +func TestCustomerPlanChangeRefusesOperatorRows(t *testing.T) // operator SetAccountPlan source operator -> 409 update.operator_plan, row unchanged |
| +func TestCustomerDeleteTombstonesAnUnclaimedAccount(t *testing.T) // manifest Deleted(); AccountBySqid nil; LinkedCustomers empty |
| +func TestCustomerDeleteRefusesClaimedOrAppHolding(t *testing.T) // AddMember owner -> 409 delete.claimed; CreateAppIn -> 409 delete.apps; manifest untouched |
| +func TestPlatformAccountDeletionRefusedWithCustomers(t *testing.T) // browser POST delete on the platform account -> flash delete.platform_has_customers, manifest not tombstoned |
| +func TestLinkedAccountBrowserDeletionRefused(t *testing.T) // console member owner of a customer -> flash delete.linked |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestCustomerRename|TestCustomerPlanChange|TestCustomerDelete|TestPlatformAccountDeletionRefused|TestLinkedAccountBrowserDeletionRefused' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** the Step 2 command plus `-run 'TestDeleteAccount|TestHandleDeleteAccount|TestAccountPlan'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add internal/console/apiplatformcustomers*.go internal/console/routedecls.go internal/console/ownership.go internal/console/platformlinked*.go internal/console/platform_copy.go |
| +git commit -m "console: platforms rename, re-plan and delete unclaimed customers" |
| +``` |
| + |
| +--- |
| + |
| +### Task 10: Per-customer credentials |
| + |
| +**Files:** |
| +- Create: `internal/console/platform_credentials.go`, `internal/console/apiplatformcredentials.go` |
| +- Modify: `internal/console/authstore.go`, `internal/console/svcprincipal.go`, `internal/console/apicli.go`, `internal/console/routedecls.go` |
| +- Test: `internal/console/platform_credentials_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: Tasks 4, 7, 8. |
| +- Produces: |
| + - `const cliKindPlatform = "platform"` in the `authstore.go:390` block, with a comment: bound to one customer account, minted only by the platform door, expiring, live only while its link and grant are. |
| + - `Principal` gains `PlatformAccountID int64` and `Platform string` (the platform's sqid); both zero for every other kind. |
| + - ```go |
| + const ( |
| + PlatformCredentialDefaultTTL = time.Hour |
| + PlatformCredentialMaxTTL = 24 * time.Hour |
| + PlatformCredentialMinTTL = time.Minute |
| + ) |
| + var ( |
| + ErrPlatformCredentialRole = errors.New("console: a customer credential is publish, or deploy on one app") |
| + ErrPlatformCredentialTTL = errors.New("console: a customer credential lives 1 minute to 24 hours") |
| + ) |
| + type PlatformCredentialRequest struct { |
| + CustomerID, PlatformAccountID int64 |
| + Name string // the minter's handle: the platform credential's name, or the person's address |
| + MintedBy string // auditActor of the minter |
| + Role svcrole.Role |
| + App string |
| + Rungs []string |
| + TTL time.Duration // 0 means PlatformCredentialDefaultTTL |
| + } |
| + func (s *Store) NewPlatformCustomerCredential(ctx context.Context, req PlatformCredentialRequest, now time.Time) (raw string, expiresAt time.Time, err error) |
| + func (s *Store) platformLinkLive(ctx context.Context, customerID, platformAccountID int64) (platformSqid string, ok bool) |
| + ``` |
| + - Door: `POST /api/cli/platform/{account}/customers/{customer}/credentials`, `Exactly(Platform)`, handler `handlePlatformCredentialMint`, body `{role, app, rungs, ttl_seconds}`, reply 201 `{"token", "account", "role", "app", "rungs", "expires_at"}`. |
| + |
| +Rules: |
| +- Mint: role Publish needs app "" and no rungs; role Deploy needs an app the customer holds (`HasAppIn`, else stdlib 404) and rungs through `canonicalRungs` (stable refused as today); anything else is `ErrPlatformCredentialRole`. TTL outside [1 min, 24 h] is `ErrPlatformCredentialTTL`. Row: `kind 'platform'`, `account_id` customer, `platform_account_id`, `address = MintedBy`, `name = Name`, `role`, `app`, `rungs`, fresh `credential_id`, `expires_at = now + TTL`. |
| +- Resolve (`CLIPrincipalContext`, new `case cliKindPlatform`): `expires != 0 && now <= expires` (0 is refused, never "never"); role Publish with app "" and rungs "", or Deploy with app and readable rungs; commands and scope empty; `platformLinkLive` true. `platformLinkLive` is one query: the customer row live with `platform` equal to the platform row's sqid, the platform row live, and its grant `active`. Anything else is `Principal{}, false`, the unknown-token 401. |
| +- `auditActor` (`apicli.go:118`): `p.Platform != ""` renders `"platform:" + p.Platform + "/" + p.Name`. |
| +- `principalKey` is unchanged: `service:<customer id>/<name>`, so each customer has its own budgets. |
| +- Door: platform gate, `platformCustomer`, write budget, then the mint, then audit on the customer (`audit.credential`). |
| +- `CLITokensContext` (`authstore.go:861`) excludes kind platform as it excludes link: these are the customer account's credentials, not the minter's terminals. `ServicePrincipals` stays `kind IN (service, app)`; `RevokeAccountToken` already reaches them by id (decision D10). |
| +- The door is a credential mint reached by a credential. It is the one deliberate exception to "a credential may never mint a credential" (`svcroutes_test.go:35-91`): what it mints is narrower than its minter in every dimension (one account, Publish at most, expiring, refused when the link or grant ends, and kind platform reaches no mint door). Say so in the declaration's comment. |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + |
| +```go |
| +func TestCustomerCredentialResolvesToTheCustomerOnly(t *testing.T) |
| + // CLIPrincipal: Kind PrincipalService, AccountID customer, Role Publish, Platform "bcd", PlatformAccountID P |
| +func TestCustomerCredentialRefusedOnASecondCustomer(t *testing.T) // GET /api/cli/apps/<customer2>/x/channels -> stdlib 404 |
| +func TestCustomerCredentialExpiryBoundary(t *testing.T) // default TTL 1h; at expires_at ok; +1s refused; ttl 25h -> 400 cred.ttl; 30s -> 400 |
| +func TestCustomerCredentialRefusedAfterRevokeAndLinkGone(t *testing.T) |
| + // RevokePlatformGrant -> 401; re-grant -> still 401 (row revoked); a fresh credential, then DeleteUnclaimedCustomer -> 401 |
| +func TestCustomerCredentialRefusedWhileGrantRevokedEvenUnrevokedRow(t *testing.T) |
| + // set grant state revoked by SQL without touching cli_tokens -> 401 (the per-request check, not only the row revoke) |
| +func TestCustomerCredentialAuditNamesThePlatform(t *testing.T) // create an app with it: audit actor "platform:bcd/cms" |
| +func TestCustomerCredentialNeverReachesPersonOrMintDoors(t *testing.T) |
| + // POST services/<customer>, instance-token, accounts/<customer>/plan, domains/purchases, platform/<customer>/customers -> refused |
| +func TestCustomerCredentialDeployNarrowedToOneApp(t *testing.T) // deploy on "site" rungs edge: promote other app -> 404 |
| +func TestUnknownTokenKindStillRefused(t *testing.T) // a row of kind "platform2" -> ok false |
| +func TestPersonalTokenListOmitsCustomerCredentials(t *testing.T) |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestCustomerCredential|TestUnknownTokenKindStillRefused|TestPersonalTokenListOmitsCustomerCredentials' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** the Step 2 command plus `-run 'TestCLIPrincipal|TestServicePrincipal|TestPlatformDoorsTakeOnlyThePlatformRole|TestNoRoleReachesAMintFleetOrPolicyDoor'`. Expected: PASS. |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add internal/console/platform_credentials*.go internal/console/apiplatformcredentials.go internal/console/authstore.go internal/console/svcprincipal.go internal/console/apicli.go internal/console/routedecls.go internal/console/platform_copy.go |
| +git commit -m "console: short-lived per-customer credentials minted by a platform" |
| +``` |
| + |
| +--- |
| + |
| +### Task 11: `carlos platform customers` and `carlos platform credentials mint` |
| + |
| +**Files:** |
| +- Create: `platform_cli.go`, `platform_cli_test.go` |
| +- Modify: `commands.go`, `platform_copy.go`, `parity/parity.tsv`, `docs/site/cli.md` |
| + |
| +**Interfaces:** |
| +- Consumes: the wire shapes of Tasks 8-10 (mirror them as root-package types, as `accounts_plan.go` mirrors the plan door). |
| +- Produces: `func platformCommand() *clireg.Node` (Audience `clireg.Customer`) with children `customers` → `create`, `list`, `show`, `update`, `delete`, and `credentials` → `mint`; each leaf `raw(name, cust, runPlatformX)` calling `runPlatformXWithSession(ctx, sess *apiSession, args []string, out io.Writer) error`. Session methods on `*apiSession` in `platform_cli.go`: `platformCustomers(ctx, platform, ref string)`, `platformCustomer`, `createPlatformCustomer`, `updatePlatformCustomer`, `deletePlatformCustomer`, `mintPlatformCredential`. |
| + |
| +Flags: every verb takes `--platform <sqid>` (required) and `--console`; `show`, `update`, `delete` and `credentials mint` take `--customer <sqid>` or `--ref <ref>` (exactly one; `--ref` resolves through `GET ...customers?ref=`); `create` takes `--name` (required), `--ref`, `--plan`; `update` takes `--name`, `--plan`, `--reason`; `mint` takes `--role` (publish|deploy, default publish), `--app`, `--rungs`, `--ttl` (Go duration, default 1h); `list`, `show`, `create`, `mint` take `--json` (prints the door's JSON reply, indented). Sessions come from `resolveMode`, so `CARLOS_SERVICE_TOKEN` with `CARLOS_CONSOLE` works with no login. Human output is the Task 1 mocks, built from the copy constants. |
| + |
| +- [ ] **Step 1: Write the failing tests** (an `httptest` console fake recording requests) |
| + |
| +```go |
| +func TestPlatformCustomersCreateSendsAndPrints(t *testing.T) // POST body {name:"shop", ref:"4812"}; prints cliPlatformCopyCreated |
| +func TestPlatformCustomersCreateRefHitPrintsExisting(t *testing.T) |
| +func TestPlatformCustomersListTable(t *testing.T) // columns and the usage summary word per worst cap |
| +func TestPlatformCustomersListEmpty(t *testing.T) |
| +func TestPlatformCustomersRefLookup(t *testing.T) // show --ref 4812 -> GET ?ref=4812 then GET .../customers/bdf; unknown ref -> cliPlatformCopyNoRef |
| +func TestPlatformCustomerFlagsNeedExactlyOneHandle(t *testing.T) |
| +func TestPlatformCredentialsMintJSON(t *testing.T) // --json output parses; token field equals the fake's |
| +func TestPlatformCredentialsMintSendsTTL(t *testing.T) // --ttl 2h -> ttl_seconds 7200 |
| +func TestPlatformCommandsNeedAConsole(t *testing.T) // CARLOS_DEPLOYMENT_DIR set -> cliPlatformCopyNeedsConsole |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test . -run 'TestPlatformCustomers|TestPlatformCustomerFlags|TestPlatformCredentialsMint|TestPlatformCommandsNeedAConsole' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement**; register `platformCommand()` after `servicesCommand()` in `commands.go:155`. Parity rows: `platform-customers-list platform gap platform customers list ; platform customers show wp-platform-customers ` plus a `packages.tsv` row `wp-platform-customers The platform account's Customers section (platform accounts slice 3) `; `platform-customers-manage platform cli-only platform customers create ; platform customers update ; platform customers delete ; platform credentials mint A platform's own servers act through the API and CLI; v1 has no pages that act in a customer account.` Adjust to `internal/parity`'s rules if it refuses a column. Docs: `### carlos platform customers` and `### carlos platform credentials`. Run `make parity-doc`. |
| +- [ ] **Step 4: Run** `go test . -run 'TestPlatform|TestCLIProjection|TestCLIGolden' -count=1` and `go test ./internal/parity/ ./internal/docsite/ -count=1`. Expected: PASS. If `TestCLIGolden` asks for a record, follow its header (`clireg_golden_test.go:30`). |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add platform_cli*.go platform_copy.go commands.go parity docs/parity.md docs/site/cli.md |
| +git commit -m "carlos platform: customers and per-customer credentials" |
| +``` |
| + |
| +--- |
| + |
| +### Task 12: A static site's first host from a service credential (§6.3) |
| + |
| +**Decision (D3), the smaller fix and why.** The spec offers two fixes. The `domains kind:"static"` route cannot do it: on a console with `CONSOLE_RESERVE_PLATFORM_DOMAINS=true` (the flagship and Tito) every host under the apps domain, including the app's own `<app>.<sqid>.<apps-domain>`, is reserved (`domainHostPolicy`, `domainpolicy.go:73`; `reservedDomainsWith`, `apidomains.go:163`). And `carlos deploy` with a Publish credential stops earlier than the spec says: `GET .../instances` admits Instance and Deploy only (`routedecls.go:613`), so `deploy.go:397` exits on the 403 before the first-host step. Opening `PUT instances-manifest` to Publish is the other spec option, but `policyDoors` (`svcroutes_test.go:89`) pins it shut to every role on purpose. The smaller fix that keeps that pin: add Publish to the instance list, and add one narrow Publish door that does exactly what `mintPlatformHost` does for a person, with no caller-chosen manifest field: write the default manifest only when there is none, then create the static record at `<app>.<manifest domain>`. Any CI Publish credential benefits, not only platforms. |
| + |
| +**Files:** |
| +- Create: `internal/console/apiplatformhost.go`, `internal/console/apiplatformhost_test.go`, `deploy_platformhost.go` |
| +- Modify: `internal/console/routedecls.go`, `deploy.go` (`mintPlatformHost :1086`), `deploy_test.go` |
| + |
| +**Interfaces:** |
| +- Produces: |
| + - `GET /api/cli/apps/{account}/{app}/instances` Allow becomes `svcrole.Allow(svcrole.Instance, svcrole.Deploy, svcrole.Publish)`. |
| + - `POST /api/cli/apps/{account}/{app}/platform-host`, `Kind: kindCLI, Allow: svcrole.Allow(svcrole.Publish)`, handler `handleAPIPlatformHost`, body `{channel, message}`, reply exactly the instance-create door's reply. |
| + - CLI: `func (s *apiSession) platformHost(ctx context.Context, a apiAcct, app, channel, message string) (apiInstanceRecord, error)` in `deploy_platformhost.go`. |
| + |
| +Handler: `apiAccountApp` → `instancesDomain(acct)` (`apiinstances.go:3783`) → `readEnableManifest` (`:3814`); when it reports `created`, `writeEnableManifest` (`:3841`) with the manifest exactly as read (the enable door's defaults for nil fields, `handleAPIInstanceEnable :3637`), audit detail `audit.platform_host_enable`; an existing manifest is left alone → then delegate to `s.handleAPIInstanceCreate(w, r2)` where `r2` is `r.Clone(r.Context())` with the body replaced by `{"host": app + "." + m.Domain, "kind": "static", "channel": channel, "message": message}`. Delegating keeps every create rule (control-plane refusal, lifetimes, host suffix check, caps) in one place, and the caller chooses nothing but channel and message. |
| + |
| +CLI: in `mintPlatformHost` (`deploy.go:1086`), when `instancesEnable` fails with `*enableError` status 403, call `sess.platformHost` instead and print the same `minted` line. A 404 from `platform-host` (an older console) returns the original 403 error unchanged. |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + |
| +```go |
| +// internal/console |
| +func TestPublishCredentialListsInstances(t *testing.T) // serviceToken(Publish) GET instances -> 200 |
| +func TestPlatformHostDoorMintsTheAppsStaticHost(t *testing.T) // fresh app: manifest Domain "<sqid>.<apps-domain>"; record Kind static at app.<domain>, Channel as sent |
| +func TestPlatformHostDoorLeavesAnExistingManifestAlone(t *testing.T) // pre-written manifest with a Channel: bytes unchanged after the call |
| +func TestPlatformHostDoorRoles(t *testing.T) // Publish and Admin pass; Deploy, Instance, Operate -> role refusal |
| +func TestPlatformHostDoorRefusesAControlPlaneApp(t *testing.T) // the instance-create refusal, nothing written |
| +// root |
| +func TestMintPlatformHostFallsBackForAServiceCredential(t *testing.T) // fake: PUT instances-manifest 403, POST platform-host 200 -> record returned, "minted" line printed |
| +func TestMintPlatformHostOnAnOlderConsole(t *testing.T) // platform-host 404 -> the 403 error is returned |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestPublishCredentialListsInstances|TestPlatformHostDoor' -count=1` and `go test . -run 'TestMintPlatformHost' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** Update any role pin the instance-list change trips (search `svcroutes_test.go` and `deploydoors_test.go` for the list pattern) with a comment: Publish reads the records of an app it already deploys and manages hostnames for. |
| +- [ ] **Step 4: Run** the Step 2 commands plus `go test ./internal/console/ -run 'TestEveryCLIDoorNamesItsRoles|TestInstanceRoleMatchesTodaysAppTokenReach|TestDeployReachesExactlyItsDoors|TestNoRoleReachesAMintFleetOrPolicyDoor' -count=1`. Expected: PASS. |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add internal/console/apiplatformhost*.go internal/console/routedecls.go internal/console/*_test.go deploy.go deploy_platformhost.go deploy_test.go |
| +git commit -m "deploy: a Publish credential can give a static app its first host" |
| +``` |
| + |
| +--- |
| + |
| +### Task 13: Linked accounts in plans, billing and notices (§8) |
| + |
| +**Files:** |
| +- Modify: `internal/console/platformlinked.go`, `internal/console/plancaps.go`, `internal/console/billinghold.go`, `internal/console/planexempt.go`, `internal/console/billingpage_copy.go`, `internal/console/domainbuy.go`, `internal/console/plangracepass.go`, `internal/console/platform_copy.go`, `internal/console/plancaps_copy.go`, `accounts_plan.go` |
| +- Test: `internal/console/platformlinked_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: `Store.AccountPlatform`, `Server.linkedPlatform` (Tasks 4, 9). |
| +- Produces: |
| + - `var errBillingPlatform = billingRefusal{Key: "notice.platform_generic"}` beside `errBillingExempt`. |
| + - `func (s *Server) planNoticeRecipients(ctx context.Context, acct *Account) (owners []string, platform *Account, err error)`. |
| + - `func (s *Server) platformPlanNoticeEmail(cust, platform *Account, due []capState, stage func(capState) string) (subject, body string)`. |
| + |
| +Changes: |
| +- Free cap (`plancaps.go:175`): skip owned accounts whose `AccountPlatform` is non-empty. The function has no context; pass `context.Background()` with a one-line comment saying so. |
| +- `holdBilling` (`billinghold.go:81`): after the exempt check, a linked account returns `errBillingPlatform` with no lock. One choke point, as for the exempt account: no door, pass, webhook or seat charge can create a Stripe customer for it. `billingOwner` (`:94`) answers linked accounts with the flash `fmt.Sprintf(billingCopy["notice.platform"], platform.Name)` and the redirect the exempt case uses. |
| +- `admitDomainBuy` (`domainbuy.go:39`): first, a linked account is 409 with `domainBuyCopy["platform"]` formatted with the platform's name. That covers the CLI and browser purchase doors and the availability check. |
| +- `notifyPlanOwners` (`plangracepass.go:222`): recipients from `planNoticeRecipients`: a linked account's notices go to the platform account's owners only (claimed or not); body from `platformPlanNoticeEmail`, which reuses `planNoticeText(n, "email")` lines and the new `email.platform.*` rows (no settings or keep link: platform staff cannot open the customer account). Marks and `RecordCapNotice` are unchanged, so a delivered notice to the platform's owners counts for `afterGraceDue` (`plangrace.go:139`). |
| +- `printAccountPlan` (`accounts_plan.go:189-196`): source `platform` prints `cliPlanCopySourcePlatform` with the reason. |
| + |
| +- [ ] **Step 1: Write the failing tests** |
| + |
| +```go |
| +func TestLinkedAccountsDoNotCountTowardsTheFreeCap(t *testing.T) // person owns one free account and is a console-member owner of a linked free one: create allowed |
| +func TestBillingHoldRefusesLinkedAccounts(t *testing.T) // errors.Is(err, errBillingPlatform); no billing row written |
| +func TestBillingDoorsShowThePlatformNotice(t *testing.T) // owner POST /a/<cust>/billing/checkout -> redirect with flash "Your plan is managed by studio." |
| +func TestDomainBuyRefusedOnLinkedAccounts(t *testing.T) // admitDomainBuy -> 409 with the copy; no Stripe customer (fake billing records none) |
| +func TestPlanNoticesForLinkedAccountsGoToPlatformOwners(t *testing.T) |
| + // fake mail: customer storage over; deliveries only to the platform's owners; subject from email.platform.subject |
| +func TestPlatformOwnerNoticeCountsForAfterGraceDue(t *testing.T) |
| + // after delivery NoticeAt set; at GraceEnds + 72h afterGraceDue true; with no platform owners NoticeAt stays zero |
| +``` |
| + |
| +- [ ] **Step 2: Run** `go test ./internal/console/ -run 'TestLinkedAccountsDoNotCount|TestBillingHoldRefusesLinked|TestBillingDoorsShowThePlatformNotice|TestDomainBuyRefusedOnLinked|TestPlanNoticesForLinked|TestPlatformOwnerNoticeCounts' -count=1`. Expected: FAIL. |
| +- [ ] **Step 3: Implement.** |
| +- [ ] **Step 4: Run** the Step 2 command plus `-run 'TestCheckNewFreeAccount|TestBillingHold|TestPlanGrace|TestNotifyPlanOwners|TestDomainBuy|TestPlanExempt'` and `go test . -run 'TestAccountsPlan' -count=1`. Expected: PASS. |
| +- [ ] **Step 5: Commit** |
| + |
| +```bash |
| +git add internal/console/platformlinked*.go internal/console/plancaps.go internal/console/billinghold.go internal/console/planexempt.go internal/console/billingpage_copy.go internal/console/domainbuy.go internal/console/plangracepass.go internal/console/platform_copy.go accounts_plan.go |
| +git commit -m "console: linked accounts skip billing and send notices to the platform" |
| +``` |
| + |
| +--- |
| + |
| +### Task 14: The acceptance witness |
| + |
| +**Files:** |
| +- Create: `platform_e2e_test.go` |
| + |
| +**Interfaces:** |
| +- Consumes: everything above, through the CLI verbs and the real console. |
| + |
| +Production wiring: `console.Open` on a temp file, `console.NewServer` with a `release.NewDirStore`, signing keys from `release.GenerateKey`, `AppsDomain: "oncarlos.test"` and a plan catalog loaded from `internal/plans/testdata/example-catalog.json`; a real `edge.Edge` with `EnableStatic`. Built from `TestE2EStaticDeployMintsPlatformHost` (`deploy_e2e_test.go:471`): same helpers (`useTempCredentials`, `clearDeploymentEnv`, `e2eDeviceLogin`, `captureStdout`, `assertServes`, `watchOrigin`), and the same edge registry row standing in for the box's reconcile pass. Every console record the test reads is one the console wrote; the record is asserted with `provision.GetRecord` before serving is checked. |
| + |
| +- [ ] **Step 1: Write the test** |
| + |
| +```go |
| +func TestE2EPlatformCustomerStaticSite(t *testing.T) { |
| + // 1. ops@example.com is an operator (cst.SetOperator) and logs in (e2eDeviceLogin). |
| + // 2. owner@example.com owns account "platform" (minted through the console's CLI create door). |
| + // 3. runAccountsPlatformWithSession(--account <p> --grant --max-customers 5 --plans free,personal |
| + // --default-plan free --reason "witness") as the operator. |
| + // 4. As the owner: carlos services create --account <p> --name cms --role platform -> token P. |
| + // 5. t.Setenv CARLOS_SERVICE_TOKEN=P, CARLOS_CONSOLE=ts.URL: |
| + // carlos platform customers create --platform <p> --name shop --ref 4812 --json -> customer c1; |
| + // again with --name bakery --ref 4813 -> c2. |
| + // 6. carlos platform credentials mint --platform <p> --customer c1 --json -> token T (expires_at within 1h). |
| + // 7. CARLOS_SERVICE_TOKEN=T: runDeploy(-app site -account c1 -kind static -version sha0001 -channel <entry> site/) |
| + // -> stdout has "minted site.<c1>.oncarlos.test" and "live https://site.<c1>.oncarlos.test"; |
| + // provision.GetRecord(c1, site, host).Kind == "static"; assertServes(edge, "hello", "sha0001"). |
| + // 8. With T: GET /api/cli/apps/<c2>/site/channels -> 404; GET /api/cli/apps/<c1>/site/channels -> 200. |
| + // 9. As the operator: --revoke --reason "witness". With T: GET .../<c1>/site/channels -> 401. |
| + // With P: GET /api/cli/platform/<p>/customers -> 401. |
| + // 10. The site still serves (assertServes again): revoking stops credentials, not sites. |
| +} |
| +``` |
| + |
| +- [ ] **Step 2: Compile only (no e2e locally):** `go vet . && go test -count=1 -run '^$' .` Expected: no output from vet, `ok` from test. CI runs the test itself. |
| +- [ ] **Step 3: Commit** |
| + |
| +```bash |
| +git add platform_e2e_test.go |
| +git commit -m "witness: a platform deploys a customer's static site end to end" |
| +``` |
| + |
| +--- |
| + |
| +### Task 15: Copy review, census, ratchet, parity; ready for branch review |
| + |
| +**Files:** |
| +- Modify: `internal/console/platform_copy.go`, `platform_copy.go`, `internal/console/billingpage_copy.go`, `internal/console/plancaps_copy.go`, `internal/console/domainbuy_copy.go`, `docs/site/cli.md` |
| +- Create: `approved_platform_accounts_copy_test.go`, the census overlay and card `make census-propose` writes |
| + |
| +- [ ] **Step 1: Copy review.** Run the `copy-review` skill over the copy table below, rendered in the layouts it ships in (the Task 1 mocks, the email body, the browser flashes). Apply the edits verbatim to the copy files and to this table. Expected: every row approved; no string in the diff that is not in the table (`git diff main -- '*.go' | grep '^+.*"' ` read by hand against the table). |
| +- [ ] **Step 2: Pin the approved copy.** `approved_platform_accounts_copy_test.go` in the shape of `approved_domains_buy_copy_test.go`: one row per table id, its file, and the approved text. Run `go test . -run TestApprovedPlatformAccountsCopy -count=1`. Expected: PASS. |
| +- [ ] **Step 3: Census.** `make census-card`, write CLAIMS for each changed unit in scope (`internal/domains/mint.go`, `internal/svcrole/svcrole.go`, root package files: new commands, the deploy fallback; no unit gains a root read), then `make census-propose NAME=platform-accounts-1 CLAIMS=<file>`. Expected: the proposal writes its overlay and card and reports the census clean. The reviewer's verdict is part of branch review. |
| +- [ ] **Step 4: Ratchet and generated files.** `make code-health` (expect PASS; then `make code-health-record` to lower the record for `(*Store).migrate`), `make parity-doc` (expect no diff after), `gofmt -l .` (expect empty). |
| +- [ ] **Step 5: Targeted run over everything this branch touched:** `go test ./internal/domains/ ./internal/svcrole/ -count=1`; `go test ./internal/console/ -run 'Platform|Customer|Linked|Materialize|ClosedDoor|EveryCLIDoor|NoRoleReaches|ServiceCreate|CLIPrincipal|DeleteAccount|BillingHold|PlanNotice|DomainBuy|FreeAccount|PublishCredential' -count=1`; `go test . -run 'Platform|AccountsPlatform|MintPlatformHost|ApprovedPlatform|CLIProjection' -count=1`; `go test ./internal/parity/ ./internal/docsite/ -count=1`. Expected: PASS. |
| +- [ ] **Step 6: Commit** |
| + |
| +```bash |
| +git add internal/console/*copy*.go platform_copy.go approved_platform_accounts_copy_test.go docs/site/cli.md .amadan/code-health.tsv |
| +git add <the overlay, chain line and card paths make census-propose printed> |
| +git commit -m "platform accounts: approved copy, census overlay, ratchet record" |
| +``` |
| + |
| +--- |
| + |
| +### Task 16: Dev witness (after merge, when dev rolls) |
| + |
| +Not part of the branch. Dev first, per the roll recipe; nothing on the flagship without Paul's go. |
| + |
| +- [ ] **Step 1:** As an operator on the dev console: `carlos accounts platform --account <a dev test account> --grant --max-customers 3 --plans free --default-plan free --reason "slice 1 witness"`. |
| +- [ ] **Step 2:** As its owner: `carlos services create --account <it> --name witness --role platform`. With that token only (`CARLOS_SERVICE_TOKEN`, `CARLOS_CONSOLE`): `carlos platform customers create --platform <it> --name shop --ref w1`, `carlos platform credentials mint ... --json`, then with the minted token `carlos deploy --account <shop> --app site --kind static <dir>`. Expected: `live https://site.<shop>.<dev apps domain>`. |
| +- [ ] **Step 3:** The minted token against a second customer's app: 404. `--revoke`: the token answers 401 and the site still serves. Record the commands and answers on the branch's discussion. |
| + |
| +--- |
| + |
| +## Copy table (pending copy review) |
| + |
| +Every row is pending copy review (Task 15). `%s`/`%d` are filled as named. CLI errors are lowercase with no closing full stop, as the existing `cli.*` copy is; browser and email copy is sentence case. Apostrophes are curly. Examples use neutral names only. |
| + |
| +**Console, JSON errors the CLI prints** (`internal/console/platform_copy.go`, map `platformCopy`) |
| + |
| +| id | text | |
| +|---|---| |
| +| grant.ops | the ops account can’t be a platform account | |
| +| grant.linked | a customer account can’t be a platform account | |
| +| grant.reason | --reason is required | |
| +| grant.max | --max-customers must be a whole number from 1 to 10000 | |
| +| grant.plans | --plans must name plans in this console’s catalog, and --default-plan must be one of them | |
| +| grant.no_catalog | this console has no plan catalog, so a grant can’t name plans | |
| +| grant.not_platform | this account isn’t a platform account | |
| +| grant.failed | could not save the grant. try again | |
| +| door.not_platform | this account isn’t a platform account. an operator can make it one with carlos accounts platform | |
| +| door.revoked | this account’s platform access is turned off. ask the operator who granted it | |
| +| door.not_owner | only an owner of this account can manage its customer accounts | |
| +| door.rate | too many requests. wait a minute and try again | |
| +| create.name | an account name appears in URLs and --account: 1-63 characters of a-z, 0-9 and hyphen, no leading or trailing hyphen | |
| +| create.ref | a customer reference is 1 to 64 letters, digits, dots, colons, hyphens or underscores | |
| +| create.plan | this platform can put customer accounts on these plans: %s | |
| +| create.no_catalog_plan | this console has no plan catalog, so leave out the plan | |
| +| create.cap | this platform has %d customer accounts, the most its grant allows. delete one, or ask the operator for more | |
| +| create.rate | too many customer accounts were created today. try again tomorrow, or ask the operator | |
| +| create.failed | could not create the customer account. try again | |
| +| update.empty | nothing to change. pass a new name, a new plan, or both | |
| +| update.operator_plan | an operator set this account’s plan. ask them to change it | |
| +| update.failed | could not change the customer account. try again | |
| +| delete.claimed | someone owns this customer account now, so it can’t be deleted from here | |
| +| delete.apps | this customer account still has %d apps. delete them first | |
| +| delete.failed | could not delete the customer account, and nothing was deleted. try again | |
| +| cred.role | a customer credential is publish for the whole account, or deploy for one app with its rungs | |
| +| cred.ttl | a customer credential lasts from 1 minute to 24 hours | |
| +| cred.failed | could not mint the credential. try again | |
| +| svc.platform_app | a platform credential works for the whole platform account, so it takes no --app | |
| +| svc.not_platform | only a platform account can hold a platform credential. an operator grants that with carlos accounts platform | |
| + |
| +**Console, browser and shared** (file named per row) |
| + |
| +| id | file | text | |
| +|---|---|---| |
| +| billing notice.platform | billingpage_copy.go | Your plan is managed by %s. | |
| +| billing notice.platform_generic | billingpage_copy.go | This account’s plan is managed by the platform account that runs it. | |
| +| domainbuy platform | domainbuy_copy.go | buying a domain isn’t available on an account run by %s. attach a domain registered elsewhere instead | |
| +| delete.platform_has_customers | platform_copy.go | This account runs %d customer accounts. Delete them first. | |
| +| delete.linked | platform_copy.go | This account is run by %s. Ask them to delete it. | |
| + |
| +**Email to a platform's owners** (`plancaps_copy.go`, `planNoticeCopy`; the per-cap lines reuse the approved `email.warn`, `email.over`, `email.lapse_grace`, `email.lapse_off`) |
| + |
| +| id | text | |
| +|---|---| |
| +| email.platform.subject | [carlos] Customer account %s (%s): plan usage | |
| +| email.platform.intro | Customer account %s (%s), run by %s, is near or over its plan limits: | |
| +| email.platform.lapse_off_list | Turned off: %s. | |
| +| email.platform.ways_out | To stay within the plan, move the account to a bigger plan or clean it up.\n\nSee its usage:\n carlos platform customers show --platform %s --customer %s\n\nChange its plan:\n carlos platform customers update --platform %s --customer %s --plan <plan> | |
| + |
| +**Audit details** (shown in account history; `platform_copy.go`) |
| + |
| +| id | text | |
| +|---|---| |
| +| audit.grant | made this a platform account: up to %d customer accounts, plans %s, new ones on %s. reason: %s | |
| +| audit.revoke | turned off platform access, %d credentials stopped working. reason: %s | |
| +| audit.customer_create | created customer account %s (%s) | |
| +| audit.customer_created_by | created by platform account %s | |
| +| audit.customer_rename | renamed customer account %s to %s | |
| +| audit.customer_plan | moved customer account %s to the %s plan | |
| +| audit.credential | minted a %s credential for %s, valid until %s | |
| +| audit.platform_host_enable | turned on instances for %s to give it its first address | |
| + |
| +**CLI** (`platform_copy.go`, constants `cliPlatformCopy*`) |
| + |
| +| id | text | |
| +|---|---| |
| +| NeedsConsole | carlos %s works through a console, and this shell is in direct bucket mode\n(CARLOS_DEPLOYMENT_BUCKET/CARLOS_DEPLOYMENT_DIR is set).\nunset the store env, then run carlos auth login --console <url> or set CARLOS_SERVICE_TOKEN | |
| +| FlagAccount | platform account sqid to show or change | |
| +| FlagGrant | make the account a platform account, or change its grant | |
| +| FlagRevoke | turn the account’s platform access off | |
| +| FlagMaxCustomers | how many customer accounts it may have | |
| +| FlagPlans | plans its customer accounts may be on, comma-separated | |
| +| FlagDefaultPlan | the plan new customer accounts start on | |
| +| FlagReason | why. it is kept with the change | |
| +| FlagPlatform | your platform account’s sqid | |
| +| FlagCustomer | the customer account’s sqid | |
| +| FlagRef | your own id for the customer, instead of --customer | |
| +| FlagName | the customer account’s name | |
| +| FlagPlan | plan to put the account on | |
| +| FlagRole | publish (the whole account) or deploy (one app) | |
| +| FlagApp | the app a deploy credential is for | |
| +| FlagRungs | the rungs a deploy credential may move, comma-separated | |
| +| FlagTTL | how long the credential works, 1m to 24h | |
| +| FlagJSON | print JSON for scripts | |
| +| GrantAndRevoke | --grant and --revoke can’t be used together | |
| +| GrantFlagsAlone | --max-customers, --plans and --default-plan go with --grant | |
| +| OneHandle | pass --customer or --ref, not both | |
| +| NoHandle | pass --customer or --ref | |
| +| NoRef | no customer account has the reference %s | |
| +| IsPlatform | %s is a platform account | |
| +| NotPlatform | %s isn’t a platform account | |
| +| LabelStatus | status | |
| +| ValueOn | on | |
| +| ValueOff | off | |
| +| LabelCustomers | customers | |
| +| ValueCustomers | %d of %d | |
| +| LabelPlans | plans | |
| +| LabelDefault | new accounts start on | |
| +| LabelGrantedBy | granted by | |
| +| LabelTurnedOffBy | turned off by | |
| +| ValueByOn | %s on %s: %s | |
| +| Granted | %s is now a platform account | |
| +| Revoked | turned off platform access for %s. %d credentials stopped working | |
| +| ListHeading | %d customer accounts, %d allowed | |
| +| ListEmpty | no customer accounts yet. create one with carlos platform customers create | |
| +| ColAccount / ColName / ColRef / ColPlan / ColOwned / ColUsage | ACCOUNT / NAME / REF / PLAN / OWNED / USAGE | |
| +| Yes / No | yes / no | |
| +| UsageOK | ok | |
| +| UsageNear | near %s | |
| +| UsageOver | over %s | |
| +| ShowHeading | %s (%s) | |
| +| LabelRef / LabelPlan / LabelOwned / LabelCreated | ref / plan / owned / created | |
| +| UsageHeading | usage | |
| +| UsageRow | %s of %s | |
| +| UsageNearLimit | near the limit | |
| +| UsageOverLimit | over the limit, grace until %s | |
| +| CapPDF | PDFs a month | |
| +| Created | created %s (%s) on the %s plan | |
| +| Exists | %s (%s) already exists for reference %s | |
| +| Renamed | %s (%s) is now called %s | |
| +| Replanned | %s (%s) is now on the %s plan | |
| +| Deleted | deleted %s (%s) | |
| +| Minted | minted a %s credential for %s (%s), valid until %s | |
| +| MintedToken | token | |
| +| MintedUse | use it as CARLOS_SERVICE_TOKEN with --account %s | |
| +| accounts plan: cliPlanCopySourcePlatform | set by its platform account: %s | |
| + |
| +Cap names in usage reuse the approved `cliPlanCopyLimit*` labels (apps and instances, object storage, emails a day, bandwidth a month, awake hours a month); `CapPDF` is the one new label. |
| + |
| +**Docs** (`docs/site/cli.md`) |
| + |
| +| id | text | |
| +|---|---| |
| +| docs.accounts_platform | `### carlos accounts platform`, then: Shows an account’s platform grant, or changes it. A platform account can create customer accounts and deploy into them for its own customers. It is a deployment-operator command. Then the three examples: show, `--grant --max-customers 50 --plans free,personal --default-plan free --reason "agreed by email"`, `--revoke --reason "..."`. Then: "Turning platform access off stops the platform’s credentials at once. Its customers’ sites keep serving." | |
| +| docs.platform_customers | `### carlos platform customers`, then: Creates and manages the customer accounts a platform account runs. Each customer account is a full account of its own, with nobody signed in to it. Examples with `--platform bcd`: create `--name shop --ref 4812`, list, show `--ref 4812`, update `--customer bdf --plan personal`, delete `--customer bdf`. Then: "`--ref` is your own id for the customer. Creating again with the same ref returns the same account. An account someone owns, or one that still has apps, can’t be deleted here." | |
| +| docs.platform_credentials | `### carlos platform credentials`, then: Mints a short-lived credential for one customer account, for deploying into it. Example: `carlos platform credentials mint --platform bcd --customer bdf --json`. Then: "It lasts an hour unless you pass `--ttl`, up to 24 hours. It works only in that one account, and stops working when the platform’s access is turned off. Use it as `CARLOS_SERVICE_TOKEN`." | |
| + |
| +(The docs rows describe the prose; the heading lines are fixed by `internal/docsite`. Write the paragraphs from these sentences without adding claims, and put them through the same copy review.) |
| + |
| +--- |
| + |
| +## Decisions this plan makes that the spec does not pin |
| + |
| +- D1. Platform doors use `/api/cli/platform/{account}/...`, not `{platform}`, so `apiPrincipalAccount`'s binding and membership resolution apply unchanged. |
| +- D2. The grant lives in its own `platform_grants` table; the link is `accounts.platform` (the platform's sqid) and `accounts.platform_ref`; per-customer rows carry `cli_tokens.platform_account_id`. |
| +- D3. §6.3: Publish on the instance list plus one narrow `platform-host` door, not the domains route (blocked on reserve consoles) and not opening `instances-manifest` (pinned by `policyDoors`). |
| +- D4. The manifest also carries `platform_ref`, so ref idempotency survives a console rebuild. |
| +- D5. Ref grammar: 1-64 of `A-Z a-z 0-9 . _ : -`, case-sensitive, unique per platform among live accounts. |
| +- D6. Revoking a grant also revokes the rows of every per-customer credential and every platform-role credential of that platform, so a re-grant restores no old credential. The per-request check stays as well. |
| +- D7. Budgets: customer create spends `allowCreate` (service 100 a day, person 10) except a ref hit, which spends nothing; update, delete and credential mint spend `allowWrite`. |
| +- D8. TTL bounds 1 minute to 24 hours; `max_customers` 1 to 10000. Without a plan catalog a grant has no plans and customers get no plan row. |
| +- D9. Linked accounts never take the launch sponsorship. |
| +- D10. Per-customer credentials are not listed in the customer's services list or the minter's tokens page in slice 1; an owner can still revoke one by id. |
| +- D11. A person cannot delete a linked account in the browser in slice 1; a platform cannot change a plan an operator set. |
| +- D12. Plan notices for a linked account are email to the platform's owners; reading usage through `customers show` records no notice. |
| +- D13. The `platform` role is not offered on the browser mint form. |
| + |
| +## Spec gaps and contradictions found |
| + |
| +- §3 and §6.3: `carlos deploy` with a Publish credential fails before the first-host step (`GET instances` excludes Publish), and the `domains kind:"static"` route cannot mint an app's platform host where `CONSOLE_RESERVE_PLATFORM_DOMAINS=true`. See D3. |
| +- §5.1/§5.2: the link survives a console rebuild, but the grant (and every account's plan row) is console-only, so a rebuilt console keeps links with no grant: the platform is refused until the operator grants again. Accepted for v1; noted for the operator runbook. Without D4, idempotent create would break on rebuild too. |
| +- §6.1/AGENTS.md: the per-customer credential door is a credential mint reached by a credential, against the standing "a credential may never mint a credential" cut. The spec's A2 intends it; the plan names it as the one exception and pins it narrower than its minter. |
| +- §5.1 is silent on whether re-granting restores the old credentials. D6 says it does not. |
| + |
| +## Slice 2/3 hand-offs |
| + |
| +Slice 2 (claim and leave) needs from slice 1: |
| +- `AccountPlatform`, `LinkedCustomer.Owners` (claimed = owners > 0), `DeleteUnclaimedCustomer`'s owner check, and `ErrCustomerClaimed`. Accepting a claim must hold `s.lockAccount(customer.Sqid)`, the lock the platform's delete door holds across its owner check and tombstone, or a claim can land between them. |
| +- Leave/release: clear `accounts.platform` and `platform_ref`, rewrite the manifest without `platform`/`platform_ref` keeping `owner` (a `domains` CAS helper beside `RenameAccountManifest`), revoke kind-platform rows for the account, set the plan row to the catalog default, and lift D11's browser deletion refusal and Task 13's billing refusal for the account (both read `AccountPlatform`, so clearing the column is enough). |
| +- Claim must write `owner` into the manifest and teach materialization to adopt a late owner for linked accounts only (spec §7.4); `materializeOwner`'s birth-only rule is untouched by slice 1. |
| +- How per-customer credentials appear to a claimed customer (D10): `ServicePrincipals` would add `cliKindPlatform`. |
| +- The platform doors gain `POST .../customers/{customer}/claim-links` through `platformGate` and `platformCustomer`. |
| + |
| +Slice 3 (visibility) needs: `LinkedCustomers`, the usage view (`platformUsageView` built from current-period cap rows), `PlatformGrant` for the operator view, and the `wp-platform-customers` parity package to close. |