Files
suaveplan/openspec/archive/2026-05-26-foundation-fix-gap-4-db-split/tasks.md
2026-05-27 23:29:53 +01:00

2.2 KiB

Tasks — foundation-fix-gap-4-db-split

  • Rename HostAdapters.db: LedgerDb → HostAdapters.ledgerDb: LedgerDb (host-private).
  • Add new optional HostAdapters.db?: AdminDatabaseLike (consumer-facing).
  • Update host config Zod schema to validate the new shape.
  • Update host constructor to pass config.adapters.ledgerDb into PluginLedger and config.adapters.db into the request-pipeline options.
  • Add optional db: AdminDatabaseLike to RequestPipelineOptions.
  • Apply createTenantScopedWrapper(admin, tenantCtx.id) per request in the pipeline driver when both options.db and tenantCtx are set; thread the result onto RequestContext.db. Surface null otherwise.
  • Add db: AdminDatabaseLike | null to PluginContext; add db: TenantScopedDatabaseLike | null to RequestContext, JobContext, ConnectionContext.
  • Update buildRequestContext signature + helpers to thread the scoped db onto the constructed context.
  • Add @suaveplan/api-db-adapter runtime dep to @suaveplan/api-host/package.json.
  • Atomically update every in-tree consumer: api-host tests (host.test.ts rename db → ledgerDb), E2E foundation-stack (server.ts).
  • Restore createDbAdapter({ engine: "sqlite", url: ":memory:" }) as adapters.db in the E2E server; keep bun:sqlite raw handle on adapters.ledgerDb. Register an inline bun:sqlite-backed engine factory.
  • Add /api/db-ping route in fixture-plugin.ts exercising ctx.db?.execute + ctx.db?.query through the tenant-scoped wrapper.
  • Add E2E test db adapter — ctx.db wired through tenant-scoped wrapper to tests/foundation.spec.ts.
  • Add api-host unit tests: (a) adapters.db threaded through to ctx.db with rewriter-applied SQL; (b) ctx.db === null when adapters.db undefined; (c) ctx.db === null when tenant resolver returns null.
  • Verify gate: bunx turbo lint typecheck test build --filter=@suaveplan/api-host --filter=@suaveplan/api-types --filter=@suaveplan/api-db-adapter.
  • Verify E2E: bun test:e2e 11/11 green.
  • Fold deltas into canonical openspec/specs/api-host/spec.md and openspec/specs/api-types/spec.md; move folder to openspec/archive/2026-05-26-foundation-fix-gap-4-db-split/.