Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

2.2 KB
Raw Blame
import { describe, expect, it, vi } from 'vitest';
import { exportDesktopDiagnostics } from '../src/main/diagnostics.js';

describe('Desktop diagnostics', () => {
  it('recursively redacts the final payload before writing', async () => {
    let writtenPayload = '';

    await expect(exportDesktopDiagnostics({
      state: {
        phase: 'failed',
        startedAt: '2026-07-16T00:00:00.000Z',
        updatedAt: '2026-07-16T00:00:00.000Z',
        attempt: 1,
        revision: 3,
        error: {
          code: 'TEST',
          message: 'Authorization: Bearer secret-value'
        }
      },
      dataDir: '/tmp/TOKEN=secret-value/data',
      logDir: '/tmp/logs',
      dependencies: {
        showSaveDialog: vi.fn(async () => ({
          canceled: false,
          filePath: '/tmp/diagnostics.json'
        })),
        getAppVersion: () => '0.1.0',
        writeFile: async (_path, contents) => {
          writtenPayload = contents;
        },
        readFile: async () => (
          '{"level":"error","message":"TOKEN=secret-value module failed"}\n'
        ),
        now: () => new Date('2026-07-16T00:00:00.000Z')
      }
    })).resolves.toEqual({ ok: true });

    const payload = writtenPayload;
    expect(payload).not.toContain('secret-value');
    expect(payload).toContain('[REDACTED]');
    expect(payload).toContain('/tmp/');
    expect(payload).toContain('desktopLogTail');
    expect(payload).toContain('module failed');
  });

  it('does not write when the user cancels the export', async () => {
    const writeFile = vi.fn(async (
      _path: string,
      _contents: string,
      _options: { mode: number }
    ) => undefined);
    const result = await exportDesktopDiagnostics({
      state: {
        phase: 'idle',
        startedAt: '2026-07-16T00:00:00.000Z',
        updatedAt: '2026-07-16T00:00:00.000Z',
        attempt: 0,
        revision: 0
      },
      dataDir: '/tmp/data',
      logDir: '/tmp/logs',
      dependencies: {
        showSaveDialog: vi.fn(async () => ({ canceled: true })),
        getAppVersion: () => '0.1.0',
        writeFile,
        now: () => new Date('2026-07-16T00:00:00.000Z')
      }
    });

    expect(result).toMatchObject({ ok: false });
    expect(writeFile).not.toHaveBeenCalled();
  });
});