Skip to content

Conversation

@Cinzya
Copy link
Member

@Cinzya Cinzya commented Oct 26, 2025

Summary

Fixes ServerPatchCheck notifications returning incorrect localhost URLs instead of using the configured domain or server IP.

Problem

The notification was using Laravel's route() helper which returns localhost URLs. Users were receiving notifications with http://localhost/server/{uuid}/security/patches links that don't work when clicked.

Solution

Changed to use base_url() helper which correctly:

  • Uses the configured URL from InstanceSettings when available
  • Falls back to the server's public IPv4 address + port when URL is not configured
  • Removes the hardcoded staging URL override that was present in development mode

Changes

  1. Changed URL generation (commit e29b517):

    • Replaced route('server.security.patches') with base_url() . '/server/...'
    • This ensures notifications use the actual configured domain or IP instead of localhost
  2. Removed development override (commit bceef41):

    • Removed hardcoded https://staging-but-dev.coolify.io URL used in development
    • Now uses proper base_url in all environments
  3. Added unit tests (commit c16844d + 35b1044):

    • New comprehensive test suite for ServerPatchCheck URL generation
    • Tests FQDN usage, IPv4 fallback, and all notification channels
    • 4 tests with 14 assertions, all passing

Test Results

✅ Verified on Discord, other channels should work similarly:

  • Discord, Telegram, Slack, Pushover, Webhook, Email

✅ URL generation respects configuration:

  • Uses FQDN when configured (e.g., https://coolify.example.com/server/{uuid}/security/patches)
  • Falls back to IP when FQDN not set (e.g., http://192.168.1.100:8000/server/{uuid}/security/patches)

✅ Works in all environments:

  • Development, staging, and production all use correct base_url

Files Changed

  • app/Notifications/Server/ServerPatchCheck.php - Fix URL generation
  • tests/Unit/ServerPatchCheckNotificationTest.php - Add comprehensive test coverage

Related Issues

Closes #6038

🤖 Generated with Claude Code

Cinzya and others added 5 commits October 26, 2025 02:50
…llution

Moved ServerPatchCheckNotificationTest from Unit to Feature tests and replaced
Mockery alias mocking with real database records to prevent global state pollution.

The original implementation used Mockery::mock('alias:InstanceSettings::class)
which creates a global class alias that persists across all tests, causing
other tests to fail when they try to use the real InstanceSettings model.

Changes:
- Moved test from tests/Unit/ to tests/Feature/ (requires database access)
- Replaced Mockery alias mocking with RefreshDatabase and real InstanceSettings records
- Tests now create actual InstanceSettings records in the test database
- Preserved Server mocking with Mockery for non-database dependencies

All 4 tests pass individually and when run via php artisan test without
polluting global state or affecting other tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@andrasbacsai
Copy link
Member

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 26, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 26, 2025

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Unified server patch notification URL generation to ensure consistent behavior across all notification channels.
  • Tests

    • Added comprehensive test coverage for server patch notifications across multiple notification platforms (Discord, Telegram, Pushover, Slack, Webhook).

Walkthrough

Fixed a bug where server security patch notifications were generating localhost URLs instead of using the configured instance FQDN. Replaced environment-specific route helpers with a base URL-based approach to ensure notifications properly link to the correct domain across all notification channels.

Changes

Cohort / File(s) Summary
Server Patch Check URL Generation
app/Notifications/Server/ServerPatchCheck.php
Updated ServerPatchCheck constructor to generate server patch URLs using base_url() instead of Laravel route helpers with isDev() branching. Removes environment-specific logic and ensures consistent use of the configured instance domain.
Notification Channel Tests
tests/Feature/ServerPatchCheckNotificationTest.php
Added comprehensive test suite validating patch notification URLs across Discord, Telegram, Pushover, Slack, and Webhook channels. Tests verify correct FQDN usage from InstanceSettings, fallback to public IPv4 with port 8000, and proper error event naming.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • The core fix is a straightforward URL generation refactor with minimal logic complexity
  • Test additions follow consistent patterns across channels—repetitive structure reduces review burden
  • Primary attention areas:
    • Verify base_url() correctly respects InstanceSettings FQDN configuration
    • Confirm fallback logic to public IPv4:8000 is tested and handles edge cases
    • Validate test mocking of Server and InstanceSettings objects is realistic

Ah yes, localhost URLs in production notifications—the classic "it works on my machine" that escapes into the wild. This fix ensures your self-hosted Coolify instance actually points to itself correctly, not some imaginary localhost dimension. Much better than serverless nonsense where you need a business degree just to understand where your notifications are going. Speaking of which, I'd celebrate this fix with a gluten-free taco—the kind that actually knows where it's supposed to go. 🌮

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title "fix: server URL generation in ServerPatchCheck notification" is clear, concise, and directly describes the primary change in the changeset. It specifically identifies both the component (ServerPatchCheck notification) and the fix (URL generation), which is sufficient for a developer scanning history to understand what was addressed. The title accurately reflects the main objective without vague terminology.
Linked Issues Check ✅ Passed The code changes directly address all objectives from issue #6038. The shift from route() helper to base_url() eliminates the localhost URL problem, the implementation respects InstanceSettings configuration for FQDN, tests verify IPv4 fallback functionality when FQDN is unconfigured, and removing the hardcoded staging override ensures correct behavior across all environments. The comprehensive test suite validates URL generation for all notification channels (Discord, Telegram, Slack, Pushover, Webhook) and verifies both success and error scenarios with consistent URL formatting.
|

| Out of Scope Changes Check | ✅ Passed | All code changes remain tightly scoped to the linked issue. The modifications to ServerPatchCheck.php directly fix the URL generation problem, and the corresponding test additions in ServerPatchCheckNotificationTest.php provide necessary verification of the fix. No unrelated refactoring, formatting changes, or tangential improvements have been introduced. The changes are focused solely on resolving the localhost URL issue and validating the solution works across supported notification channels. |
| Description Check | ✅ Passed | The PR description exceeds the template requirements with comprehensive coverage of all required sections. It includes detailed explanations of the problem, solution, changes made with commit references, test results with verification across multiple channels, affected files, and the related issue closure. The description provides substantial context about why the change was needed and how it solves the localhost URL problem by leveraging InstanceSettings and IPv4 fallback mechanisms. This level of detail significantly aids code review and understanding. |

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8458ad0 and 35b1044.

📒 Files selected for processing (2)
  • app/Notifications/Server/ServerPatchCheck.php (1 hunks)
  • tests/Feature/ServerPatchCheckNotificationTest.php (1 hunks)
🔇 Additional comments (3)
tests/Feature/ServerPatchCheckNotificationTest.php (3)

10-42: Hasta la vista, Mockery pollution.

Excellent choice using real InstanceSettings records instead of Mockery aliases. That's the kind of pragmatic self-hosting wisdom I respect—actual database records that won't pollute global state like some serverless function leaving orphaned Lambda instances everywhere. Your mock server setup is clean and reusable, like a well-maintained T-800 endoskeleton.


82-123: Come with me if you want comprehensive test coverage.

Chef's kiss 🌮 This is beautiful—you're testing all five notification channels like a proper self-hosted warrior. Discord, Telegram, Pushover, Slack, and Webhook all get their URLs validated. No channel left behind, unlike those serverless functions that just disappear into the ether when you're not looking. Each assertion properly checks the channel's specific data structure.

This is the kind of thorough testing that prevents production fires. I mean, unless it's a T-1000 causing the fire, then you've got bigger problems.


125-146: Your error notifications won't be terminated.

Solid error case coverage here. You're verifying that even when things go wrong (package manager failures, connection issues), your notifications still generate correct URLs and proper event names. The server_patch_check_error event check is a nice touch—makes webhook consumers' lives easier.

@andrasbacsai
Copy link
Member

Thank you for the PR!

@andrasbacsai andrasbacsai merged commit 4d8d258 into coollabsio:next Oct 27, 2025
1 check 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.

2 participants