diff --git a/src/scheduler/cron.js b/src/scheduler/cron.js index 150ecb31..0356cad9 100644 --- a/src/scheduler/cron.js +++ b/src/scheduler/cron.js @@ -104,12 +104,11 @@ export const Cron = { */ async _readCrontab() { try { - return ( - (await _execOverride("crontab -l 2>&1", { - encoding: "utf-8", - stdio: ["pipe", "pipe", "pipe"], - })) || "" - ).trim(); + const { stdout } = await _execOverride("crontab -l 2>&1", { + encoding: "utf-8", + stdio: ["pipe", "pipe", "pipe"], + }); + return (stdout || "").trim(); } catch (_err) { return ""; } diff --git a/tests/unit/scheduler/cron.test.js b/tests/unit/scheduler/cron.test.js index 0f380360..1d0e6910 100644 --- a/tests/unit/scheduler/cron.test.js +++ b/tests/unit/scheduler/cron.test.js @@ -12,18 +12,18 @@ function mockExec(command, options) { // Intercept crontab commands if (command.includes("crontab -l")) { - return Promise.resolve(mockCrontabContent || ""); + return Promise.resolve({ stdout: mockCrontabContent || "", stderr: "" }); } if (command.includes("crontab -")) { // Read from stdin (the content to install) const stdin = options?.input || ""; mockCrontabContent = stdin; - return Promise.resolve(""); + return Promise.resolve({ stdout: "", stderr: "" }); } if (command.includes("which crontab")) { - return Promise.resolve("/usr/bin/crontab"); + return Promise.resolve({ stdout: "/usr/bin/crontab", stderr: "" }); } // Reject unknown commands to prevent hanging