Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

11.9 KB
Raw Blame
import { cleanup, fireEvent, render, screen } from '@solidjs/testing-library';
import { Route, Router } from '@solidjs/router';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { DiagnosticsResultsPanel } from '@/components/Settings/DiagnosticsResultsPanel';
import type { DiagnosticsData } from '@/components/Settings/diagnosticsModel';

describe('DiagnosticsResultsPanel', () => {
  afterEach(() => {
    cleanup();
    vi.useRealTimers();
  });

  it('ages the network discovery Last Scan label on the shared clock', async () => {
    const start = Date.parse('2026-10-16T22:00:00Z');
    vi.useFakeTimers({ now: start });
    const diagnosticsData = {
      version: '6.4.1',
      runtime: 'go',
      uptime: 3600,
      nodes: [],
      pbs: [],
      system: {
        os: 'linux',
        arch: 'amd64',
        goVersion: 'go1.26.7',
        numCPU: 4,
        numGoroutine: 40,
        memoryMB: 24,
      },
      discovery: {
        enabled: true,
        lastScanStartedAt: new Date(start - 60_000).toISOString(),
      },
      errors: [],
    } as DiagnosticsData;

    render(() => (
      <Router>
        <Route
          path="/"
          component={() => (
            <DiagnosticsResultsPanel
              diagnosticsData={diagnosticsData}
              loading={false}
              onRunDiagnostics={() => {}}
            />
          )}
        />
      </Router>
    ));

    const lastScan = () => screen.getByText('Last Scan').nextElementSibling;
    expect(lastScan()).toHaveTextContent('1m ago');
    await vi.advanceTimersByTimeAsync(2 * 3_600_000);
    expect(lastScan()).toHaveTextContent('2h ago');
  });

  it('keeps the empty-state action linked to its live-check safety explanation', () => {
    const run = vi.fn();
    render(() => (
      <>
        <p id="run-safety">Do not run during a backup or freeze/thaw.</p>
        <DiagnosticsResultsPanel
          diagnosticsData={null}
          loading={false}
          onRunDiagnostics={run}
          runDescriptionId="run-safety"
        />
      </>
    ));
    const action = screen.getByRole('button', { name: 'Run Diagnostics' });
    expect(action).toHaveAccessibleDescription('Do not run during a backup or freeze/thaw.');
    expect(run).not.toHaveBeenCalled();
    fireEvent.click(action);
    expect(run).toHaveBeenCalledOnce();
  });

  it('distinguishes live heap, retained runtime memory, and process RSS', () => {
    const diagnosticsData = {
      version: '6.4.1',
      runtime: 'go',
      uptime: 3600,
      nodes: [],
      pbs: [],
      system: {
        os: 'linux',
        arch: 'amd64',
        goVersion: 'go1.26.7',
        numCPU: 4,
        numGoroutine: 40,
        memoryMB: 24,
        heapAllocMB: 24,
        heapIdleMB: 40,
        heapReleasedMB: 16,
        runtimeRetainedMB: 64,
        processRssMB: 96,
        gcMemoryLimitMB: 230,
      },
      errors: [],
    } as DiagnosticsData;

    render(() => (
      <Router>
        <Route
          path="/"
          component={() => (
            <DiagnosticsResultsPanel
              diagnosticsData={diagnosticsData}
              loading={false}
              onRunDiagnostics={() => {}}
            />
          )}
        />
      </Router>
    ));

    expect(screen.getByText('Live Heap')).toBeInTheDocument();
    expect(screen.getByText('24 MB')).toBeInTheDocument();
    expect(screen.getByText('Process RSS')).toBeInTheDocument();
    expect(screen.getByText('96 MB')).toBeInTheDocument();
    expect(screen.getByText('Go Retained')).toBeInTheDocument();
    expect(screen.getByText('64 MB')).toBeInTheDocument();
    expect(screen.getByText('Heap Idle / Released')).toBeInTheDocument();
    expect(screen.getByText('40 / 16 MB')).toBeInTheDocument();
    expect(screen.getByText('GC Soft Limit')).toBeInTheDocument();
    expect(screen.getByText('230 MB')).toBeInTheDocument();
  });

  it('labels the shared AI runtime diagnostics as Patrol investigation status', () => {
    const diagnosticsData = {
      version: '6.0.0',
      runtime: 'go',
      uptime: 3600,
      nodes: [],
      pbs: [],
      system: {
        os: 'linux',
        arch: 'amd64',
        goVersion: 'go1.25',
        numCPU: 8,
        numGoroutine: 32,
        memoryMB: 128,
      },
      aiChat: {
        enabled: true,
        running: true,
        healthy: true,
        model: 'ollama:llama3',
        assistantRuntimeConnected: true,
        notes: [],
      },
      errors: [],
    } as DiagnosticsData;

    render(() => (
      <Router>
        <Route
          path="/"
          component={() => (
            <DiagnosticsResultsPanel
              diagnosticsData={diagnosticsData}
              loading={false}
              onRunDiagnostics={() => {}}
            />
          )}
        />
      </Router>
    ));

    expect(screen.getByText('AI runtime')).toBeInTheDocument();
    expect(screen.getByText('Runs Patrol investigations')).toBeInTheDocument();
    expect(screen.getByText('Runtime connection')).toBeInTheDocument();
    expect(screen.queryByText('Pulse Assistant Service')).not.toBeInTheDocument();
    expect(screen.queryByText('MCP Connection')).not.toBeInTheDocument();
  });

  it('does not render internal analytics fields from diagnostics payloads', () => {
    const diagnosticsData = {
      version: '6.0.0',
      runtime: 'go',
      uptime: 3600,
      nodes: [],
      pbs: [],
      system: {
        os: 'linux',
        arch: 'amd64',
        goVersion: 'go1.25',
        numCPU: 8,
        numGoroutine: 32,
        memoryMB: 128,
      },
      commercialFunnel: {
        enabled: true,
        status: 'active',
        windowDays: 30,
        summary: {
          pricing_viewed: 3,
          paywall_viewed: 0,
          trial_started: 1,
          upgrade_clicked: 0,
          checkout_clicked: 2,
          checkout_started: 2,
          checkout_completed: 1,
          license_activated: 1,
          license_activation_failed: 0,
          period: {
            from: '2026-03-19T00:00:00Z',
            to: '2026-04-18T00:00:00Z',
          },
        },
        daily: [
          {
            day: '2026-04-17',
            pricing_viewed: 1,
            paywall_viewed: 0,
            trial_started: 0,
            upgrade_clicked: 0,
            checkout_clicked: 1,
            checkout_started: 1,
            checkout_completed: 0,
            license_activated: 0,
            license_activation_failed: 0,
          },
          {
            day: '2026-04-18',
            pricing_viewed: 2,
            paywall_viewed: 0,
            trial_started: 1,
            upgrade_clicked: 0,
            checkout_clicked: 1,
            checkout_started: 1,
            checkout_completed: 1,
            license_activated: 1,
            license_activation_failed: 0,
          },
        ],
        surfaces: [
          {
            key: 'settings_self_hosted_billing_compare_prompt',
            pricing_viewed: 0,
            paywall_viewed: 0,
            trial_started: 0,
            upgrade_clicked: 0,
            checkout_clicked: 2,
            checkout_started: 0,
            checkout_completed: 0,
            license_activated: 0,
            license_activation_failed: 0,
          },
        ],
        capabilities: [
          {
            key: 'self_hosted_plan',
            pricing_viewed: 3,
            paywall_viewed: 0,
            trial_started: 0,
            upgrade_clicked: 0,
            checkout_clicked: 2,
            checkout_started: 2,
            checkout_completed: 1,
            license_activated: 1,
            license_activation_failed: 0,
          },
        ],
        notes: ['Local pricing and activation events show at least one completed conversion.'],
      },
      infrastructureOnboarding: {
        enabled: true,
        status: 'warning',
        windowDays: 30,
        summary: {
          opened: 4,
          api_path_selected: 2,
          agent_path_selected: 1,
          probe_detected: 1,
          probe_no_match: 2,
          probe_error: 0,
          catalog_selected: 2,
          credentials_opened: 1,
          period: {
            from: '2026-03-19T00:00:00Z',
            to: '2026-04-18T00:00:00Z',
          },
        },
        daily: [
          {
            day: '2026-04-17',
            opened: 2,
            api_path_selected: 1,
            agent_path_selected: 1,
            probe_detected: 0,
            probe_no_match: 1,
            probe_error: 0,
            catalog_selected: 1,
            credentials_opened: 0,
          },
          {
            day: '2026-04-18',
            opened: 2,
            api_path_selected: 1,
            agent_path_selected: 0,
            probe_detected: 1,
            probe_no_match: 1,
            probe_error: 0,
            catalog_selected: 1,
            credentials_opened: 1,
          },
        ],
        paths: [
          { key: 'api', count: 2 },
          { key: 'agent', count: 1 },
        ],
        platforms: [
          {
            key: 'truenas',
            catalog_selected: 2,
            credentials_opened: 1,
          },
        ],
        notes: ['More probed addresses miss than detect a supported API-backed platform.'],
      },
      dockerAgents: {
        agentsOnline: 1,
        agentsTotal: 2,
        agentsReportingVersion: 2,
        agentsWithTokenBinding: 1,
        agentsWithoutTokenBinding: 1,
        agentsNeedingAttention: 1,
      },
      errors: [],
    } as DiagnosticsData;

    render(() => (
      <Router>
        <Route
          path="/"
          component={() => (
            <DiagnosticsResultsPanel
              diagnosticsData={diagnosticsData}
              loading={false}
              onRunDiagnostics={() => {}}
            />
          )}
        />
      </Router>
    ));

    expect(screen.queryByText('Commercial Funnel')).not.toBeInTheDocument();
    expect(screen.queryByText('Pricing Views')).not.toBeInTheDocument();
    expect(screen.queryByText('Checkout Clicks')).not.toBeInTheDocument();
    expect(screen.queryByText('Self Hosted Plan')).not.toBeInTheDocument();
    expect(
      screen.queryByText('Settings Self Hosted Billing Compare Prompt'),
    ).not.toBeInTheDocument();
    expect(screen.queryByText('Infrastructure Onboarding')).not.toBeInTheDocument();
    expect(screen.queryByText('Credentials Opened')).not.toBeInTheDocument();
    expect(screen.queryByText('TrueNAS SCALE')).not.toBeInTheDocument();
    expect(screen.getByText('Docker / Podman agents')).toBeInTheDocument();
    expect(screen.getByText('Agent-backed Docker / Podman monitoring')).toBeInTheDocument();
    expect(screen.getByRole('link', { name: 'Open Agent Doctor' })).toHaveAttribute(
      'href',
      '/settings/infrastructure/agent-doctor',
    );
    expect(screen.queryByText('Container Runtime Agents')).not.toBeInTheDocument();
  });

  it('shows direct PBS probe evidence without replacing monitored state', () => {
    const diagnosticsData = {
      version: '6.1.1',
      runtime: 'go',
      uptime: 3600,
      nodes: [],
      pbs: [
        {
          id: 'pbs-primary',
          name: 'pbs-primary',
          host: 'https://backup.local:8007',
          connected: false,
          state: 'unreachable',
          stateReason: 'connection timed out',
          probe: {
            connected: true,
            details: { version: '3.4.2' },
          },
        },
      ],
      system: {
        os: 'linux',
        arch: 'amd64',
        goVersion: 'go1.25',
        numCPU: 8,
        numGoroutine: 32,
        memoryMB: 128,
      },
      errors: [],
    } as DiagnosticsData;

    render(() => (
      <Router>
        <Route
          path="/"
          component={() => (
            <DiagnosticsResultsPanel
              diagnosticsData={diagnosticsData}
              loading={false}
              onRunDiagnostics={() => {}}
            />
          )}
        />
      </Router>
    ));

    expect(screen.getByText('pbs-primary')).toBeInTheDocument();
    expect(screen.getByText('Monitor: unreachable. Live check: connected')).toBeInTheDocument();
  });
});