Skip to content

fix(validation): launch sample processes via executable shim on Windows#249

Merged
dluces merged 1 commit into
user/dluces/sample_app_test_planfrom
user/gnjoseph/pr-248-windows-startprocess-fix
Jul 3, 2026
Merged

fix(validation): launch sample processes via executable shim on Windows#249
dluces merged 1 commit into
user/dluces/sample_app_test_planfrom
user/gnjoseph/pr-248-windows-startprocess-fix

Conversation

@gnjoseph

@gnjoseph gnjoseph commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

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 (in Tools/powershell/SampleValidation.ps1) returned the highest-precedence Get-Command match. On Windows, PowerShell command precedence puts the .ps1 script shim first (e.g. npx.ps1, npm.ps1).

Start-LoggedProcess then passes that path to Start-Process with output redirection, which forces UseShellExecute = $false → the OS CreateProcess API. CreateProcess cannot 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/.cmd shims. Only the Start-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 launches dotnet, a real .exe). Non-Windows is unaffected (shebang executables exec directly).

The change

Resolve-CommandPath now prefers a directly-executable form (.exe/.cmd/.bat/.com) when one exists, so Start-Process can launch it. It falls back to the Application command 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-CommandPath now returns npx.cmd / npm.cmd / node.exe (was npx.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.ps1 now builds → lints (non-blocking) → starts the preview server (the previously-fatal step) → passes the HTTP wait → completes, exit 0.
  • Script parses with no syntax errors.

Known follow-up (separate issue, intentionally not in this PR)

Once launch works, the full smoke surfaces a distinct process-teardown bug: npx/npm spawn a deep tree (cmd.exe → node(npx-cli) → node(server)); npx-cli exits and orphans the server node, so Stop-LoggedProcess's Kill($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

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>
@dluces dluces merged commit fc25847 into user/dluces/sample_app_test_plan Jul 3, 2026
1 check passed
@dluces dluces deleted the user/gnjoseph/pr-248-windows-startprocess-fix branch July 3, 2026 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants