Skip to content

[MXC] Add checks and fixes for Python and App Execution Aliases#326

Merged
huzaifa-d merged 6 commits into
mainfrom
feat/test-prereq-checks
May 19, 2026
Merged

[MXC] Add checks and fixes for Python and App Execution Aliases#326
huzaifa-d merged 6 commits into
mainfrom
feat/test-prereq-checks

Conversation

@huzaifa-d

@huzaifa-d huzaifa-d commented May 15, 2026

Copy link
Copy Markdown
Contributor

Description

E2E tests failed with cryptic errors (exit 9009, CreateProcessW 0x80070057) when Python was missing/per-user or Windows Store App Execution Aliases shadowed real executables. Store reparse points cannot be launched inside AppContainer/BaseContainer sandboxes.

Changes:

  • build.bat: post-build prereq warnings with interactive fix (install Python via winget + remove Store aliases) when running elevated; opens a fresh terminal after fix for PATH to take effect
  • src/wxc/build.rs: emit cargo:warning during compilation when Python/pwsh are missing or resolve to Store aliases
  • src/wxc_e2e_tests: assert_python()/assert_pwsh() fail tests with clear remediation messages instead of cryptic exit codes; checks if any non-Store path exists (not just the first)
  • test_configs/basic_lpac.json: fix import sys being inside print() string literal
  • test_configs/pwsh_setlocation.json: use full path for pwsh.exe, remove hardcoded C:\Users\st path
  • scripts/setup-test-prereqs.ps1: standalone elevated setup script for one-time machine setup

References

Closes #323

Validation

  • Tested on ARM64 Windows (build 26617) via SSH and interactive terminal
  • Verified: build warnings appear during cargo build
  • Verified: build.bat detects missing Python/Store aliases, prompts to fix when elevated, opens fresh terminal
  • Verified: tests fail with clear message when Python missing, pass after fix
  • Verified: pwsh_setlocation passes with full path in config
  • All 14 E2E tests pass after prerequisites are installed

Checklist

Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

…E2E tests

E2E tests failed with cryptic errors (exit 9009, CreateProcessW 0x80070057)
when Python was missing/per-user or Windows Store App Execution Aliases
shadowed real executables. Store reparse points cannot be launched inside
AppContainer/BaseContainer sandboxes.

Changes:
- build.bat: add post-build prereq warnings with interactive fix (install
  Python via winget + remove Store aliases) when running elevated
- build.rs (wxc): emit cargo:warning during compilation when Python/pwsh
  are missing or resolve to Store aliases
- wxc_e2e_tests: add assert_python()/assert_pwsh() that fail tests with
  clear remediation messages instead of cryptic exit codes
- test_configs/basic_lpac.json: fix import sys being inside print() string
- test_configs/pwsh_setlocation.json: use full path for pwsh.exe, remove
  hardcoded C:\Users\st path
- scripts/setup-test-prereqs.ps1: standalone elevated setup script

Closes #323

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 15, 2026 22:56
@huzaifa-d huzaifa-d added Issue-Bug Something isn't working Needs-Triage labels May 15, 2026

This comment was marked as outdated.

- build.bat: only warn when ALL python/pwsh matches are Store aliases
  (no false positive when real install coexists); remove duplicate
  ALIAS_ISSUE assignment; apply same logic to pwsh check
- build.rs: add cargo:rerun-if-env-changed=PATH so warnings update
  after installing Python/PowerShell
- lib.rs: use case-insensitive check (to_ascii_lowercase) for
  WindowsApps detection in assert_python() and assert_pwsh()

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Comment thread scripts/setup-test-prereqs.ps1
Comment thread scripts/setup-test-prereqs.ps1 Outdated
Comment thread src/wxc_e2e_tests/src/lib.rs Outdated
Comment thread build.bat Outdated
Comment thread src/wxc_e2e_tests/src/lib.rs Outdated
- assert_python: fail when *first* PATH match is a Store alias (shadowing),
  not just when all matches are aliases — matches actual sandbox behavior
- assert_pwsh: validate hardcoded C:\Program Files\PowerShell\7\pwsh.exe
  path exists instead of generic where.exe check
- build.bat: detect first-match Store alias shadowing for python.exe;
  simplified pwsh check to validate expected install path
- setup-test-prereqs.ps1: use Get-Command -All to find any real Python
  even when Store alias shadows it; check \0 after winget
  install; handle missing winget gracefully

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Comment thread build.bat Outdated
Comment on lines +150 to +156
if "!PYTHON_FIRST_ALIAS!"=="1" (
echo WARNING: python.exe first resolves to a Store alias.
echo Store aliases shadow real installs and cannot be launched inside sandbox containers.
set "PREREQ_WARN=1"
set "PYTHON_MISSING=1"
set "ALIAS_ISSUE=1"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this one valid?

Comment thread build.bat Outdated
Comment on lines +181 to +200
set /p "FIX_ALL= Fix issues and install Python? [Y/n] "
if /i "!FIX_ALL!"=="n" goto :done

if "%PYTHON_MISSING%"=="1" (
echo Installing Python 3.12 via winget...
winget install Python.Python.3.12 --scope machine --accept-package-agreements --accept-source-agreements
)

if "%ALIAS_ISSUE%"=="1" (
echo Removing Store aliases...
if exist "%LOCALAPPDATA%\Microsoft\WindowsApps\python.exe" del /f "%LOCALAPPDATA%\Microsoft\WindowsApps\python.exe" 2>nul && echo Removed python.exe alias
if exist "%LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe" del /f "%LOCALAPPDATA%\Microsoft\WindowsApps\python3.exe" 2>nul && echo Removed python3.exe alias
if exist "%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe" del /f "%LOCALAPPDATA%\Microsoft\WindowsApps\pwsh.exe" 2>nul && echo Removed pwsh.exe alias
)

echo.
echo Prerequisites fixed. Starting a fresh terminal to pick up PATH changes...
echo.
start cmd /k "cd /d %~dp0 && echo Ready. Run your tests now."

Comment thread src/wxc/build.rs Outdated
Comment on lines +58 to +86
// Check pwsh
let pwsh_ok = Command::new("where.exe")
.arg("pwsh.exe")
.output()
.ok()
.and_then(|o| {
if !o.status.success() {
return None;
}
let stdout = String::from_utf8_lossy(&o.stdout).to_string();
let first = stdout.lines().next().unwrap_or("").to_string();
Some(first)
});

match pwsh_ok {
None => {
println!("cargo:warning=pwsh.exe not found. PowerShell 7 sandbox tests will fail.");
println!(
"cargo:warning=Fix: Run scripts\\setup-test-prereqs.ps1 (elevated) or install PowerShell 7"
);
}
Some(ref path) if path.to_ascii_lowercase().contains("windowsapps") => {
println!("cargo:warning=pwsh.exe resolves to a Store alias. Store aliases cannot be launched inside sandbox containers.");
println!(
"cargo:warning=Fix: Run scripts\\setup-test-prereqs.ps1 (elevated) or disable App Execution Aliases for PowerShell"
);
}
_ => {}
}
Comment thread scripts/setup-test-prereqs.ps1 Outdated
Comment on lines +125 to +132
$pwshReal = Get-Command pwsh.exe -All -ErrorAction SilentlyContinue |
Where-Object { $_.Source -notlike "*WindowsApps*" } |
Select-Object -First 1
if ($pwshReal) {
Write-Host " OK ($($pwshReal.Source))" -ForegroundColor Green
} else {
Write-Host " MISSING (no non-Store pwsh.exe found)" -ForegroundColor Red
$issues += "PowerShell 7 is not installed (or only available via Store alias)."
Comment on lines +220 to +257
/// Check whether `python.exe` is available and the *first* match in PATH
/// is NOT a Windows Store App Execution Alias. Store aliases are reparse
/// points under `WindowsApps` that cannot be launched inside
/// AppContainer/BaseContainer sandboxes. Even when a real Python exists
/// later in PATH, the sandbox will try to launch the first match and fail.
///
/// Panics with a clear remediation message when Python is missing or
/// the first PATH match is a Store alias.
pub fn assert_python() {
let output = Command::new("where.exe").arg("python.exe").output().ok();

let Some(output) = output else {
panic!(
"python.exe not found.\n\
E2E tests require a system-wide Python install.\n\
Fix: Run scripts\\setup-test-prereqs.ps1 (elevated) or install Python system-wide \
(winget install Python.Python.3.12 --scope machine)"
);
};

if !output.status.success() {
panic!(
"python.exe not found.\n\
E2E tests require a system-wide Python install.\n\
Fix: Run scripts\\setup-test-prereqs.ps1 (elevated) or install Python system-wide \
(winget install Python.Python.3.12 --scope machine)"
);
}

let stdout = String::from_utf8_lossy(&output.stdout);
let first_path = stdout.lines().next().unwrap_or("");
if first_path.to_ascii_lowercase().contains("windowsapps") {
panic!(
"python.exe first resolves to a Windows Store alias ({first_path}).\n\
Store aliases shadow real installs and cannot be launched inside sandbox containers.\n\
Fix: Run scripts\\setup-test-prereqs.ps1 (elevated) or disable App Execution Aliases for Python"
);
}
Comment thread scripts/setup-test-prereqs.ps1 Outdated
$userAlias = Join-Path $env:LOCALAPPDATA "Microsoft\WindowsApps\$ExeName"
if (Test-Path $userAlias) {
Remove-Item $userAlias -Force -ErrorAction SilentlyContinue
Write-Host " Disabled user alias: $userAlias" -ForegroundColor Green
- build.bat: check winget exists before invoking; report if install fails
- build.rs: check pwsh at hardcoded C:\Program Files\PowerShell\7\pwsh.exe
  instead of where.exe (matches test config and assert_pwsh)
- setup-test-prereqs.ps1: check pwsh at expected install path instead of
  Get-Command PATH lookup (consistent with test config)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@huzaifa-d huzaifa-d marked this pull request as ready for review May 18, 2026 18:48
@huzaifa-d huzaifa-d changed the title fix(test): add prereq checks for Python and App Execution Aliases in E2E tests [MXC] Add checks and fixes for Python and App Execution Aliases May 18, 2026
Comment thread scripts/setup-test-prereqs.ps1 Outdated
Comment thread scripts/setup-test-prereqs.ps1 Outdated
# Removing them from the user-local path disables the alias for the current user.
$userAlias = Join-Path $env:LOCALAPPDATA "Microsoft\WindowsApps\$ExeName"
if (Test-Path $userAlias) {
Remove-Item $userAlias -Force -ErrorAction SilentlyContinue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

as long as it's understood that updates may restore the behavior, and this will nuke aliases from legitimate packaged python (i.e. this is for test machines only)

Comment thread build.bat
…Test-StoreAlias

Per Jeff's feedback (PR #326):
- build.bat: remove all interactive fix logic (winget install, alias
  removal, terminal restart). build.bat is for dev machines; nuking
  aliases there is inappropriate. It now just emits warnings + a pointer
  to scripts\setup-test-prereqs.ps1 for test machines.
- setup-test-prereqs.ps1: simplify Test-StoreAlias to just check
  %LOCALAPPDATA%\Microsoft\WindowsApps\<exe> (the redundant AppData
  subset clause is gone). Disable-StoreAlias now documents that:
    1. This is intended for TEST MACHINES ONLY.
    2. Deleting the reparse point IS the Windows-documented mechanism
       to disable an alias (per AppAliasListItemSetting::SetValue in
       onecore/base/appmodel/AppExecutionAlias/settingshandlers).
    3. Updates may restore aliases.

Verified via Windows OS source (Os.2020 br_current).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread build.bat Outdated
for /f "tokens=*" %%P in ('where python.exe') do (
echo %%P | findstr /i "WindowsApps" >nul 2>&1
if not errorlevel 1 (
echo WARNING: python.exe first resolves to a Store alias.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store

"MSIX AppModel" alias

you haven't checked whether or not it's the store alias.

Comment thread build.bat Outdated
echo All E2E test prerequisites met.
) else (
echo.
echo To fix, run from an elevated PowerShell prompt:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

echo

can you write to standard WARN or make it yellow (i'm not sure in .bat)?

Comment thread build.bat Outdated
echo All E2E test prerequisites met.
) else (
echo.
echo To fix, run from an elevated PowerShell prompt:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix

to "disable the alias"

Comment thread scripts/setup-test-prereqs.ps1 Outdated
Remove-Item $userAlias -Force -ErrorAction Stop
Write-Host " Disabled user alias: $userAlias" -ForegroundColor Green
} catch {
Write-Host " WARNING: failed to remove $userAlias`: $($_.Exception.Message)" -ForegroundColor Yellow

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write-Host

Write-Warning?

Comment thread scripts/setup-test-prereqs.ps1 Outdated
# Fix: Disable Store aliases
foreach ($exe in @("python.exe", "python3.exe", "pwsh.exe")) {
if (Test-StoreAlias $exe) {
Write-Host "Disabling Store alias for $exe..." -ForegroundColor Cyan

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store

should not say "store"

- build.bat: check the exact App Execution Alias reparse point path
  (%LOCALAPPDATA%\Microsoft\WindowsApps\python.exe) instead of any
  substring containing 'WindowsApps'. Reword 'fix' -> 'install Python
  and disable the alias'.
- setup-test-prereqs.ps1: rename Test-StoreAlias/Disable-StoreAlias to
  Test-AppExecutionAlias/Disable-AppExecutionAlias. Replace all 'Store
  alias' wording with 'App Execution Alias'. Use Write-Warning instead
  of Write-Host for warnings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@jsidewhite jsidewhite left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@huzaifa-d huzaifa-d merged commit e042115 into main May 19, 2026
18 checks passed
@huzaifa-d huzaifa-d deleted the feat/test-prereq-checks branch May 19, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Issue-Bug Something isn't working Needs-Triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants