play.ps1: find victory.exe on Windows PowerShell 5.1 #17

Open
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/17 into main
0xkn0wh3r3 commented 2026-11-25 03:06:39 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by 0xkn0wh3r3 on 2026-11-25T02:59:44Z.


Problem

scripts\play.ps1 sets its -Exe default from $PSScriptRoot in the param() block. Windows PowerShell 5.1 (the powershell the README's command runs) leaves $PSScriptRoot empty in the parameter defaults of a script with [Parameter()] attributes, which play.ps1 has. The default becomes \..\target\release\victory.exe and the launch fails:

& : The term '\..\target\release\victory.exe' is not recognized as the name of a cmdlet, function, script file, or operable program.
Exited with 0; log: ...\ztrx.log

Fix

  • Leave -Exe without a default in param() and compute it in the script body from $PSScriptRoot, which is set there on 5.1 and 7.
  • Resolve -Exe once and launch exactly what was found:
    • a path (anything with a directory separator, or rooted) must be an existing file and is made absolute;
    • a bare name is looked up on PATH with Get-Command -CommandType Application, as & $Exe does.
  • If nothing is found (including a directory passed as -Exe), stop with a clear message and exit 1 before launching.

Explicit paths and PATH names launch the same executable as before; the difference is that a missing one is reported up front.

Exit-code propagation (#3) is left to #15, which changes only the last lines of the script; the two merge cleanly.

Tested

A stub executable in place of victory.exe, run from a working directory outside the repository, with the repository copy at a path containing spaces and brackets and a game path containing spaces and brackets. Same results on Windows PowerShell 5.1 and PowerShell 7.6:

Case Exit Child ran
Default executable 0 yes
Explicit absolute path 0 yes
Explicit path relative to the caller 0 yes
Bare name on PATH (with and without .exe) 0 yes
Bare name not on PATH 1 no
Missing default executable 1 no
Missing explicit path 1 no
Directory as -Exe 1 no
Child exits 7 / 42 0 / 0 (7 / 42 with #15) yes

When the child ran, it received the game path as one argument and both output streams reached the log. The same matrix on this branch merged with #15 passes, with exit codes 7 and 42 returned to the caller. cargo xtask policy --staged passes.

<!-- greyfinch-sync:Zettrox/ztrx:issue:6596183868 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/17). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T02:59:44Z. --- ## Problem `scripts\play.ps1` sets its `-Exe` default from `$PSScriptRoot` in the `param()` block. Windows PowerShell 5.1 (the `powershell` the README's command runs) leaves `$PSScriptRoot` empty in the parameter defaults of a script with `[Parameter()]` attributes, which `play.ps1` has. The default becomes `\..\target\release\victory.exe` and the launch fails: ``` & : The term '\..\target\release\victory.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Exited with 0; log: ...\ztrx.log ``` ## Fix - Leave `-Exe` without a default in `param()` and compute it in the script body from `$PSScriptRoot`, which is set there on 5.1 and 7. - Resolve `-Exe` once and launch exactly what was found: - a path (anything with a directory separator, or rooted) must be an existing file and is made absolute; - a bare name is looked up on `PATH` with `Get-Command -CommandType Application`, as `& $Exe` does. - If nothing is found (including a directory passed as `-Exe`), stop with a clear message and exit 1 before launching. Explicit paths and `PATH` names launch the same executable as before; the difference is that a missing one is reported up front. Exit-code propagation (#3) is left to #15, which changes only the last lines of the script; the two merge cleanly. ## Tested A stub executable in place of `victory.exe`, run from a working directory outside the repository, with the repository copy at a path containing spaces and brackets and a game path containing spaces and brackets. Same results on Windows PowerShell 5.1 and PowerShell 7.6: | Case | Exit | Child ran | |---|---|---| | Default executable | 0 | yes | | Explicit absolute path | 0 | yes | | Explicit path relative to the caller | 0 | yes | | Bare name on `PATH` (with and without `.exe`) | 0 | yes | | Bare name not on `PATH` | 1 | no | | Missing default executable | 1 | no | | Missing explicit path | 1 | no | | Directory as `-Exe` | 1 | no | | Child exits 7 / 42 | 0 / 0 (7 / 42 with #15) | yes | When the child ran, it received the game path as one argument and both output streams reached the log. The same matrix on this branch merged with #15 passes, with exit codes 7 and 42 returned to the caller. `cargo xtask policy --staged` passes.
Yoshi-233 commented 2026-11-25 03:06:40 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Yoshi-233 on 2026-11-25T03:03:25Z.


I tested how this interacts with #15, since both change play.ps1. Git merged 1d1ffaa (#17) and afe450a (#15) cleanly on 90b529f. I ran 12 process-level cases on #17 alone, then the same 12 on the combined script, using PowerShell 7.7.0 on Ubuntu and a small native executable. The working directory was outside the project.

  • With the default executable location, an explicit absolute path, and an explicit path relative to the caller, the child received the game path (including spaces and brackets) as one argument. Both output streams reached the log.
  • A missing default executable, a missing explicit executable, and a directory supplied as -Exe all returned 1 before the child ran.
  • With the executable present, child exits 0/7/42 reached the caller as 0/0/0 on #17 alone and 0/7/42 with both changes.

This covers the interaction between locating the executable and returning its status. The Windows PowerShell 5.1 check is the author's; my runs used PowerShell 7.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7151546367 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/17#issuecomment-7151546367). Originally posted by [Yoshi-233](https://github.com/Yoshi-233) on 2026-11-25T03:03:25Z. --- I tested how this interacts with #15, since both change `play.ps1`. Git merged `1d1ffaa` (#17) and `afe450a` (#15) cleanly on `90b529f`. I ran 12 process-level cases on #17 alone, then the same 12 on the combined script, using PowerShell 7.7.0 on Ubuntu and a small native executable. The working directory was outside the project. - With the default executable location, an explicit absolute path, and an explicit path relative to the caller, the child received the game path (including spaces and brackets) as one argument. Both output streams reached the log. - A missing default executable, a missing explicit executable, and a directory supplied as `-Exe` all returned 1 before the child ran. - With the executable present, child exits 0/7/42 reached the caller as 0/0/0 on #17 alone and 0/7/42 with both changes. This covers the interaction between locating the executable and returning its status. The Windows PowerShell 5.1 check is the author's; my runs used PowerShell 7.
kaayzouee commented 2026-11-25 04:11:30 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by kaayzouee on 2026-11-25T03:19:12Z.


Code review — Changes recommended

Reviewed commit 0971fd8. Moving default executable discovery out of the parameter block is a reasonable fix for Windows PowerShell 5.1. However, the new existence check introduces a compatibility regression.

  1. Preserve explicit executable resolution

Previously, & $Exe could resolve a bare executable name through PATH. The new Test-Path -LiteralPath $Exe -PathType Leaf rejects such a name when the executable is not in the current directory.

Conversely, a bare filename can pass the existence check but fail to launch or resolve to a different executable on PATH.

Please resolve and invoke the same executable. If explicit paths are required, resolve them to filesystem paths before invocation and document that requirement. If preserving PATH lookup, resolve bare names using Get-Command with -CommandType Application and invoke the resolved application path.

  1. Exit status propagation

The script still prints $LASTEXITCODE without returning it to the caller.

This is the existing issue #3, not a regression introduced by this PR. Consider capturing the child’s exit code immediately after execution, reporting it, and ending with exit $code. Launch failures should also be handled explicitly rather than relying on a potentially stale $LASTEXITCODE.

This can be addressed separately if keeping the PR narrowly scoped.

  1. Simplification

The default executable path can be computed directly in the script body without the additional Split-Path call:

if (-not $Exe) {
$Exe = Join-Path $PSScriptRoot '..\target\release\victory.exe'
}

The PowerShell 5.1 issue concerns parameter default evaluation, not $PSScriptRoot inside the script body.

  1. Recommended regression tests
  • Launch from a working directory outside the repository.
  • Repository paths containing spaces.
  • Explicit relative and absolute executable paths.
  • Executable resolution through PATH.
  • Missing executable.
  • Child process returning a nonzero exit code.
  • Compatibility with Windows PowerShell 5.1 and PowerShell 7.

A controlled executable stub is sufficient; no game data is necessary.

Verdict

The default-path fix is small, readable, and appropriately scoped. However, I recommend correcting the explicit -Exe resolution regression before merging, particularly because the PR states that explicitly supplied values behave as before.

Static review only. Windows PowerShell tests were not independently executed.

⸻

This is an automated message, if you believe this is incorrect, please reply with the relevant technical context or a reproducible counterexample so the finding can be reassessed.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7151802573 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/17#issuecomment-7151802573). Originally posted by [kaayzouee](https://github.com/kaayzouee) on 2026-11-25T03:19:12Z. --- Code review — Changes recommended Reviewed commit 0971fd8. Moving default executable discovery out of the parameter block is a reasonable fix for Windows PowerShell 5.1. However, the new existence check introduces a compatibility regression. 1. Preserve explicit executable resolution Previously, & $Exe could resolve a bare executable name through PATH. The new Test-Path -LiteralPath $Exe -PathType Leaf rejects such a name when the executable is not in the current directory. Conversely, a bare filename can pass the existence check but fail to launch or resolve to a different executable on PATH. Please resolve and invoke the same executable. If explicit paths are required, resolve them to filesystem paths before invocation and document that requirement. If preserving PATH lookup, resolve bare names using Get-Command with -CommandType Application and invoke the resolved application path. 2. Exit status propagation The script still prints $LASTEXITCODE without returning it to the caller. This is the existing issue #3, not a regression introduced by this PR. Consider capturing the child’s exit code immediately after execution, reporting it, and ending with exit $code. Launch failures should also be handled explicitly rather than relying on a potentially stale $LASTEXITCODE. This can be addressed separately if keeping the PR narrowly scoped. 3. Simplification The default executable path can be computed directly in the script body without the additional Split-Path call: if (-not $Exe) { $Exe = Join-Path $PSScriptRoot '..\target\release\victory.exe' } The PowerShell 5.1 issue concerns parameter default evaluation, not $PSScriptRoot inside the script body. 4. Recommended regression tests * Launch from a working directory outside the repository. * Repository paths containing spaces. * Explicit relative and absolute executable paths. * Executable resolution through PATH. * Missing executable. * Child process returning a nonzero exit code. * Compatibility with Windows PowerShell 5.1 and PowerShell 7. A controlled executable stub is sufficient; no game data is necessary. Verdict The default-path fix is small, readable, and appropriately scoped. However, I recommend correcting the explicit -Exe resolution regression before merging, particularly because the PR states that explicitly supplied values behave as before. Static review only. Windows PowerShell tests were not independently executed. ⸻ This is an automated message, if you believe this is incorrect, please reply with the relevant technical context or a reproducible counterexample so the finding can be reassessed.
0xkn0wh3r3 commented 2026-11-25 04:11:31 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by 0xkn0wh3r3 on 2026-11-25T03:39:06Z.


Thanks to both of you. Changes are in 6657725:

  1. Explicit -Exe resolution: fixed. -Exe is resolved once and that exact file is launched. A path must be an existing file and is made absolute. A bare name is looked up with Get-Command -CommandType Application, matching what & $Exe finds on PATH. A bare name sitting only in the current directory is no longer accepted, because & would not run it from there either.
  2. Exit status: left to #15 to keep this PR narrow. #15 only touches the last lines, so the two merge cleanly. I re-ran the matrix on this branch merged with #15, and child exits 7 and 42 now reach the caller.
  3. $PSScriptRoot in the body: done, and the root cause is now stated more precisely. On 5.1 it's empty only in the parameter defaults of a script with [Parameter()] attributes. A plain param() script gets it, and the body always does.
  4. Tests: every case on your list, using a stub executable on Windows PowerShell 5.1 and PowerShell 7.6 from outside the repository, with spaces and brackets in the repository and game paths. The results table is in the PR description.

@Yoshi-233, your PowerShell 7 results agree with mine. The 5.1 rows in the table are from a Windows machine.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7152115560 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/17#issuecomment-7152115560). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T03:39:06Z. --- Thanks to both of you. Changes are in 6657725: 1. **Explicit `-Exe` resolution:** fixed. `-Exe` is resolved once and that exact file is launched. A path must be an existing file and is made absolute. A bare name is looked up with `Get-Command -CommandType Application`, matching what `& $Exe` finds on `PATH`. A bare name sitting only in the current directory is no longer accepted, because `&` would not run it from there either. 2. **Exit status:** left to #15 to keep this PR narrow. #15 only touches the last lines, so the two merge cleanly. I re-ran the matrix on this branch merged with #15, and child exits 7 and 42 now reach the caller. 3. **`$PSScriptRoot` in the body:** done, and the root cause is now stated more precisely. On 5.1 it's empty only in the parameter defaults of a script with `[Parameter()]` attributes. A plain `param()` script gets it, and the body always does. 4. **Tests:** every case on your list, using a stub executable on Windows PowerShell 5.1 and PowerShell 7.6 from outside the repository, with spaces and brackets in the repository and game paths. The results table is in the PR description. @Yoshi-233, your PowerShell 7 results agree with mine. The 5.1 rows in the table are from a Windows machine.
whamre commented 2026-11-25 09:08:58 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by whamre on 2026-11-25T09:00:35Z.


Tested on Windows PowerShell 5.1 with an RTX 2080 SUPER. On main, play.ps1 fails with The term '\..\target\release\victory.exe' is not recognized, because $PSScriptRoot is empty in the param default. With this PR (built together with #32 and #68 on 90b529f), the launcher found and started target\release\victory.exe with no -Exe argument. AI-assisted.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7157752870 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/17#issuecomment-7157752870). Originally posted by [whamre](https://github.com/whamre) on 2026-11-25T09:00:35Z. --- Tested on Windows PowerShell 5.1 with an RTX 2080 SUPER. On main, `play.ps1` fails with `The term '\..\target\release\victory.exe' is not recognized`, because `$PSScriptRoot` is empty in the param default. With this PR (built together with #32 and #68 on 90b529f), the launcher found and started `target\release\victory.exe` with no `-Exe` argument. AI-assisted.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/17:upstream-pr/17'
git switch 'upstream-pr/17'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/17'
git switch 'upstream-pr/17'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/17'
git switch 'upstream-pr/17'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/17'
git switch 'main'
git merge --squash 'upstream-pr/17'
git switch 'main'
git merge --ff-only 'upstream-pr/17'
git switch 'main'
git merge 'upstream-pr/17'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Zettrox/ztrx!17
No description provided.