refactor: unify restart gating and update availability sync

This commit is contained in:
Peter Steinberger
2026-02-19 10:00:27 +01:00
parent 18179fc2c1
commit b4dbe03298
25 changed files with 288 additions and 41 deletions

View File

@@ -58,7 +58,7 @@ describe("trigger handling", () => {
);
});
});
it("rejects /restart by default", async () => {
it("restarts by default", async () => {
await withTempHome(async (home) => {
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
const res = await getReplyFromConfig(
@@ -72,14 +72,14 @@ describe("trigger handling", () => {
makeCfg(home),
);
const text = Array.isArray(res) ? res[0]?.text : res?.text;
expect(text).toContain("/restart is disabled");
expect(text?.startsWith("⚙️ Restarting") || text?.startsWith("⚠️ Restart failed")).toBe(true);
expect(runEmbeddedPiAgentMock).not.toHaveBeenCalled();
});
});
it("restarts when enabled", async () => {
it("rejects /restart when explicitly disabled", async () => {
await withTempHome(async (home) => {
const runEmbeddedPiAgentMock = getRunEmbeddedPiAgentMock();
const cfg = { ...makeCfg(home), commands: { restart: true } } as OpenClawConfig;
const cfg = { ...makeCfg(home), commands: { restart: false } } as OpenClawConfig;
const res = await getReplyFromConfig(
{
Body: "/restart",
@@ -91,7 +91,7 @@ describe("trigger handling", () => {
cfg,
);
const text = Array.isArray(res) ? res[0]?.text : res?.text;
expect(text?.startsWith("⚙️ Restarting") || text?.startsWith("⚠️ Restart failed")).toBe(true);
expect(text).toContain("/restart is disabled");
expect(runEmbeddedPiAgentMock).not.toHaveBeenCalled();
});
});

View File

@@ -1,4 +1,5 @@
import { abortEmbeddedPiRun } from "../../agents/pi-embedded.js";
import { isRestartEnabled } from "../../config/commands.js";
import type { SessionEntry } from "../../config/sessions.js";
import { updateSessionStore } from "../../config/sessions.js";
import { logVerbose } from "../../globals.js";
@@ -256,11 +257,11 @@ export const handleRestartCommand: CommandHandler = async (params, allowTextComm
);
return { shouldContinue: false };
}
if (params.cfg.commands?.restart !== true) {
if (!isRestartEnabled(params.cfg)) {
return {
shouldContinue: false,
reply: {
text: "⚠️ /restart is disabled. Set commands.restart=true to enable.",
text: "⚠️ /restart is disabled (commands.restart=false).",
},
};
}