Files
familysync/apps/api/vitest.config.ts
T
Lucas BergerandClaude Opus 4.8 717c859f3c
CI / changes (pull_request) Successful in 2s
CI / fast-checks (pull_request) Successful in 1m56s
CI / api (pull_request) Successful in 1m27s
CI / security (pull_request) Has been cancelled
CI / gate (pull_request) Has been cancelled
CI / harness (pull_request) Has been cancelled
fix(12): make api test suite hermetic — provide OIDC env so fallback skips DB
oidcConfigFallbackMiddleware (Phase 12) reads OIDC config from app_config on
every /api/* request when OIDC_ISSUER/CLIENT_ID/AUTH_EXTERNAL_URL are absent.
CI's api job sets no OIDC env, so events/login tests (which mock db with a
partial query chain) 500'd on every request. Local runs passed only because
ambient .env supplied the vars. Set dummy OIDC config in vitest test.env so the
middleware always takes the env path — hermetic across CI and local.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-16 17:43:48 -04:00

45 lines
2.0 KiB
TypeScript

import { defineConfig } from 'vitest/config';
// Under CI the job-level env already sets DB_NAME=familysync and DB_HOST=mariadb
// (the ephemeral service container). Do not override those — CI provisions and
// migrates its own DB via the db:migrate step (T-ndv-04).
// Locally, force workers to connect to the isolated test DB so the dev
// `familysync` DB is never mutated by the test suite (T-ndv-02).
const isCI = !!process.env.CI;
export default defineConfig({
test: {
environment: 'node',
globals: true,
globalSetup: ['./test/global-setup.ts'],
setupFiles: ['./test/setup.ts'],
// Disable parallel file execution so concurrent DB tests do not interfere
// via the shared MariaDB. The global afterEach in test/setup.ts truncates
// list tables; running test files in parallel causes FK violations when one
// file's afterEach deletes rows that another file's test is still using.
fileParallelism: false,
env: {
// OIDC discovery config — supplied so oidcConfigFallbackMiddleware
// (src/auth/middleware.ts) always takes its env path and never reads
// app_config on every /api/* request. Without these, the middleware hits
// the DB, which 500s any test file that mocks `db` with a partial query
// chain (e.g. events/login). CI's api job provides no OIDC env, so this
// also makes the suite hermetic rather than depending on a local .env.
// Dummy values are safe: tests exercising the real OIDC flow mock
// @hono/oidc-auth directly.
OIDC_ISSUER: 'https://auth.test.local',
OIDC_CLIENT_ID: 'familysync-test',
OIDC_AUTH_EXTERNAL_URL: 'https://familysync.test.local',
// Local: force the isolated test DB so the dev `familysync` DB is never
// mutated. Under CI the job-level env already sets DB_NAME=familysync and
// DB_HOST=mariadb — do not override those.
...(isCI
? {}
: {
DB_NAME: 'familysync_test',
DB_HOST: process.env.DB_HOST ?? '127.0.0.1',
}),
},
},
});