From e6d14da5f3d26bccd4da236cfbc6d0177f9b8be6 Mon Sep 17 00:00:00 2001 From: Simon Date: Tue, 7 Apr 2026 17:31:16 +0200 Subject: [PATCH] fix: flaky oidc tests --- CODE_GUIDELINES.md | 2 ++ docs/development-progress-log.md | 4 ++++ test/test_helper.exs | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/CODE_GUIDELINES.md b/CODE_GUIDELINES.md index 199ceed..0d478f9 100644 --- a/CODE_GUIDELINES.md +++ b/CODE_GUIDELINES.md @@ -1712,6 +1712,8 @@ mix test test/membership/member_test.exs:42 ### 4.7 Testing Best Practices +**Process environment (`test/test_helper.exs`):** Vereinfacht and OIDC-related `System.get_env/1` keys are cleared at test startup so configuration comes from the test database (Membership settings) unless a test explicitly sets variables in `setup` and restores them with `on_exit`. This matches production priority (ENV over settings) while keeping the suite deterministic when `.env` is loaded (e.g. via `just`). + **Testing Philosophy: Focus on Business Logic, Not Framework Functionality** We test our business logic and domain-specific behavior, not core framework features. Framework features (Ash validations, Ecto relationships, etc.) are already tested by their respective libraries. diff --git a/docs/development-progress-log.md b/docs/development-progress-log.md index 6d8e523..04c35f3 100644 --- a/docs/development-progress-log.md +++ b/docs/development-progress-log.md @@ -710,6 +710,10 @@ end ## Testing Strategy +### Test process environment + +`test/test_helper.exs` clears Vereinfacht and OIDC-related environment variables at startup (same rationale as not hitting real APIs when `.env` is loaded). `Mv.Config` prefers ENV over database settings; without this, OIDC sign-in redirect tests would depend on the developer shell and become flaky. Tests that need specific OIDC env values set them in `setup` and restore with `on_exit`. + ### Test Coverage Areas #### 1. Unit Tests (Domain Logic) diff --git a/test/test_helper.exs b/test/test_helper.exs index 01a0613..b35503d 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -4,6 +4,13 @@ System.delete_env("VEREINFACHT_API_URL") System.delete_env("VEREINFACHT_API_KEY") System.delete_env("VEREINFACHT_CLUB_ID") +# Mv.Config.oidc_* reads ENV before database Settings (see lib/mv/config.ex). If a developer +# or CI loads .env with OIDC variables, OidcOnlySignInRedirect and oidc_configured?/0 would +# ignore Membership settings and tests become flaky. Tests that need OIDC env (e.g. group +# claim) set it in setup and restore via on_exit. +~w(OIDC_CLIENT_ID OIDC_BASE_URL OIDC_REDIRECT_URI OIDC_CLIENT_SECRET OIDC_CLIENT_SECRET_FILE OIDC_ONLY OIDC_ADMIN_GROUP_NAME OIDC_GROUPS_CLAIM) +|> Enum.each(&System.delete_env/1) + ExUnit.start( # shows 10 slowest tests at the end of the test run # slowest: 10