Daemon: scope relaxed systemd probes to install flows

This commit is contained in:
Vincent Koc
2026-03-07 16:45:18 -08:00
parent fcb990e369
commit 0d66834f94
6 changed files with 102 additions and 19 deletions

View File

@@ -11,6 +11,7 @@ vi.mock("node:child_process", () => ({
import { splitArgsPreservingQuotes } from "./arg-split.js";
import { parseSystemdExecStart } from "./systemd-unit.js";
import {
isNonFatalSystemdInstallProbeError,
isSystemdUserServiceAvailable,
parseSystemdShow,
readSystemdServiceExecStart,
@@ -177,8 +178,11 @@ describe("isSystemdServiceEnabled", () => {
cb(err, "", "");
});
const result = await isSystemdServiceEnabled({ env: { HOME: "/tmp/openclaw-test-home" } });
expect(result).toBe(false);
await expect(
isSystemdServiceEnabled({ env: { HOME: "/tmp/openclaw-test-home" } }),
).rejects.toThrow(
"systemctl is-enabled unavailable: Command failed: systemctl --user is-enabled openclaw-gateway.service",
);
});
it("returns false when is-enabled cannot connect to the user bus without machine fallback", async () => {
@@ -196,10 +200,11 @@ describe("isSystemdServiceEnabled", () => {
);
});
const result = await isSystemdServiceEnabled({
env: { HOME: "/tmp/openclaw-test-home", USER: "", LOGNAME: "" },
});
expect(result).toBe(false);
await expect(
isSystemdServiceEnabled({
env: { HOME: "/tmp/openclaw-test-home", USER: "", LOGNAME: "" },
}),
).rejects.toThrow("systemctl is-enabled unavailable: Failed to connect to bus");
});
it("returns false when both direct and machine-scope is-enabled checks report bus unavailability", async () => {
@@ -232,10 +237,11 @@ describe("isSystemdServiceEnabled", () => {
);
});
const result = await isSystemdServiceEnabled({
env: { HOME: "/tmp/openclaw-test-home", USER: "debian" },
});
expect(result).toBe(false);
await expect(
isSystemdServiceEnabled({
env: { HOME: "/tmp/openclaw-test-home", USER: "debian" },
}),
).rejects.toThrow("systemctl is-enabled unavailable: Failed to connect to user scope bus");
});
it("throws when generic wrapper errors report infrastructure failures", async () => {
@@ -295,6 +301,32 @@ describe("isSystemdServiceEnabled", () => {
});
});
describe("isNonFatalSystemdInstallProbeError", () => {
it("matches wrapper-only WSL install probe failures", () => {
expect(
isNonFatalSystemdInstallProbeError(
new Error("Command failed: systemctl --user is-enabled openclaw-gateway.service"),
),
).toBe(true);
});
it("matches bus-unavailable install probe failures", () => {
expect(
isNonFatalSystemdInstallProbeError(
new Error("systemctl is-enabled unavailable: Failed to connect to bus"),
),
).toBe(true);
});
it("does not match real infrastructure failures", () => {
expect(
isNonFatalSystemdInstallProbeError(
new Error("systemctl is-enabled unavailable: read-only file system"),
),
).toBe(false);
});
});
describe("systemd runtime parsing", () => {
it("parses active state details", () => {
const output = [