fix: unify daemon service label resolution with env

This commit is contained in:
Benjamin Jesuiter
2026-01-15 11:34:27 +01:00
committed by Peter Steinberger
parent cb78fa46a1
commit daf471c450
24 changed files with 450 additions and 100 deletions

View File

@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
import { parseSystemdShow } from "./systemd.js";
import { parseSystemdShow, resolveSystemdUserUnitPath } from "./systemd.js";
describe("systemd runtime parsing", () => {
it("parses active state details", () => {
@@ -19,3 +19,78 @@ describe("systemd runtime parsing", () => {
});
});
});
describe("resolveSystemdUserUnitPath", () => {
it("uses default service name when CLAWDBOT_PROFILE is default", () => {
const env = { HOME: "/home/test", CLAWDBOT_PROFILE: "default" };
expect(resolveSystemdUserUnitPath(env)).toBe(
"/home/test/.config/systemd/user/clawdbot-gateway.service",
);
});
it("uses default service name when CLAWDBOT_PROFILE is unset", () => {
const env = { HOME: "/home/test" };
expect(resolveSystemdUserUnitPath(env)).toBe(
"/home/test/.config/systemd/user/clawdbot-gateway.service",
);
});
it("uses profile-specific service name when CLAWDBOT_PROFILE is set to a custom value", () => {
const env = { HOME: "/home/test", CLAWDBOT_PROFILE: "jbphoenix" };
expect(resolveSystemdUserUnitPath(env)).toBe(
"/home/test/.config/systemd/user/clawdbot-gateway-jbphoenix.service",
);
});
it("prefers CLAWDBOT_SYSTEMD_UNIT over CLAWDBOT_PROFILE", () => {
const env = {
HOME: "/home/test",
CLAWDBOT_PROFILE: "jbphoenix",
CLAWDBOT_SYSTEMD_UNIT: "custom-unit",
};
expect(resolveSystemdUserUnitPath(env)).toBe(
"/home/test/.config/systemd/user/custom-unit.service",
);
});
it("handles CLAWDBOT_SYSTEMD_UNIT with .service suffix", () => {
const env = {
HOME: "/home/test",
CLAWDBOT_SYSTEMD_UNIT: "custom-unit.service",
};
expect(resolveSystemdUserUnitPath(env)).toBe(
"/home/test/.config/systemd/user/custom-unit.service",
);
});
it("trims whitespace from CLAWDBOT_SYSTEMD_UNIT", () => {
const env = {
HOME: "/home/test",
CLAWDBOT_SYSTEMD_UNIT: " custom-unit ",
};
expect(resolveSystemdUserUnitPath(env)).toBe(
"/home/test/.config/systemd/user/custom-unit.service",
);
});
it("handles case-insensitive 'Default' profile", () => {
const env = { HOME: "/home/test", CLAWDBOT_PROFILE: "Default" };
expect(resolveSystemdUserUnitPath(env)).toBe(
"/home/test/.config/systemd/user/clawdbot-gateway.service",
);
});
it("handles case-insensitive 'DEFAULT' profile", () => {
const env = { HOME: "/home/test", CLAWDBOT_PROFILE: "DEFAULT" };
expect(resolveSystemdUserUnitPath(env)).toBe(
"/home/test/.config/systemd/user/clawdbot-gateway.service",
);
});
it("trims whitespace from CLAWDBOT_PROFILE", () => {
const env = { HOME: "/home/test", CLAWDBOT_PROFILE: " myprofile " };
expect(resolveSystemdUserUnitPath(env)).toBe(
"/home/test/.config/systemd/user/clawdbot-gateway-myprofile.service",
);
});
});