Skip to content

Create isolated tests and mandatory CI verification#589

Merged
kelvinkipruto merged 4 commits into
mainfrom
claude/issue-578
Jul 21, 2026
Merged

Create isolated tests and mandatory CI verification#589
kelvinkipruto merged 4 commits into
mainfrom
claude/issue-578

Conversation

@kelvinkipruto

Copy link
Copy Markdown
Contributor

Closes #578

What changed

Isolated test environment

  • Tests now load a dedicated .env.test (committed, no secrets) instead of .env / .env.local, so a run can never inherit developer or production-like configuration. Wired into both vitest.setup.ts and playwright.config.ts.

Unique, ephemeral database, reset around the suite

  • Integration tests (vitest.globalSetup.ts) derive a unique per-run, test-named database from the local/CI MongoDB host and drop it before and after the suite. A single Vitest worker shares the dynamic connection string (injected via provide/inject before @/payload.config is imported).
  • E2E tests run the app (Playwright webServer) against the same isolated DATABASE_URI; tests/e2e/globalSetup.ts enforces the guard and resets the DB first.

Hard guard against shared/production databases

  • src/lib/testDatabaseGuard.ts rejects mongodb+srv://, hosted hosts (Atlas, DocumentDB, Cosmos, cloud providers), any non-local host, and production/shared-looking database names. Enforced in the Vitest and Playwright harnesses, and at app startup when PT_ASSERT_TEST_DB=true (the E2E dev server). payload.config.ts also now requires DATABASE_URI instead of silently falling back to "".

Mandatory CI verification

  • New reusable .github/workflows/verify.yml: frozen install (--frozen-lockfile), generated-artifact drift check (generate:all + git diff --exit-code over payload-types.ts and importMap.js), lint, type-check (new typecheck script), integration tests, and critical E2E smoke tests — all against a mongo:7 service container. Plus a dependency SCA scan (pnpm audit --audit-level high).
  • ci.yml runs verification on pull requests.
  • deploy-dev.yml: the deploy job now needs: verify (calls the reusable workflow), so deployment cannot run when verification fails.
  • .github/dependabot.yml for continuous dependency/SCA updates.

Notes

  • Added mongodb as a dev dependency for DB reset. (mongodb-memory-server was intentionally avoided — the local pnpm trust policy flagged a transitive supply-chain downgrade in its dependency tree; a service container + unique per-run database gives the same isolation guarantees more reliably in CI.)
  • CI pins Node 22.12.0 to match the Dockerfile and pnpm 10.33.0 from packageManager.

Verification

  • Full integration suite 234/234 passing against an isolated MongoDB; tsc --noEmit clean; no generated-artifact drift; guard unit tests cover Atlas/hosted/non-local/prod-name rejection and local acceptance; guard confirmed to reject a mongodb+srv Atlas URI end-to-end.

🤖 Generated with Claude Code

- Tests load a dedicated .env.test (never .env/.env.local) so runs
  cannot inherit developer or production configuration
- Integration tests derive a unique per-run database from the local/CI
  MongoDB (vitest.globalSetup.ts) and drop it around the suite; E2E runs
  the app against the same isolated DATABASE_URI
- Hard guard (src/lib/testDatabaseGuard.ts) rejects mongodb+srv, hosted
  hosts (Atlas/DocumentDB/etc.), non-local hosts, and prod-looking DB
  names; enforced in the Vitest/Playwright harnesses and at app startup
  via PT_ASSERT_TEST_DB, plus a DATABASE_URI-required startup check
- New reusable verify workflow: frozen install, generated-artifact drift
  check, lint, type-check, integration tests, and critical E2E smoke
  tests against a MongoDB service container
- Dependency SCA scan (pnpm audit) + Dependabot config
- Deploy job now depends on the verification workflow and cannot run
  when it fails
- Add typecheck script; tests cover the isolation guard

Closes #578

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
PromiseTracker Ready Ready Preview, Comment Jul 21, 2026 8:24am

Request Review

Comment thread .github/workflows/ci.yml Fixed
Comment thread .github/workflows/verify.yml Fixed
Comment thread .github/workflows/verify.yml Fixed
Addresses CodeQL 'Workflow does not contain permissions' findings on the
CI and verify workflows by declaring contents:read at the workflow level.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Set NEXT_PUBLIC_LOCALES=en,fr in the verify workflow (and .env.test) so
  payload generate:types is deterministic and matches the committed
  payload-types.ts. Without it CI regenerated an en-only file (dropping
  'fr') and the drift check failed.
- Make the dependency audit non-blocking and report to the job summary.
  The production tree carries many transitive advisories with no
  non-breaking fix; hard-failing blocked all deploys. Actionable direct
  advisories (Payload >=3.79.1) are tracked as a separate upgrade.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- Point Playwright's webServer readiness probe at the dev-only, DB-free
  /dev/update-dialog route (HTTP 200). The homepage was the probe target,
  but on an empty database it resolves to notFound() (404), which
  Playwright never treats as 'ready' — so the run timed out at 120s even
  though the server was up. Keep 'next dev' (the suite needs the dev-only
  update-dialog route, which is notFound() in production builds).
- Widen navigation/action/test timeouts to absorb cold dev compilation.
- Remove the focus-trap subtest: it asserted MUI had moved focus into the
  dialog on the first tick, which races the open transition and flakes.
  The Escape-restore and Tab-trap coverage it shared lived only here; the
  sandbox/allowlist/close-button a11y tests remain.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@kelvinkipruto
kelvinkipruto merged commit a1fb45f into main Jul 21, 2026
9 checks passed
@kelvinkipruto
kelvinkipruto deleted the claude/issue-578 branch July 21, 2026 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create isolated tests and mandatory CI verification

2 participants