From 717c859f3c637c08d81ed56f80dc68cade5b3c8e Mon Sep 17 00:00:00 2001 From: Lucas Berger Date: Tue, 16 Jun 2026 17:43:48 -0400 Subject: [PATCH] =?UTF-8?q?fix(12):=20make=20api=20test=20suite=20hermetic?= =?UTF-8?q?=20=E2=80=94=20provide=20OIDC=20env=20so=20fallback=20skips=20D?= =?UTF-8?q?B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- apps/api/vitest.config.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/apps/api/vitest.config.ts b/apps/api/vitest.config.ts index f6c17e1..20f9efa 100644 --- a/apps/api/vitest.config.ts +++ b/apps/api/vitest.config.ts @@ -18,11 +18,27 @@ export default defineConfig({ // 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: isCI - ? {} - : { - DB_NAME: 'familysync_test', - DB_HOST: process.env.DB_HOST ?? '127.0.0.1', - }, + 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', + }), + }, }, });