harden env handling #481

Merged
simon merged 4 commits from bugfix/harden-env-handling into main 2026-04-08 10:40:24 +02:00
3 changed files with 13 additions and 0 deletions
Showing only changes of commit e6d14da5f3 - Show all commits

View file

@ -1712,6 +1712,8 @@ mix test test/membership/member_test.exs:42
### 4.7 Testing Best Practices ### 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** **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. 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.

View file

@ -710,6 +710,10 @@ end
## Testing Strategy ## 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 ### Test Coverage Areas
#### 1. Unit Tests (Domain Logic) #### 1. Unit Tests (Domain Logic)

View file

@ -4,6 +4,13 @@ System.delete_env("VEREINFACHT_API_URL")
System.delete_env("VEREINFACHT_API_KEY") System.delete_env("VEREINFACHT_API_KEY")
System.delete_env("VEREINFACHT_CLUB_ID") 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( ExUnit.start(
# shows 10 slowest tests at the end of the test run # shows 10 slowest tests at the end of the test run
# slowest: 10 # slowest: 10