Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
import { describe, expect, it, vi, beforeEach } from 'vitest';
import { SettingsAPI, type SystemSettingsResponse, type TelemetryPingPreview } from '../settings';
import { apiFetchJSON } from '@/utils/apiClient';
vi.mock('@/utils/apiClient', () => ({
apiFetchJSON: vi.fn(),
}));
const mockTelemetryPreviewPayload = {
schema_version: 19,
successful_history_reads_over_7d_30d: 7,
sent_at: '2026-07-23T08:30:00Z',
install_id: 'preview-install-id',
version: '6.0.0',
version_channel: 'stable',
version_is_development: false,
version_is_published_release: true,
platform: 'docker',
os: 'linux',
arch: 'amd64',
event: 'heartbeat',
deployment_method: 'docker_compose',
known_install_age_bucket: '1_7d',
activation_stage: 'monitoring',
time_to_first_monitored_resource_bucket: 'under_15m',
estate_size_bucket: '1_10',
auth_configured: true,
configured_connections: 1,
monitoring_active: true,
outcome_observed_30d: false,
pve_nodes: 1,
pbs_instances: 0,
pmg_instances: 0,
vms: 2,
containers: 3,
agent_hosts: 1,
docker_hosts: 0,
docker_containers: 0,
kubernetes_clusters: 0,
kubernetes_nodes: 0,
kubernetes_pods: 0,
kubernetes_deployments: 0,
storage_pools: 1,
physical_disks: 2,
ceph_clusters: 0,
network_shares: 0,
truenas_systems: 0,
truenas_vms: 0,
truenas_apps: 0,
vmware_hosts: 0,
vmware_vms: 0,
vmware_datastores: 0,
availability_targets: 1,
availability_probe_targets: 0,
availability_probe_agents: 0,
ai_enabled: false,
patrol_enabled: false,
discovery_enabled: false,
notifications_enabled: false,
ai_actions_enabled: false,
alert_ai_enabled: false,
ai_provider_class: 'none',
active_alerts: 0,
relay_enabled: false,
sso_enabled: false,
multi_tenant: false,
paid_license: false,
has_api_tokens: true,
rbac_custom_roles: 0,
rbac_user_assignments: 0,
audit_reads_30d: 0,
report_schedules: 0,
report_schedules_enabled: 0,
report_schedules_run_30d: 0,
agent_profiles: 0,
update_attempts_30d: 0,
update_successes_30d: 0,
update_failures_30d: 0,
update_last_failure_category: undefined,
update_channel: 'stable',
update_check_outcome: 'up_to_date',
update_available: false,
service_health_observed: true,
service_health_healthy: true,
service_health_failure_category: undefined,
service_health_cohort: 'same_version',
service_health_previous_version: '6.3.0',
service_health_previous_observed: true,
service_health_previous_healthy: true,
node_test_attempts_30d: 0,
node_test_failures_30d: 0,
workload_history_preview_sessions_30d: 0,
workload_history_scrub_sessions_30d: 0,
workload_history_range_change_sessions_30d: 0,
workload_history_details_selection_sessions_30d: 0,
alerts_fired_30d: 0,
alerts_acknowledged_30d: 0,
alerts_resolved_30d: 0,
active_alerts_info: 0,
active_alerts_warning: 0,
active_alerts_critical: 0,
active_alerts_age_under_1h: 0,
active_alerts_age_1h_24h: 0,
active_alerts_age_1d_7d: 0,
active_alerts_age_7d_plus: 0,
alerts_fired_info_30d: 0,
alerts_fired_warning_30d: 0,
alerts_fired_critical_30d: 0,
alerts_resolved_info_30d: 0,
alerts_resolved_warning_30d: 0,
alerts_resolved_critical_30d: 0,
alerts_resolution_under_15m_30d: 0,
alerts_resolution_15m_1h_30d: 0,
alerts_resolution_1h_24h_30d: 0,
alerts_resolution_1d_7d_30d: 0,
alerts_resolution_7d_plus_30d: 0,
alerts_repeat_occurrences_30d: 0,
alerts_snoozed_occurrences_30d: 0,
alerts_resolved_while_snoozed_30d: 0,
alert_manager_tenants: 0,
alert_delivery_active_tenants: 0,
alert_flapping_enabled_tenants: 0,
alert_intent_policy_configured_tenants: 0,
alert_event_history_authoritative_tenants: 0,
alert_active_state_authoritative_tenants: 0,
alert_active_state_persistence_degraded_tenants: 0,
notification_attempts_7d: 0,
notification_deliveries_7d: 0,
notification_failures_7d: 0,
notification_failures_authentication_7d: 0,
notification_failures_rate_limited_7d: 0,
notification_failures_connectivity_7d: 0,
notification_failures_tls_7d: 0,
notification_failures_configuration_7d: 0,
notification_failures_rejected_7d: 0,
notification_failures_server_error_7d: 0,
notification_failures_unknown_7d: 0,
pulse_intelligence_loop_configured: false,
pulse_intelligence_loop_active_30d: false,
pulse_intelligence_complete_operations_loop_30d: false,
pulse_intelligence_approved_execution_loop_30d: false,
pulse_intelligence_resolved_operations_loop_30d: false,
pulse_intelligence_patrol_control_completed_operations_loop_30d: false,
pulse_intelligence_patrol_control_resolved_operations_loop_30d: false,
pulse_intelligence_patrol_control_paid_completed_operations_loop_30d: false,
pulse_intelligence_patrol_control_paid_resolved_operations_loop_30d: false,
pulse_intelligence_pro_activation_completed_operations_loop_30d: false,
pulse_intelligence_pro_activation_resolved_operations_loop_30d: false,
pulse_intelligence_pro_activation_paid_completed_operations_loop_30d: false,
pulse_intelligence_pro_activation_paid_resolved_operations_loop_30d: false,
pulse_intelligence_governed_action_active_30d: false,
pulse_intelligence_assistant_operations_loop_30d: false,
pulse_intelligence_assistant_approved_execution_loop_30d: false,
pulse_intelligence_assistant_approved_action_success_loop_30d: false,
pulse_intelligence_assistant_resolved_operations_loop_30d: false,
pulse_intelligence_external_agent_operations_loop_30d: false,
pulse_intelligence_external_agent_approved_execution_loop_30d: false,
pulse_intelligence_external_agent_approved_action_success_loop_30d: false,
pulse_intelligence_external_agent_resolved_operations_loop_30d: false,
pulse_intelligence_mcp_adapter_operations_loop_30d: false,
pulse_intelligence_mcp_adapter_approved_execution_loop_30d: false,
pulse_intelligence_mcp_adapter_approved_action_success_loop_30d: false,
pulse_intelligence_mcp_adapter_resolved_operations_loop_30d: false,
pulse_intelligence_operations_loop_starter_requests_30d: 0,
pulse_intelligence_assistant_operations_loop_starter_requests_30d: 0,
pulse_intelligence_patrol_operations_loop_starter_requests_30d: 0,
pulse_intelligence_patrol_control_operations_loop_starter_requests_30d: 0,
pulse_intelligence_pro_activation_operations_loop_starter_requests_30d: 0,
pulse_intelligence_mcp_operations_loop_starter_requests_30d: 0,
pulse_intelligence_assistant_ai_calls_30d: 0,
pulse_intelligence_assistant_context_ai_calls_30d: 0,
pulse_intelligence_assistant_tool_calls_30d: 0,
pulse_intelligence_patrol_ai_calls_30d: 0,
pulse_intelligence_patrol_runs_30d: 0,
pulse_intelligence_patrol_new_findings_30d: 0,
pulse_intelligence_patrol_investigations_30d: 0,
pulse_intelligence_patrol_resolved_findings_30d: 0,
pulse_intelligence_patrol_blocked_cause: undefined,
pulse_intelligence_patrol_autonomy_level: 'monitor',
pulse_intelligence_patrol_input_tokens_bucket_30d: 'zero',
pulse_intelligence_patrol_output_tokens_bucket_30d: 'zero',
pulse_intelligence_patrol_investigation_outcome_fix_verified_30d: 0,
pulse_intelligence_patrol_investigation_outcome_fix_queued_30d: 0,
pulse_intelligence_patrol_investigation_outcome_fix_executed_30d: 0,
pulse_intelligence_patrol_investigation_outcome_fix_rejected_30d: 0,
pulse_intelligence_patrol_investigation_outcome_fix_failed_30d: 0,
pulse_intelligence_patrol_investigation_outcome_fix_verification_unknown_30d: 0,
pulse_intelligence_patrol_investigation_outcome_resolved_30d: 0,
pulse_intelligence_patrol_investigation_outcome_needs_attention_30d: 0,
pulse_intelligence_patrol_investigation_outcome_cannot_fix_30d: 0,
pulse_intelligence_patrol_investigation_outcome_timed_out_30d: 0,
pulse_intelligence_patrol_investigation_outcome_in_progress_30d: 0,
pulse_intelligence_patrol_investigation_outcome_failed_30d: 0,
pulse_intelligence_patrol_investigation_outcome_other_30d: 0,
pulse_intelligence_external_agent_enabled: false,
pulse_intelligence_external_agent_used_30d: false,
pulse_intelligence_mcp_adapter_used_30d: false,
pulse_intelligence_external_agent_context_requests_30d: 0,
pulse_intelligence_external_agent_event_stream_requests_30d: 0,
pulse_intelligence_external_agent_history_read_days_30d: 0,
pulse_intelligence_external_agent_provisioning_requests_30d: 0,
pulse_intelligence_external_agent_operator_state_requests_30d: 0,
pulse_intelligence_external_agent_finding_requests_30d: 0,
pulse_intelligence_external_agent_action_requests_30d: 0,
pulse_intelligence_action_plans_30d: 0,
pulse_intelligence_approval_requests_30d: 0,
pulse_intelligence_rejected_action_decisions_30d: 0,
pulse_intelligence_approved_action_decisions_30d: 0,
pulse_intelligence_approved_action_attempts_30d: 0,
pulse_intelligence_approved_action_successes_30d: 0,
pulse_intelligence_patrol_action_plans_30d: 0,
pulse_intelligence_patrol_approval_requests_30d: 0,
pulse_intelligence_patrol_rejected_action_decisions_30d: 0,
pulse_intelligence_patrol_approved_action_decisions_30d: 0,
pulse_intelligence_patrol_approved_action_attempts_30d: 0,
pulse_intelligence_patrol_approved_action_successes_30d: 0,
pulse_intelligence_approved_action_failures_pre_dispatch_30d: 0,
pulse_intelligence_approved_action_failures_execution_30d: 0,
pulse_intelligence_approved_action_failures_unverified_30d: 0,
pulse_intelligence_approved_action_stuck_executing_30d: 0,
pulse_intelligence_approved_action_in_flight_30d: 0,
pulse_intelligence_approved_action_unclassified_30d: 0,
pulse_intelligence_approved_action_refusals_plan_stale_30d: 0,
pulse_intelligence_approved_action_refusals_policy_30d: 0,
pulse_intelligence_approved_action_refusals_capability_30d: 0,
pulse_intelligence_approved_action_refusals_target_changed_30d: 0,
pulse_intelligence_approved_action_refusals_prerequisite_30d: 0,
pulse_intelligence_approved_action_refusals_contract_30d: 0,
pulse_intelligence_approved_action_refusals_other_30d: 0,
pulse_intelligence_approved_action_refusals_uncoded_30d: 0,
pulse_intelligence_verified_finding_resolutions_30d: 0,
pulse_intelligence_approved_action_last_failure_reason_30d: undefined,
} satisfies TelemetryPingPreview;
describe('SettingsAPI', () => {
beforeEach(() => {
vi.clearAllMocks();
});
describe('updateSystemSettings', () => {
it('updates system settings', async () => {
vi.mocked(apiFetchJSON).mockResolvedValueOnce(undefined);
await SettingsAPI.updateSystemSettings({ fullWidthMode: true });
expect(apiFetchJSON).toHaveBeenCalledWith(
'/api/system/settings/update',
expect.objectContaining({
method: 'POST',
body: JSON.stringify({ fullWidthMode: true }),
}),
);
});
});
describe('getSystemSettings', () => {
it('fetches system settings', async () => {
const mockSettings: SystemSettingsResponse = {
autoUpdateEnabled: true,
fullWidthMode: true,
};
vi.mocked(apiFetchJSON).mockResolvedValueOnce(mockSettings);
const result = await SettingsAPI.getSystemSettings();
expect(apiFetchJSON).toHaveBeenCalledWith('/api/system/settings');
expect(result).toEqual(mockSettings);
});
});
describe('getRuntimeBranding', () => {
it('fetches the narrow runtime branding payload', async () => {
const branding = {
enabled: true,
displayName: 'Acme Operations',
logoDataUrl: 'data:image/png;base64,YWJj',
};
vi.mocked(apiFetchJSON).mockResolvedValueOnce(branding);
const result = await SettingsAPI.getRuntimeBranding();
expect(apiFetchJSON).toHaveBeenCalledWith('/api/runtime/branding');
expect(result).toEqual(branding);
});
});
describe('getRuntimeDisplay', () => {
it('fetches display settings from the authenticated runtime route', async () => {
const display = {
theme: 'dark',
fullWidthMode: true,
disableDockerUpdateActions: true,
telemetryEnabled: false,
reduceProUpsellNoise: false,
pvePollingInterval: 60,
};
vi.mocked(apiFetchJSON).mockResolvedValueOnce(display);
const result = await SettingsAPI.getRuntimeDisplay();
expect(apiFetchJSON).toHaveBeenCalledWith('/api/runtime/display');
expect(apiFetchJSON).not.toHaveBeenCalledWith('/api/system/settings');
expect(result).toEqual(display);
});
});
describe('getTelemetryPreview', () => {
it('fetches the telemetry preview payload', async () => {
const mockPreview = {
enabled: true,
payload: mockTelemetryPreviewPayload,
};
vi.mocked(apiFetchJSON).mockResolvedValueOnce(mockPreview);
const result = await SettingsAPI.getTelemetryPreview();
expect(apiFetchJSON).toHaveBeenCalledWith('/api/system/settings/telemetry-preview');
expect(result.payload.successful_history_reads_over_7d_30d).toBe(7);
expect(result).toEqual(mockPreview);
});
});
describe('resetTelemetryInstallID', () => {
it('posts the telemetry install-id reset action', async () => {
vi.mocked(apiFetchJSON).mockResolvedValueOnce({
enabled: true,
payload: {
install_id: 'rotated-install-id',
},
});
await SettingsAPI.resetTelemetryInstallID();
expect(apiFetchJSON).toHaveBeenCalledWith(
'/api/system/settings/telemetry-reset-id',
expect.objectContaining({
method: 'POST',
}),
);
});
});
});