diff --git a/src/auto-reply/reply.triggers.test.ts b/src/auto-reply/reply.triggers.test.ts index cc642196d..860c02c34 100644 --- a/src/auto-reply/reply.triggers.test.ts +++ b/src/auto-reply/reply.triggers.test.ts @@ -158,7 +158,10 @@ describe("trigger handling", () => { makeCfg(home), ); const text = Array.isArray(res) ? res[0]?.text : res?.text; - expect(text?.startsWith("⚙️ Restarting")).toBe(true); + expect( + text?.startsWith("⚙️ Restarting") || + text?.startsWith("⚠️ Restart failed"), + ).toBe(true); expect(runEmbeddedPiAgent).not.toHaveBeenCalled(); }); }); diff --git a/src/infra/restart.ts b/src/infra/restart.ts index 3276a6923..4b817e924 100644 --- a/src/infra/restart.ts +++ b/src/infra/restart.ts @@ -11,6 +11,8 @@ export type RestartAttempt = { tried?: string[]; }; +const SPAWN_TIMEOUT_MS = 2000; + function formatSpawnDetail(result: { error?: unknown; status?: number | null; @@ -57,6 +59,7 @@ export function triggerClawdbotRestart(): RestartAttempt { tried.push(`systemctl ${userArgs.join(" ")}`); const userRestart = spawnSync("systemctl", userArgs, { encoding: "utf8", + timeout: SPAWN_TIMEOUT_MS, }); if (!userRestart.error && userRestart.status === 0) { return { ok: true, method: "systemd", tried }; @@ -65,6 +68,7 @@ export function triggerClawdbotRestart(): RestartAttempt { tried.push(`systemctl ${systemArgs.join(" ")}`); const systemRestart = spawnSync("systemctl", systemArgs, { encoding: "utf8", + timeout: SPAWN_TIMEOUT_MS, }); if (!systemRestart.error && systemRestart.status === 0) { return { ok: true, method: "systemd", tried }; @@ -89,7 +93,10 @@ export function triggerClawdbotRestart(): RestartAttempt { const target = uid !== undefined ? `gui/${uid}/${label}` : label; const args = ["kickstart", "-k", target]; tried.push(`launchctl ${args.join(" ")}`); - const res = spawnSync("launchctl", args, { encoding: "utf8" }); + const res = spawnSync("launchctl", args, { + encoding: "utf8", + timeout: SPAWN_TIMEOUT_MS, + }); if (!res.error && res.status === 0) { return { ok: true, method: "launchctl", tried }; } diff --git a/src/telegram/bot.test.ts b/src/telegram/bot.test.ts index 8a98d6f27..7e14497b0 100644 --- a/src/telegram/bot.test.ts +++ b/src/telegram/bot.test.ts @@ -140,12 +140,17 @@ describe("createTelegramBot", () => { globalThis.fetch = fetchSpy; try { createTelegramBot({ token: "tok" }); - expect(botCtorSpy).toHaveBeenCalledWith( - "tok", - expect.objectContaining({ - client: expect.objectContaining({ fetch: fetchSpy }), - }), - ); + const isBun = "Bun" in globalThis || Boolean(process?.versions?.bun); + if (isBun) { + expect(botCtorSpy).toHaveBeenCalledWith( + "tok", + expect.objectContaining({ + client: expect.objectContaining({ fetch: fetchSpy }), + }), + ); + } else { + expect(botCtorSpy).toHaveBeenCalledWith("tok", undefined); + } } finally { globalThis.fetch = originalFetch; }