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.

3.1 KB
Raw Blame
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import test from 'node:test';

import {
  managedVerifyLockActive,
  shouldRestartManagedDevRuntimeForVerification,
} from './managed-dev-runtime.mjs';

test('managedVerifyLockActive returns true for a live verify lock owner', async () => {
  const rootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'pulse-managed-dev-runtime-'));
  const lockPath = path.join(rootDir, 'hot-dev.verify.lock');
  await fs.writeFile(lockPath, `pid=${process.pid}\ncreated_at=2026-03-28T23:00:00Z\n`, 'utf8');

  assert.equal(managedVerifyLockActive({ HOT_DEV_VERIFY_LOCK_FILE: lockPath }), true);
});

test('managedVerifyLockActive clears false when the verify lock owner is stale', async () => {
  const rootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'pulse-managed-dev-runtime-'));
  const lockPath = path.join(rootDir, 'hot-dev.verify.lock');
  await fs.writeFile(lockPath, 'pid=999999\ncreated_at=2026-03-28T23:00:00Z\n', 'utf8');

  assert.equal(managedVerifyLockActive({ HOT_DEV_VERIFY_LOCK_FILE: lockPath }), false);
});

test('shouldRestartManagedDevRuntimeForVerification restarts existing sessions under verify lock', async () => {
  const rootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'pulse-managed-dev-runtime-'));
  const lockPath = path.join(rootDir, 'hot-dev.verify.lock');
  await fs.writeFile(lockPath, `pid=${process.pid}\ncreated_at=2026-03-28T23:00:00Z\n`, 'utf8');

  assert.equal(
    shouldRestartManagedDevRuntimeForVerification({
      env: { HOT_DEV_VERIFY_LOCK_FILE: lockPath },
      wasRunning: true,
    }),
    true,
  );
  assert.equal(
    shouldRestartManagedDevRuntimeForVerification({
      env: { HOT_DEV_VERIFY_LOCK_FILE: lockPath },
      wasRunning: false,
    }),
    false,
  );
});

test('shouldRestartManagedDevRuntimeForVerification restarts existing sessions with non-deterministic auth', async () => {
  const rootDir = await fs.mkdtemp(path.join(os.tmpdir(), 'pulse-managed-dev-runtime-'));
  const envPath = path.join(rootDir, 'tmp', 'dev-config', '.env');
  await fs.mkdir(path.dirname(envPath), { recursive: true });

  const env = { PULSE_E2E_REPO_ROOT: rootDir };

  assert.equal(
    shouldRestartManagedDevRuntimeForVerification({
      env,
      wasRunning: true,
    }),
    true,
  );

  await fs.writeFile(
    envPath,
    [
      '# Managed by hot-dev.sh for deterministic dev auth',
      "PULSE_AUTH_USER='admin'",
      "PULSE_AUTH_PASS='$2a$12$J/Vu6FlBUJDTK.VAkysjB.AnvFOcijDbETyumhCB.nJVes5gvpiI6'",
      '',
    ].join('\n'),
    'utf8',
  );
  assert.equal(
    shouldRestartManagedDevRuntimeForVerification({
      env,
      wasRunning: true,
    }),
    false,
  );

  await fs.writeFile(
    envPath,
    [
      '# Auto-generated by Pulse Quick Security Setup',
      "PULSE_AUTH_USER='setup-user'",
      "PULSE_AUTH_PASS='$2a$12$setupgeneratedauthhashvalue'",
      '',
    ].join('\n'),
    'utf8',
  );
  assert.equal(
    shouldRestartManagedDevRuntimeForVerification({
      env,
      wasRunning: true,
    }),
    true,
  );
});