Conversation
Adds multi-layer protection against running destructive tests on production: 1. Pre-flight check (hooks.js): Verifies NODE_ENV=test before any DB connection 2. Database name check: Requires 'test' substring in database name 3. Entry count threshold: Refuses if database has >100 entries (configurable) Environment Variables: - TEST_SAFETY_MAX_ENTRIES: Max entries before refusing (default: 100) - TEST_SAFETY_REQUIRE_TEST_DB: Require 'test' in DB name (default: true) - TEST_SAFETY_SKIP: Emergency bypass for all checks (default: false) Files: - tests/lib/production-safety.js: Core safety check module - tests/00_production-safety.test.js: Runs first to gate test suite - tests/production-safety.test.js: Unit tests for safety module - tests/hooks.js: Updated to use new module This addresses concerns about users with 'test' in production DB names by adding the entry count threshold as a secondary safety measure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The ctx.entries module isn't always available depending on boot context. Access the entries collection directly via ctx.store.db.collection(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Change 'FAILED' to 'ACTIVATED' - this is protective, not a failure - Explain that tests WILL DELETE data in the database - Explain the purpose: preventing accidental production data loss - List all override options clearly Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Use a tally of entries to detect production data and bail out on tests. Use env vars to control the behavior.
Integration tested by inserting 150 entries and watching it fail.