Add database test safety configuration #13

Closed
opened 2026-04-01 01:28:30 +00:00 by david · 4 comments
Owner

Summary

Add database test safety configuration to ensure tests always run against the development database.

Changes

  1. Remove hardcoded database URLs from package.json scripts
  2. Update scripts to load environment variables from .env files
  3. Add database validation in test setup files
  4. Update error messages to avoid exposing passwords

Files Changed

  • package.json
  • scripts/cleanup-prod-db.js
  • scripts/check-test-records.js
  • scripts/setup-postgres.js
  • src/tests/e2e/global.setup.ts
  • vitest.setup.ts

Security

  • Removed hardcoded database passwords from version control
  • Scripts now require explicit environment variables or .env files
  • Production database operations require explicit confirmation

Testing

  • Unit tests pass with dev database validation
  • E2E tests now properly configured to use dev database
## Summary Add database test safety configuration to ensure tests always run against the development database. ## Changes 1. Remove hardcoded database URLs from package.json scripts 2. Update scripts to load environment variables from .env files 3. Add database validation in test setup files 4. Update error messages to avoid exposing passwords ## Files Changed - package.json - scripts/cleanup-prod-db.js - scripts/check-test-records.js - scripts/setup-postgres.js - src/__tests__/e2e/global.setup.ts - vitest.setup.ts ## Security - Removed hardcoded database passwords from version control - Scripts now require explicit environment variables or .env files - Production database operations require explicit confirmation ## Testing - Unit tests pass with dev database validation - E2E tests now properly configured to use dev database
Author
Owner

Status Update

Completed:

  1. Removed hardcoded database URLs from package.json scripts
  2. Updated scripts to load environment variables from .env and .env.development files
  3. Added database validation in test setup files
  4. Updated error messages to avoid exposing passwords
  5. Removed hardcoded password from cleanup-prod-db.js and check-test-records.js

Testing Results:

  • Unit tests: All 103 tests pass
  • E2E tests: Running against dev database (6/9 passed, 3 failures unrelated to database config)
  • Database cleanup: Working correctly in test teardown

Notes:

  • The 3 failing E2E tests are unrelated to database configuration (tournament name display issue)
  • All database operations now safely use the development database for tests
  • Production database operations require explicit environment variable configuration
## Status Update Completed: 1. Removed hardcoded database URLs from package.json scripts 2. Updated scripts to load environment variables from .env and .env.development files 3. Added database validation in test setup files 4. Updated error messages to avoid exposing passwords 5. Removed hardcoded password from cleanup-prod-db.js and check-test-records.js Testing Results: - Unit tests: All 103 tests pass - E2E tests: Running against dev database (6/9 passed, 3 failures unrelated to database config) - Database cleanup: Working correctly in test teardown Notes: - The 3 failing E2E tests are unrelated to database configuration (tournament name display issue) - All database operations now safely use the development database for tests - Production database operations require explicit environment variable configuration
Author
Owner

Final Status Update

All changes completed successfully:

Security Improvements:

  1. Removed hardcoded database passwords from version control
  2. Updated all scripts to use environment variables
  3. Regenerated docker-compose files with environment variable placeholders
  4. Updated playwright.config.ts to use environment variables

Files Changed:

  • package.json - Removed hardcoded database URLs
  • scripts/cleanup-prod-db.js - Removed hardcoded production URL
  • scripts/check-test-records.js - Removed hardcoded production URL
  • scripts/setup-postgres.js - Load .env.development first
  • scripts/generate-docker-compose.js - Use environment variables with defaults
  • src/tests/e2e/global.setup.ts - Load .env.development with override
  • vitest.setup.ts - Load .env.development with override
  • playwright.config.ts - Use environment variables for dev server
  • docker-compose*.yml - Regenerated with environment variable placeholders

Testing Results:

  • Unit tests: All 103 tests pass
  • E2E tests: Running against dev database (6/9 passed, 3 failures unrelated to database config)
  • Database cleanup: Working correctly in test teardown

Next Steps:
The 3 failing E2E tests are related to tournament name display, not database configuration. These should be addressed separately.

## Final Status Update All changes completed successfully: Security Improvements: 1. Removed hardcoded database passwords from version control 2. Updated all scripts to use environment variables 3. Regenerated docker-compose files with environment variable placeholders 4. Updated playwright.config.ts to use environment variables Files Changed: - package.json - Removed hardcoded database URLs - scripts/cleanup-prod-db.js - Removed hardcoded production URL - scripts/check-test-records.js - Removed hardcoded production URL - scripts/setup-postgres.js - Load .env.development first - scripts/generate-docker-compose.js - Use environment variables with defaults - src/__tests__/e2e/global.setup.ts - Load .env.development with override - vitest.setup.ts - Load .env.development with override - playwright.config.ts - Use environment variables for dev server - docker-compose*.yml - Regenerated with environment variable placeholders Testing Results: - Unit tests: All 103 tests pass - E2E tests: Running against dev database (6/9 passed, 3 failures unrelated to database config) - Database cleanup: Working correctly in test teardown Next Steps: The 3 failing E2E tests are related to tournament name display, not database configuration. These should be addressed separately.
Author
Owner

Fix: Best Partner Logic Updated

Changed the best partner calculation from using win rate to using ELO contribution:

Before:

  • Best partner = partner with highest win rate (among partnerships with 3+ games)
  • Problem: AJ with 33.3% win rate was best because it was the only partnership with 3+ games

After:

  • Best partner = partner with highest totalELOChange (among partnerships with 2+ games)
  • Uses the field which tracks cumulative ELO gains/losses
  • Reduced minimum games from 3 to 2 to be more inclusive

Why this is better:

  • ELO change directly measures contribution to your rating
  • A partner who helps you gain rating is truly best
  • Andy with +16 ELO change will now be Kevin's best partner (not AJ with -14)
  • John with +18 ELO change might be even better

Code change: lines 89-95

## Fix: Best Partner Logic Updated Changed the best partner calculation from using win rate to using ELO contribution: **Before:** - Best partner = partner with highest win rate (among partnerships with 3+ games) - Problem: AJ with 33.3% win rate was best because it was the only partnership with 3+ games **After:** - Best partner = partner with highest totalELOChange (among partnerships with 2+ games) - Uses the field which tracks cumulative ELO gains/losses - Reduced minimum games from 3 to 2 to be more inclusive **Why this is better:** - ELO change directly measures contribution to your rating - A partner who helps you gain rating is truly best - Andy with +16 ELO change will now be Kevin's best partner (not AJ with -14) - John with +18 ELO change might be even better **Code change:** lines 89-95
Author
Owner

Fixed the best partner logic in player profiles.

The issue was that the logic was using win rate to determine best partner, which had a flaw:

  • It required partnerships to have 3+ games to be considered
  • If only one partnership met that threshold, it became the "best" regardless of win rate
  • This caused AJ with 33.3% win rate to be Kevin's "best partner" even though Andy and John had 100% win rates

The fix changes the logic to use ELO contribution (totalEloChange) instead:

  • Best partner is now the one who contributed most to your rating
  • Uses the totalEloChange field which tracks cumulative ELO gains/losses
  • Reduced minimum games from 3 to 2 to be more inclusive
  • Now Andy (+16) and John (+18) will correctly show as better partners than AJ (-14)

This makes the "Best Partner" label actually meaningful - it reflects who helps you win and gain rating, not just who you've played many games with.

Fixed the best partner logic in player profiles. The issue was that the logic was using win rate to determine best partner, which had a flaw: - It required partnerships to have 3+ games to be considered - If only one partnership met that threshold, it became the "best" regardless of win rate - This caused AJ with 33.3% win rate to be Kevin's "best partner" even though Andy and John had 100% win rates The fix changes the logic to use ELO contribution (totalEloChange) instead: - Best partner is now the one who contributed most to your rating - Uses the totalEloChange field which tracks cumulative ELO gains/losses - Reduced minimum games from 3 to 2 to be more inclusive - Now Andy (+16) and John (+18) will correctly show as better partners than AJ (-14) This makes the "Best Partner" label actually meaningful - it reflects who helps you win and gain rating, not just who you've played many games with.
david closed this issue 2026-04-01 05:03:17 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/euchre_camp#13