Files
suaveplan/openspec/archive/2026-05-26-api-auth-better-auth/tasks.md
2026-05-27 23:29:53 +01:00

4.1 KiB

Tasks — @suaveplan/api-auth-better-auth

Every checkbox MUST reflect work actually done in this change.

0. Pre-flight (non-negotiable)

  • 0.1 Confirm clean working tree (git status reports nothing) and no in-flight worktrees with uncommitted work (git worktree list then git status in each)
  • 0.2 If any worktrees exist under .claude/worktrees/, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (git worktree remove) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
  • 0.3 Confirm the package set in MANIFEST.md matches find packages -maxdepth 3 -name package.json count. Drift here means a prior change archived without regenerating the manifest.

1. Spec authoring

  • 1.1 Read design doc §2.3 (auth contracts) end-to-end
  • 1.2 Read umbrella proposal (Stage 6)
  • 1.3 Read openspec/AGENTS.md Sections 13 and 14
  • 1.4 Draft proposal.md
  • 1.5 Draft specs/api-auth-better-auth/spec.md
  • 1.6 Every requirement has a **Verified by:** line

2. Implementation

  • 2.1 Scaffold packages/api/api-auth-better-auth/
  • 2.2 src/options/options.ts — BetterAuthOptions Zod schema
  • 2.3 src/db/database.ts — separate DB connection construction; lazy-init on first use
  • 2.4 src/principal/map-user-to-principal.ts — default mapping; pluggable
  • 2.5 src/session/create-session.ts — createBetterAuthSession(opts); implements auth.session
  • 2.6 src/provider/create-provider.ts — createBetterAuthProvider(opts); implements auth.provider; mounts routes at routePrefix
  • 2.7 src/route-prefix/route-prefix.ts — collision check vs host-reserved prefixes
  • 2.8 src/oauth/github.ts — GitHub OAuth provider wiring; canonical reference flow
  • 2.9 src/instruments/instruments.ts — OTel counters / histograms per proposal
  • 2.10 src/error-codes.ts — 10 AUTH_BA_* codes
  • 2.11 ./testing subpath — re-export both conformance suites bound to Postgres-backed factories
  • 2.12 src/index.ts — explicit named re-exports

3. Tests

  • 3.1 Unit tests per module, every it(...) { timeout: 5000 }
  • 3.2 runAuthSessionConformance + runAuthProviderConformance against Postgres container ({ timeout: 30000 })
  • 3.3 src/oauth/github-oauth.test.ts — end-to-end with a mock OAuth server ({ timeout: 60000 })
  • 3.4 src/independence/session-without-provider.test.ts — pins that the two sides are independently usable
  • 3.5 tests/integration/postgres-better-auth.test.ts ({ timeout: 60000 }) — register → login → protected route
  • 3.6 All tests import from @suaveplan/testing/runner

4. Documentation

  • 4.1 Sibling .md per implementation file
  • 4.2 README.md with ## Modules AND a top-level note that two capability surfaces ship and may be wired independently

5. Pre-archive verification (the 5-gate triple)

  • 5.1 bun run check — 0/0/0
  • 5.2 bunx turbo lint typecheck test --filter=@suaveplan/api-auth-better-auth — green
  • 5.3 bunx turbo test:coverage --filter=@suaveplan/api-auth-better-auth — 100/100/100/100
  • 5.4 bun scripts/openspec-conformance.ts @suaveplan/api-auth-better-auth — exit 0
  • 5.5 bunx turbo build --filter=@suaveplan/api-auth-better-auth — green

6. Pre-archive 7-row checklist

  • 6.1 Generics on Principal mapping; expectTypeOf assertions
  • 6.2 BetterAuthOptions Zod-validated at the factory boundary
  • 6.3 Every AUTH_BA_* code thrown from production paths
  • 6.4 Strict-mode tested (session-only wiring, provider-only wiring, both wired)
  • 6.5 OTel instruments asserted against in-memory MeterProvider
  • 6.6 Lifecycle dedup: session resolution is idempotent across retries
  • 6.7 No retroactive tick

7. Archive

  • 7.1 Fold spec delta into openspec/specs/api-auth-better-auth/spec.md
  • 7.2 Move to openspec/archive/<yyyy-mm-dd>-api-auth-better-auth/
  • 7.3 Tick Stage-6 row in umbrella tasks
  • 7.4 Refresh MANIFEST.md