Files
Zachary Lowden ef8c158d7c test(preview): browser smoke tests for deployed PR previews (#2466)
* test(preview): browser smoke tests for deployed PR previews

Adds a Playwright suite that runs against a live PR preview URL and asserts
the IS_PREVIEW login gate (preview-auth.middleware) behaves per role:

- mod / tester / gold clear the gate and core pages render
- a logged-in non-tester is redirected to /preview-restricted
- an anonymous request is redirected to /login

The local /testing/testing-login flow is dead against a preview (NODE_ENV=
production disables the provider + route), so preview-auth.setup.ts mints the
NextAuth session cookie directly with the preview's shared NEXTAUTH_SECRET via
next-auth/jwt encode() — the same function the app signs with. The middleware
reads token.user straight from the cookie and the session callback fail-opens
on an untracked token id, yielding a fully authenticated session. Backing User
rows (+ a gold subscription) are seeded into cnpg-cluster-dev out-of-band.

Runs only under the new playwright.preview.config.ts (needs PREVIEW_URL); the
default config ignores preview-* files so local `npm test` is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(preview): clarify auth-mint model + fix parallelism

Addresses audit feedback:
- Correct the setup-file comment: the minted cookie clears the gate, but SSR
  refreshes token.user from the seeded DB row (refreshToken on an untracked
  token id), so the DB row — not the minted fields — drives the session past
  the gate. The minted object only needs id + isModerator (+ tier for the
  gate's Flipt context).
- playwright.preview.config.ts: workers 1 -> 4 (workers:1 defeated fullyParallel).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* test(preview): harden against cold-preview SSR latency

The first SSR render of a freshly-deployed preview (the homepage especially)
can take 30-40s while Next warms up — the default 30s per-test timeout flaked
on `mod loads /` (passed on retry). Hardening:

- timeout 30s -> 60s (per-test), navigationTimeout 45s.
- setup fires a warm-up GET / before the suite so the first real test doesn't
  pay the full cold-start cost.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci: retrigger preview to exercise pr-smoke-bot comment

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-10 14:32:57 -05:00

27 lines
1.1 KiB
TypeScript

import path from 'path';
/**
* Shared fixtures for the preview smoke tests. NOT a test file (Playwright
* forbids test files importing each other), so the setup + spec both import
* from here. Matched by the default config's `**\/preview-*.ts` testIgnore and
* excluded from the preview config's testMatch, so Playwright never treats it
* as a test.
*/
export type PreviewRole = 'mod' | 'tester' | 'gold' | 'restricted';
// Must mirror datapacket-talos seed-smoke-test-users.yaml (fixed reserved ids)
// and the flipt-state `testers` allowlist (tester + gold).
export const PREVIEW_USERS: Record<
PreviewRole,
{ id: number; username: string; isModerator: boolean; tier?: 'gold' }
> = {
mod: { id: 2000000001, username: 'ci-smoke-mod', isModerator: true },
tester: { id: 2000000002, username: 'ci-smoke-tester', isModerator: false },
gold: { id: 2000000004, username: 'ci-smoke-gold', isModerator: false, tier: 'gold' },
restricted: { id: 2000000003, username: 'ci-smoke-restricted', isModerator: false },
};
export const storageStatePath = (role: PreviewRole) =>
path.join('tests/auth', `.preview-${role}.json`);