Skip to content

Wip/test improvements#8460

Merged
bewest merged 4 commits intodevfrom
wip/test-improvements
Mar 19, 2026
Merged

Wip/test improvements#8460
bewest merged 4 commits intodevfrom
wip/test-improvements

Conversation

@bewest
Copy link
Member

@bewest bewest commented Mar 19, 2026

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.

bewest and others added 4 commits March 18, 2026 19:49
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>
@bewest bewest merged commit 8cf4a1a into dev Mar 19, 2026
11 checks passed
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