fix(labd): wire v2.0 Phase 1 routes + smoke tests #15
Reference in New Issue
Block a user
Delete Branch "fix/v2-wire-and-smoke-test"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Completes the v2.0 Phase 1 PR test plan items 3-5 by:
createApp(they were dead code)What was wrong
The v2.0 Phase 1 commit (
04faa07) addedAuthService,RbacService,ResourceStore,AuditService, thebearer-authmiddleware, and thev2-auth/environments/resourcesroute files — butserver.ts:createApp()never registered any of them.POST /api/auth/login,GET /api/resources,GET /api/eventswould all 404 on a running labd.What this changes
server.ts— instantiates the four services at app creation, starts theAuditServicetimer, registers the v2 routes inside a Fastify scope withbearer-authaspreHandler. v1 routes are on the root scope so they're unaffected. Adds anonClosehook to flush pending audit events on shutdown.audit.ts— exposesflushPending()so tests don't have to wait the 5s flush interval. One-line wrapper around the existing privateflush().v2-smoke.test.ts— 11 cases organized into three describe blocks:auth_bootstrap; second login uses normal flow; wrong password 401 + audit failure; missing credentials 400./api/events?correlation=...; explicit parent/child chain preserved.Tests use a mock PrismaClient (in-memory Maps) following the project's existing test pattern. No CockroachDB needed.
Test plan
vitest --run src/labd— 63 pass (52 prior + 11 new)vitest --run(whole workspace) — 246/246pnpm --filter {@lab/shared,@lab/core,@lab/labd} build— cleanNow ticks the previously-unchecked items from PR #14:
POST /api/auth/loginwith no users seeds the admin/api/events