fix(portal-bff): set REDIS_URL + SESSION_* in auth.module.spec so ci:check passes on a clean runner #116

Merged
julien merged 1 commits from fix/portal-bff/auth-module-spec-env into main 2026-05-12 23:58:56 +02:00
Owner

Summary

CI red on main after #115. Failure was masked locally because nx test auto-loads apps/portal-bff/.env — the CI runner has no such file, so process.env.REDIS_URL is genuinely unset there and the test sees the real failure path.

Root cause: #115 made AuthModule import SessionModule so AuthController could inject UserSessionIndexService. SessionModule pulls in RedisModule, whose factory calls assertRedisConfig() and refuses to compile without REDIS_URL. The existing auth.module.spec.ts only set the ENTRA_* env vars — so as soon as the spec's compile() walks the new import graph, assertRedisConfig throws.

Fix is one file: add REDIS_URL, SESSION_SECRET, SESSION_ENCRYPTION_KEY to the spec's VALID env block and dispose the ioredis client in afterEach (the spec now compiles a full SessionModule, which opens a connection at module init). Same pattern as session.module.spec.ts.

Verification

The reason the bug didn't surface locally was Nx's .env loading. To repro the CI condition locally:

env -u REDIS_URL -u SESSION_SECRET -u SESSION_ENCRYPTION_KEY -u DATABASE_URL \
    -u ENTRA_INSTANCE_URL -u ENTRA_TENANT_ID -u ENTRA_CLIENT_ID \
    -u ENTRA_CLIENT_SECRET -u ENTRA_REDIRECT_URI -u ENTRA_POST_LOGOUT_REDIRECT_URI \
    pnpm exec nx test portal-bff --skip-nx-cache

Before this PR (on main): auth.module.spec.ts fails with REDIS_URL is not set at assertRedisConfig. After: 123/123 pass under that same clean env.

Test plan

  • nx test portal-bff with all BFF env vars unset123/123 pass (the CI condition).
  • nx lint portal-bff → clean.
  • nx build portal-bff → clean.
  • Prettier-clean.
  • CI re-run after merge → ci:check green.
## Summary CI red on `main` after #115. Failure was masked locally because `nx test` auto-loads `apps/portal-bff/.env` — the CI runner has no such file, so `process.env.REDIS_URL` is genuinely unset there and the test sees the real failure path. Root cause: #115 made `AuthModule` import `SessionModule` so `AuthController` could inject `UserSessionIndexService`. `SessionModule` pulls in `RedisModule`, whose factory calls `assertRedisConfig()` and refuses to compile without `REDIS_URL`. The existing `auth.module.spec.ts` only set the `ENTRA_*` env vars — so as soon as the spec's `compile()` walks the new import graph, `assertRedisConfig` throws. Fix is one file: add `REDIS_URL`, `SESSION_SECRET`, `SESSION_ENCRYPTION_KEY` to the spec's `VALID` env block and dispose the `ioredis` client in `afterEach` (the spec now compiles a full SessionModule, which opens a connection at module init). Same pattern as `session.module.spec.ts`. ## Verification The reason the bug didn't surface locally was Nx's `.env` loading. To repro the CI condition locally: ``` env -u REDIS_URL -u SESSION_SECRET -u SESSION_ENCRYPTION_KEY -u DATABASE_URL \ -u ENTRA_INSTANCE_URL -u ENTRA_TENANT_ID -u ENTRA_CLIENT_ID \ -u ENTRA_CLIENT_SECRET -u ENTRA_REDIRECT_URI -u ENTRA_POST_LOGOUT_REDIRECT_URI \ pnpm exec nx test portal-bff --skip-nx-cache ``` Before this PR (on main): `auth.module.spec.ts` fails with `REDIS_URL is not set` at `assertRedisConfig`. After: 123/123 pass under that same clean env. ## Test plan - [x] `nx test portal-bff` with all BFF env vars `unset` → **123/123 pass** (the CI condition). - [x] `nx lint portal-bff` → clean. - [x] `nx build portal-bff` → clean. - [x] Prettier-clean. - [ ] CI re-run after merge → `ci:check` green.
julien added 1 commit 2026-05-12 23:52:59 +02:00
fix(portal-bff): set REDIS_URL + SESSION_* in auth.module.spec so ci:check passes on a clean runner
CI / commits (pull_request) Successful in 1m21s
CI / scan (pull_request) Successful in 1m29s
CI / check (pull_request) Successful in 1m35s
CI / a11y (pull_request) Successful in 50s
CI / perf (pull_request) Successful in 2m18s
a84c4c95a5
#115 made AuthModule import SessionModule (for AuthController to
inject UserSessionIndexService). SessionModule transitively pulls
in RedisModule whose factory calls assertRedisConfig() — that
throws when REDIS_URL is unset. auth.module.spec only seeded the
ENTRA_* env vars, so compile() blew up the moment it walked the
new import graph.

caught only by ci, not locally: nx auto-loads apps/portal-bff/.env
for tasks, which my dev box has. the ci runner starts with a clean
environment, surfaces the real failure path, and ci:check went red
on main right after #115 merged.

repro of the ci condition locally:
  env -u REDIS_URL -u SESSION_SECRET -u SESSION_ENCRYPTION_KEY \
      -u DATABASE_URL -u ENTRA_INSTANCE_URL -u ENTRA_TENANT_ID \
      -u ENTRA_CLIENT_ID -u ENTRA_CLIENT_SECRET \
      -u ENTRA_REDIRECT_URI -u ENTRA_POST_LOGOUT_REDIRECT_URI \
      pnpm exec nx test portal-bff --skip-nx-cache

fix: extend the spec's VALID env block with REDIS_URL (a
well-formed but unreachable url so ioredis stays lazy),
SESSION_SECRET, and SESSION_ENCRYPTION_KEY — same pattern as
session.module.spec.ts. and dispose the ioredis client in
afterEach so jest doesn't hang on its reconnect timer (the spec
now opens a real connection at module init).

123/123 pass under the clean-env repro. no production code change.
julien merged commit c427e5d4fe into main 2026-05-12 23:58:56 +02:00
julien deleted branch fix/portal-bff/auth-module-spec-env 2026-05-12 23:58:56 +02:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: julien/apf_portal#116