Skip to content

Commit da348c1

Browse files
committed
fix(update): handle default enabled Windows tasks
1 parent 3be0bfa commit da348c1

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

src/daemon/schtasks.stop.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ describe("Scheduled Task stop/restart cleanup", () => {
119119
{ ...SUCCESS_RESPONSE },
120120
{
121121
...SUCCESS_RESPONSE,
122-
stdout: "<Task><Settings><Enabled>true</Enabled></Settings></Task>",
122+
stdout: "<Task><Settings><StartWhenAvailable>true</StartWhenAvailable></Settings></Task>",
123123
},
124124
{ ...SUCCESS_RESPONSE },
125125
);
@@ -201,6 +201,28 @@ describe("Scheduled Task stop/restart cleanup", () => {
201201
});
202202
});
203203

204+
it("treats omitted Settings Enabled state as enabled", async () => {
205+
await withPreparedGatewayTask(async ({ env }) => {
206+
schtasksResponses.push(
207+
{ ...SUCCESS_RESPONSE },
208+
{
209+
...SUCCESS_RESPONSE,
210+
stdout:
211+
"<Task><Triggers><LogonTrigger><Enabled>false</Enabled></LogonTrigger></Triggers><Settings><Hidden>false</Hidden></Settings></Task>",
212+
},
213+
{ ...SUCCESS_RESPONSE },
214+
);
215+
216+
await expect(suspendScheduledTaskAutoStartForUpdate(env)).resolves.toBe(true);
217+
218+
expect(schtasksCalls).toEqual([
219+
["/Query"],
220+
["/Query", "/TN", "OpenClaw Gateway", "/XML"],
221+
["/Change", "/TN", "OpenClaw Gateway", "/DISABLE"],
222+
]);
223+
});
224+
});
225+
204226
it("reads NUL-separated Scheduled Task XML enabled state", async () => {
205227
await withPreparedGatewayTask(async ({ env }) => {
206228
const xml = "<Task><Settings><Enabled>true</Enabled></Settings></Task>";

src/daemon/schtasks.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,10 +1283,13 @@ function isTaskNotRunning(res: { stdout: string; stderr: string; code: number })
12831283
function parseScheduledTaskXmlEnabled(output: string): boolean | null {
12841284
const normalizedOutput = output.replace(/^\uFEFF/u, "").replaceAll(String.fromCharCode(0), "");
12851285
const settings = /<Settings(?:\s[^>]*)?>([\s\S]*?)<\/Settings>/iu.exec(normalizedOutput);
1286-
const match = settings?.[1] ? /<Enabled>\s*(true|false)\s*<\/Enabled>/iu.exec(settings[1]) : null;
1287-
if (!match?.[1]) {
1286+
if (!settings?.[1]) {
12881287
return null;
12891288
}
1289+
const match = /<Enabled>\s*(true|false)\s*<\/Enabled>/iu.exec(settings[1]);
1290+
if (!match?.[1]) {
1291+
return true;
1292+
}
12901293
return match[1].toLowerCase() === "true";
12911294
}
12921295

0 commit comments

Comments
 (0)