Skip to content

Commit 2a140e6

Browse files
committed
fix(daemon): resolve Windows scheduled-task tools
1 parent 6e5f4d6 commit 2a140e6

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/daemon/schtasks.startup-fallback.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import fs from "node:fs/promises";
33
import path from "node:path";
44
import { PassThrough } from "node:stream";
55
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
6-
import { getWindowsCmdExePath } from "../infra/windows-install-roots.js";
6+
import {
7+
getWindowsCmdExePath,
8+
getWindowsPowerShellExePath,
9+
} from "../infra/windows-install-roots.js";
710
import "./test-helpers/schtasks-base-mocks.js";
811
import {
912
inspectPortUsage,
@@ -136,7 +139,11 @@ function makeSpawnSyncResult(overrides: Partial<SpawnSyncResult> = {}): SpawnSyn
136139
function mockWindowsNodeHostProcess(processId = 5151): void {
137140
vi.spyOn(process, "platform", "get").mockReturnValue("win32");
138141
spawnSync.mockImplementation((command, args) => {
139-
if (command === "powershell" && Array.isArray(args) && args.includes(NODE_PROCESS_QUERY)) {
142+
if (
143+
command === getWindowsPowerShellExePath() &&
144+
Array.isArray(args) &&
145+
args.includes(NODE_PROCESS_QUERY)
146+
) {
140147
return makeSpawnSyncResult({
141148
stdout: JSON.stringify([
142149
{
@@ -405,7 +412,7 @@ describe("Windows startup fallback", () => {
405412
findVerifiedGatewayListenerPidsOnPortSync.mockReturnValue([4242]);
406413
spawnSync.mockImplementation((command, args) => {
407414
if (
408-
command === "powershell" &&
415+
command === getWindowsPowerShellExePath() &&
409416
Array.isArray(args) &&
410417
args.includes(
411418
"Get-CimInstance Win32_Process | Select-Object ProcessId,CommandLine | ConvertTo-Json -Compress",
@@ -475,7 +482,7 @@ describe("Windows startup fallback", () => {
475482
fastForwardTaskStartWait();
476483
spawnSync.mockImplementation((command, args) => {
477484
if (
478-
command === "powershell" &&
485+
command === getWindowsPowerShellExePath() &&
479486
Array.isArray(args) &&
480487
args.includes(
481488
"Get-CimInstance Win32_Process | Select-Object ProcessId,CommandLine | ConvertTo-Json -Compress",
@@ -563,7 +570,7 @@ describe("Windows startup fallback", () => {
563570
);
564571
spawnSync.mockImplementation((command, args) => {
565572
if (
566-
command === "powershell" &&
573+
command === getWindowsPowerShellExePath() &&
567574
Array.isArray(args) &&
568575
args.includes(
569576
"Get-CimInstance Win32_Process | Select-Object ProcessId,CommandLine | ConvertTo-Json -Compress",

src/daemon/schtasks.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import { isGatewayArgv } from "../infra/gateway-process-argv.js";
99
import { findVerifiedGatewayListenerPidsOnPortSync } from "../infra/gateway-processes.js";
1010
import { inspectPortUsage } from "../infra/ports.js";
1111
import { parseTcpPort } from "../infra/tcp-port.js";
12-
import { getWindowsCmdExePath, getWindowsInstallRoots } from "../infra/windows-install-roots.js";
12+
import {
13+
getWindowsCmdExePath,
14+
getWindowsPowerShellExePath,
15+
getWindowsSystem32ExePath,
16+
} from "../infra/windows-install-roots.js";
1317
import { killProcessTree } from "../process/kill-tree.js";
1418
import { sleep } from "../utils.js";
1519
import { parseCmdScriptCommandLine, quoteCmdScriptArg } from "./cmd-argv.js";
@@ -743,7 +747,7 @@ async function terminateGatewayProcessTree(pid: number, graceMs: number): Promis
743747
killProcessTree(pid, { graceMs });
744748
return;
745749
}
746-
const taskkillPath = path.join(getWindowsInstallRoots().systemRoot, "System32", "taskkill.exe");
750+
const taskkillPath = getWindowsSystem32ExePath("taskkill.exe");
747751
spawnSync(taskkillPath, ["/T", "/PID", String(pid)], {
748752
stdio: "ignore",
749753
timeout: 5_000,
@@ -796,7 +800,7 @@ function readWindowsProcessSnapshot(): WindowsProcessSnapshotEntry[] | null {
796800
}
797801

798802
const processSnapshot = spawnSync(
799-
"powershell",
803+
getWindowsPowerShellExePath(),
800804
[
801805
"-NoProfile",
802806
"-Command",

0 commit comments

Comments
 (0)