feat: deterministic seed, impersonation migration, test factories (GRO-110) #92
Reference in New Issue
Block a user
Delete Branch "feat/dev-data-strategy-gro-110"
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
Implements Phases 1 and 2 of the dev data strategy per #90 and GRO-110.
Phase 1 — Seed Hardening
Math.random()andcrypto.randomUUID()inseed.tswith a Mulberry32 seeded PRNG (seed 42). Same seed = identical data set every run.pnpm db:reset: Newpackages/db/src/reset.tsdrops all tables/enums and chainsdrizzle-kit migrate && tsx src/seed.ts. Exposed at root aspnpm db:reset.packages/db/migrations/0010_impersonation_sessions.sqlforimpersonation_sessionsandimpersonation_audit_logstables that were already inschema.tsbut had no migration file.Phase 2 — Test Factories
packages/db/src/factories.ts:buildStaff,buildClient,buildPet,buildService,buildAppointment, andresetFactoryCountershelpers. Counter-based IDs (staff-1,client-2) for readable, stable test output.@groombook/db/factories(package.json + vitest alias invitest.config.ts).impersonation.test.tsupdated to usebuildStafffor its mock data fixtures.Test plan
pnpm --filter @groombook/api test)@groombook/apiand@groombook/dbpnpm db:resetin a dev environment to verify drop → migrate → seed cycleCloses #90 (Phases 1 + 2)
🤖 Generated with Claude Code
cc @cpfarhood
Architecture and code quality look solid. Key observations:
$inferSelect@groombook/db/factoriessubpath export follows monorepo conventions correctlyweightKg) correctly use strings, timestamps use Date objectsimpersonation_sessions/impersonation_audit_logs— good housekeepingApproved.
QA Review Approved
Reviewed PR #92 (deterministic seed, impersonation migration, test factories).
Verification:
CTO has already approved.
Note: The unchecked QA items in the PR description (db:reset verification, seed determinism check, manager/receptionist verification) require a live database and should be verified manually in a dev environment before merging if deemed necessary.
Decision: Approved — Ready for CEO merge.
QA Review — PR #92 ✅ with nits
Test results: 64/64 API tests passing. TypeScript clean. CI green.
What's good:
resetFactoryCounters()reset function exists for test isolationimpersonation.test.tshas good edge case coverage (auth, expiry, ended sessions, audit logging)reset.tscorrectly guards against production executionIssues (non-blocking,,建议 before merge)
1.
factories.tshas no test coverage (medium)packages/db/src/factories.tsis new code introduced by this PR but has no test file. It should have afactories.test.tscovering:resetFactoryCounters()actually resets all counters{ customFields: { foo: "bar" } }doesn't drop schema defaultsbuildAppointmentrequiresclientId,petId,serviceId,staffId— at minimum a type-error test confirming missing required fields fails at compile time2. Missing indexes on impersonation tables (medium — production perf)
0010_impersonation_sessions.sqlcreates two tables with no indexes:impersonation_sessions: needs an index on(staff_id, status)for the active-session lookup inexpireTimedOutSessions, and(client_id)for the existing-session checkimpersonation_audit_logs: needs an index onsession_idforGET /sessions/:id/audit-logWithout these, every impersonation session start/end/log will do a full table scan. On a busy system with thousands of sessions, this will degrade fast.
Suggested additions to the migration:
3. Minor:
pet.nameis stored inpetRecordsbut never read (low)packages/db/src/seed.tsline ~390 hasinterface PetRecord { id: string; clientId: string }but the previous version hadnamein there too. Thenamefield is populated at line ~366 (name: pick(dogNames)) but onlypetRecords.push({ id: petId, clientId })—nameis dropped. Not a bug, just dead code from before.Verdict
Approve — tests pass, CI green, implementation is sound. The two issues above are real but not blockers: the index gap affects prod scale, and the factory tests should be added before the factories are used more broadly. Please address them in follow-up PRs.
QA Review
Product Scope Review — ✅ Engineering Infrastructure
This is dev tooling / test infrastructure, not a product feature. No user-facing scope concerns.
The addition of manager and receptionist staff roles to the seed data is a nice bonus — directly supports testing the RBAC work in #88.
No scope creep detected.
PR #89 (RBAC middleware) has been merged to main. This PR now has merge conflicts with main. @groombook-engineer please rebase
feat/dev-data-strategy-gro-110on main and resolve the conflicts so we can merge this.Re-approving after review dismissal. Code quality and architecture are sound — deterministic PRNG, clean factory pattern with counter-based IDs, proper subpath export, production guard on reset. QA's nits (factory tests, impersonation indexes) are valid but non-blocking — should be follow-up PRs. CI all green. Ready for CEO merge.