Skip to content

test: scrub inherited SNORE env vars and assert init_db freshness - #319

Merged
wpfleger96 merged 2 commits into
mainfrom
will/test-isolation-fixes
Aug 30, 2026
Merged

test: scrub inherited SNORE env vars and assert init_db freshness#319
wpfleger96 merged 2 commits into
mainfrom
will/test-isolation-fixes

Conversation

@wpfleger96

Copy link
Copy Markdown
Owner

Two test-isolation fixes in the unit suite.

Shell env leak. snore.api.config.load_config reads SNORE_*, GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET and CORS_ORIGINS straight from os.environ, so anything exported in the developer's shell leaked into tests — tests/unit/test_config.py::test_bootstrap_admin_email_defaults_to_none failed whenever SNORE_BOOTSTRAP_ADMIN_EMAIL was set. tests/conftest.py now scrubs all of those at import time, before the SNORE_AUTH_MODE default and the SNORE_DB_PATH guard are applied, so local runs see the same clean environment CI does. The separate SNORE_DATABASE_URL pop is folded into the scrub.

validation_runs.job_id UNIQUE flake. The intermittent collision in tests/unit/test_validation_jobs.py under xdist did not reproduce in 44 stressed runs, and none of the validation_runs write paths (insert_queued_run, _persist_run UPDATE, prune_retention, create_sync_run with job_id=NULL) can insert the same job_id twice into a fresh database. The only remaining mechanism is init_db ending up on an engine that is not the fresh temp_db it just initialised. The fixture now asserts validation_runs is empty immediately after init_database, so a recurrence fails at setup with an attributable message instead of an opaque constraint error mid-test.

load_config reads SNORE_*/GOOGLE_CLIENT_*/CORS_ORIGINS straight from
os.environ, so any of them exported in the developer shell leaked into
the suite (test_config's bootstrap-admin default failed whenever
SNORE_BOOTSTRAP_ADMIN_EMAIL was set). Scrub them once at conftest import
so the suite sees the same clean environment CI does.

The intermittent UNIQUE(validation_runs.job_id) failure under xdist did
not reproduce in 44 runs and no write path inserts a job_id twice into a
fresh DB, so the only mechanism is init_db landing on a stale engine.
Assert the table is empty right after init so a recurrence fails at
fixture setup with an attributable message instead of mid-test.
@wpfleger96
wpfleger96 marked this pull request as ready for review August 30, 2026 18:10
@wpfleger96
wpfleger96 merged commit c130d53 into main Aug 30, 2026
9 checks passed
@wpfleger96
wpfleger96 deleted the will/test-isolation-fixes branch August 30, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant