Daemon: tighten systemctl failure classification

This commit is contained in:
Vincent Koc 2026-03-07 16:40:38 -08:00
parent 360dffbe9d
commit 1a256b8670
2 changed files with 23 additions and 3 deletions

View File

@ -224,6 +224,23 @@ describe("isSystemdServiceEnabled", () => {
expect(result).toBe(false);
});
it("throws when generic wrapper errors report infrastructure failures", async () => {
const { isSystemdServiceEnabled } = await import("./systemd.js");
mockManagedUnitPresent();
execFileMock.mockImplementationOnce((_cmd, args, _opts, cb) => {
expect(args).toEqual(["--user", "is-enabled", "openclaw-gateway.service"]);
const err = new Error(
"Command failed: systemctl --user is-enabled openclaw-gateway.service",
) as Error & { code?: number };
err.code = 1;
cb(err, "", "read-only file system");
});
await expect(
isSystemdServiceEnabled({ env: { HOME: "/tmp/openclaw-test-home" } }),
).rejects.toThrow("systemctl is-enabled unavailable: read-only file system");
});
it("throws when systemctl is-enabled fails for non-state errors", async () => {
const { isSystemdServiceEnabled } = await import("./systemd.js");
mockManagedUnitPresent();

View File

@ -189,8 +189,7 @@ function isSystemctlBusUnavailable(detail: string): boolean {
normalized.includes("failed to connect to user scope bus") ||
normalized.includes("dbus_session_bus_address") ||
normalized.includes("xdg_runtime_dir") ||
normalized.includes("no medium found") ||
normalized.includes("connection refused")
normalized.includes("no medium found")
);
}
@ -203,7 +202,11 @@ function isGenericSystemctlIsEnabledFailure(detail: string): boolean {
normalized.startsWith("command failed: systemctl") &&
normalized.includes(" is-enabled ") &&
!normalized.includes("permission denied") &&
!normalized.includes("access denied")
!normalized.includes("access denied") &&
!normalized.includes("no space left") &&
!normalized.includes("read-only file system") &&
!normalized.includes("out of memory") &&
!normalized.includes("cannot allocate memory")
);
}