Files
openclaw/src/daemon/systemd-unit.test.ts
neo1027144 2cf9ed782d fix(daemon): prevent systemd restart storm on config validation failure
Exit gateway configuration failures with EX_CONFIG and teach generated systemd units not to restart on that exit status.\n\nCo-authored-by: neo1027144-creator <neo1027144-creator@users.noreply.github.com>
2026-04-10 16:23:46 +01:00

42 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { buildSystemdUnit } from "./systemd-unit.js";
describe("buildSystemdUnit", () => {
it("quotes arguments with whitespace", () => {
const unit = buildSystemdUnit({
description: "OpenClaw Gateway",
programArguments: ["/usr/bin/openclaw", "gateway", "--name", "My Bot"],
environment: {},
});
const execStart = unit.split("\n").find((line) => line.startsWith("ExecStart="));
expect(execStart).toBe('ExecStart=/usr/bin/openclaw gateway --name "My Bot"');
});
it("renders control-group kill mode for child-process cleanup", () => {
const unit = buildSystemdUnit({
description: "OpenClaw Gateway",
programArguments: ["/usr/bin/openclaw", "gateway", "run"],
environment: {},
});
expect(unit).toContain("KillMode=control-group");
expect(unit).toContain("TimeoutStopSec=30");
expect(unit).toContain("TimeoutStartSec=30");
expect(unit).toContain("SuccessExitStatus=0 143");
expect(unit).toContain("StartLimitBurst=5");
expect(unit).toContain("StartLimitIntervalSec=60");
expect(unit).toContain("RestartPreventExitStatus=78");
});
it("rejects environment values with line breaks", () => {
expect(() =>
buildSystemdUnit({
description: "OpenClaw Gateway",
programArguments: ["/usr/bin/openclaw", "gateway", "start"],
environment: {
INJECT: "ok\nExecStartPre=/bin/touch /tmp/oc15789_rce",
},
}),
).toThrow(/CR or LF/);
});
});