Include desktop app logs in diagnostics (#1914)

* fix(diagnostics): include desktop app logs

Settings diagnostics now collect the Electron main-process log separately from daemon.log so desktop startup and environment-probe failures are included in app reports.

* refactor(desktop): share log tail reader

* fix(diagnostics): surface desktop app log read errors

* refactor(diagnostics): tighten desktop report API
This commit is contained in:
Mohamed Boudra
2026-07-06 17:50:45 +02:00
committed by GitHub
parent 7c1da0077b
commit f21c997b17
10 changed files with 322 additions and 48 deletions
@@ -19,6 +19,8 @@ const mocks = vi.hoisted(() => ({
spawnProcess: vi.fn(),
logInfo: vi.fn(),
logError: vi.fn(),
appLogPath: "/tmp/paseo-desktop-daemon-manager-test-main.log",
getElectronLogFile: vi.fn(),
}));
vi.mock("electron", () => ({
@@ -32,7 +34,15 @@ vi.mock("electron", () => ({
}));
vi.mock("electron-log/main", () => ({
default: { info: mocks.logInfo, error: mocks.logError },
default: {
info: mocks.logInfo,
error: mocks.logError,
transports: {
file: {
getFile: mocks.getElectronLogFile,
},
},
},
}));
vi.mock("@getpaseo/server", () => ({
@@ -105,11 +115,15 @@ describe("daemon-manager commands", () => {
mocks.spawnProcess.mockReset();
mocks.logInfo.mockReset();
mocks.logError.mockReset();
mocks.getElectronLogFile.mockReset();
mocks.getElectronLogFile.mockReturnValue({ path: mocks.appLogPath });
rmSync(mocks.paseoHome, { recursive: true, force: true });
rmSync(mocks.appLogPath, { force: true });
});
afterEach(() => {
rmSync(mocks.paseoHome, { recursive: true, force: true });
rmSync(mocks.appLogPath, { force: true });
});
it("refuses start and restart while built-in daemon management is disabled", async () => {
@@ -435,4 +449,19 @@ describe("daemon-manager commands", () => {
}),
);
});
it("returns the Electron main-process log tail from electron-log", () => {
writeFileSync(
mocks.appLogPath,
Array.from({ length: 105 }, (_value, index) => `main log line ${index + 1}`).join("\n"),
);
const handlers = createDaemonCommandHandlers();
expect(handlers.desktop_app_logs()).toEqual({
logPath: mocks.appLogPath,
contents: Array.from({ length: 100 }, (_value, index) => `main log line ${index + 6}`).join(
"\n",
),
});
});
});
@@ -39,6 +39,8 @@ import {
import type { DesktopSettings } from "../settings/desktop-settings.js";
import { getDesktopSettingsStore } from "../settings/desktop-settings-electron.js";
import { isRunningUnderARM64Translation } from "../system/arm64-translation.js";
import { getDesktopAppLogs } from "../diagnostics/app-logs.js";
import { tailFile } from "../diagnostics/tail-file.js";
const DAEMON_LOG_FILENAME = "daemon.log";
const STARTUP_POLL_INTERVAL_MS = 200;
@@ -211,15 +213,6 @@ function sleep(ms: number): Promise<void> {
});
}
function tailFile(filePath: string, lines = 50): string {
try {
const content = readFileSync(filePath, "utf-8");
return content.split("\n").filter(Boolean).slice(-lines).join("\n");
} catch {
return "";
}
}
function logDesktopDaemonLifecycle(message: string, details?: Record<string, unknown>): void {
log.info("[desktop daemon]", message, {
pid: process.pid,
@@ -574,6 +567,7 @@ export function createDaemonCommandHandlers(): Record<string, DesktopCommandHand
stop_desktop_daemon: (args) => stopDesktopDaemon(parseDesktopDaemonStopReason(args)),
restart_desktop_daemon: () => restartDaemon(),
desktop_daemon_logs: () => getDaemonLogs(),
desktop_app_logs: () => getDesktopAppLogs(),
desktop_daemon_pairing: () => getDaemonPairing(),
desktop_get_system_idle_time: () => powerMonitor.getSystemIdleTime() * 1000,
cli_daemon_status: () => getCliDaemonStatus(),