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.

8.1 KB
Raw Blame
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { beforeEach, describe, expect, it } from 'vitest';
import { PRIVACY_DOC_URL } from '@/utils/docsLinks';
import { EN_MESSAGES } from '@/i18n/messages';
import {
  areSystemSettingsLoaded,
  clearRuntimeBranding,
  markSystemSettingsLoadedWithDefaults,
  runtimeBranding,
  shouldHideDockerUpdateActions,
  shouldReduceProUpsellNoise,
  updateRuntimeBrandingFromResponse,
  updateRuntimeDisplayFromResponse,
} from '@/stores/systemSettings';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const frontendRoot = path.resolve(__dirname, '..', '..', '..');
const repoRoot = path.resolve(frontendRoot, '..');

describe('systemSettings store', () => {
  beforeEach(() => {
    markSystemSettingsLoadedWithDefaults();
    clearRuntimeBranding();
  });

  it('applies route and docker feature flags from API response', () => {
    updateRuntimeDisplayFromResponse({
      theme: 'dark',
      disableDockerUpdateActions: true,
      reduceProUpsellNoise: true,
    });

    expect(shouldHideDockerUpdateActions()).toBe(true);
    expect(shouldReduceProUpsellNoise()).toBe(true);
  });

  it('resets route and docker feature flags to safe defaults', () => {
    updateRuntimeDisplayFromResponse({
      theme: 'dark',
      disableDockerUpdateActions: true,
      reduceProUpsellNoise: true,
    });

    markSystemSettingsLoadedWithDefaults();
    expect(shouldHideDockerUpdateActions()).toBe(false);
    expect(shouldReduceProUpsellNoise()).toBe(false);
  });

  it('keeps privacy and local paid-flow defaults safe when flags are omitted', () => {
    updateRuntimeDisplayFromResponse({
      theme: 'dark',
    });

    expect(areSystemSettingsLoaded()).toBe(true);
    expect(shouldHideDockerUpdateActions()).toBe(false);
    expect(shouldReduceProUpsellNoise()).toBe(false);
  });

  it('normalizes the entitlement-filtered runtime branding payload', () => {
    updateRuntimeBrandingFromResponse({
      enabled: true,
      displayName: '  Acme Operations  ',
      logoDataUrl: 'data:image/png;base64,YWJj',
    });

    expect(runtimeBranding()).toEqual({
      enabled: true,
      displayName: 'Acme Operations',
      logoDataUrl: 'data:image/png;base64,YWJj',
    });

    clearRuntimeBranding();
    expect(runtimeBranding()).toEqual({ enabled: false, displayName: '', logoDataUrl: '' });
  });

  it('drops branding values from a disabled runtime response', () => {
    updateRuntimeBrandingFromResponse({
      enabled: false,
      displayName: 'Must not render',
      logoDataUrl: 'data:image/png;base64,YWJj',
    });

    expect(runtimeBranding()).toEqual({ enabled: false, displayName: '', logoDataUrl: '' });
  });

  it('keeps the telemetry disclosure on the shipped local privacy doc', () => {
    expect(PRIVACY_DOC_URL).toBe('/docs/PRIVACY');
  });

  it('keeps the telemetry disclosure in user-facing product language', () => {
    const telemetryDescription = EN_MESSAGES['settings.general.telemetry.description'];

    expect(telemetryDescription).toContain('coarse deployment and lifecycle buckets');
    expect(telemetryDescription).toContain('aggregate resource and outcome counts');
    expect(telemetryDescription).toContain(
      'content-free Patrol, Assistant, and capability-API usage counters',
    );
    expect(telemetryDescription).toContain('URLs, paths, locale, raw browser events');
    expect(telemetryDescription).not.toContain('Pulse Intelligence loop adoption');
    expect(telemetryDescription).not.toContain('activation loop');
    expect(telemetryDescription).not.toContain('operations loop');
  });

  it('documents telemetry retention and field-level rationale in the privacy doc', () => {
    const privacyDoc = readFileSync(path.join(repoRoot, 'docs', 'PRIVACY.md'), 'utf8');
    const shippedPrivacyDoc = readFileSync(
      path.join(frontendRoot, 'public', 'docs', 'PRIVACY.md'),
      'utf8',
    );
    const privacyText = privacyDoc.replace(/\s+/g, ' ');

    expect(privacyDoc).not.toContain('secure remote web access');
    expect(privacyDoc).toContain('Relay does not provide remote access to the web UI');
    expect(privacyDoc).toContain('## Usage Data');
    expect(privacyDoc).toContain('Pulse has one outbound usage-data scope');
    expect(privacyDoc).toContain('Commercial activation and license-recovery runtime records');
    expect(privacyDoc).not.toContain('Local-only commercial handoff events');
    expect(privacyDoc).not.toContain('Disable local-only commercial events');
    expect(privacyDoc).not.toContain('reduceProUpsellNoise');
    expect(privacyDoc).toContain('Every field is listed below with the reason it exists');
    expect(privacyDoc).toContain('rows older than **90 days** are purged automatically');
    expect(privacyDoc).toContain('uses request IP addresses transiently for abuse/rate limiting');
    expect(privacyDoc).toContain('Reset ID');
    expect(privacyDoc).toContain('active Patrol objective briefs');
    expect(privacyText).toMatch(/encrypted at rest in the local organi[sz]ation data directory/);
    expect(privacyText).toContain('objective text is not included in Pulse usage telemetry');
    expect(privacyDoc).toContain('Pulse Intelligence Patrol control completed operations loop 30d');
    expect(privacyDoc).toContain(
      'Pulse Intelligence Patrol control paid resolved operations loop 30d',
    );
    expect(privacyDoc).not.toContain('completed-work proof');
    expect(privacyDoc).not.toContain('resolved-work proof');
    expect(privacyDoc).not.toContain('governed-operation proof');
    expect(shippedPrivacyDoc).toBe(privacyDoc);
  });

  it('keeps internal commercial compatibility switches out of public configuration docs', () => {
    const configurationDoc = readFileSync(path.join(repoRoot, 'docs', 'CONFIGURATION.md'), 'utf8');

    expect(configurationDoc).not.toContain('reduceProUpsellNoise');
    expect(configurationDoc).not.toContain('disableLocalUpgradeMetrics');
    expect(configurationDoc).not.toContain('PULSE_DISABLE_LOCAL_UPGRADE_METRICS');
    expect(configurationDoc).toContain('PULSE_TELEMETRY');
  });

  it('keeps existing mobile pairing security without offering retired Relay', () => {
    const securityDoc = readFileSync(path.join(repoRoot, 'SECURITY.md'), 'utf8');
    const publicSecurityDoc = readFileSync(
      path.join(frontendRoot, 'public', 'docs', 'SECURITY.md'),
      'utf8',
    );

    for (const copy of [securityDoc, publicSecurityDoc]) {
      expect(copy).toContain('### Existing Mobile Pairings (Retirement)');
      expect(copy).toContain('Pulse Mobile and Relay retire on **31 March 2027**');
      expect(copy).toContain('Existing paired phones keep\nworking until then');
      expect(copy).toContain('Relay is no longer sold');
      expect(copy).toContain('receive Pro features at their current price');
      expect(copy).toContain('Paired-app access remains license-gated until retirement');
      expect(copy).toMatch(/Relay connects the app, not the\s+web UI/);
      expect(copy).not.toContain('Relay Security (Relay and Above)');
      expect(copy).not.toContain('Relay Security (Pro)');
      expect(copy).not.toContain('Relay functionality requires a Pro or Cloud license');
    }
    expect(publicSecurityDoc).toBe(securityDoc);
  });

  it('documents self-hosted AI provider transport and resource-policy redaction in the privacy doc', () => {
    const privacyDoc = readFileSync(path.join(repoRoot, 'docs', 'PRIVACY.md'), 'utf8');
    const privacyText = privacyDoc.replace(/\s+/g, ' ');

    expect(privacyText).toContain(
      'providers receive this context directly from your self-managed Pulse instance',
    );
    expect(privacyText).toContain('AI prompts do not transit Pulse infrastructure');
    expect(privacyText).toContain('Pulse applies secret filtering and resource-policy handling');
    expect(privacyText).toContain('known restricted resource identifiers are redacted');
    expect(privacyText).toContain(
      'Internal and Sensitive resources can still be shared with a hosted model',
    );
    expect(privacyText).toContain(
      'verify that the chosen endpoint runs within your trusted network and does not forward requests elsewhere',
    );
  });
});