PR1: server test-infra split + Prisma migration safety net (E2/E1/E10)#3785
Conversation
…ract placeholder
E2: a single jsdom project forced setupTests.ts's window.matchMedia mock onto
Express/server tests, which blocks DB-free Node unit tests (the mock throws
without `window`). Split into two Vitest 4 projects — `web` (jsdom + setupTests)
and `server` (node, no DOM setup) — so server/**/*.{spec,test}.ts run in Node.
JWT.test.ts (8 tests) now runs under the server project; the full suite stays
green (79 passed | 7 todo | 1 skipped).
E1: add authenticateStockRequest.contract.test.ts — 7 it.todo capturing the PR2
PAT-middleware regression guards (U5 confused-deputy no-cookie-clear, U6
malformed-header 401-not-500, U7 cookie fallback, U8 lastUsedAt, E4 full
session-user hydrate, E14 single atomic query). It imports nothing from the
not-yet-existent middleware so collection stays green; the server project
collects it in Node (the file reads as the "1 skipped" until PR2 fills it in).
Refs #3783
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…start E10: `pnpm deploy` rsynced server_build (which already bundles the Prisma client via the relative `../generated/prisma` import — esbuild's --packages=external does not externalize relative paths) but never applied migrations, so a newly-added table would be missing on the host after a manual deploy. scripts/deploy now rsyncs prisma/ and runs `migrate status` -> `migrate deploy` on the host BEFORE the server restarts, aborting on drift/failure. This mirrors the safety net in .github/workflows/deploy.yml so the manual path matches the GitHub Actions path. Ordering: migrate runs before the new server_build lands, so a failed migration never precedes a PM2 restart. No remote `prisma generate` is needed — the client is bundled into server_build. Other changes (intentional, flagged for review): - add `set -euo pipefail` and quote rsync paths - wire the previously-dead usage() to the getopts `*)` case (unknown flags now error instead of silently doing a full deploy) - run migrations for -s and the default path; -f (frontend-only) skips them Verified on production (DB backed up, owner-authorized): `migrate status` and `migrate deploy` both exit 0 when the schema is already up to date, so the abort-on-nonzero logic does not false-trip on a clean deploy. Refs #3783 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR establishes foundational infrastructure for PAT (Personal Access Token) authentication work by enabling server tests with proper node environment isolation and enforcing safe Prisma migrations during deployment. The deploy script gains a remote migration preflight that validates pending schema changes before shipping artifacts, while Vitest's configuration shifts from single-environment to multi-project setup. ChangesPAT Auth Foundation — Test Infrastructure and Deploy Safety
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: dependency version conflict. Check your lock file or package.json. Comment |
Summary
Safety-net PR for the extension-login-flow feature (the scoped-PAT feature itself lands in #3784). Three independent, low-risk changes that make PR2 safe to build on:
E2 — Vitest web/server project split (
vitest.config.ts)A single jsdom project forced
setupTests.ts'swindow.matchMediamock onto every test, which throws in Node and blocks DB-free Express unit tests. Split into two Vitest 4 projects:web(jsdom + setupTests, for the SPA / lib / scripts) andserver(node, no DOM setup, forserver/**).JWT.test.ts(8 tests) now runs under the server project. This is the foundation PR2's PAT-middleware unit tests (U1–U8) build on.E1 — PAT middleware contract placeholder (
server/lib/authenticateStockRequest.contract.test.ts)7
it.todocapturing the regression guards the PR2authenticateStockRequestmiddleware must satisfy — U5 (invalid/revoked PAT must NOT clear the owner's auth cookies / confused-deputy), U6 (malformed header → 401 not 500), U7 (cookie fallback when noAuthorizationheader), U8 (lastUsedAtupdate), E4 (full session-user hydrate), E14 (single atomic revoked/expired query). It imports nothing from the not-yet-existent middleware so collection stays green; PR2 replaces each todo with a real DB-backed assertion.E10 — Prisma migrations in the manual deploy script (
scripts/deploy)pnpm deployshippedserver_buildbut never ran migrations, so a new table (PR2 addspersonal_access_tokens) would be missing on the host after a manual deploy. The script now rsyncsprisma/and runsmigrate status→migrate deployon the host before the server restarts, aborting on drift/failure — mirroring the existing.github/workflows/deploy.ymlsafety net. No remoteprisma generateis needed: esbuild bundles the Prisma client intoserver_build(the../generated/prismaimport is relative, so--packages=externaldoesn't externalize it).Test Coverage
Test-infra / deploy-script changes — no new application code paths. The new contract test is itself the coverage scaffold for PR2.
tsc --noEmitclean--max-warnings=0cleanit.todoplaceholders, so the file has no executable tests yet)Pre-Landing Review
Self-reviewed and reviewed by the advisor model (the E10 migrate-before-code ordering and the projects split). The E10 ordering was corrected to run
migrate deploybefore the code rsync, so a failed migration never precedes a PM2 restart. External review by CodeRabbit is expected on this PR.Intentional behavior changes in
scripts/deploy(flagged for the reviewer):set -euo pipefailand quotes rsync pathsusage()into the getopts*)case — unknown flags now error instead of silently doing a full deploy-sand the default path now migrate;-f(frontend-only) skips migrationsVerification
Production-verified the migrate mechanism (the owner took a DB backup and authorized prod verification): on the live host,
migrate status→ "Database schema is up to date!" (exit 0) andmigrate deploy→ "No pending migrations to apply." (exit 0). This confirms the abort-on-nonzero logic does not false-trip on a clean deploy. PR1 itself adds no migration, so applying it is a no-op — the real exercise is PR2'spersonal_access_tokenstable.Notes
This is a focused 3-file safety-net PR. The heavier gstack review passes (specialist army, Codex multi-pass) were skipped as redundant for an infra-only diff that already has advisor review, production verification, and an incoming CodeRabbit review. Rollback is trivial (revert; no schema or runtime behavior changes in PR1).
Closes #3783
🤖 Generated with Claude Code
Summary by CodeRabbit