Skip to content

Commit af5e834

Browse files
m4r1kclaude
andcommitted
fix: correct legacy Discord config detection in validate_config
The has_legacy_discord check was incorrectly checking if any notification URL contained 'discord://', which would always be true for Discord users regardless of config format. Now properly detects legacy Discord config by checking for 'webhook_url' in the raw config data. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent f07e811 commit af5e834

2 files changed

Lines changed: 49 additions & 12 deletions

File tree

src/eneru/monitor.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Version is set at build time via git describe --tags
99
# Format: "4.3.0" for tagged releases, "4.3.0-5-gabcdef1" for dev builds
10-
__version__ = "4.7.0-rc0"
10+
__version__ = "4.7.0-rc1"
1111

1212
import subprocess
1313
import sys
@@ -513,7 +513,7 @@ def _parse_config(cls, data: Dict[str, Any]) -> Config:
513513
return config
514514

515515
@classmethod
516-
def validate_config(cls, config: Config) -> List[str]:
516+
def validate_config(cls, config: Config, raw_data: Optional[Dict[str, Any]] = None) -> List[str]:
517517
"""Validate configuration and return list of warnings/info messages."""
518518
messages = []
519519

@@ -524,14 +524,23 @@ def validate_config(cls, config: Config) -> List[str]:
524524
"Notifications will be disabled. Install with: pip install apprise"
525525
)
526526

527-
# Check for legacy Discord configuration
528-
has_legacy_discord = any(
529-
'discord://' in url.lower() for url in config.notifications.urls
530-
)
527+
# Check for legacy Discord configuration (webhook_url in discord section)
528+
has_legacy_discord = False
529+
if raw_data:
530+
# Check for legacy discord.webhook_url in notifications section
531+
if 'notifications' in raw_data:
532+
notif_data = raw_data['notifications']
533+
if 'discord' in notif_data and notif_data['discord'].get('webhook_url'):
534+
has_legacy_discord = True
535+
# Check for top-level legacy discord section
536+
if 'discord' in raw_data and 'notifications' not in raw_data:
537+
if raw_data['discord'].get('webhook_url'):
538+
has_legacy_discord = True
539+
531540
if has_legacy_discord:
532541
messages.append(
533-
"INFO: Discord webhook detected. Using Apprise for notifications. "
534-
"Native Discord embeds are now handled via Apprise."
542+
"INFO: Legacy Discord webhook_url detected. Using Apprise for notifications. "
543+
"Consider migrating to the 'notifications.urls' format."
535544
)
536545

537546
return messages

tests/test_config.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -727,11 +727,39 @@ class TestConfigValidation:
727727
"""Test configuration validation."""
728728

729729
@pytest.mark.unit
730-
def test_validate_config_with_apprise(self, full_config):
731-
"""Test validation returns info about Apprise."""
730+
def test_validate_config_with_modern_discord(self, full_config):
731+
"""Test validation with modern discord:// URL format."""
732732
messages = ConfigLoader.validate_config(full_config)
733-
# Should have message about Discord via Apprise
734-
assert any("Discord" in msg or "Apprise" in msg for msg in messages)
733+
# Modern discord:// URLs should not trigger legacy warning
734+
assert not any("Legacy" in msg for msg in messages)
735+
736+
@pytest.mark.unit
737+
def test_validate_config_with_legacy_discord(self, full_config):
738+
"""Test validation returns info about legacy Discord webhook_url."""
739+
# Simulate raw config data with legacy discord.webhook_url
740+
raw_data = {
741+
'notifications': {
742+
'discord': {
743+
'webhook_url': 'https://discord.com/api/webhooks/123/abc'
744+
}
745+
}
746+
}
747+
messages = ConfigLoader.validate_config(full_config, raw_data)
748+
# Should have message about legacy Discord webhook_url
749+
assert any("Legacy Discord webhook_url" in msg for msg in messages)
750+
751+
@pytest.mark.unit
752+
def test_validate_config_with_toplevel_legacy_discord(self, full_config):
753+
"""Test validation detects top-level legacy discord config."""
754+
# Simulate raw config data with top-level legacy discord section
755+
raw_data = {
756+
'discord': {
757+
'webhook_url': 'https://discord.com/api/webhooks/456/def'
758+
}
759+
}
760+
messages = ConfigLoader.validate_config(full_config, raw_data)
761+
# Should have message about legacy Discord webhook_url
762+
assert any("Legacy Discord webhook_url" in msg for msg in messages)
735763

736764
@pytest.mark.unit
737765
def test_validate_config_empty_notifications(self, minimal_config):

0 commit comments

Comments
 (0)