fix(daemon): use locale-invariant schtasks running code detection (#39076)

Co-authored-by: ademczuk <andrew.demczuk@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-07 19:56:47 +00:00
parent 3c1176110a
commit 80a6eb3131
3 changed files with 50 additions and 4 deletions

View File

@@ -63,6 +63,41 @@ describe("scheduled task runtime derivation", () => {
detail: "Task reports Running but Last Run Result=0x0; treating as stale runtime state.",
});
});
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" });
});
it("treats localized status without result code as stopped", () => {
expect(
deriveScheduledTaskRuntimeStatus({
status: "Wird ausgeführt",
}),
).toEqual({ status: "stopped" });
});
});
describe("resolveTaskScriptPath", () => {

View File

@@ -163,13 +163,23 @@ export function deriveScheduledTaskRuntimeStatus(parsed: ScheduledTaskInfo): {
if (!statusRaw) {
return { status: "unknown" };
}
if (statusRaw !== "running") {
return { status: "stopped" };
}
const normalizedResult = normalizeTaskResultCode(parsed.lastRunResult);
const runningCodes = new Set(["0x41301"]);
if (normalizedResult && !runningCodes.has(normalizedResult)) {
const isRunningByCode = normalizedResult != null && runningCodes.has(normalizedResult);
const isRunningByStatus = statusRaw === "running";
// schtasks.exe localizes its Status field ("Running" in English,
// "Wird ausgeführt" in German, "En cours" in French, etc.).
// Prefer the locale-invariant Last Run Result code 0x41301
// ("task is currently running") over string matching. (#39057)
if (!isRunningByStatus && !isRunningByCode) {
return { status: "stopped" };
}
// Cross-check: if the English status says "running" but the result
// code disagrees, the runtime state is likely stale.
if (isRunningByStatus && normalizedResult && !isRunningByCode) {
return {
status: "stopped",
detail: `Task reports Running but Last Run Result=${parsed.lastRunResult}; treating as stale runtime state.`,