Files
suaveplan/openspec/archive/2026-05-26-foundation-fix-gap-5-default-tenant/tasks.md
2026-05-27 23:29:53 +01:00

2.2 KiB

Tasks — foundation gap 5: configurable default tenant

1. Implementation

  • 1.1 Add defaultTenant?: TenantContext | null to RequestPipelineOptions (request-pipeline.types.ts).
  • 1.2 Add defaultTenant?: TenantContext | null to HostConfig (host/host.types.ts).
  • 1.3 Wire config.defaultTenant ?? null through host.ts → RequestPipeline constructor.
  • 1.4 Replace hard-coded {id: "public", slug: "public"} injection in request-pipeline.ts with config-aware logic.
  • 1.5 Widen PipelineCapabilityResolver.forRequest's tenant parameter to TenantContext | null.
  • 1.6 Update downstream pipeline call sites (rateKey, logger meta, buildRequestContext, succeed()/fail() signatures) to tolerate tenantCtx === null.

2. Tests

  • 2.1 Replace the legacy "public stub" test with a "null tenant by default" assertion.
  • 2.2 Add a test asserting an explicit defaultTenant is propagated verbatim to ctx.tenant / ctx.tenantId / PipelineResult.tenantId.
  • 2.3 Add a test asserting auth-required routes still 400 on a resolver miss regardless of defaultTenant.

3. Migration

  • 3.1 Migrate the foundation-stack E2E (e2e/foundation-stack/src/server.ts) to opt into the legacy fallback (defaultTenant: { id: "public", ... }) so the existing tenantId === "public" assertion remains green.

4. Docs

  • 4.1 Document the new behaviour in packages/api-stack/api/api-host/src/host/host.md.
  • 4.2 Document the per-step interaction in request-pipeline.types.ts (RequestPipelineOptions.defaultTenant).

5. Spec

  • 5.1 Author MODIFIED Requirements delta under specs/api-host/spec.md.
  • 5.2 Fold delta into openspec/specs/api-host/spec.md.
  • 5.3 Move change folder to openspec/archive/2026-05-26-foundation-fix-gap-5-default-tenant/.

6. Gate

  • 6.1 bunx turbo lint typecheck test build --filter=@suaveplan/api-host green.
  • 6.2 bunx turbo test:coverage --filter=@suaveplan/api-host — request-pipeline.ts reports 100% line + branch coverage; touched lines in host.ts are exercised by existing createHost(...) tests.