test: guard @pg_only fixtures against wiping a remote DB#144
Merged
Conversation
The @pg_only fixtures run unconditional `DELETE FROM` against whatever TEST_POSTGRES_URL names, and conftest.py deliberately does not strip that var (it is the opt-in for the live tier). So `export TEST_POSTGRES_URL=$CONTENT_DATABASE_URL` would wipe prod accounts, agents, and API keys. Add require_local_postgres_url(): the four destructive fixtures now refuse any non-localhost host, failing loud instead of silently wiping prod. Closes #136. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Closes #136.
The
@pg_onlyfixturesDELETE FROM external_agents / agent_versions / strategies / usersagainst whateverTEST_POSTGRES_URLnames, andconftest.pydeliberately does not strip that var (it is the opt-in for the live tier).CONTENT_DATABASE_URL/USERS_DATABASE_URLare the same prod Neon DB, soexport TEST_POSTGRES_URL=$CONTENT_DATABASE_URL && pytestwould wipe prod accounts + agents + API keys.require_local_postgres_url()(new_postgres_testing.py, following the_v2_fakes.pyshared-helper convention) allowlistslocalhost/127.0.0.1/::1viaurlsplit. The four destructive fixtures call it first, so a remote URL now fails loud (red errors) instead of silently wiping prod — or silently skipping.Tests: 5 unit + 4 fixture-guard integration cases (the latter prove each fixture refuses before touching the network). Suite: 1095 passed, 18 skipped;
@pg_onlytier still skips cleanly with noTEST_POSTGRES_URL.Note: protection is per destructive fixture (the four that exist). A future 5th destructive fixture must call the guard too — left as a convention rather than an import-time raise, which this repo's CLAUDE.md warns can abort the whole collection session.
🤖 Generated with Claude Code