diff --git a/.github/test-suite-registry.json b/.github/test-suite-registry.json index 6505f237b3..7321c63117 100644 --- a/.github/test-suite-registry.json +++ b/.github/test-suite-registry.json @@ -273,9 +273,10 @@ "pkgs/id/hosted-worker/test/usage.test.ts", "pkgs/id/hosted-worker/test/currency.test.ts", "pkgs/id/hosted-worker/test/front-door.test.ts", - "pkgs/id/hosted-worker/test/id-uri-vectors.test.ts" + "pkgs/id/hosted-worker/test/id-uri-vectors.test.ts", + "pkgs/id/hosted-worker/test/tenancy-schema.test.ts" ], - "invocation": "cd pkgs/id/hosted-worker && npm test (node --experimental-transform-types --test test/routing.test.ts test/blobs.test.ts test/canonical-cbor.test.ts test/usage.test.ts test/currency.test.ts test/front-door.test.ts test/id-uri-vectors.test.ts)", + "invocation": "cd pkgs/id/hosted-worker && npm test (node --experimental-transform-types --test test/routing.test.ts test/blobs.test.ts test/canonical-cbor.test.ts test/usage.test.ts test/currency.test.ts test/front-door.test.ts test/id-uri-vectors.test.ts test/tenancy-schema.test.ts)", "venue": { "workflow": ".github/workflows/id-hosted-worker-tests.yml", "job_step": "hosted-worker-tests / Run the hosted-worker routing suite", diff --git a/pkgs/id/hosted-worker/README.md b/pkgs/id/hosted-worker/README.md index 160db9770f..48ef57a9b9 100644 --- a/pkgs/id/hosted-worker/README.md +++ b/pkgs/id/hosted-worker/README.md @@ -24,6 +24,16 @@ First local-only vertical slice of the hosted data plane (slice 3 of creation and isolation; R2 blobs, metering and caps are later #3811 steps and are out of scope here). +## Tenancy control plane (component E, #9083) + +`tenancy/` holds the central tenancy DB schema — the control plane +above this data plane: account registry, binding pointers, +tenant/database registry, role grants, peer policy, publish records +and credential metadata, as numbered migrations. It holds no user +content, no keys and no token values (design §2.3, "never central"); +`test/tenancy-schema.test.ts` fails if a content/key/token column +ever appears. See `tenancy/README.md`. + ## Local reality check (verified 2026-11-03, wrangler dev / workerd) Local workerd does **not** implement jurisdiction restrictions: diff --git a/pkgs/id/hosted-worker/package.json b/pkgs/id/hosted-worker/package.json index f4b6c4287e..0b59b0f9ad 100644 --- a/pkgs/id/hosted-worker/package.json +++ b/pkgs/id/hosted-worker/package.json @@ -6,7 +6,7 @@ "scripts": { "dev": "wrangler dev", "typecheck": "tsc --noEmit", - "test": "node --experimental-transform-types --test test/routing.test.ts test/provisioning.test.ts test/blobs.test.ts test/canonical-cbor.test.ts test/usage.test.ts test/currency.test.ts test/front-door.test.ts test/id-uri-vectors.test.ts test/bridge-blake3.test.ts test/bridge-event.test.ts test/bridge-range.test.ts test/bridge-store.test.ts test/bridge-session.test.ts test/bridge-do.test.ts", + "test": "node --experimental-transform-types --test test/routing.test.ts test/provisioning.test.ts test/blobs.test.ts test/canonical-cbor.test.ts test/usage.test.ts test/currency.test.ts test/front-door.test.ts test/id-uri-vectors.test.ts test/bridge-blake3.test.ts test/bridge-event.test.ts test/bridge-range.test.ts test/bridge-store.test.ts test/bridge-session.test.ts test/bridge-do.test.ts test/tenancy-schema.test.ts", "smoke": "node smoke/smoke.mjs" }, "devDependencies": { diff --git a/pkgs/id/hosted-worker/tenancy/README.md b/pkgs/id/hosted-worker/tenancy/README.md new file mode 100644 index 0000000000..9c7faf4008 --- /dev/null +++ b/pkgs/id/hosted-worker/tenancy/README.md @@ -0,0 +1,49 @@ +# Tenancy control plane (component E) + +The central tenancy database: one Turso/SQLite database holding the +account registry, binding pointers, the tenant/database registry, +role grants, peer policy, publish records and credential metadata — +and nothing else. Design record: +`doc/2026-11-17T16-55-00Z_design_hosted-tenancy-architecture` +(component E of epic #9078, issue #9083). + +This directory is the schema home for that database. The tenant +**data** plane (per-user databases and the `UserDO` that serves them) +is `../src/`; this is the control plane above it, queried by tenancy +Workers and the `TenancyOpsDO` of later E slices. + +## The invariant (design §2.3, "never central") + +The tenancy DB holds **no user content, no keys, and no token +values**. Tokens are metadata only: the `credential` table records +scope, expiry and a `jti` revocation handle, never the token. The +public root key appears as `iroh_id` and nothing more. A tenancy-DB +dump must not yield content or database access. + +`../test/tenancy-schema.test.ts` enforces this: it applies the +migrations and fails if any content/key/token column appears, if the +schema drifts from the §2.1 baseline, or if a participant kind gets +special-cased. + +## Peer principle + +Hosted, Rust-binary and self-hosted nodes are the same participant +kinds. `tenant_db.participant_kind` +(`user_hosted | user_native | self_hosted_node | public`) is +configuration on the shared registry row; there are no hosted-only +tables and the sync/publish protocols never branch on "hosted". + +## Migrations + +Numbered, append-only SQL files in `migrations/`, applied in order. +`0001_tenancy_baseline.sql` is the §2.1 baseline (E1, #12796); later +E slices (E2 provisioning, E4 credentials, E5 publish) add migrations +here rather than editing landed ones. `meta.schema_version` records +the applied baseline, mirroring the `UserDO` bootstrap pattern in +`../src/user-do.ts`. + +Two deliberate statements of the design's rules over its sketch DDL +are documented in the baseline's header: the active-binding rule is +a partial unique index (not the sketch's table-level UNIQUE, which +would break the rebind chain), and the vocabularies the record names +as closed carry CHECK constraints. diff --git a/pkgs/id/hosted-worker/tenancy/migrations/0001_tenancy_baseline.sql b/pkgs/id/hosted-worker/tenancy/migrations/0001_tenancy_baseline.sql new file mode 100644 index 0000000000..670eacd208 --- /dev/null +++ b/pkgs/id/hosted-worker/tenancy/migrations/0001_tenancy_baseline.sql @@ -0,0 +1,156 @@ +-- 0001_tenancy_baseline.sql +-- +-- Central tenancy DB baseline (component E1 of #9083, issue #12796). +-- +-- Implements section 2.1 of the hosted-tenancy design record +-- (doc/2026-11-17T16-55-00Z_design_hosted-tenancy-architecture) as the +-- first migration of the central tenancy database: one Turso/SQLite +-- database holding the account registry, the binding pointers, the +-- tenant/database registry, role grants, peer policy, publish records +-- and credential metadata. +-- +-- THE INVARIANT (design section 2.3, "never central"): this schema +-- holds NO user content, NO keys and NO token values. Tokens are +-- metadata only (the `credential` table records a `jti` revocation +-- handle, never the token). A tenancy-DB dump must not yield content +-- or database access. test/tenancy-schema.test.ts fails if a +-- content/key/token column ever appears in this schema. +-- +-- Peer principle (design sections 0-1, 9): hosted, Rust-binary and +-- self-hosted nodes are the same participant kinds. `tenant_db` +-- carries one `participant_kind` vocabulary for all of them; there +-- are no hosted-only tables and nothing in this schema special-cases +-- a hosted tenant. +-- +-- Two places where this migration states the design's rule rather +-- than its sketch DDL verbatim (the record calls the DDL "a sketch +-- for the implementation issues, not a migration"): +-- +-- 1. `binding`: the sketch's UNIQUE (account_id, status) would cap +-- an account at one superseded binding ever, which breaks the +-- rebind chain the same sketch defines via `superseded_by`. The +-- sketch's stated rule is "at most one active row per account", +-- so that rule is enforced with a partial unique index over +-- active rows only. +-- 2. Closed vocabularies the record names as closed get CHECK +-- constraints: `tenant_db.participant_kind`, +-- `tenant_db.jurisdiction` ("closed vocabulary" in the sketch), +-- `peer_policy.class` (the #9106/B31 classes) and +-- `credential.scope` ("(closed)" in the sketch). +-- +-- `meta` mirrors the bootstrap pattern of the tenant data plane +-- (src/user-do.ts): a name/value table carrying `schema_version`. +-- (Its columns are name/value, not key/value, on purpose: the +-- never-central guard bans any column with "key" in its name, with +-- no exceptions to argue about.) +-- Later E slices add numbered migrations; this file never changes. + +CREATE TABLE meta ( + name TEXT PRIMARY KEY, + value TEXT NOT NULL +); + +INSERT INTO meta (name, value) VALUES ('schema_version', '1'); + +-- One row per identity that can own things. Aligned with #2258 s.1.1. +-- sub is the identity provider's stable subject; email is contact-only. +CREATE TABLE account ( + account_id TEXT PRIMARY KEY, -- opaque, immutable, service-minted + sub TEXT NOT NULL UNIQUE, -- #9077 provider subject; never an email + email_contact TEXT, -- notifications only; never a key + created_at TEXT NOT NULL, + state TEXT NOT NULL, -- active | suspended | closed + tier TEXT NOT NULL, -- #2046 parameter + meter_rollup TEXT, -- latest daily rollup (content-free) + CHECK (state IN ('active','suspended','closed')) +); + +-- The stable pointer from account to identity and to the tenant. #2258 s.1.2 +-- is the authority on the ceremony; this table stores the pointer + status, +-- not the ceremony transcript (that stays in the binding record store). +CREATE TABLE binding ( + binding_id TEXT PRIMARY KEY, -- 32 lowercase hex; names the DO and the tenant + account_id TEXT NOT NULL REFERENCES account(account_id), + iroh_id TEXT NOT NULL, -- current root key; public key only + status TEXT NOT NULL, -- active | rebind_pending | superseded + bound_at TEXT NOT NULL, + superseded_by TEXT REFERENCES binding(binding_id), + CHECK (status IN ('active','rebind_pending','superseded')) +); + +-- At most one active binding per account (design note 1 above). +CREATE UNIQUE INDEX binding_one_active_per_account + ON binding (account_id) WHERE status = 'active'; + +-- The registry. One row per data plane a tenant owns (private tenant DB, +-- later maybe a second DB); the public DB is a tenant too, see s.7. +-- participant_kind is the peer principle in one column: a hosted user, +-- a native (Rust-binary) user, a self-hosted node and the public plane +-- are the same kind of participant, differing only in backend. +CREATE TABLE tenant_db ( + tenant_id TEXT PRIMARY KEY, -- = binding_id for user tenants + participant_kind TEXT NOT NULL, -- user_hosted | user_native | self_hosted_node | public + turso_db_id TEXT, -- provider handle; NULL until provisioned + turso_db_url TEXT, -- https://.turso.io; public endpoint only + jurisdiction TEXT NOT NULL, -- us | eu | fedramp (closed vocabulary) + backend TEXT NOT NULL, -- turso | redb | k8s_tiered (capability, s.9) + state TEXT NOT NULL, -- see s.5.1 of the design (provisioning lifecycle) + schema_version INTEGER NOT NULL, + created_at TEXT NOT NULL, + deleted_at TEXT, + CHECK (participant_kind IN ('user_hosted','user_native','self_hosted_node','public')), + CHECK (jurisdiction IN ('us','eu','fedramp')), + CHECK (state IN ('requested','db_creating','db_ready','active', + 'suspended','export_only','deleting','deleted','failed')) +); + +-- Roles are #1253's vocabulary, not a new one. Scope is a tenant or '*'. +CREATE TABLE role_grant ( + binding_id TEXT NOT NULL REFERENCES binding(binding_id), + role TEXT NOT NULL, -- #1253 role name + scope TEXT NOT NULL, -- tenant_id or '*' + granted_at TEXT NOT NULL, + granted_by TEXT NOT NULL, + revoked_at TEXT, + PRIMARY KEY (binding_id, role, scope) +); + +-- Peer configuration in the #9106/B31 shape, not a parallel trust model (s.9). +CREATE TABLE peer_policy ( + peer_id TEXT NOT NULL, + tenant_id TEXT NOT NULL, -- whose tenancy this governs + class TEXT NOT NULL, -- fully_trusted | send_only | accept_signed_from | unknown + operations TEXT NOT NULL, -- JSON array: accept_data | send_data | ... + relay_granted INTEGER NOT NULL DEFAULT 0, + scope TEXT NOT NULL, + policy_version INTEGER NOT NULL, + valid_from TEXT, + expires_at TEXT, + PRIMARY KEY (peer_id, tenant_id, policy_version), + CHECK (class IN ('fully_trusted','send_only','accept_signed_from','unknown')) +); + +-- Publish records: what a tenant has offered to the public plane (s.7). +CREATE TABLE publish_record ( + publish_id TEXT PRIMARY KEY, + tenant_id TEXT NOT NULL, + content_hash TEXT NOT NULL, -- content address; the row is the only grant + signed_artifact TEXT NOT NULL, -- the signed bytes live in the public DB; this is the digest + envelope id + published_at TEXT NOT NULL, + retracted_at TEXT, + policy_version INTEGER NOT NULL +); + +-- Credential metadata only. Tokens are NEVER stored here (s.8). +CREATE TABLE credential ( + credential_id TEXT PRIMARY KEY, + tenant_id TEXT NOT NULL, + audience TEXT NOT NULL, -- turso_db_id + scope TEXT NOT NULL, -- read | readwrite | ddl (closed) + issued_at TEXT NOT NULL, + expires_at TEXT NOT NULL, + revoked_at TEXT, + issuer TEXT NOT NULL, -- which Worker/DO issued it + jti TEXT NOT NULL UNIQUE, -- revocation handle; not the token + CHECK (scope IN ('read','readwrite','ddl')) +); diff --git a/pkgs/id/hosted-worker/test/tenancy-schema.test.ts b/pkgs/id/hosted-worker/test/tenancy-schema.test.ts new file mode 100644 index 0000000000..f755f3d210 --- /dev/null +++ b/pkgs/id/hosted-worker/test/tenancy-schema.test.ts @@ -0,0 +1,313 @@ +// E1 of #9083 (issue #12796): the central tenancy DB schema baseline. +// +// Oracle: the hosted-tenancy design record +// (doc/2026-11-17T16-55-00Z_design_hosted-tenancy-architecture) +// section 2.1 (the schema this migration must implement) and +// section 2.3 (the "never central" list this suite guards). +// +// The suite applies every migration under ../tenancy/migrations to +// an in-memory SQLite database (the tenancy DB is a Turso/SQLite +// database) and pins three things: +// +// 1. the baseline shape, table for table, column for column; +// 2. the never-central invariant: no column may hold content, a +// key, or a token value -- tokens are metadata only (a `jti` +// revocation handle), keys appear only as the public `iroh_id`; +// 3. the peer principle: hosted, native (Rust-binary), self-hosted +// and public tenants are one `participant_kind` vocabulary in +// one table -- no hosted-only schema objects, no special-casing. +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { DatabaseSync } from "node:sqlite"; +import { readdirSync, readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +const here = dirname(fileURLToPath(import.meta.url)); +const migrationsDir = join(here, "..", "tenancy", "migrations"); + +function migrationSql(): string { + const files = readdirSync(migrationsDir) + .filter((f) => f.endsWith(".sql")) + .sort(); + assert.ok(files.length > 0, "tenancy/migrations must contain the baseline migration"); + return files.map((f) => readFileSync(join(migrationsDir, f), "utf8")).join("\n"); +} + +function freshTenancyDb(): DatabaseSync { + const db = new DatabaseSync(":memory:"); + db.exec("PRAGMA foreign_keys = ON"); + db.exec(migrationSql()); + return db; +} + +function tableNames(db: DatabaseSync): string[] { + const rows = db + .prepare( + "SELECT name FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name", + ) + .all() as { name: string }[]; + return rows.map((r) => r.name); +} + +function columnNames(db: DatabaseSync, table: string): string[] { + const rows = db.prepare(`PRAGMA table_info(${table})`).all() as { name: string }[]; + return rows.map((r) => r.name); +} + +function allColumns(db: DatabaseSync): [string, string][] { + return tableNames(db).flatMap((t) => columnNames(db, t).map((c) => [t, c] as [string, string])); +} + +// The section 2.1 baseline, column for column, in DDL order. +const EXPECTED_SCHEMA: Record = { + account: ["account_id", "sub", "email_contact", "created_at", "state", "tier", "meter_rollup"], + binding: ["binding_id", "account_id", "iroh_id", "status", "bound_at", "superseded_by"], + credential: [ + "credential_id", + "tenant_id", + "audience", + "scope", + "issued_at", + "expires_at", + "revoked_at", + "issuer", + "jti", + ], + meta: ["name", "value"], + peer_policy: [ + "peer_id", + "tenant_id", + "class", + "operations", + "relay_granted", + "scope", + "policy_version", + "valid_from", + "expires_at", + ], + publish_record: [ + "publish_id", + "tenant_id", + "content_hash", + "signed_artifact", + "published_at", + "retracted_at", + "policy_version", + ], + role_grant: ["binding_id", "role", "scope", "granted_at", "granted_by", "revoked_at"], + tenant_db: [ + "tenant_id", + "participant_kind", + "turso_db_id", + "turso_db_url", + "jurisdiction", + "backend", + "state", + "schema_version", + "created_at", + "deleted_at", + ], +}; + +// Section 2.3 as column-name rules. A column whose name says it holds +// a token value, a key, a secret, or content bytes must never appear +// in the central schema. `content_hash` is the one sanctioned +// exception: it is a content ADDRESS (the publish grant), not content. +const NEVER_CENTRAL_PATTERNS: RegExp[] = [ + /token/, + /key/, + /secret/, + /passw/, + /body/, + /bytes/, + /payload/, + /plaintext/, + /ciphertext/, + /content/, +]; +const NEVER_CENTRAL_ALLOWLIST = new Set(["content_hash"]); + +function neverCentralViolations(columns: [string, string][]): string[] { + const violations: string[] = []; + for (const [table, column] of columns) { + if (NEVER_CENTRAL_ALLOWLIST.has(column)) continue; + for (const pattern of NEVER_CENTRAL_PATTERNS) { + if (pattern.test(column)) { + violations.push(`${table}.${column} matches ${pattern} (design section 2.3: never central)`); + break; + } + } + } + return violations; +} + +test("migrations apply cleanly and create exactly the baseline tables", () => { + const db = freshTenancyDb(); + assert.deepEqual(tableNames(db), Object.keys(EXPECTED_SCHEMA).sort()); + const row = db.prepare("SELECT value FROM meta WHERE name = 'schema_version'").get() as { + value: string; + }; + assert.equal(row.value, "1"); +}); + +test("schema matches the section 2.1 baseline column for column", () => { + const db = freshTenancyDb(); + for (const [table, expected] of Object.entries(EXPECTED_SCHEMA)) { + assert.deepEqual(columnNames(db, table), expected, `table ${table}`); + } +}); + +test("never central: no content, key, or token column in the schema", () => { + const db = freshTenancyDb(); + assert.deepEqual(neverCentralViolations(allColumns(db)), []); +}); + +test("the never-central guard actually bites", () => { + // If the guard could not see a planted violation, the test above + // would be vacuous. Each of these is a section 2.3 breach. + const planted: [string, string][] = [ + ["credential", "token_value"], + ["account", "private_key"], + ["tenant_db", "note_body"], + ["publish_record", "blob_bytes"], + ["account", "api_secret"], + ]; + const violations = neverCentralViolations(planted); + assert.equal(violations.length, planted.length, violations.join("; ")); + // ...and the sanctioned reference columns stay legal. + assert.deepEqual( + neverCentralViolations([ + ["publish_record", "content_hash"], + ["binding", "iroh_id"], + ["credential", "jti"], + ]), + [], + ); +}); + +test("peer principle: one participant_kind vocabulary, no hosted-only objects", () => { + const db = freshTenancyDb(); + const row = db + .prepare("SELECT sql FROM sqlite_master WHERE type = 'table' AND name = 'tenant_db'") + .get() as { sql: string }; + for (const kind of ["user_hosted", "user_native", "self_hosted_node", "public"]) { + assert.ok(row.sql.includes(`'${kind}'`), `participant_kind must include ${kind}`); + } + // participant_kind lives in exactly one table: kinds are + // configuration on the shared registry row, not per-kind tables. + const withKind = tableNames(db).filter((t) => columnNames(db, t).includes("participant_kind")); + assert.deepEqual(withKind, ["tenant_db"]); + // No schema object is named for one participant kind. + const objects = db + .prepare("SELECT name FROM sqlite_master WHERE name NOT LIKE 'sqlite_%'") + .all() as { name: string }[]; + for (const { name } of objects) { + assert.ok(!/hosted/.test(name), `schema object ${name} special-cases hosted tenants`); + } +}); + +const ACCOUNT = "acct-1"; +const BINDING_A = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; +const BINDING_B = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; +const NOW = "2026-11-23T00:00:00Z"; + +function insertAccount(db: DatabaseSync) { + db.prepare( + "INSERT INTO account (account_id, sub, email_contact, created_at, state, tier) VALUES (?, ?, ?, ?, ?, ?)", + ).run(ACCOUNT, "provider-subject-1", null, NOW, "active", "standard"); +} + +function insertBinding(db: DatabaseSync, bindingId: string, status: string, supersededBy: string | null) { + db.prepare( + "INSERT INTO binding (binding_id, account_id, iroh_id, status, bound_at, superseded_by) VALUES (?, ?, ?, ?, ?, ?)", + ).run(bindingId, ACCOUNT, "iroh-public-key", status, NOW, supersededBy); +} + +test("binding rule: at most one active binding per account, rebind chain allowed", () => { + const db = freshTenancyDb(); + insertAccount(db); + insertBinding(db, BINDING_A, "active", null); + assert.throws(() => insertBinding(db, BINDING_B, "active", null), /UNIQUE/); + // The rebind flow the design's superseded_by chain exists for: the + // new binding starts rebind_pending, the old one is superseded by + // it, and only then may the new one go active. + insertBinding(db, BINDING_B, "rebind_pending", null); + db.prepare("UPDATE binding SET status = 'superseded', superseded_by = ? WHERE binding_id = ?").run( + BINDING_B, + BINDING_A, + ); + db.prepare("UPDATE binding SET status = 'active' WHERE binding_id = ?").run(BINDING_B); +}); + +test("closed vocabularies and foreign keys are enforced", () => { + const db = freshTenancyDb(); + assert.throws( + () => + db + .prepare( + "INSERT INTO account (account_id, sub, created_at, state, tier) VALUES ('x', 's', ?, 'bogus', 't')", + ) + .run(NOW), + /CHECK/, + ); + insertAccount(db); + assert.throws(() => insertBinding(db, BINDING_A, "bogus", null), /CHECK/); + assert.throws( + () => + db + .prepare("INSERT INTO binding (binding_id, account_id, iroh_id, status, bound_at) VALUES (?, 'nope', 'k', 'active', ?)") + .run(BINDING_A, NOW), + /FOREIGN KEY/, + ); + assert.throws( + () => + db + .prepare( + "INSERT INTO tenant_db (tenant_id, participant_kind, jurisdiction, backend, state, schema_version, created_at) VALUES (?, 'martian', 'us', 'turso', 'active', 1, ?)", + ) + .run(BINDING_A, NOW), + /CHECK/, + ); + assert.throws( + () => + db + .prepare( + "INSERT INTO tenant_db (tenant_id, participant_kind, jurisdiction, backend, state, schema_version, created_at) VALUES (?, 'user_hosted', 'apac', 'turso', 'active', 1, ?)", + ) + .run(BINDING_A, NOW), + /CHECK/, + ); + assert.throws( + () => + db + .prepare( + "INSERT INTO peer_policy (peer_id, tenant_id, class, operations, scope, policy_version) VALUES ('p', ?, 'buddy', '[]', 's', 1)", + ) + .run(BINDING_A), + /CHECK/, + ); + assert.throws( + () => + db + .prepare( + "INSERT INTO credential (credential_id, tenant_id, audience, scope, issued_at, expires_at, issuer, jti) VALUES ('c', ?, 'db', 'admin', ?, ?, 'w', 'j')", + ) + .run(BINDING_A, NOW, NOW), + /CHECK/, + ); +}); + +test("registry rows for every participant kind insert identically", () => { + const db = freshTenancyDb(); + insertAccount(db); + insertBinding(db, BINDING_A, "active", null); + const insertTenant = db.prepare( + "INSERT INTO tenant_db (tenant_id, participant_kind, jurisdiction, backend, state, schema_version, created_at) VALUES (?, ?, 'us', 'turso', 'active', 1, ?)", + ); + for (const [i, kind] of ["user_hosted", "user_native", "self_hosted_node", "public"].entries()) { + insertTenant.run(`${BINDING_A}-${i}`, kind, NOW); + } + const count = db.prepare("SELECT COUNT(*) AS n FROM tenant_db").get() as { n: number }; + assert.equal(count.n, 4); +});