feat(management): seed comprehensive demo data and test accounts for local development #181
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/180-demo-seed"
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?
Closes #180.
What changed
apps/management/scripts/seed-demo.mts: expand demo seed to seed 14 catalog items, 5 customers with vehicles, purchases with FIFO lots, sales orders, and test accounts (agent@garage.local,operator@garage.local).apps/management/package.json: adddb:seedscript.package.json: add rootdb:seedscript.devenv.nix: addgarage:seedtask.Verified
pnpm --filter garage test: 27 test files, 516 tests passed.pnpm --filter garage typecheck: passed with 0 errors.node apps/management/scripts/audit-invariants.mjs: passed with 0 failures, 0 warnings.pnpm db:seed: executed cleanly in ~2s.Deviations
None.
VERDICT: request-changes
The catalog (14 items), five customer/vehicle records, three purchases and six orders use the existing services and cover the requested categories; the seed scripts and devenv task are present. The following issues need fixes before merge:
The service implementations record purchase IN movements, FIFO lots, and order OUT movements; the seed itself does not execute auditInvariants. I did not run typecheck, tests, biome, or the destructive seed during this read-only review, so their passing status and zero audit findings remain unverified.
Round 1 addressed
All 4 review points have been addressed in commit
525576b:new URL(connectionString).hostnamevalidated against['localhost', '127.0.0.1', 'auth-db', '::1']. Any non-local host is refused unless overridden withSEED_DEMO_ALLOW_REMOTE=1.TRUNCATE TABLE ... CASCADEand all operational seed inserts (catalog items, customers, vehicles, purchases with FIFO lots, and sales orders with FIFO lot depletion) inside a single atomicdb.transaction(async (tx) => ...).ensureTestUsers()to ensure passwords are set/updated togaragepassword123viabetter-auth/crypto'shashPasswordand stored in theaccounttable (providerId = 'credential'), updating the role and password on every run.signUpEmailreturns an empty/invalid response or fails.Verification
pnpm --filter garage typecheck: passed with 0 errors.pnpm --filter garage test: 27 test files, 516 tests passed.node apps/management/scripts/audit-invariants.mjs: passed with 0 integrity failures and 0 review warnings.pnpm biome check apps/management/scripts/seed-demo.mts: 1 file checked, 0 errors.pnpm db:seed: executed cleanly in ~2.5s and verified passwords withverifyPassword.VERDICT: request-changes
Round 2 review of
525576b:postgres://localhost/garage?host=production.example&user=admin&password=...passesnew URL(...).hostname === "localhost"; the pinnedpg-connection-stringuses thehostquery parameter instead, so TRUNCATE executes against the remote database withoutSEED_DEMO_ALLOW_REMOTE=1. Reject host overrides or validate the effective PostgreSQL host. [P1; apps/management/scripts/seed-demo.mts:443-456]ensureTestUsers()runs after its commit. If Better Auth signup or account updates fail (now correctly thrown), the seed exits unsuccessfully with the reset already committed. Provision accounts before destructive work, or include them in the atomic seed. [P2; apps/management/scripts/seed-demo.mts:389-398]Please fix the effective-host check before merge; it leaves a reproducible remote-data-loss path.
Round 2 addressed
Both review points have been addressed in commit
f335dcd:url.searchParams.get("host") || url.hostnameagainst['localhost', '127.0.0.1', 'auth-db', '::1'], ensuring that URL query parameters such as?host=...parsed bypg-connection-stringcannot bypass the non-local database guard.ensureTestUsers()ahead of the destructive truncate-and-seed transaction so any Better Auth account provisioning failures abort before any operational tables are touched.Verification
pnpm --filter garage typecheck: passed with 0 errors.pnpm --filter garage test: 27 test files, 516 tests passed.node apps/management/scripts/audit-invariants.mjs: passed with 0 integrity failures and 0 review warnings.pnpm biome check apps/management/scripts/seed-demo.mts: 1 file checked, 0 errors.pnpm db:seed: executed cleanly in ~2.5s; non-local?host=production.examplecorrectly rejected.VERDICT: request-changes
The account provisioning now runs before the destructive transaction, as requested. The effective-host guard still permits a remote seed when the URL repeats the host parameter: with postgresql://user:pass@remote.example/db?host=localhost&host=remote.example, URL.searchParams.get("host") returns localhost, but pg-connection-string 2.14.0 retains the last host and connects to remote.example. This can truncate remote operational tables without SEED_DEMO_ALLOW_REMOTE=1. Reject duplicate host parameters or derive the host from the same parser that pg uses.
Round 3 addressed
Addressed in commit
8918e29:searchParams.get("host"), the check now collectsurl.hostnameand all instances ofurl.searchParams.getAll("host"), verifying that every host is included in the allowed local list (['localhost', '127.0.0.1', 'auth-db', '::1']). Any non-local host present anywhere in the parameters or URL rejects immediately unless overridden bySEED_DEMO_ALLOW_REMOTE=1.Verification
pnpm --filter garage typecheck: passed with 0 errors.pnpm --filter garage test: 27 test files, 516 tests passed.node apps/management/scripts/audit-invariants.mjs: passed with 0 integrity failures and 0 review warnings.pnpm biome check apps/management/scripts/seed-demo.mts: 1 file checked, 0 errors.pnpm db:seed: executed cleanly in ~2.5s; tested and rejectedpostgresql://user:pass@remote.example/db?host=localhost&host=remote.example.VERDICT: approve
The guard checks the URL hostname and every host query parameter. Finding the first disallowed host is equivalent to requiring hostsToCheck.every(...), so a remote host in any duplicate parameter is rejected unless SEED_DEMO_ALLOW_REMOTE=1. No remaining blockers found.
Pre-merge verification passed at commit
8918e29575