Skip to content

docs(examples): TenantRegistry DB-driven example + concurrent-recheck CI tests - #1358

Merged
bokelley merged 3 commits into
mainfrom
claude/issue-1346-tenant-registry-db-example
May 2, 2026
Merged

bokelley merged 3 commits into
mainfrom
claude/issue-1346-tenant-registry-db-example

Conversation

@bokelley

@bokelley bokelley commented May 2, 2026

Copy link
Copy Markdown
Contributor

Refs #1346

Adds a worked example for createTenantRegistry covering the patterns multi-tenant SaaS adopters need but that the existing static example (decisioning-platform-multi-tenant.ts) doesn't cover: DB-driven startup, runtime register/unregister without restart, zero-gap JWKS recheck, and the update-pattern traffic gap. Also fixes a stale skill doc that showed a non-existent constructor API.

What changed

examples/decisioning-platform-multi-tenant-db.ts (new) — exports:

  • buildDbMultiTenantRegistry() — seeds from async DB loader; compatible with pg, Prisma, fetch, etc.
  • adminRegisterTenant() — add tenant without restart
  • adminRecheckTenant() — zero-traffic-gap JWKS recheck after key rotation
  • adminUpdateTenant() — unregister+re-register for platform-config changes (brief 503 gap documented; concurrent-write serialization requirement called out)
  • adminUnregisterTenant() — immediate removal; no drain period

test/examples/decisioning-platform-multi-tenant-db.test.js (new) — 6-assertion CI test:

  1. Strict typecheck gate (--strict --noUncheckedIndexedAccess --exactOptionalPropertyTypes)
  2. Startup: three tenants reach healthy via awaitFirstValidation
  3. Concurrent recheck: Promise.all([recheck×3]) asserts ≤3 validator calls (dedup invariant)
  4. Unregister: resolveByHost returns null immediately — no drain
  5. Re-register: resolves healthy again after re-register
  6. Update gap: null during the unregister→register window, healthy after

skills/build-decisioning-platform/advanced/MULTI-TENANT.md (fixed) — previous version showed a resolveTenant/buildPlatform callback constructor that doesn't exist in the real createTenantRegistry API. Any agent reading the skill would have generated non-compiling code on line 1. Updated to show correct register() call pattern, health state table, and link to the new worked example.

tsconfig.examples.json — new example added to include list.

.changeset/tenant-registry-db-example.md — patch changeset.

Partial scope note

The issue's acceptance criterion "callout on docs/migration-6.6-to-6.7.md" (tracked in #1344) is not shipped here — that doc doesn't exist yet. The example's adminUpdateTenant JSDoc carries a // Migrating from a hand-rolled tenant map? See docs/migration-6.6-to-6.7.md (#1344) placeholder. The final PR in the #1344 sequence should carry Closes #1346.

What was tested

  • npm run typecheck:examples — passes
  • NODE_ENV=test node --test test/examples/decisioning-platform-multi-tenant-db.test.js — 6/6 pass
  • npm run format:check — clean (ran prettier)
  • Pre-push hook (format + typecheck + build:lib) — passed

Pre-PR review

  • code-reviewer: approved — blocker (recheck assertion bound ≤2 → ≤3) fixed; concurrent-write hazard in adminUpdateTenant documented; minimalPlatform() stub aligned with buildPlatform stub
  • dx-expert: approved — stale skill doc fixed; as any cast comment moved adjacent to cast site; migration TODO placed on adminUpdateTenant JSDoc

Nit noted (not fixed): register() return type is Promise<TenantStatus> | void union — the as Promise<TenantStatus> cast in registerRow is a necessary workaround until the interface gains overloaded signatures for awaitFirstValidation: true. Tracked as a follow-up DX improvement.

Triage-managed PR. This bot does not currently iterate on
review comments or PR conversation threads (only on the source
issue). To unblock:

  • Push fixup commits directly: gh pr checkout <num> →
    fix → push.
  • Or re-trigger: comment /triage execute on the source
    issue.

See adcp#3121
for context.

Session: https://claude.ai/code/session_018eA64njEkERwFaBmtAyQUV


Generated by Claude Code

claude and others added 3 commits May 2, 2026 17:53
… CI tests (#1346)

Add worked example for `createTenantRegistry` covering the patterns that
multi-tenant SaaS adopters need: DB-seeded startup, runtime register/unregister,
zero-traffic-gap JWKS recheck, and config-update semantics (unregister+re-register).

Also fixes the stale `MULTI-TENANT.md` skill doc that showed a non-existent
`resolveTenant`/`buildPlatform` callback constructor — any agent reading
the skill would have generated code that fails to compile on line 1.

Refs #1346

https://claude.ai/code/session_018eA64njEkERwFaBmtAyQUV
CI typecheck-skill-examples failed: top-level await in CommonJS
module + missing identifiers. Wrap each example block in an
async function and inline the loadTenant call so referenced
identifiers stay within the existing baseline. Tighten baseline
to drop 5 errors that no longer reproduce after the previous
skill rewrite.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@bokelley
bokelley force-pushed the claude/issue-1346-tenant-registry-db-example branch from c5afaa1 to 220bcda Compare May 2, 2026 21:53
@bokelley
bokelley merged commit d292fe5 into main May 2, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants