Repository navigation
fix(discord-bridge): check DISCORD_BOT_TOKEN env var before .env file - #1050
Merged
qingyun-wu merged 2 commits intoMay 23, 2026
Merged
Conversation
Matches telegram-bridge.py pattern. Allows test suites to inject a stub token via os.environ without needing a real ~/.claude/channels/ discord/.env file — unblocks CI for VasiliyRad PRs sonichi#1046 and sonichi#1048 whose tests already set the env var before importing the bridge. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced May 23, 2026
qingyun-wu
reviewed
May 23, 2026
qingyun-wu
left a comment
Collaborator
There was a problem hiding this comment.
LGTM — this is the right, minimal fix and correctly diagnosed. Env-var-takes-precedence with .env fallback is the standard "env overrides config file" precedence, the exit(1) when neither is set is preserved, and it's appropriately surgical (8/-7, one file). CI is green.
This is effectively the keystone for the restart-safety series: it unblocks #1046's CI directly. One nuance worth flagging — it's necessary but not sufficient for #1048: that test imports the bridge without stubbing the discord module (whereas #1046 does), so after this lands #1048 will likely still fail at import discord until it adds the stub. (Raised that on #1048.)
Two minor, non-blocking nits:
- Strip consistency. The
.envpath does.split("=", 1)[1].strip(), but the new env-var path doesn't strip —os.environ.get("DISCORD_BOT_TOKEN", ""). A stray trailing newline in the env var would slip through. Consider.strip()for parity:os.environ.get("DISCORD_BOT_TOKEN", "").strip(). - Error message. Now that the env var is also consulted, the failure message (
"DISCORD_BOT_TOKEN not set in ~/.claude/channels/discord/.env") is slightly misleading — it doesn't mention the env var that was also checked. e.g."DISCORD_BOT_TOKEN not set (checked env var and ~/.claude/channels/discord/.env)"would aid debugging.
Neither blocks. Nice clean fix.
1 of 2 tasks
qingyun-wu
approved these changes
May 23, 2026
1 of 2 tasks
liususan091219
pushed a commit
to liususan091219/sutando-fork
that referenced
this pull request
May 28, 2026
…sonichi#1050) Matches telegram-bridge.py pattern. Allows test suites to inject a stub token via os.environ without needing a real ~/.claude/channels/ discord/.env file — unblocks CI for VasiliyRad PRs sonichi#1046 and sonichi#1048 whose tests already set the env var before importing the bridge. Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Qingyun Wu <qingyun0327@gmail.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.
Problem
discord-bridge.pyreadsDISCORD_BOT_TOKENexclusively from~/.claude/channels/discord/.envat module-load time. There is no fallback toos.environ. This causes test suites that inject a stub token viaos.environ.setdefault("DISCORD_BOT_TOKEN", "test-token-not-real")to fail with:Affects VasiliyRad PRs #1046 (
bridges-sending-orphan-recovery.test.py) and #1048 (discord-bridge-delivery-sentinel.test.py) — both set the env var before import but the bridge never checked it.Fix
Check
os.environ.get("DISCORD_BOT_TOKEN")first; fall back to the.envfile. This is the same pattern already used bytelegram-bridge.py(lines 102–104).Impact
DISCORD_BOT_TOKENas a real env var now get it picked up without needing the file.envfile🤖 Generated with Claude Code