Skip to content

fix: prevent duplicate newsletter sends from dev/test containers (#440)#441

Merged
fatherlinux merged 1 commit into
masterfrom
fix/440-newsletter-preview-broadcast
May 29, 2026
Merged

fix: prevent duplicate newsletter sends from dev/test containers (#440)#441
fatherlinux merged 1 commit into
masterfrom
fix/440-newsletter-preview-broadcast

Conversation

@fatherlinux
Copy link
Copy Markdown
Member

Summary

  • Dev, test, and production ROTV containers all share the same Buttondown API key (seeded from prod backups), causing each to independently fire the newsletter preview cron — resulting in 3 identical preview emails every Thursday
  • Adds NEWSLETTER_SEND_ENABLED env var guard to buttondownClient.js — when false, all outbound Buttondown sends are skipped (addSubscriber, sendEmail, sendDraftToRecipients)
  • Defaults to false in dev environments (run.sh template + .env.example); production is unaffected (defaults to enabled)

Closes #440

Test plan

  • ./run.sh build passes
  • Existing tests pass (3 pre-existing flaky UI test failures unrelated)
  • Deploy to prod (no env change — sends remain enabled)
  • Add NEWSLETTER_SEND_ENABLED=false to test container env on lotor
  • Next Thursday: confirm only 1 preview email arrives

🤖 Generated with Claude Code

Dev, test, and production containers all share the same Buttondown API
key (seeded from prod backups). Each independently fires the newsletter
preview cron, resulting in 3 identical preview emails every Thursday.

Add NEWSLETTER_SEND_ENABLED env var (default: true in prod, false in
dev/test). When false, buttondownClient.js skips all outbound sends
(addSubscriber, sendEmail, sendDraftToRecipients) while still allowing
digest generation and UI testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@fatherlinux fatherlinux merged commit ecbb8a7 into master May 29, 2026
3 checks passed
@fatherlinux fatherlinux deleted the fix/440-newsletter-preview-broadcast branch May 29, 2026 02:28
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a NEWSLETTER_SEND_ENABLED environment variable to control whether Buttondown newsletter operations (adding subscribers, sending emails, and sending drafts) are executed, defaulting to false for development and test environments. The feedback highlights two key issues: first, adding the variable to ENV_ARGS in run.sh is dead code, and the test environment configuration needs to explicitly disable this variable to prevent tests from accidentally sending emails; second, the check in buttondownClient.js is case-sensitive and should be updated to a case-insensitive check to avoid accidental sends if configured with values like FALSE or False.

Comment thread run.sh
[ -n "$PGUSER" ] && ENV_ARGS="$ENV_ARGS -e PGUSER=$PGUSER"
[ -n "$PGPASSWORD" ] && ENV_ARGS="$ENV_ARGS -e PGPASSWORD=$PGPASSWORD"
[ -n "$PGDATABASE" ] && ENV_ARGS="$ENV_ARGS -e PGDATABASE=$PGDATABASE"
[ -n "$NEWSLETTER_SEND_ENABLED" ] && ENV_ARGS="$ENV_ARGS -e NEWSLETTER_SEND_ENABLED=$NEWSLETTER_SEND_ENABLED"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The ENV_ARGS variable is built here but is never actually used or passed to any podman run command in this script (the container instead relies on the mounted /etc/rotv/environment file). Adding NEWSLETTER_SEND_ENABLED to ENV_ARGS here is dead code and has no effect. Additionally, to ensure that the test container also has newsletter sends disabled by default, NEWSLETTER_SEND_ENABLED=false (or NEWSLETTER_SEND_ENABLED=${NEWSLETTER_SEND_ENABLED:-false}) should be added to the ~/.rotv/environment-test file generation block around line 244-255. Otherwise, since isSendEnabled() in buttondownClient.js defaults to true when the environment variable is undefined, the test container will run with newsletter sends enabled.

Comment on lines +5 to +7
function isSendEnabled() {
return process.env.NEWSLETTER_SEND_ENABLED !== 'false';
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The environment variable check is currently case-sensitive. If a user or environment configuration sets NEWSLETTER_SEND_ENABLED=FALSE or False, the check !== 'false' will evaluate to true, and newsletter sends will remain enabled. To prevent accidental sends due to casing differences, we should perform a case-insensitive check.

function isSendEnabled() { const val = process.env.NEWSLETTER_SEND_ENABLED; return !val || val.toLowerCase() !== 'false'; }

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.

[Bug]: Newsletter preview sends to ALL subscribers instead of specified recipient

1 participant