Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

1.8 KB
Raw Blame
import { existsSync, mkdtempSync, rmSync, statSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
import { excludeFromSpotlight, SPOTLIGHT_EXCLUDED_DIRS, SPOTLIGHT_MARKER } from './lib/spotlightExclude.js';
import { setupSpotlight } from './setup-spotlight.js';

describe('Spotlight exclusion of data/', () => {
  const dirs = [];
  const tmp = () => { const d = mkdtempSync(join(tmpdir(), 'spotlight-')); dirs.push(d); return d; };
  afterEach(() => dirs.splice(0).forEach(d => rmSync(d, { recursive: true, force: true })));

  it('marks only the machinery dirs once on macOS, keeps media indexed, and skips other platforms', () => {
    const dir = tmp();
    expect(excludeFromSpotlight(dir, { platform: 'linux' })).toBe('unsupported');
    expect(existsSync(join(dir, 'cos/worktrees', SPOTLIGHT_MARKER))).toBe(false);
    expect(excludeFromSpotlight(dir, { platform: 'darwin' })).toBe('created');
    expect(existsSync(join(dir, 'cos/worktrees', SPOTLIGHT_MARKER))).toBe(true);
    expect(existsSync(join(dir, SPOTLIGHT_MARKER))).toBe(false);
    expect(existsSync(join(dir, 'videos', SPOTLIGHT_MARKER))).toBe(false);
    expect(excludeFromSpotlight(dir, { platform: 'darwin' })).toBe('present');
  });

  it('honors the opt-out without touching the directory', () => {
    const dir = join(tmp(), 'data');
    expect(setupSpotlight(dir, { log: () => {}, env: { PORTOS_SKIP_SPOTLIGHT_EXCLUDE: '1' } })).toBe('skipped');
    expect(existsSync(dir)).toBe(false);
  });

  it.skipIf(process.platform === 'win32')('creates private machinery directories on macOS', () => {
    const dir = tmp();
    excludeFromSpotlight(dir, { platform: 'darwin' });
    for (const rel of SPOTLIGHT_EXCLUDED_DIRS) {
      expect(statSync(join(dir, rel)).mode & 0o777, rel).toBe(0o700);
    }
  });
});