Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Add a configuration overview to System Health (#3929)

Juan José Matabb71cafaf3e2
diff --git a/app/controllers/admin/system_health_controller.rb b/app/controllers/admin/system_health_controller.rb
index 0be21768f3..01969ca5b5 100644
--- a/app/controllers/admin/system_health_controller.rb
+++ b/app/controllers/admin/system_health_controller.rb
@@ -13,9 +13,10 @@ module Admin
# work in managed mode, where `current_sidekiq_health` is nil.
def show
@hosted_usage_available = hosted_usage_available?
- tabs = %w[background_jobs ai]
+ tabs = %w[background_jobs ai configuration]
tabs << "hosted_usage" if @hosted_usage_available
@active_tab = params[:tab].presence_in(tabs) || "background_jobs"
+ @configuration_health = ConfigurationHealth.new
if Apns::Client.hosted?
@push_notification_test = PushNotificationTest.new(Current.user)
@push_disabled_reason = @push_notification_test.disabled_reason
diff --git a/app/helpers/admin/system_health_helper.rb b/app/helpers/admin/system_health_helper.rb
new file mode 100644
index 0000000000..173d31ad44
--- /dev/null
+++ b/app/helpers/admin/system_health_helper.rb
@@ -0,0 +1,7 @@
+module Admin::SystemHealthHelper
+ def configuration_health_text(text)
+ safe_join(text.split(/\b([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+)\b/).each_with_index.map do |part, index|
+ index.odd? ? tag.code(part) : part
+ end)
+ end
+end
diff --git a/app/helpers/feedback_helper.rb b/app/helpers/feedback_helper.rb
index 282b0afe90..29bd3b6a09 100644
--- a/app/helpers/feedback_helper.rb
+++ b/app/helpers/feedback_helper.rb
@@ -1,6 +1,6 @@
module FeedbackHelper
def posthog_enabled?
- Rails.env.production? || (Rails.env.development? && Rails.configuration.x.posthog.development_enabled)
+ Rails.configuration.x.posthog.browser_enabled?
end
def feedback_config(feature)
diff --git a/app/models/configuration_health.rb b/app/models/configuration_health.rb
new file mode 100644
index 0000000000..773d65f2ee
--- /dev/null
+++ b/app/models/configuration_health.rb
@@ -0,0 +1,143 @@
+# frozen_string_literal: true
+
+# A read-only snapshot of optional installation configuration. Resolving a
+# provider constructs its client; it never tests credentials or fetches data.
+class ConfigurationHealth
+ STORAGE_BACKENDS = {
+ "local" => "Disk", "test" => "Disk", "amazon" => "S3",
+ "cloudflare" => "S3", "generic_s3" => "S3", "google" => "GCS"
+ }.freeze
+
+ Check = Data.define(:key, :status, :issues, :providers, :backend) do
+ def tone
+ status.in?([ :not_configured, :incomplete ]) ? :warning : :neutral
+ end
+ end
+
+ ProviderStatus = Data.define(:key, :status)
+
+ def checks
+ @checks ||= [ smtp, securities, exchange_rates, storage ]
+ end
+
+ def optional_services
+ @optional_services ||= OptionalServices.new.checks
+ end
+
+ def smtp
+ return check(:smtp, :disabled) unless ApplicationMailer.perform_deliveries
+ return check(:smtp, :not_checked) unless ApplicationMailer.delivery_method == :smtp
+
+ settings = ApplicationMailer.smtp_settings.symbolize_keys
+ issues = []
+ issues << :address if settings[:address].blank?
+ unless settings[:port].nil?
+ port = Integer(settings[:port], exception: false)
+ issues << :port unless port && (1..65_535).cover?(port)
+ end
+ issues << :sender unless email_sender_configured?
+ issues << :app_domain if ApplicationMailer.default_url_options[:host].blank?
+ # Unauthenticated relays are supported; a half-configured credential pair
+ # is different from intentionally supplying neither field.
+ issues << :authentication if settings[:user_name].present? != settings[:password].present?
+
+ status = if issues.include?(:address)
+ :not_configured
+ elsif issues.any?
+ :incomplete
+ else
+ :configured
+ end
+ check(:smtp, status, issues: issues)
+ end
+
+ def securities
+ providers = provider_statuses(:securities, Setting.enabled_securities_providers)
+ check(:securities, provider_status(providers, empty_status: :disabled), providers: providers)
+ end
+
+ def exchange_rates
+ selected = ENV["EXCHANGE_RATE_PROVIDER"].presence || Setting.exchange_rate_provider
+ providers = provider_statuses(:exchange_rates, [ selected ].compact_blank)
+ invalid = providers.first&.status == :invalid
+ check(:exchange_rates, invalid ? :not_configured : provider_status(providers),
+ providers: providers, issues: invalid ? [ :invalid_provider ] : [])
+ end
+
+ def storage
+ # Let Rails load its configuration, including environment-specific storage files.
+ ActiveStorage::Blob
+ name = Rails.application.config.active_storage.service.to_s
+ configurations = Rails.application.config.active_storage.service_configurations
+ settings = configurations.with_indifferent_access[name]
+ backend = STORAGE_BACKENDS.key?(name) ? name.to_sym : :other
+ return check(:storage, :not_configured, backend: backend) if settings.blank?
+ settings = settings.symbolize_keys
+ unless STORAGE_BACKENDS[name] == settings[:service]
+ return check(:storage, :not_checked, backend: :other)
+ end
+ issues = storage_issues(name, settings)
+ status = if issues.any?
+ :incomplete
+ elsif name.in?(%w[amazon cloudflare generic_s3]) && settings[:access_key_id].blank?
+ :not_checked # An SDK credential chain / instance role may supply access.
+ elsif name == "google" && settings[:credentials].blank?
+ :not_checked # Application Default Credentials may supply access.
+ else
+ :configured
+ end
+ check(:storage, status, issues: issues, backend: backend)
+ end
+
+ private
+ def check(key, status, issues: [], providers: [], backend: nil)
+ Check.new(key: key, status: status, issues: issues, providers: providers, backend: backend)
+ end
+
+ def email_sender_configured?
+ sender = Mail::Address.new(ApplicationMailer.default[:from].to_s)
+ sender.local.present? && sender.domain.present? && sender.address != "[email protected]"
+ rescue Mail::Field::ParseError
+ false
+ end
+
+ def storage_issues(name, settings)
+ return settings[:root].present? ? [] : [ :root ] if name.in?(%w[local test])
+
+ issues = []
+ issues << :bucket if settings[:bucket].blank?
+ if name.in?(%w[amazon cloudflare generic_s3])
+ issues << :region if settings[:region].blank?
+ if settings[:access_key_id].present? != settings[:secret_access_key].present?
+ issues << :credentials
+ end
+ end
+ if name.in?(%w[cloudflare generic_s3])
+ if settings[:endpoint].blank? || settings[:endpoint] == "https://.r2.cloudflarestorage.com"
+ issues << :endpoint
+ end
+ end
+ issues
+ end
+
+ def provider_statuses(concept, names)
+ registry = Provider::Registry.for_concept(concept)
+ names.uniq.map do |name|
+ # Never display an arbitrary ENV/setting value (it may contain an
+ # accidentally pasted credential), or resolve outside this concept.
+ key = registry.provider_keys.find { |candidate| candidate.to_s == name }
+ next ProviderStatus.new(key: :unknown, status: :invalid) unless key
+
+ status = registry.get_provider(key).present? ? :configured : :not_configured
+ ProviderStatus.new(key: key, status: status)
+ end
+ end
+
+ def provider_status(providers, empty_status: :not_configured)
+ return empty_status if providers.empty?
+ return :configured if providers.all? { |provider| provider.status == :configured }
+ return :incomplete if providers.any? { |provider| provider.status.in?([ :configured, :invalid ]) }
+
+ :not_configured
+ end
+end
diff --git a/app/models/configuration_health/optional_services.rb b/app/models/configuration_health/optional_services.rb
new file mode 100644
index 0000000000..41a34f4339
--- /dev/null
+++ b/app/models/configuration_health/optional_services.rb
@@ -0,0 +1,94 @@
+# frozen_string_literal: true
+
+# Configuration-only checks for optional operator integrations. This class never
+# initializes a client, sends a test event, or changes telemetry consent.
+class ConfigurationHealth::OptionalServices
+ Service = Data.define(:key, :status, :settings, :notes) do
+ def tone
+ status == :incomplete ? :warning : :neutral
+ end
+ end
+
+ LANGFUSE_KEYS = %w[LANGFUSE_PUBLIC_KEY LANGFUSE_SECRET_KEY].freeze
+ STRIPE_KEYS = %w[STRIPE_SECRET_KEY STRIPE_WEBHOOK_SECRET].freeze
+ STRIPE_PRICES = %w[STRIPE_MONTHLY_PRICE_ID STRIPE_ANNUAL_PRICE_ID].freeze
+ LOGTAIL_KEYS = %w[LOGTAIL_API_KEY LOGTAIL_INGESTING_HOST].freeze
+
+ # Returns only static identifiers and status metadata, never setting values.
+ def checks
+ [ langfuse, sentry, skylight, stripe, posthog, logtail ]
+ end
+
+ def langfuse
+ environment_service(:langfuse, LANGFUSE_KEYS)
+ end
+
+ def sentry
+ config = Sentry.configuration
+ return service(:sentry, :not_configured) unless config&.dsn.present?
+ return service(:sentry, :disabled, notes: [ :environment_disabled ]) unless config.enabled_in_current_env?
+
+ service(:sentry, :configured)
+ end
+
+ def skylight
+ if ENV["SKYLIGHT_ENABLED"]&.match?(/\Afalse\z/i)
+ return service(:skylight, :disabled, notes: [ :explicitly_disabled ])
+ end
+ environment_service(:skylight, %w[SKYLIGHT_AUTHENTICATION], intended: ENV["SKYLIGHT_ENABLED"].present?)
+ end
+
+ def stripe
+ # Self-hosted subscription checkout is disabled, but webhook processing can
+ # still use Stripe. Price IDs are required only for the managed checkout UI.
+ self_hosted = Rails.application.config.app_mode.self_hosted?
+ required = self_hosted ? STRIPE_KEYS : STRIPE_KEYS + STRIPE_PRICES
+ notes = self_hosted ? [ :self_hosted_checkout_disabled ] : []
+ environment_service(:stripe, required, intended: STRIPE_PRICES.any? { |key| ENV[key].present? }, notes: notes)
+ end
+
+ def posthog
+ # Use the boot-loaded values also used by the shared head and feedback helper.
+ # The server client is not gated by the browser's production/development rule.
+ config = Rails.configuration.x.posthog
+ status = if config.api_key.blank?
+ :not_configured
+ elsif config.host.blank?
+ :incomplete
+ else
+ :configured
+ end
+ browser_enabled = config.browser_enabled?
+ notes = browser_enabled ? [] : [ :browser_analytics_disabled ]
+ if Rails.application.config.app_mode.self_hosted?
+ notes << (browser_enabled && config.feedback_enabled ? :shared_feedback_configured : :shared_feedback_disabled)
+ end
+ settings = status == :incomplete ? %w[POSTHOG_HOST] : []
+ service(:posthog, status, settings: settings, notes: notes)
+ end
+
+ def logtail
+ result = environment_service(:logtail, LOGTAIL_KEYS)
+ return result unless result.status == :configured
+ return service(:logtail, :disabled, notes: [ :production_only ]) unless Rails.env.production?
+
+ result
+ end
+
+ private
+ def service(key, status, settings: [], notes: [])
+ Service.new(key: key, status: status, settings: settings, notes: notes)
+ end
+
+ def environment_service(key, required, intended: false, notes: [])
+ missing = required.select { |name| ENV[name].blank? }
+ status = if missing.empty?
+ :configured
+ elsif missing.length == required.length && !intended
+ :not_configured
+ else
+ :incomplete
+ end
+ service(key, status, settings: status == :incomplete ? missing : [], notes: notes)
+ end
+end
diff --git a/app/views/admin/system_health/_configuration.html.erb b/app/views/admin/system_health/_configuration.html.erb
new file mode 100644
index 0000000000..12cdc0fa9d
--- /dev/null
+++ b/app/views/admin/system_health/_configuration.html.erb
@@ -0,0 +1,46 @@
+<div class="space-y-4" data-testid="configuration-health">
+ <p class="text-sm text-secondary"><%= t(".description") %></p>
+
+ <% health.checks.each do |check| %>
+ <%= render DS::Card.new(class: "gap-4", data: { testid: "configuration-#{check.key}" }) do %>
+ <div class="flex items-start justify-between gap-2">
+ <h2 class="min-w-0 text-lg font-semibold text-primary"><%= t(".checks.#{check.key}.title") %></h2>
+ <div class="shrink-0"><%= render DS::Pill.new(label: t(".statuses.#{check.status}"), tone: check.tone, marker: false) %></div>
+ </div>
+ <p class="text-sm text-secondary"><%= t(".checks.#{check.key}.statuses.#{check.status}") %></p>
+
+ <% if check.backend %>
+ <p class="text-sm text-primary"><%= t(".storage_backend", backend: t(".storage_backends.#{check.backend}")) %></p>
+ <% end %>
+
+ <% if check.issues.any? %>
+ <div class="space-y-2 text-sm">
+ <p class="font-medium text-primary"><%= t(".settings_needed") %></p>
+ <ul class="list-disc pl-5 text-secondary">
+ <% check.issues.each do |issue| %>
+ <li><%= configuration_health_text(t(".checks.#{check.key}.issues.#{issue}")) %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <% if check.providers.any? %>
+ <dl class="space-y-2 text-sm">
+ <% check.providers.each do |provider| %>
+ <%= render DS::DetailRow.new(
+ label: provider.key == :unknown ? t(".unknown_provider") : t("settings.hostings.provider_selection.providers.#{provider.key}"),
+ value: t(".provider_statuses.#{provider.status}"),
+ align: :center) %>
+ <% end %>
+ </dl>
+ <% end %>
+
+ <p class="text-sm text-secondary"><%= configuration_health_text(t(".checks.#{check.key}.guidance")) %></p>
+ <% if self_hosted? && check.key.in?(%i[securities exchange_rates]) %>
+ <%= render DS::Link.new(text: t(".configure_providers"), href: settings_hosting_path) %>
+ <% end %>
+ <% end %>
+ <% end %>
+
+ <%= render "optional_services", services: health.optional_services %>
+</div>
diff --git a/app/views/admin/system_health/_optional_services.html.erb b/app/views/admin/system_health/_optional_services.html.erb
new file mode 100644
index 0000000000..74b28fc039
--- /dev/null
+++ b/app/views/admin/system_health/_optional_services.html.erb
@@ -0,0 +1,31 @@
+<%= render DS::Card.new(class: "gap-4", data: { testid: "optional-services" }) do %>
+ <div>
+ <h2 class="text-lg font-semibold text-primary"><%= t(".title") %></h2>
+ <p class="mt-1 text-sm text-secondary"><%= t(".description") %></p>
+ </div>
+
+ <% services.each do |service| %>
+ <%= render DS::Disclosure.new(data: { testid: "optional-service-#{service.key}" }) do |disclosure| %>
+ <% disclosure.with_summary_content do %>
+ <div class="flex items-center gap-2">
+ <%= icon "chevron-right", class: "group-open:rotate-90 motion-safe:transition-transform" %>
+ <span class="font-medium text-sm text-primary"><%= t(".services.#{service.key}.title") %></span>
+ </div>
+ <% unless service.status == :not_configured %>
+ <%= render DS::Pill.new(label: t(".statuses.#{service.status}"), tone: service.tone, marker: false) %>
+ <% end %>
+ <% end %>
+
+ <div class="space-y-2 px-3 text-sm text-secondary">
+ <p><%= t(".services.#{service.key}.description") %></p>
+ <% service.notes.each do |note| %>
+ <p><%= configuration_health_text(t(".notes.#{note}")) %></p>
+ <% end %>
+ <% if service.settings.any? %>
+ <p><%= configuration_health_text(t(".missing_settings", settings: service.settings.join(", "))) %></p>
+ <% end %>
+ <p><%= configuration_health_text(t(".services.#{service.key}.guidance")) %></p>
+ </div>
+ <% end %>
+ <% end %>
+<% end %>
diff --git a/app/views/admin/system_health/show.html.erb b/app/views/admin/system_health/show.html.erb
index 3032669ed6..9560171a07 100644
--- a/app/views/admin/system_health/show.html.erb
+++ b/app/views/admin/system_health/show.html.erb
@@ -8,6 +8,7 @@
<% tabs.with_nav do |nav| %>
<% nav.with_btn(id: "background_jobs", label: t(".tabs.background_jobs")) %>
<% nav.with_btn(id: "ai", label: t(".tabs.ai")) %>
+ <% nav.with_btn(id: "configuration", label: t(".tabs.configuration")) %>
<% if @hosted_usage_available %>
<% nav.with_btn(id: "hosted_usage", label: t(".tabs.hosted_usage")) %>
<% end %>
@@ -32,6 +33,10 @@
<% end %>
<% end %>
+ <% tabs.with_panel(tab_id: "configuration") do %>
+ <%= render "configuration", health: @configuration_health %>
+ <% end %>
+
<% if @hosted_usage_available %>
<% tabs.with_panel(tab_id: "hosted_usage") do %>
<%= turbo_frame_tag "hosted_usage",
diff --git a/config/initializers/posthog.rb b/config/initializers/posthog.rb
index 43d5a5a1d3..125853e07f 100644
--- a/config/initializers/posthog.rb
+++ b/config/initializers/posthog.rb
@@ -3,6 +3,11 @@ require "posthog"
Rails.configuration.x.posthog = ActiveSupport::OrderedOptions.new
# Explicit opt-in for local analytics testing; production remains enabled.
Rails.configuration.x.posthog.development_enabled = ActiveModel::Type::Boolean.new.cast(ENV.fetch("POSTHOG_DEVELOPMENT_ENABLED", "false"))
+# One environment gate for browser analytics, feedback, and configuration health.
+def (Rails.configuration.x.posthog).browser_enabled?
+ Rails.env.production? || (Rails.env.development? && development_enabled)
+end
+
Rails.configuration.x.posthog.api_key = ENV["POSTHOG_KEY"].presence
Rails.configuration.x.posthog.host = ENV.fetch("POSTHOG_HOST", "https://us.i.posthog.com")
Rails.configuration.x.posthog.feedback_enabled = ActiveModel::Type::Boolean.new.cast(ENV.fetch("POSTHOG_FEEDBACK_ENABLED", "true"))
@@ -34,7 +39,7 @@ end
# Daily UI usage shares the bundled feedback destination, independently of any
# installation-owned analytics project. Capture also checks these gates.
feedback_config = Rails.configuration.x.posthog
-if feedback_config.feedback_enabled && (Rails.env.production? || (Rails.env.development? && feedback_config.development_enabled))
+if feedback_config.feedback_enabled && feedback_config.browser_enabled?
$posthog_feedback = PostHog::Client.new(
feedback_config.self_hosted_feedback_project.merge(
on_error: Proc.new { |status, _msg| Rails.logger.debug("PostHog feedback capture failed (status #{status})") }
diff --git a/config/locales/views/admin/system_health/de.yml b/config/locales/views/admin/system_health/de.yml
index 78d623a214..babda4d332 100644
--- a/config/locales/views/admin/system_health/de.yml
+++ b/config/locales/views/admin/system_health/de.yml
@@ -105,12 +105,126 @@ de:
body: "Dies ist eine Testbenachrichtigung für dein Sure-Konto."
verify_worker_ai:
queued: Die Worker-Prüfung wurde in die Warteschlange gestellt. Das Ergebnis erscheint unten, sobald ein Worker-Prozess die Prüfung übernimmt – normalerweise innerhalb weniger Sekunden.
+ optional_services:
+ title: Optionale Dienste
+ description: "Optionale Betreiber-Integrationen. Nicht konfigurierte Dienste sind Hinweise. Diese Prüfungen lesen nur Einstellungen; sie testen keine Verbindungen, senden keine Testereignisse und ändern keine Analytics-Einwilligung. Öffnen Sie einen Dienst für Einrichtungshinweise."
+ missing_settings: "Fehlende Einstellungen: %{settings}"
+ statuses:
+ configured: Konfiguriert
+ not_configured: Nicht konfiguriert
+ incomplete: Unvollständige Konfiguration
+ disabled: In diesem Prozess deaktiviert
+ not_checked: Nicht überprüft
+ notes:
+ environment_disabled: "Die geladene Integration ist für diese Rails-Umgebung deaktiviert."
+ explicitly_disabled: "SKYLIGHT_ENABLED deaktiviert die Instrumentierung ausdrücklich."
+ self_hosted_checkout_disabled: "Abonnement-Checkout und Abrechnungsportal sind im Self-Hosting-Modus deaktiviert. Stripe-Webhooks können weiterhin konfiguriert werden; Checkout-Preis-IDs sind hier nicht erforderlich."
+ browser_analytics_disabled: "Browser-Analytics sind für diese Umgebung deaktiviert. Dies deaktiviert den separat konfigurierten Server-Client nicht."
+ shared_feedback_configured: "Self-Hosting-Feedback hat ein separates mitgeliefertes Projekt und ist laut Konfiguration aktiviert. Ein eigener POSTHOG_KEY ist nicht erforderlich. Browser-Opt-out und SDK-Verfügbarkeit werden nicht überprüft."
+ shared_feedback_disabled: "Das separate Self-Hosting-Feedback-Projekt ist durch seine Feedback- oder Umgebungseinstellung deaktiviert. Eigene Betreiber-Analytics werden dadurch nicht deaktiviert."
+ production_only: "Diese Integration wird von der aktuellen Anwendungskonfiguration nur in Produktion verwendet."
+ services:
+ langfuse:
+ title: Langfuse
+ description: "Optionales KI-Tracing und Evaluierungsberichte. Diese Prüfung sendet keine Traces oder Evaluierungsanfragen."
+ guidance: "Setzen Sie LANGFUSE_PUBLIC_KEY und LANGFUSE_SECRET_KEY gemeinsam. LANGFUSE_HOST ist optional. Starten Sie betroffene Dienste nach Änderungen neu."
+ sentry:
+ title: Sentry
+ description: "Optionale Fehler- und Leistungsberichte. Der aktuelle Initializer aktiviert Berichte nur in Produktion."
+ guidance: "Setzen Sie SENTRY_DSN und starten Sie betroffene Dienste neu. Die geladene SDK-Konfiguration wird geprüft, ohne Fehler zu erfassen oder Ereignisse zu senden."
+ skylight:
+ title: Skylight
+ description: "Optionale Instrumentierung der Anwendungsleistung. Vorhandene Einstellungen bestätigen nicht, dass der Agent läuft oder Berichte sendet."
+ guidance: "Setzen Sie SKYLIGHT_AUTHENTICATION und stellen Sie sicher, dass Skylight in der vorgesehenen Rails-Umgebung geladen ist. SKYLIGHT_ENABLED=false deaktiviert die Instrumentierung; das Flag allein lädt das Gem nicht. Starten Sie nach Änderungen neu."
+ stripe:
+ title: Stripe
+ description: "Optionale Abonnementabrechnung und Zahlungs-Webhooks. Diese Prüfung erstellt keinen Stripe-Client, validiert keine Zugangsdaten und stellt keine Zahlungsanfragen."
+ guidance: "Setzen Sie STRIPE_SECRET_KEY und STRIPE_WEBHOOK_SECRET gemeinsam. Der verwaltete Abonnement-Checkout benötigt zusätzlich STRIPE_MONTHLY_PRICE_ID und STRIPE_ANNUAL_PRICE_ID."
+ posthog:
+ title: PostHog
+ description: "Optionale betreibereigene Analytics mit der beim Start geladenen Konfiguration. Konfiguriert bedeutet nicht, dass ein Benutzer Analytics zugestimmt hat."
+ guidance: "Setzen Sie POSTHOG_KEY und einen nicht leeren POSTHOG_HOST oder lassen Sie den Host für den Standardwert ungesetzt. Browser-Analytics benötigen Produktion oder POSTHOG_DEVELOPMENT_ENABLED in Entwicklung. POSTHOG_FEEDBACK_ENABLED steuert separates Self-Hosting-Feedback, nicht Betreiber-Analytics."
+ logtail:
+ title: Logtail
+ description: "Optionale Weiterleitung von Produktionslogs. Ohne Konfiguration protokolliert die Anwendung weiterhin über die Standardausgabe."
+ guidance: "Setzen Sie LOGTAIL_API_KEY und LOGTAIL_INGESTING_HOST gemeinsam und starten Sie betroffene Dienste neu. Diese Prüfung erzeugt keinen Test-Logeintrag."
+ configuration:
+ description: "Die für diesen Web-Prozess sichtbare Konfiguration. Diese Prüfungen versenden keine E-Mails, kontaktieren keine Anbieter und laden keine Dateien hoch oder herunter. Konfiguriert bedeutet, dass Einstellungen vorhanden sind. Zustellung, Anbieterzugriff und Speicherzugriff wurden damit nicht überprüft."
+ statuses:
+ configured: Konfiguriert
+ not_configured: Nicht konfiguriert
+ incomplete: Unvollständige Konfiguration
+ disabled: Deaktiviert
+ not_checked: Nicht überprüft
+ settings_needed: Zu prüfende Einstellungen
+ unknown_provider: Unbekannte Anbieterauswahl
+ provider_statuses:
+ configured: Konfiguriert
+ not_configured: API-Schlüssel fehlt
+ invalid: Ungültige Auswahl
+ configure_providers: Self-Hosting-Einstellungen öffnen
+ storage_backend: "Ausgewählter Speicher: %{backend}"
+ storage_backends:
+ local: Lokaler Datenträger
+ test: Test-Datenträger
+ amazon: Amazon S3
+ cloudflare: Cloudflare R2
+ generic_s3: S3-kompatibler Speicher
+ google: Google Cloud Storage
+ other: Benutzerdefinierter oder unbekannter Speicher
+ checks:
+ smtp:
+ title: E-Mail (SMTP)
+ statuses:
+ configured: "SMTP-Einstellungen sind vorhanden."
+ not_configured: "SMTP ist nicht konfiguriert. Passwort-Zurücksetzungen, Einladungen und andere System-E-Mails können nicht über SMTP versendet werden."
+ incomplete: "Einige E-Mail-Einstellungen fehlen oder sind unvollständig. System-E-Mails oder darin enthaltene Links funktionieren möglicherweise nicht."
+ disabled: "Der E-Mail-Versand ist in der laufenden Mailer-Konfiguration deaktiviert."
+ not_checked: "Dieser Prozess verwendet eine andere Versandmethode als SMTP, beispielsweise eine Entwicklungsvorschau. Der SMTP-Versand wird nicht beurteilt."
+ guidance: "SMTP kann nicht in der Verwaltungsoberfläche konfiguriert werden. Setzen Sie die E-Mail-Umgebungsvariablen für den Web- und den Worker-Dienst und starten Sie beide neu. Für ein Relay ohne Authentifizierung können SMTP_USERNAME und SMTP_PASSWORD beide entfallen."
+ issues:
+ address: SMTP_ADDRESS
+ port: SMTP_PORT (eine Zahl von 1 bis 65535)
+ sender: EMAIL_SENDER (den Standard [email protected] ersetzen)
+ app_domain: APP_DOMAIN (für Links in E-Mails)
+ authentication: SMTP_USERNAME und SMTP_PASSWORD (beide oder keines angeben)
+ securities:
+ title: Marktpreise
+ statuses:
+ configured: "Alle aktivierten Marktpreisanbieter sind konfiguriert."
+ not_configured: "Bei den aktivierten Marktpreisanbietern fehlen die API-Schlüssel. Automatische Wertpapiersuchen und Preisabfragen sind über diese Anbieter nicht verfügbar."
+ incomplete: "Bei mindestens einem aktivierten Marktpreisanbieter fehlt die Konfiguration oder die Auswahl ist ungültig. Zugeordnete Wertpapiere erhalten möglicherweise keine Preisaktualisierungen."
+ disabled: "Kein Marktpreisanbieter ist aktiviert. Automatische Wertpapiersuchen und Preisabfragen sind nicht verfügbar."
+ guidance: "Wählen Sie Anbieter und ergänzen Sie erforderliche API-Schlüssel in den Self-Hosting-Einstellungen oder in der Bereitstellungsumgebung. Umgebungsvariablen haben Vorrang. Öffentliche Anbieter benötigen keinen API-Schlüssel."
+ exchange_rates:
+ title: Wechselkurse
+ statuses:
+ configured: "Der ausgewählte Wechselkursanbieter ist konfiguriert."
+ not_configured: "Kein nutzbarer Wechselkursanbieter ist konfiguriert. Automatische Währungsumrechnung ist möglicherweise nicht verfügbar, wenn ein gespeicherter Kurs fehlt."
+ guidance: "Wählen Sie einen Wechselkursanbieter und ergänzen Sie bei Bedarf dessen API-Schlüssel in den Self-Hosting-Einstellungen oder in der Bereitstellungsumgebung. EXCHANGE_RATE_PROVIDER und Umgebungsvariablen für API-Schlüssel haben Vorrang."
+ issues:
+ invalid_provider: "Der ausgewählte Wechselkursanbieter wird nicht erkannt. Automatische Kursabfragen schlagen fehl, bis ein unterstützter Anbieter ausgewählt wird."
+ storage:
+ title: Datei-Uploads und Speicher
+ statuses:
+ configured: "Speichereinstellungen sind vorhanden; lokaler Speicher benötigt keine Cloud-Zugangsdaten."
+ not_configured: "Für den ausgewählten Speicher ist keine passende Konfiguration vorhanden. Datei-Uploads sind möglicherweise nicht verfügbar."
+ incomplete: "Erforderliche Speichereinstellungen fehlen oder sind unvollständig. Datei-Uploads oder Abrufe funktionieren möglicherweise nicht."
+ not_checked: "Dieser Speicher verwendet eine externe Zugangsdatenquelle oder eine benutzerdefinierte Konfiguration. Der Zugriff lässt sich allein anhand dieser Einstellungen nicht beurteilen."
+ guidance: "Prüfen Sie ACTIVE_STORAGE_SERVICE und die Bereitstellungseinstellungen des gewählten Speichers. Lokaler Speicher muss dauerhaft und für Web- und Worker-Dienst gemeinsam verfügbar sein. Ein Speicherwechsel verschiebt bestehende Dateien nicht; planen Sie eine Migration gesondert."
+ issues:
+ root: Stammverzeichnis des lokalen Speichers
+ bucket: Speicher-Bucket
+ region: Speicherregion
+ credentials: Zugriffsschlüssel und geheimer Schlüssel (beide angeben oder externe Zugangsdatenquelle verwenden)
+ endpoint: Speicher-Endpunkt (und CLOUDFLARE_ACCOUNT_ID für R2)
show:
title: Systemstatus
tabs:
- hosted_usage: "Hosting-Nutzung"
- background_jobs: Hintergrundaufgaben
- ai: KI-Status
+ hosted_usage: "Nutzung"
+ background_jobs: "Jobs"
+ ai: "KI"
+ configuration: "Konfig."
alert:
title: Hintergrundaufgaben werden nicht ausgeführt
status_section_title: Sidekiq-Status
diff --git a/config/locales/views/admin/system_health/en.yml b/config/locales/views/admin/system_health/en.yml
index e6d318e26a..3298b65426 100644
--- a/config/locales/views/admin/system_health/en.yml
+++ b/config/locales/views/admin/system_health/en.yml
@@ -105,12 +105,126 @@ en:
body: "This is a test push notification for your Sure account."
verify_worker_ai:
queued: "Worker check queued. It will appear below once a worker process picks it up, usually within a few seconds."
+ optional_services:
+ title: Optional services
+ description: "Optional operator integrations. Unconfigured services are informational. These checks inspect settings only; they do not test connectivity, send test events, or change analytics consent. Expand a service for setup details."
+ missing_settings: "Missing settings: %{settings}"
+ statuses:
+ configured: Configured
+ not_configured: Not configured
+ incomplete: Incomplete configuration
+ disabled: Disabled in this process
+ not_checked: Not verified
+ notes:
+ environment_disabled: "The loaded integration is disabled for this Rails environment."
+ explicitly_disabled: "SKYLIGHT_ENABLED explicitly disables instrumentation."
+ self_hosted_checkout_disabled: "Subscription checkout and the billing portal are disabled in self-hosted mode. Stripe webhooks can still be configured; checkout price IDs are not required here."
+ browser_analytics_disabled: "Browser analytics are disabled for this environment. This does not disable the separately configured server client."
+ shared_feedback_configured: "Self-hosted feedback has a separate bundled project and is enabled by its configuration. It does not require an operator POSTHOG_KEY. Browser opt-out and SDK availability are not checked."
+ shared_feedback_disabled: "The separate self-hosted feedback project is disabled by its feedback or environment setting. This does not disable operator-owned analytics."
+ production_only: "This integration is used only in production by the application's current configuration."
+ services:
+ langfuse:
+ title: Langfuse
+ description: "Optional AI tracing and evaluation reporting. No traces or evaluation requests are sent by this check."
+ guidance: "Set LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY together. LANGFUSE_HOST is optional. Restart the affected services after changing these settings."
+ sentry:
+ title: Sentry
+ description: "Optional error and performance reporting. The current initializer enables reporting only in production."
+ guidance: "Set SENTRY_DSN and restart the affected services. This checks the loaded SDK configuration without capturing an error or sending an event."
+ skylight:
+ title: Skylight
+ description: "Optional application performance instrumentation. Configuration presence does not confirm that the agent is running or reporting."
+ guidance: "Set SKYLIGHT_AUTHENTICATION and ensure Skylight is loaded in the intended Rails environment. SKYLIGHT_ENABLED=false disables instrumentation; the flag alone does not load the gem. Restart after changes."
+ stripe:
+ title: Stripe
+ description: "Optional subscription billing and payment webhooks. This check does not create a Stripe client, validate credentials, or make payment requests."
+ guidance: "Set STRIPE_SECRET_KEY and STRIPE_WEBHOOK_SECRET together. Managed subscription checkout also needs STRIPE_MONTHLY_PRICE_ID and STRIPE_ANNUAL_PRICE_ID."
+ posthog:
+ title: PostHog
+ description: "Optional operator-owned analytics, using the configuration loaded at boot. Configured does not mean that a user has consented to analytics."
+ guidance: "Set POSTHOG_KEY and a nonblank POSTHOG_HOST, or leave the host unset to use the default. Browser analytics require production or POSTHOG_DEVELOPMENT_ENABLED in development. POSTHOG_FEEDBACK_ENABLED controls separate self-hosted feedback, not operator analytics."
+ logtail:
+ title: Logtail
+ description: "Optional production log forwarding. When it is unconfigured, the application continues logging to standard output."
+ guidance: "Set LOGTAIL_API_KEY and LOGTAIL_INGESTING_HOST together and restart the affected services. No test log is emitted by this check."
+ configuration:
+ description: "Configuration visible to this web process. These checks do not send emails, contact providers, or upload or download files. Configured means settings are present, not that delivery, provider access, or storage access has been verified."
+ statuses:
+ configured: Configured
+ not_configured: Not configured
+ incomplete: Incomplete configuration
+ disabled: Disabled
+ not_checked: Not verified
+ settings_needed: Settings to review
+ unknown_provider: Unrecognized provider selection
+ provider_statuses:
+ configured: Configured
+ not_configured: API key missing
+ invalid: Invalid selection
+ configure_providers: Open self-hosting settings
+ storage_backend: "Selected storage: %{backend}"
+ storage_backends:
+ local: Local disk
+ test: Test disk
+ amazon: Amazon S3
+ cloudflare: Cloudflare R2
+ generic_s3: S3-compatible storage
+ google: Google Cloud Storage
+ other: Custom or unrecognized backend
+ checks:
+ smtp:
+ title: Email (SMTP)
+ statuses:
+ configured: "SMTP settings are present."
+ not_configured: "SMTP is not configured. Password resets, invitations, and other system emails cannot be sent through SMTP."
+ incomplete: "Some email settings are missing or incomplete. System emails or the links they contain may not work."
+ disabled: "Email delivery is disabled in the running mailer configuration."
+ not_checked: "This process uses a delivery method other than SMTP, such as a development preview. SMTP delivery is not assessed."
+ guidance: "SMTP cannot be configured in the admin UI. Set the email environment variables for both the web and worker services, then restart both. SMTP_USERNAME and SMTP_PASSWORD can both be omitted for an unauthenticated relay."
+ issues:
+ address: SMTP_ADDRESS
+ port: SMTP_PORT (a number from 1 to 65535)
+ sender: EMAIL_SENDER (replace the default [email protected])
+ app_domain: APP_DOMAIN (used in email links)
+ authentication: SMTP_USERNAME and SMTP_PASSWORD (supply both or neither)
+ securities:
+ title: Market prices
+ statuses:
+ configured: "All enabled market-price providers have configuration."
+ not_configured: "The enabled market-price providers are missing their API keys. Automatic security searches and price lookups are unavailable through these providers."
+ incomplete: "At least one enabled market-price provider has missing configuration or an invalid selection. Securities assigned to that provider may not receive price updates."
+ disabled: "No market-price provider is enabled. Automatic security searches and price lookups are unavailable."
+ guidance: "Choose providers and add any required API keys in self-hosting settings, or configure them in the deployment environment. Environment overrides take precedence. Public providers do not need an API key."
+ exchange_rates:
+ title: Foreign exchange rates
+ statuses:
+ configured: "The selected exchange-rate provider has configuration."
+ not_configured: "No usable exchange-rate provider is configured. Automatic currency conversion may be unavailable when a stored rate is missing."
+ guidance: "Choose an exchange-rate provider and add its API key if required in self-hosting settings, or configure it in the deployment environment. EXCHANGE_RATE_PROVIDER and provider API-key environment overrides take precedence."
+ issues:
+ invalid_provider: "The selected exchange-rate provider is not recognized. Automatic rate lookups fail until a supported provider is selected."
+ storage:
+ title: File uploads and storage
+ statuses:
+ configured: "Storage settings are present; local disk needs no cloud credentials."
+ not_configured: "The selected storage backend has no matching configuration. File uploads may be unavailable."
+ incomplete: "Required storage settings are missing or incomplete. File uploads or retrieval may not work."
+ not_checked: "This backend uses external credential discovery or a custom configuration. Its access cannot be determined from these settings alone."
+ guidance: "Review ACTIVE_STORAGE_SERVICE and the selected backend's deployment settings. Local disk needs persistent storage shared by the web and worker services. Changing backends does not migrate existing files; plan any migration separately."
+ issues:
+ root: Local storage root
+ bucket: Storage bucket
+ region: Storage region
+ credentials: Storage access key and secret key (supply both or use external credential discovery)
+ endpoint: Storage endpoint (and CLOUDFLARE_ACCOUNT_ID for R2)
show:
title: System health
tabs:
- hosted_usage: "Hosted usage"
- background_jobs: Background jobs
- ai: AI status
+ hosted_usage: "Usage"
+ background_jobs: "Jobs"
+ ai: "AI"
+ configuration: "Config"
alert:
title: Background jobs aren't running
status_section_title: Sidekiq status
diff --git a/test/controllers/admin/system_health_controller_test.rb b/test/controllers/admin/system_health_controller_test.rb
index f98cbf1f60..22c612f50c 100644
--- a/test/controllers/admin/system_health_controller_test.rb
+++ b/test/controllers/admin/system_health_controller_test.rb
@@ -45,7 +45,7 @@ class Admin::SystemHealthControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_match(/Sidekiq status/, response.body)
assert_match(/Healthy/, response.body)
- assert_select "button[role='tab']", text: "AI status"
+ assert_select "button[role='tab']", text: "AI"
# Nothing in the queue table takes focus, so on a narrow screen the scroll
# area has to be a named tab stop of its own for a keyboard to scroll it.
assert_select "[role='region'][aria-label='Queues']"
@@ -73,7 +73,7 @@ class Admin::SystemHealthControllerTest < ActionDispatch::IntegrationTest
test "German background job translations are present without fallback" do
keys = %w[
- title tabs.background_jobs tabs.ai alert.title
+ title tabs.background_jobs tabs.ai tabs.configuration alert.title
status_section_title status_section_description counters_section_title
counters_section_description queues_section_title queues_section_description
labels.status labels.processes labels.last_heartbeat labels.max_queue_latency
@@ -103,8 +103,8 @@ class Admin::SystemHealthControllerTest < ActionDispatch::IntegrationTest
assert_response :success
assert_select "h1", text: "Systemstatus"
- assert_select "button[role='tab'][aria-selected='true']", text: "Hintergrundaufgaben"
- assert_select "button[role='tab']", text: "KI-Status"
+ assert_select "button[role='tab'][aria-selected='true']", text: "Jobs"
+ assert_select "button[role='tab']", text: "KI"
assert_select "h2", text: "Sidekiq-Status"
assert_select "h2", text: "Aufgabenstatistik"
assert_select "h2", text: "Warteschlangen"
@@ -208,7 +208,7 @@ class Admin::SystemHealthControllerTest < ActionDispatch::IntegrationTest
AiHealth::Probe.any_instance.expects(:openai_vector_store).never
with_ai_environment("OPENAI_ACCESS_TOKEN" => "sk-secret-openai") do
- { "background_jobs" => "Background jobs", "ai" => "AI status" }.each do |tab, label|
+ { "background_jobs" => "Jobs", "ai" => "AI", "configuration" => "Config" }.each do |tab, label|
get admin_system_health_url(tab: tab)
assert_response :success
@@ -817,6 +817,190 @@ class Admin::SystemHealthControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to root_path
end
+ test "configuration tab reports missing email and provider configuration without secrets or probes" do
+ sign_in users(:sure_support_staff)
+ stub_healthy_sidekiq
+ ApplicationMailer.stubs(:perform_deliveries).returns(true)
+ ApplicationMailer.stubs(:delivery_method).returns(:smtp)
+ ApplicationMailer.stubs(:smtp_settings).returns({ address: nil, port: nil, password: "smtp-secret" })
+ ApplicationMailer.stubs(:default).returns({ from: "Sure <[email protected]>" })
+ ApplicationMailer.stubs(:default_url_options).returns({})
+ Setting.stubs(:enabled_securities_providers).returns([ "twelve_data", "yahoo_finance" ])
+ Setting.stubs(:twelve_data_api_key).returns(nil)
+ Setting.stubs(:exchange_rate_provider).returns("twelve_data")
+ Provider::TwelveData.any_instance.expects(:usage).never
+ Provider::YahooFinance.any_instance.expects(:health_status).never
+ AiHealth.expects(:new).never
+
+ ClimateControl.modify("TWELVE_DATA_API_KEY" => nil, "EXCHANGE_RATE_PROVIDER" => nil) do
+ get admin_system_health_url(tab: "configuration")
+ end
+
+ assert_response :success
+ assert_select "button[role='tab'][aria-selected='true']", text: "Config"
+ assert_select "[data-testid='configuration-smtp']" do
+ assert_select "h2", text: "Email (SMTP)"
+ assert_select "li", text: "SMTP_ADDRESS"
+ assert_match(/SMTP cannot be configured in the admin UI/, response.body)
+ end
+ assert_select "[data-testid='configuration-securities']" do
+ assert_select "span", text: "Incomplete configuration"
+ assert_select "dt", text: "Twelve Data"
+ assert_select "dd", text: "API key missing"
+ assert_select "dt", text: "Yahoo Finance"
+ end
+ assert_select "[data-testid='configuration-exchange_rates']" do
+ assert_select "span", text: "Not configured"
+ end
+ assert_select "[data-testid='configuration-storage']"
+ assert_select "[data-testid='configuration-smtp'] code", text: "SMTP_USERNAME"
+ assert_no_match(/smtp-secret/, response.body)
+ end
+
+ test "configuration tab does not expose configured mailer or storage values" do
+ sign_in users(:sure_support_staff)
+ stub_healthy_sidekiq
+ ApplicationMailer.stubs(:perform_deliveries).returns(true)
+ ApplicationMailer.stubs(:delivery_method).returns(:smtp)
+ ApplicationMailer.stubs(:smtp_settings).returns({
+ address: "smtp.private.test", port: 587, user_name: "private-user", password: "private-password"
+ })
+ ApplicationMailer.stubs(:default).returns({ from: "Sure <[email protected]>" })
+ ApplicationMailer.stubs(:default_url_options).returns({ host: "private-domain.test" })
+ Rails.application.config.active_storage.stubs(:service).returns(:generic_s3)
+ Rails.application.config.active_storage.stubs(:service_configurations).returns({
+ generic_s3: {
+ service: "S3", region: "private-region", bucket: "private-bucket", endpoint: "https://private-endpoint.test",
+ access_key_id: "private-access-key", secret_access_key: "private-secret"
+ }
+ })
+
+ get admin_system_health_url(tab: "configuration")
+
+ assert_response :success
+ assert_select "[data-testid='configuration-smtp'] span", text: "Configured"
+ assert_select "[data-testid='configuration-storage'] span", text: "Configured"
+ assert_no_match(/private-|smtp.private.test/, response.body)
+ end
+
+ test "German configuration tab has localized copy without fallback" do
+ sign_in users(:sure_support_staff)
+ stub_healthy_sidekiq
+ get admin_system_health_url(tab: "configuration", locale: :de)
+
+ assert_response :success
+ assert_select "button[role='tab'][aria-selected='true']", text: "Konfig."
+ assert_select "[data-testid='configuration-smtp'] h2", text: "E-Mail (SMTP)"
+ assert_select "[data-testid='configuration-securities'] h2", text: "Marktpreise"
+ assert_select "[data-testid='configuration-exchange_rates'] h2", text: "Wechselkurse"
+ assert_select "[data-testid='configuration-storage'] h2", text: "Datei-Uploads und Speicher"
+ end
+
+ test "optional services are at the bottom with neutral absent statuses and collapsed guidance" do
+ sign_in users(:sure_support_staff)
+ stub_healthy_sidekiq
+ get admin_system_health_url(tab: "configuration")
+
+ assert_response :success
+ assert_select "[data-testid='configuration-health'] > :last-child[data-testid='optional-services']" do
+ assert_select "h2", text: "Optional services"
+ assert_select "details:not([open])", count: 6
+ %w[Langfuse Sentry Skylight Stripe PostHog Logtail].each do |name|
+ assert_select "summary span", text: name
+ end
+ assert_select "input, form, button", count: 0
+ end
+ end
+
+ test "optional service rendering exposes no configured values and creates no clients" do
+ sign_in users(:sure_support_staff)
+ stub_healthy_sidekiq
+ Langfuse.stubs(:configuration).returns(OpenStruct.new(public_key: "optional-public-secret", secret_key: "optional-langfuse-secret"))
+ Sentry.stubs(:configuration).returns(OpenStruct.new(dsn: "optional-sentry-secret", enabled_in_current_env?: true))
+ Langfuse.expects(:new).never
+ Stripe::StripeClient.expects(:new).never
+ PostHog::Client.expects(:new).never
+ Sentry.expects(:capture_exception).never
+ Logtail::Logger.expects(:create_default_logger).never
+ posthog = Rails.configuration.x.posthog.clone
+ posthog.api_key = "optional-posthog-secret"
+ posthog.host = "https://optional-private-host.test"
+ Rails.configuration.x.stubs(:posthog).returns(posthog)
+
+ ClimateControl.modify(
+ "LANGFUSE_PUBLIC_KEY" => "optional-public-secret", "LANGFUSE_SECRET_KEY" => "optional-langfuse-secret",
+ "SKYLIGHT_AUTHENTICATION" => "optional-skylight-secret", "STRIPE_SECRET_KEY" => "optional-stripe-secret",
+ "STRIPE_WEBHOOK_SECRET" => "optional-webhook-secret", "STRIPE_MONTHLY_PRICE_ID" => "optional-monthly-secret",
+ "STRIPE_ANNUAL_PRICE_ID" => "optional-annual-secret", "LOGTAIL_API_KEY" => "optional-logtail-secret",
+ "LOGTAIL_INGESTING_HOST" => "optional-logtail-host"
+ ) do
+ get admin_system_health_url(tab: "configuration")
+ end
+
+ assert_response :success
+ assert_select "[data-testid='optional-services']" do |section|
+ assert_no_match(/optional-.*?(secret|host)/, section.first.to_html)
+ assert_select "[data-testid='optional-service-langfuse'] summary", text: /Configured/
+ assert_select "[data-testid='optional-service-stripe'] summary", text: /Configured/
+ end
+ end
+
+ test "German optional service copy renders with setup guidance" do
+ sign_in users(:sure_support_staff)
+ stub_healthy_sidekiq
+ get admin_system_health_url(tab: "configuration", locale: :de)
+
+ assert_response :success
+ assert_select "[data-testid='optional-services'] h2", text: "Optionale Dienste"
+ assert_select "[data-testid='optional-service-stripe'] p", text: /STRIPE_WEBHOOK_SECRET/
+ end
+
+ test "configuration translations exist in German without English fallback" do
+ paths = lambda do |tree, prefix|
+ tree.flat_map do |key, value|
+ path = "#{prefix}.#{key}"
+ value.is_a?(Hash) ? paths.call(value, path) : [ path ]
+ end
+ end
+ %w[configuration optional_services].each do |section|
+ prefix = "admin.system_health.#{section}"
+ paths.call(I18n.t(prefix, locale: :en), prefix).each do |key|
+ assert_kind_of String, I18n.t(key, locale: :de, fallback: false, default: nil), key
+ end
+ end
+ end
+
+ test "provider settings links belong only to the two provider cards in self hosted mode" do
+ sign_in users(:sure_support_staff)
+ stub_healthy_sidekiq
+ Rails.application.config.stubs(:app_mode).returns("self_hosted".inquiry)
+ ClimateControl.modify("EXCHANGE_RATE_PROVIDER" => "private-invalid-provider") do
+ get admin_system_health_url(tab: "configuration")
+ end
+ %w[securities exchange_rates].each do |key|
+ assert_select "[data-testid='configuration-#{key}'] a[href=?]", settings_hosting_path, count: 1
+ end
+ assert_select "[data-testid='configuration-health'] a[href=?]", settings_hosting_path, count: 2
+ assert_select "[data-testid='configuration-exchange_rates']" do
+ assert_select "span", text: "Not configured"
+ assert_select "li", text: /Automatic rate lookups fail/
+ end
+ assert_no_match(/private-invalid-provider/, response.body)
+ Rails.application.config.stubs(:app_mode).returns("managed".inquiry)
+ get admin_system_health_url(tab: "configuration")
+ assert_select "[data-testid='configuration-health'] a[href=?]", settings_hosting_path, count: 0
+ end
+
+ test "configuration tab preserves super admin authorization" do
+ ConfigurationHealth.expects(:new).never
+ get admin_system_health_url(tab: "configuration")
+ assert_redirected_to new_session_path
+
+ sign_in users(:family_admin)
+ get admin_system_health_url(tab: "configuration")
+ assert_redirected_to root_path
+ end
+
private
# Stubs Rails.cache with an in-process MemoryStore for the duration of
# the block. Test env normally runs a NullStore (see config/environments/test.rb),
diff --git a/test/controllers/admin/system_health_hosted_usage_test.rb b/test/controllers/admin/system_health_hosted_usage_test.rb
index 67a1a20cac..514aa51a36 100644
--- a/test/controllers/admin/system_health_hosted_usage_test.rb
+++ b/test/controllers/admin/system_health_hosted_usage_test.rb
@@ -18,11 +18,12 @@ class Admin::SystemHealthHostedUsageControllerTest < ActionDispatch::Integration
host! domain
sign_in @user
ClimateControl.modify("APP_DOMAIN" => domain) do
- %w[background_jobs ai hosted_usage].each do |tab|
+ %w[background_jobs ai configuration hosted_usage].each do |tab|
get admin_system_health_path(tab: tab)
assert_response :success
- assert_select "button[role='tab'][data-id='hosted_usage']", text: "Hosted usage"
+ assert_select "button[role='tab'][data-id='configuration']", text: "Config"
+ assert_select "button[role='tab'][data-id='hosted_usage']", text: "Usage"
assert_select "button[role='tab'][aria-selected='true'][data-id='#{tab}']"
assert_select "turbo-frame#hosted_usage[loading='lazy'][src='#{hosted_usage_admin_system_health_path}']"
assert_select "[data-testid='hosted-usage-report']", count: 0
@@ -190,7 +191,7 @@ class Admin::SystemHealthHostedUsageControllerTest < ActionDispatch::Integration
test "the hosted frame preserves valid locale overrides and drops invalid ones" do
ClimateControl.modify("APP_DOMAIN" => "app.sure.am") do
get admin_system_health_path(tab: "hosted_usage", locale: "de")
- assert_select "button[role='tab'][aria-selected='true']", text: "Hosting-Nutzung"
+ assert_select "button[role='tab'][aria-selected='true']", text: "Nutzung"
assert_select "turbo-frame#hosted_usage[src='#{hosted_usage_admin_system_health_path(locale: "de")}']"
[ "xx", { "x" => "de" } ].each do |locale|
diff --git a/test/controllers/admin/system_health_push_notifications_test.rb b/test/controllers/admin/system_health_push_notifications_test.rb
index 7f0c6698d2..484a040dc7 100644
--- a/test/controllers/admin/system_health_push_notifications_test.rb
+++ b/test/controllers/admin/system_health_push_notifications_test.rb
@@ -12,7 +12,7 @@ class Admin::SystemHealthPushNotificationsTest < ActionDispatch::IntegrationTest
test "button is disabled until this super admin registers a device" do
get admin_system_health_url(tab: "background_jobs")
assert_response :success
- assert_select "button[role='tab']", count: 2
+ assert_select "button[role='tab']", count: 3
assert_select "button[disabled][aria-describedby='push-notification-help']", text: "Send test push notification"
assert_match "Enable push notifications in the Sure iOS app", response.body
diff --git a/test/models/configuration_health/optional_services_test.rb b/test/models/configuration_health/optional_services_test.rb
new file mode 100644
index 0000000000..d9ebc9c360
--- /dev/null
+++ b/test/models/configuration_health/optional_services_test.rb
@@ -0,0 +1,205 @@
+require "test_helper"
+
+class ConfigurationHealth::OptionalServicesTest < ActiveSupport::TestCase
+ ENVIRONMENT = %w[
+ LANGFUSE_PUBLIC_KEY LANGFUSE_SECRET_KEY LANGFUSE_HOST SENTRY_DSN
+ SKYLIGHT_AUTHENTICATION SKYLIGHT_ENABLED STRIPE_SECRET_KEY STRIPE_WEBHOOK_SECRET
+ STRIPE_MONTHLY_PRICE_ID STRIPE_ANNUAL_PRICE_ID POSTHOG_KEY POSTHOG_HOST
+ POSTHOG_FEEDBACK_ENABLED POSTHOG_DEVELOPMENT_ENABLED LOGTAIL_API_KEY LOGTAIL_INGESTING_HOST
+ ].index_with(nil).freeze
+
+ setup do
+ @health = ConfigurationHealth::OptionalServices.new
+ @langfuse = OpenStruct.new(public_key: nil, secret_key: nil)
+ @posthog = Rails.configuration.x.posthog.clone
+ @posthog.api_key = nil
+ @posthog.host = "https://us.i.posthog.com"
+ @posthog.development_enabled = false
+ @posthog.feedback_enabled = true
+ Langfuse.stubs(:configuration).returns(@langfuse)
+ Sentry.stubs(:configuration).returns(nil)
+ Rails.configuration.x.stubs(:posthog).returns(@posthog)
+ Rails.application.config.stubs(:app_mode).returns("managed".inquiry)
+ Rails.stubs(:env).returns("test".inquiry)
+ end
+
+ test "absent optional services are informational and initialize no clients" do
+ Langfuse.expects(:new).never
+ Sentry.expects(:init).never
+ Sentry.expects(:capture_exception).never
+ Sentry.expects(:capture_message).never
+ Stripe::StripeClient.expects(:new).never
+ PostHog::Client.expects(:new).never
+ Logtail::Logger.expects(:create_default_logger).never
+
+ with_environment do
+ checks = @health.checks
+ assert_equal %i[langfuse sentry skylight stripe posthog logtail], checks.map(&:key)
+ assert checks.all? { |check| check.status == :not_configured }
+ assert checks.all? { |check| check.tone == :neutral }
+ assert checks.all? { |check| check.settings.empty? }
+ end
+ end
+
+ test "Langfuse host alone is optional and either single key is incomplete" do
+ with_environment("LANGFUSE_HOST" => "https://private-host.test") do
+ assert_equal :not_configured, @health.langfuse.status
+ end
+ %w[LANGFUSE_PUBLIC_KEY LANGFUSE_SECRET_KEY].each do |key|
+ with_environment(key => "private-value") do
+ check = @health.langfuse
+ assert_equal :incomplete, check.status
+ assert_equal [ (%w[LANGFUSE_PUBLIC_KEY LANGFUSE_SECRET_KEY] - [ key ]).first ], check.settings
+ assert_equal :warning, check.tone
+ assert_no_match(/private-value/, check.inspect)
+ end
+ end
+ end
+
+ test "Langfuse reports both environment keys without initializing a client" do
+ Langfuse.expects(:new).never
+ with_environment("LANGFUSE_PUBLIC_KEY" => "private-public", "LANGFUSE_SECRET_KEY" => "private-secret") do
+ assert_equal :configured, @health.langfuse.status
+ assert_no_match(/private-/, @health.langfuse.inspect)
+ end
+ end
+
+ test "Sentry reports its actual loaded configuration and enabled environment" do
+ config = Sentry::Configuration.new
+ config.dsn = "https://[email protected]/123"
+ config.enabled_environments = [ "production" ]
+ Sentry.stubs(:configuration).returns(config)
+
+ with_environment do
+ config.environment = "development"
+ assert_equal :disabled, @health.sentry.status
+ config.environment = "production"
+ assert_equal :configured, @health.sentry.status
+ assert_no_match(/private-key/, @health.sentry.inspect)
+ end
+ end
+
+ test "explicit Skylight false disables it even if authentication exists" do
+ with_environment("SKYLIGHT_AUTHENTICATION" => "private-token", "SKYLIGHT_ENABLED" => "FaLsE") do
+ assert_equal :disabled, @health.skylight.status
+ assert_equal [ :explicitly_disabled ], @health.skylight.notes
+ end
+ end
+
+ test "explicit Skylight opt in without authentication is incomplete" do
+ with_environment("SKYLIGHT_ENABLED" => "true") do
+ assert_equal :incomplete, @health.skylight.status
+ assert_equal [ "SKYLIGHT_AUTHENTICATION" ], @health.skylight.settings
+ end
+ end
+
+ test "Skylight reports configuration presence without reproducing SDK activation" do
+ with_environment("SKYLIGHT_AUTHENTICATION" => "private-token") do
+ assert_equal :configured, @health.skylight.status
+ assert_no_match(/private-token/, @health.skylight.inspect)
+ end
+ end
+
+ test "managed Stripe requires both credentials and both offered plan IDs" do
+ with_environment("STRIPE_SECRET_KEY" => "private-secret", "STRIPE_WEBHOOK_SECRET" => "private-webhook") do
+ check = @health.stripe
+ assert_equal :incomplete, check.status
+ assert_equal %w[STRIPE_MONTHLY_PRICE_ID STRIPE_ANNUAL_PRICE_ID], check.settings
+ end
+ with_environment(stripe_settings) do
+ assert_equal :configured, @health.stripe.status
+ assert_no_match(/private-/, @health.stripe.inspect)
+ end
+ with_environment(stripe_settings.merge("STRIPE_WEBHOOK_SECRET" => nil)) do
+ assert_equal [ "STRIPE_WEBHOOK_SECRET" ], @health.stripe.settings
+ end
+ end
+
+ test "self hosted Stripe does not require checkout prices or claim all processing is disabled" do
+ Rails.application.config.stubs(:app_mode).returns("self_hosted".inquiry)
+ with_environment do
+ assert_equal :not_configured, @health.stripe.status
+ assert_equal :neutral, @health.stripe.tone
+ assert_equal [ :self_hosted_checkout_disabled ], @health.stripe.notes
+ end
+ with_environment("STRIPE_SECRET_KEY" => "private-secret", "STRIPE_WEBHOOK_SECRET" => "private-webhook") do
+ assert_equal :configured, @health.stripe.status
+ assert_empty @health.stripe.settings
+ assert_equal [ :self_hosted_checkout_disabled ], @health.stripe.notes
+ end
+ end
+
+ test "Stripe price IDs alone still reveal missing credentials in self hosted mode" do
+ Rails.application.config.stubs(:app_mode).returns("self_hosted".inquiry)
+ with_environment("STRIPE_MONTHLY_PRICE_ID" => "private-price") do
+ assert_equal :incomplete, @health.stripe.status
+ assert_equal %w[STRIPE_SECRET_KEY STRIPE_WEBHOOK_SECRET], @health.stripe.settings
+ end
+ end
+
+ test "PostHog reads boot loaded settings rather than later environment changes" do
+ with_environment("POSTHOG_KEY" => "later-key", "POSTHOG_HOST" => "https://later-host.test") do
+ assert_equal :not_configured, @health.posthog.status
+ end
+ @posthog.api_key = "private-key"
+ with_environment do
+ assert_equal :configured, @health.posthog.status
+ assert_no_match(/private-key/, @health.posthog.inspect)
+ @posthog.host = ""
+ assert_equal :incomplete, @health.posthog.status
+ assert_equal [ "POSTHOG_HOST" ], @health.posthog.settings
+ end
+ end
+
+ test "PostHog browser gating does not misreport the server client as disabled" do
+ @posthog.api_key = "private-key"
+ with_environment do
+ assert_equal :configured, @health.posthog.status
+ assert_includes @health.posthog.notes, :browser_analytics_disabled
+ Rails.stubs(:env).returns("production".inquiry)
+ assert_not_includes @health.posthog.notes, :browser_analytics_disabled
+ Rails.stubs(:env).returns("development".inquiry)
+ assert_includes @health.posthog.notes, :browser_analytics_disabled
+ @posthog.development_enabled = true
+ assert_not_includes @health.posthog.notes, :browser_analytics_disabled
+ end
+ end
+
+ test "shared PostHog feedback is separate from operator analytics and consent" do
+ Rails.application.config.stubs(:app_mode).returns("self_hosted".inquiry)
+ Rails.stubs(:env).returns("production".inquiry)
+ with_environment do
+ assert_equal :not_configured, @health.posthog.status
+ assert_includes @health.posthog.notes, :shared_feedback_configured
+ @posthog.api_key = "private-key"
+ @posthog.feedback_enabled = false
+ assert_equal :configured, @health.posthog.status
+ assert_includes @health.posthog.notes, :shared_feedback_disabled
+ end
+ end
+
+ test "Logtail needs both fields and is used only in production" do
+ with_environment("LOGTAIL_API_KEY" => "private-key") do
+ assert_equal :incomplete, @health.logtail.status
+ assert_equal [ "LOGTAIL_INGESTING_HOST" ], @health.logtail.settings
+ end
+ with_environment("LOGTAIL_API_KEY" => "private-key", "LOGTAIL_INGESTING_HOST" => "private-host") do
+ assert_equal :disabled, @health.logtail.status
+ Rails.stubs(:env).returns("production".inquiry)
+ assert_equal :configured, @health.logtail.status
+ assert_no_match(/private-/, @health.logtail.inspect)
+ end
+ end
+
+ private
+ def with_environment(overrides = {}, &block)
+ ClimateControl.modify(ENVIRONMENT.merge(overrides), &block)
+ end
+
+ def stripe_settings
+ {
+ "STRIPE_SECRET_KEY" => "private-secret", "STRIPE_WEBHOOK_SECRET" => "private-webhook",
+ "STRIPE_MONTHLY_PRICE_ID" => "private-monthly", "STRIPE_ANNUAL_PRICE_ID" => "private-annual"
+ }
+ end
+end
diff --git a/test/models/configuration_health_test.rb b/test/models/configuration_health_test.rb
new file mode 100644
index 0000000000..f3fcaaf54a
--- /dev/null
+++ b/test/models/configuration_health_test.rb
@@ -0,0 +1,271 @@
+require "test_helper"
+
+class ConfigurationHealthTest < ActiveSupport::TestCase
+ setup do
+ ApplicationMailer.stubs(:perform_deliveries).returns(true)
+ ApplicationMailer.stubs(:delivery_method).returns(:smtp)
+ ApplicationMailer.stubs(:smtp_settings).returns({ address: "smtp.example.test", port: "587" })
+ ApplicationMailer.stubs(:default).returns({ from: "Sure <[email protected]>" })
+ ApplicationMailer.stubs(:default_url_options).returns({ host: "sure.example.test" })
+ end
+
+ test "missing SMTP address is not configured and never sends email" do
+ ApplicationMailer.stubs(:smtp_settings).returns({ address: nil, port: nil })
+ ApplicationMailer.expects(:mail).never
+
+ check = ConfigurationHealth.new.smtp
+
+ assert_equal :not_configured, check.status
+ assert_equal [ :address ], check.issues
+ end
+
+ test "an unauthenticated SMTP relay is configured without requiring credentials" do
+ check = ConfigurationHealth.new.smtp
+
+ assert_equal :configured, check.status
+ assert_empty check.issues
+ assert_equal :neutral, check.tone
+ end
+
+ test "SMTP uses running mailer settings rather than changed environment variables" do
+ ClimateControl.modify("SMTP_ADDRESS" => nil, "EMAIL_SENDER" => nil, "APP_DOMAIN" => nil) do
+ assert_equal :configured, ConfigurationHealth.new.smtp.status
+ end
+ end
+
+ test "SMTP credentials must be supplied together and are never included in results" do
+ ApplicationMailer.stubs(:smtp_settings).returns({
+ address: "private-smtp.example.test", port: 587, user_name: "private-username", password: nil
+ })
+ check = ConfigurationHealth.new.smtp
+ assert_equal :incomplete, check.status
+ assert_equal [ :authentication ], check.issues
+
+ ApplicationMailer.stubs(:smtp_settings).returns({
+ address: "private-smtp.example.test", port: 587, user_name: "private-username", password: "private-password"
+ })
+ check = ConfigurationHealth.new.smtp
+ assert_equal :configured, check.status
+ assert_no_match(/private-/, check.inspect)
+ end
+
+ test "missing or placeholder sender and missing link domain are incomplete" do
+ [ nil, "", "Sure", "Sure <>", "not an email <", "Sure <[email protected]>" ].each do |sender|
+ ApplicationMailer.stubs(:default).returns({ from: sender })
+ ApplicationMailer.stubs(:default_url_options).returns({})
+
+ check = ConfigurationHealth.new.smtp
+ assert_equal :incomplete, check.status
+ assert_equal [ :sender, :app_domain ], check.issues
+ end
+ end
+
+ test "omitted SMTP port uses the SMTP default" do
+ ApplicationMailer.stubs(:smtp_settings).returns({ address: "smtp.example.test", port: nil })
+ assert_equal :configured, ConfigurationHealth.new.smtp.status
+ assert_empty ConfigurationHealth.new.smtp.issues
+ end
+
+ test "SMTP port must be a valid port number" do
+ [ "", "smtp", "0", "65536", -1 ].each do |port|
+ ApplicationMailer.stubs(:smtp_settings).returns({ address: "smtp.example.test", port: port })
+ assert_includes ConfigurationHealth.new.smtp.issues, :port
+ end
+ end
+
+ test "disabled delivery is distinct from missing SMTP configuration" do
+ ApplicationMailer.stubs(:perform_deliveries).returns(false)
+ ApplicationMailer.expects(:smtp_settings).never
+
+ assert_equal :disabled, ConfigurationHealth.new.smtp.status
+ end
+
+ test "non SMTP delivery methods are not assessed as missing SMTP" do
+ ApplicationMailer.stubs(:delivery_method).returns(:letter_opener)
+ ApplicationMailer.expects(:smtp_settings).never
+
+ assert_equal :not_checked, ConfigurationHealth.new.smtp.status
+ end
+
+ test "selected market providers use the existing ENV precedence and no live checks" do
+ Setting.stubs(:securities_providers).returns("yahoo_finance")
+ Setting.stubs(:twelve_data_api_key).returns("database-key")
+ Provider::TwelveData.expects(:new).with("environment-key").returns(stub("provider without probe methods"))
+
+ ClimateControl.modify("SECURITIES_PROVIDERS" => "twelve_data", "TWELVE_DATA_API_KEY" => "environment-key") do
+ check = ConfigurationHealth.new.securities
+ assert_equal :configured, check.status
+ assert_equal [ :twelve_data ], check.providers.map(&:key)
+ assert_no_match(/environment-key|database-key/, check.inspect)
+ end
+ end
+
+ test "blank environment API key falls back to the database key" do
+ Setting.stubs(:enabled_securities_providers).returns([ "twelve_data" ])
+ Setting.stubs(:twelve_data_api_key).returns("database-key")
+ Provider::TwelveData.expects(:new).with("database-key").returns(stub("provider"))
+
+ ClimateControl.modify("TWELVE_DATA_API_KEY" => "") do
+ assert_equal :configured, ConfigurationHealth.new.securities.status
+ end
+ end
+
+ test "keyless public providers are configured without API keys" do
+ Setting.stubs(:enabled_securities_providers).returns([ "yahoo_finance", "mfapi", "binance_public", "moex_public" ])
+ Provider::YahooFinance.any_instance.expects(:health_status).never
+ Provider::YahooFinance.any_instance.expects(:healthy?).never
+
+ assert_equal :configured, ConfigurationHealth.new.securities.status
+ end
+
+ test "missing selected API keys are not configured" do
+ Setting.stubs(:enabled_securities_providers).returns([ "twelve_data" ])
+ Setting.stubs(:twelve_data_api_key).returns(nil)
+
+ ClimateControl.modify("TWELVE_DATA_API_KEY" => nil) do
+ check = ConfigurationHealth.new.securities
+ assert_equal :not_configured, check.status
+ assert_equal :not_configured, check.providers.first.status
+ end
+ end
+
+ test "mixed providers identify incomplete configuration without hiding the working selection" do
+ Setting.stubs(:enabled_securities_providers).returns([ "yahoo_finance", "twelve_data" ])
+ Setting.stubs(:twelve_data_api_key).returns(nil)
+
+ ClimateControl.modify("TWELVE_DATA_API_KEY" => nil) do
+ check = ConfigurationHealth.new.securities
+ assert_equal :incomplete, check.status
+ assert_equal [ :configured, :not_configured ], check.providers.map(&:status)
+ end
+ end
+
+ test "no enabled market provider is disabled" do
+ Setting.stubs(:enabled_securities_providers).returns([])
+
+ assert_equal :disabled, ConfigurationHealth.new.securities.status
+ end
+
+ test "invalid provider selections are not invoked or exposed" do
+ Setting.stubs(:enabled_securities_providers).returns([ "credential-pasted-in-wrong-setting" ])
+ Provider::Registry.expects(:get_provider).never
+
+ check = ConfigurationHealth.new.securities
+ assert_equal :incomplete, check.status
+ assert_equal :unknown, check.providers.first.key
+ assert_equal :invalid, check.providers.first.status
+ assert_no_match(/credential-pasted/, check.inspect)
+ end
+
+ test "exchange rates honor the ENV provider selection and support keyless providers" do
+ Setting.stubs(:exchange_rate_provider).returns("twelve_data")
+ Provider::Frankfurter.any_instance.expects(:healthy?).never
+
+ ClimateControl.modify("EXCHANGE_RATE_PROVIDER" => "frankfurter") do
+ check = ConfigurationHealth.new.exchange_rates
+ assert_equal :configured, check.status
+ assert_equal :frankfurter, check.providers.first.key
+ end
+ end
+
+ test "exchange rates reject a provider from another concept" do
+ ClimateControl.modify("EXCHANGE_RATE_PROVIDER" => "openai") do
+ check = ConfigurationHealth.new.exchange_rates
+ assert_equal :not_configured, check.status
+ assert_equal [ :invalid_provider ], check.issues
+ assert_equal :unknown, check.providers.first.key
+ end
+ end
+
+ test "blank exchange rate selection is not configured" do
+ Setting.stubs(:exchange_rate_provider).returns(nil)
+
+ ClimateControl.modify("EXCHANGE_RATE_PROVIDER" => nil) do
+ assert_equal :not_configured, ConfigurationHealth.new.exchange_rates.status
+ end
+ end
+
+ test "local storage is configured without cloud credentials or filesystem access" do
+ stub_storage("local", { service: "Disk", root: "/private/storage/root" })
+ File.expects(:writable?).never
+
+ check = ConfigurationHealth.new.storage
+ assert_equal :configured, check.status
+ assert_equal :local, check.backend
+ assert_empty check.issues
+ assert_no_match(%r{/private/storage}, check.inspect)
+ end
+
+ test "cloud storage settings are checked without constructing a storage client" do
+ stub_storage("amazon", {
+ service: "S3", region: "us-east-1", bucket: "private-bucket",
+ access_key_id: "private-access-key", secret_access_key: "private-secret-key"
+ })
+ ActiveStorage::Service.expects(:configure).never
+
+ check = ConfigurationHealth.new.storage
+ assert_equal :configured, check.status
+ assert_equal :amazon, check.backend
+ assert_no_match(/private-/, check.inspect)
+ end
+
+ test "cloud role credentials are unverified rather than missing" do
+ stub_storage("amazon", { service: "S3", region: "us-east-1", bucket: "private-bucket" })
+ assert_equal :not_checked, ConfigurationHealth.new.storage.status
+
+ stub_storage("google", { service: "GCS", bucket: "private-bucket" })
+ assert_equal :not_checked, ConfigurationHealth.new.storage.status
+ end
+
+ test "incomplete cloud storage shows only missing field names" do
+ stub_storage("generic_s3", { service: "S3", access_key_id: "private-key" })
+
+ check = ConfigurationHealth.new.storage
+ assert_equal :incomplete, check.status
+ assert_equal [ :bucket, :region, :credentials, :endpoint ], check.issues
+ assert_no_match(/private-key/, check.inspect)
+ end
+
+ test "R2 with no account ID is incomplete despite the interpolated endpoint" do
+ stub_storage("cloudflare", {
+ service: "S3", region: "auto", bucket: "bucket",
+ endpoint: "https://.r2.cloudflarestorage.com", access_key_id: "key", secret_access_key: "secret"
+ })
+
+ check = ConfigurationHealth.new.storage
+ assert_equal :incomplete, check.status
+ assert_equal [ :endpoint ], check.issues
+ end
+
+ test "missing selected storage configuration is not configured and name is sanitized" do
+ Rails.application.config.active_storage.stubs(:service).returns(:unexpected_secret)
+ Rails.application.config.active_storage.stubs(:service_configurations).returns({})
+
+ check = ConfigurationHealth.new.storage
+ assert_equal :not_configured, check.status
+ assert_equal :other, check.backend
+ assert_no_match(/unexpected_secret/, check.inspect)
+ end
+
+ test "custom storage is left unverified" do
+ stub_storage("custom", { service: "OtherStorage" })
+
+ check = ConfigurationHealth.new.storage
+ assert_equal :not_checked, check.status
+ assert_equal :other, check.backend
+ end
+
+ test "a standard storage name with a custom adapter is not misreported" do
+ stub_storage("local", { service: "OtherStorage" })
+
+ check = ConfigurationHealth.new.storage
+ assert_equal :not_checked, check.status
+ assert_equal :other, check.backend
+ end
+
+ private
+ def stub_storage(name, settings)
+ Rails.application.config.active_storage.stubs(:service).returns(name.to_sym)
+ Rails.application.config.active_storage.stubs(:service_configurations).returns({ name => settings })
+ end
+end
diff --git a/test/system/admin/system_health_hosted_usage_test.rb b/test/system/admin/system_health_hosted_usage_test.rb
index cc7c12492c..f235c83d53 100644
--- a/test/system/admin/system_health_hosted_usage_test.rb
+++ b/test/system/admin/system_health_hosted_usage_test.rb
@@ -17,10 +17,15 @@ class Admin::SystemHealthHostedUsageTest < ApplicationSystemTestCase
visit admin_system_health_path
assert_selector "turbo-frame#hosted_usage[loading='lazy']:not([complete])", visible: :all
- click_button "Hosted usage"
+ click_button "Config"
+ assert_current_path admin_system_health_path(tab: "configuration")
+ assert_selector "[data-testid='configuration-health']"
+ assert_selector "turbo-frame#hosted_usage[loading='lazy']:not([complete])", visible: :all
+ click_button "Usage"
+ assert_no_selector "[data-testid='configuration-health']"
assert_current_path admin_system_health_path(tab: "hosted_usage")
- assert_selector "button[role='tab'][aria-selected='true']", text: "Hosted usage"
+ assert_selector "button[role='tab'][aria-selected='true']", text: "Usage"
within "turbo-frame#hosted_usage" do
assert_text "Recent trial households"
assert_text(/Retained sign-in sessions/i)
@@ -31,7 +36,13 @@ class Admin::SystemHealthHostedUsageTest < ApplicationSystemTestCase
end
page.save_screenshot(Rails.root.join("tmp", "system-health-hosted-usage.png"))
- page.current_window.resize_to(390, 844)
+ page.current_window.resize_to(375, 844)
+ tabs = all("button[role='tab']")
+ assert_equal 4, tabs.size
+ tabs.each do |tab|
+ assert tab.evaluate_script("this.scrollWidth <= this.clientWidth"), "Tab must fit"
+ assert tab.evaluate_script("this.getBoundingClientRect().height < 48"), "Tab label must stay on one line"
+ end
within "turbo-frame#hosted_usage" do
assert_selector "[role='region'][aria-label='Recent trial households'][tabindex='0']"
assert_no_selector "form, button, a[data-turbo-method]"
@@ -55,8 +66,8 @@ class Admin::SystemHealthHostedUsageTest < ApplicationSystemTestCase
visit admin_system_health_path(tab: "hosted_usage")
- assert_selector "button[role='tab'][aria-selected='true']", text: "Background jobs"
- assert_no_selector "button[role='tab']", text: "Hosted usage"
+ assert_selector "button[role='tab'][aria-selected='true']", text: "Jobs"
+ assert_no_selector "button[role='tab']", text: "Usage"
assert_no_selector "turbo-frame#hosted_usage", visible: :all
end
diff --git a/test/system/admin/system_health_test.rb b/test/system/admin/system_health_test.rb
index 70ab4106e4..1bafa6ab71 100644
--- a/test/system/admin/system_health_test.rb
+++ b/test/system/admin/system_health_test.rb
@@ -21,10 +21,10 @@ class Admin::SystemHealthTest < ApplicationSystemTestCase
with_openai_access_token do
visit admin_system_health_path
- click_button "AI status"
+ click_button "AI"
assert_current_path admin_system_health_path(tab: "ai")
- assert_selector "button[role='tab'][aria-selected='true']", text: "AI status"
+ assert_selector "button[role='tab'][aria-selected='true']", text: "AI"
assert_text "Live check passed"
assert_text "Live tool call succeeded"
assert_text "PDF text-extraction path"
@@ -50,7 +50,7 @@ class Admin::SystemHealthTest < ApplicationSystemTestCase
test "going back after switching tabs returns to system health" do
with_openai_access_token do
visit admin_system_health_path
- click_button "AI status"
+ click_button "AI"
assert_text "Live check passed"
click_link "Preferences", match: :first
@@ -58,7 +58,7 @@ class Admin::SystemHealthTest < ApplicationSystemTestCase
page.go_back
assert_current_path admin_system_health_path(tab: "ai")
- assert_selector "button[role='tab'][aria-selected='true']", text: "AI status"
+ assert_selector "button[role='tab'][aria-selected='true']", text: "AI"
end
end
@@ -69,7 +69,7 @@ class Admin::SystemHealthTest < ApplicationSystemTestCase
test "queueing a worker check keeps the AI status on screen" do
with_openai_access_token do
visit admin_system_health_path
- click_button "AI status"
+ click_button "AI"
assert_text "Live check passed"
page.execute_script(<<~JS)
document.addEventListener("turbo:morph", () => {
@@ -89,8 +89,8 @@ class Admin::SystemHealthTest < ApplicationSystemTestCase
Apns::Client.stubs(:configured?).returns(true)
Rails.stubs(:cache).returns(ActiveSupport::Cache::MemoryStore.new)
visit admin_system_health_path
- assert_selector "button[role='tab']", count: 2
- assert_selector "button[role='tab'][aria-selected='true']", text: "Background jobs"
+ assert_selector "button[role='tab']", count: 3
+ assert_selector "button[role='tab'][aria-selected='true']", text: "Jobs"
assert_selector "h2", text: "Push notifications"
assert_button "Send test push notification", disabled: true
assert_text "Enable push notifications in the Sure iOS app"
@@ -120,6 +120,72 @@ class Admin::SystemHealthTest < ApplicationSystemTestCase
end
end
+ test "configuration tab supports repeated selection and navigation without running AI probes" do
+ ApplicationMailer.stubs(:perform_deliveries).returns(true)
+ ApplicationMailer.stubs(:delivery_method).returns(:smtp)
+ ApplicationMailer.stubs(:smtp_settings).returns({ address: nil, port: 465 })
+ ApplicationMailer.stubs(:default).returns({ from: "Sure <[email protected]>" })
+ Rails.application.config.active_storage.stubs(:service).returns(:local)
+ Rails.application.config.active_storage.stubs(:service_configurations).returns({
+ local: { service: "Disk", root: Rails.root.join("storage") }
+ })
+ AiHealth.expects(:new).never
+ visit admin_system_health_path
+
+ 2.times do
+ click_button "Config"
+ assert_current_path admin_system_health_path(tab: "configuration")
+ assert_selector "button[role='tab'][aria-selected='true']", text: "Config"
+ assert_selector "h2", text: "Email (SMTP)"
+ assert_selector "h2", text: "Market prices"
+ assert_selector "h2", text: "Foreign exchange rates"
+ assert_selector "h2", text: "File uploads and storage"
+ assert_no_selector "[data-testid='configuration-health'] input"
+ click_button "Jobs"
+ assert_no_selector "[data-testid='configuration-health']"
+ end
+
+ click_button "Config"
+ click_link "Preferences", match: :first
+ assert_no_selector "[data-testid='system-health-tabs']"
+ page.go_back
+ assert_current_path admin_system_health_path(tab: "configuration")
+ assert_selector "h2", text: "File uploads and storage"
+ page.go_forward
+ assert_no_selector "[data-testid='system-health-tabs']"
+
+ visit admin_system_health_path(tab: "configuration")
+ assert_selector "button[role='tab'][aria-selected='true']", text: "Config"
+ assert_selector "h2", text: "Email (SMTP)"
+ within "[data-testid='optional-services']" do
+ assert_selector "h2", text: "Optional services"
+ assert_selector "details:not([open])", count: 6
+ find("summary", text: "Langfuse").click
+ assert_text "LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY"
+ find("summary", text: "Langfuse").click
+ assert_selector "details:not([open])", count: 6
+ end
+ page.current_window.resize_to(390, 844)
+ %w[exchange_rates storage].each do |key|
+ header = find("[data-testid='configuration-#{key}'] h2").find(:xpath, "..")
+ bounds = header.evaluate_script(<<~JS)
+ (() => {
+ const title = this.querySelector("h2").getBoundingClientRect();
+ const pill = this.querySelector(".shrink-0").getBoundingClientRect();
+ const card = this.getBoundingClientRect();
+ return { titleRight: title.right, titleTop: title.top,
+ pillLeft: pill.left, pillTop: pill.top, pillRight: pill.right, cardRight: card.right };
+ })()
+ JS
+ assert_operator bounds["titleRight"], :<=, bounds["pillLeft"]
+ assert_in_delta bounds["titleTop"], bounds["pillTop"], 1
+ assert_operator bounds["pillRight"], :<=, bounds["cardRight"] + 1
+ end
+ page.save_screenshot("/tmp/pr3929-configuration-mobile.png")
+ page.current_window.resize_to(1400, 2000)
+ page.save_screenshot(Rails.root.join("tmp", "system-health-configuration.png"))
+ end
+
private
def with_openai_access_token(&block)
ClimateControl.modify(