import fs from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; import {
deriveScheduledTaskRuntimeStatus,
parseSchtasksQuery,
readScheduledTaskCommand,
resolveTaskScriptPath,
} from "./schtasks.js";
it("treats Running without numeric result as unknown", () => {
expect(
deriveScheduledTaskRuntimeStatus({
status: "Running",
}),
).toEqual({
status: "unknown",
detail: "Task status is locale-dependent and no numeric Last Run Result was available.",
});
});
it("treats non-running result codes as stopped", () => {
expect(
deriveScheduledTaskRuntimeStatus({
status: "Running",
lastRunResult: "0x0",
}),
).toEqual({
status: "stopped",
detail: "Task Last Run Result=0x0; treating as not running.",
});
});
it("detects running via result code when status is localized (German)", () => {
expect(
deriveScheduledTaskRuntimeStatus({
status: "Wird ausgeführt",
lastRunResult: "0x41301",
}),
).toEqual({ status: "running" });
});
it("detects running via result code when status is localized (French)", () => {
expect(
deriveScheduledTaskRuntimeStatus({
status: "En cours",
lastRunResult: "267009",
}),
).toEqual({ status: "running" });
});
it("treats localized status as stopped when result code is not a running code", () => {
expect(
deriveScheduledTaskRuntimeStatus({
status: "Wird ausgeführt",
lastRunResult: "0x0",
}),
).toEqual({
status: "stopped",
detail: "Task Last Run Result=0x0; treating as not running.",
});
});
it("treats localized status without result code as unknown", () => {
expect(
deriveScheduledTaskRuntimeStatus({
status: "Wird ausgeführt",
}),
).toEqual({
status: "unknown",
detail: "Task status is locale-dependent and no numeric Last Run Result was available.",
});
});
});
describe("resolveTaskScriptPath", () => {
it.each([
{
name: "uses default path when OPENCLAW_PROFILE is unset",
env: { USERPROFILE: "C:\\Users\\test" },
expected: path.join("C:\\Users\\test", ".openclaw", "gateway.cmd"),
},
{
name: "uses profile-specific path when OPENCLAW_PROFILE is set to a custom value",
env: { USERPROFILE: "C:\\Users\\test", OPENCLAW_PROFILE: "jbphoenix" },
expected: path.join("C:\\Users\\test", ".openclaw-jbphoenix", "gateway.cmd"),
},
{
name: "prefers OPENCLAW_STATE_DIR over profile-derived defaults",
env: {
USERPROFILE: "C:\\Users\\test",
OPENCLAW_PROFILE: "rescue",
OPENCLAW_STATE_DIR: "C:\\State\\openclaw",
},
expected: path.join("C:\\State\\openclaw", "gateway.cmd"),
},
{
name: "falls back to HOME when USERPROFILE is not set",
env: { HOME: "/home/test", OPENCLAW_PROFILE: "default" },
expected: path.join("/home/test", ".openclaw", "gateway.cmd"),
},
])("$name", ({ env, expected }) => {
expect(resolveTaskScriptPath(env)).toBe(expected);
});
});
it("parses script with quoted arguments containing spaces", async () => {
await withScheduledTaskScript(
{ // Use forward slashes which work in Windows cmd and avoid escape parsing issues.
scriptLines: ["@echo off", '"C:/Program Files/Node/node.exe" gateway.js'],
},
async (env) => { const result = await readScheduledTaskCommand(env);
expect(result).toEqual({
programArguments: ["C:/Program Files/Node/node.exe", "gateway.js"],
sourcePath: resolveTaskScriptPath(env),
});
},
);
});
it("returns null when script does not exist", async () => {
await withScheduledTaskScript({}, async (env) => { const result = await readScheduledTaskCommand(env);
expect(result).toBeNull();
});
});
it("returns null when script has no command", async () => {
await withScheduledTaskScript(
{ scriptLines: ["@echo off", "rem This is just a comment"] },
async (env) => { const result = await readScheduledTaskCommand(env);
expect(result).toBeNull();
},
);
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.