From 10f41e370f04814861476c627b2dae5a3b02fdc2 Mon Sep 17 00:00:00 2001 From: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com> Date: Mon, 6 Jul 2026 18:46:00 -0400 Subject: [PATCH] fix(win-update-e2e): escape \$ for the outer shell so nested-pwsh loops actually run --- tools/win-update-e2e/app-driver.mjs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tools/win-update-e2e/app-driver.mjs b/tools/win-update-e2e/app-driver.mjs index ec778c074..8c4004141 100644 --- a/tools/win-update-e2e/app-driver.mjs +++ b/tools/win-update-e2e/app-driver.mjs @@ -275,12 +275,16 @@ export async function sendCtrlC(page) { } /** - * Run a PowerShell command inside the active terminal, shell-agnostically: - * invoking powershell.exe works whether the pty's shell is cmd, pwsh, - * PowerShell, or a POSIX shell on Windows. Used to write sentinel files. + * Run a PowerShell command inside the active terminal by invoking a nested + * powershell.exe. The command is wrapped in double quotes for the OUTER + * interactive shell (also pwsh), which would otherwise expand `$var`, `$(...)` + * and consume backticks before the nested shell sees them — so escape backticks, + * quotes, and `$`. Without the `$` escape, `while($true)` reaches the nested + * shell as `while(True)` and never runs (the bug that silently broke every + * loop/heartbeat probe while simple `$`-free commands worked). */ export async function runShellCommand(page, psCommand) { - const escaped = psCommand.replace(/"/g, '`"') + const escaped = psCommand.replace(/`/g, '``').replace(/"/g, '`"').replace(/\$/g, '`$') await typeLine(page, `powershell.exe -NoProfile -NonInteractive -Command "${escaped}"`) }