fix(validation): launch sample processes via executable shim on Windows#249
Merged
dluces merged 1 commit intoJul 3, 2026
Conversation
Resolve-CommandPath returned the highest-precedence Get-Command match, which on Windows is the PowerShell script shim (e.g. npx.ps1). Start- LoggedProcess passes that path to Start-Process with output redirection, forcing the CreateProcess code path -- which cannot execute .ps1 (or the extensionless npm/npx) shims. Every Windows runtime/browser smoke step therefore failed immediately with "%1 is not a valid Win32 application". Resolve a directly executable form (.cmd/.exe/...) when one exists, while falling back to the Application command form for Linux/macOS, where the shebang executable can be exec'd directly. The call operator path (Invoke-ExternalCommand) is unaffected since it runs .cmd shims fine too. Verified on Windows (pwsh 7.4): Resolve-CommandPath now returns npx.cmd / npm.cmd / node.exe; Start-LoggedProcess launches with redirection without error; and project-management/validate-sample.ps1 reaches and passes the preview-server startup it previously crashed on (exit code 0). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
This PR targets
user/dluces/sample_app_test_plan(the branch behind #248) so the fix flows into that PR after your review. It fixes a Windows-specific defect in the validation harness added by #248: every runtime/browser smoke step fails immediately on Windows with%1 is not a valid Win32 application.Root cause
Resolve-CommandPath(inTools/powershell/SampleValidation.ps1) returned the highest-precedenceGet-Commandmatch. On Windows, PowerShell command precedence puts the.ps1script shim first (e.g.npx.ps1,npm.ps1).Start-LoggedProcessthen passes that path toStart-Processwith output redirection, which forcesUseShellExecute = $false→ the OSCreateProcessAPI.CreateProcesscannot execute PowerShell script shims (.ps1) or the extensionless npm/npx shims — hence the failure.Build/install/test steps are unaffected because they run through
Invoke-ExternalCommand, which uses the PowerShell call operator (&), and that can run.ps1/.cmdshims. Only theStart-Process-based launches (long-running servers + browser smoke) break.Scope of impact (before this fix): all Node-based samples that reach the runtime/browser step on Windows —
mcp-server,ocr, both boilerplates' client smokes,legal-docs,project-management,webhook. The ASP.NET sample is unaffected (it launchesdotnet, a real.exe). Non-Windows is unaffected (shebang executables exec directly).The change
Resolve-CommandPathnow prefers a directly-executable form (.exe/.cmd/.bat/.com) when one exists, soStart-Processcan launch it. It falls back to theApplicationcommand form (extensionless / shebang executable) for Linux/macOS, then to the first match. One function changed; no behavior change for the call-operator path.Verification (Windows, pwsh 7.4)
Resolve-CommandPathnow returnsnpx.cmd/npm.cmd/node.exe(wasnpx.ps1).Start-LoggedProcess npx --version(redirected — the exact previously-failing pattern) launches cleanly, exit 0, no%1 is not a valid Win32 application.Custom Apps/project-management/validate-sample.ps1now builds → lints (non-blocking) → starts the preview server (the previously-fatal step) → passes the HTTP wait → completes, exit 0.Known follow-up (separate issue, intentionally not in this PR)
Once launch works, the full smoke surfaces a distinct process-teardown bug:
npx/npmspawn a deep tree (cmd.exe → node(npx-cli) → node(server));npx-cliexits and orphans the server node, soStop-LoggedProcess'sKill($true)on the wrapper can't reach it and the server lingers on its port. That needs a heavier fix (Windows Job Object with kill-on-close, or PID-tree/port-based teardown) and is kept out of this surgical change.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com