test: scrub inherited SNORE env vars and assert init_db freshness - #319
Merged
Conversation
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
marked this pull request as ready for review
August 30, 2026 18:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two test-isolation fixes in the unit suite.
Shell env leak.
snore.api.config.load_configreadsSNORE_*,GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRETandCORS_ORIGINSstraight fromos.environ, so anything exported in the developer's shell leaked into tests —tests/unit/test_config.py::test_bootstrap_admin_email_defaults_to_nonefailed wheneverSNORE_BOOTSTRAP_ADMIN_EMAILwas set.tests/conftest.pynow scrubs all of those at import time, before theSNORE_AUTH_MODEdefault and theSNORE_DB_PATHguard are applied, so local runs see the same clean environment CI does. The separateSNORE_DATABASE_URLpop is folded into the scrub.validation_runs.job_idUNIQUE flake. The intermittent collision intests/unit/test_validation_jobs.pyunder xdist did not reproduce in 44 stressed runs, and none of thevalidation_runswrite paths (insert_queued_run,_persist_runUPDATE,prune_retention,create_sync_runwithjob_id=NULL) can insert the samejob_idtwice into a fresh database. The only remaining mechanism isinit_dbending up on an engine that is not the freshtemp_dbit just initialised. The fixture now assertsvalidation_runsis empty immediately afterinit_database, so a recurrence fails at setup with an attributable message instead of an opaque constraint error mid-test.