Scripts: smoke.ps1 leaves XCL_NETWORK=0 in the caller's session, and a -Game path ending in a backslash breaks the run #2259

Closed
opened 2026-11-26 05:24:51 +00:00 by github-bot · 2 comments
Owner

@⁠itsonewi on GitHub · 2026-11-25 11:42 UTC · original

Summary

Two small defects in the run block of scripts/smoke.ps1 (426a5a7). Neither changes the numbers in the block; both change what the machine does around it.

1. XCL_NETWORK=0 is left set in the caller's session

$env:XCL_NETWORK = '0'
$env:XCL_RUN_SECONDS = "$Seconds"
$env:XCL_ACTIVITY = '1'
$null = $p.Start()
...
Remove-Item Env:XCL_RUN_SECONDS, Env:XCL_ACTIVITY

Three variables are set, two are removed. A script runs in the caller's process, so XCL_NETWORK=0 stays in the PowerShell session after .\scripts\smoke.ps1 returns, and everything started from that window afterwards inherits it:

  • a later xcl run in the same session is silently offline, which is easy to misread as a title or network bug;
  • someone checking the "XCL_NETWORK=0 still connects, still binds UDP 3074" reports (#444, #568) in that window gets a misleading result whichever way it goes;
  • a wrapper inherits it too: scripts/test-smoke-artifacts.tests.ps1 runs smoke.ps1 twice in the runner's session;
  • and if the session already had XCL_NETWORK set to something else, the script overwrites it and never puts it back.

The same three variables also survive any throw before the Remove-Item line - XCL printed no log path is one - because nothing restores them on the way out. A try/finally around the run covers both cases: save the three values first, restore them in the block.

2. A -Game path ending in a backslash breaks the command line

$psi.FileName = $Xcl
$psi.Arguments = 'run "' + $Game + '"'

ProcessStartInfo.Arguments is one command-line string, so Windows parses it by its usual rules: a backslash directly before a quote does not escape anything, it makes that quote literal. So -Game 'D:\Games\Foo\' produces the command line run "D:\Games\Foo\", and XCL receives D:\Games\Foo" with no closing quote - a path error that says nothing about the real cause. The cmd.exe branch (/c ""<xcl>" run "<game>"") has the same hole.

This is not a hypothetical input shape: scripts/smoke-title.tests.ps1 already passes D:\Games\<name>\ with a trailing separator in its foreach ($game in @(...)) loop, but it asserts only the title: hash, so the command line built from that value is never exercised - the fixture is a .cmd that ignores its arguments.

Suggested fix

$Game = $Game.TrimEnd('\')

before the block that builds $psi, plus the save/restore above. Trimming the separator does not change the title: line, which hashes (Split-Path $Game -Leaf).Trim().

Not reported elsewhere

Searched open and closed issues for smoke.ps1, XCL_NETWORK, trailing backslash and command line escaping: nothing covers either point. #717 and #1855 are about what the block says; #1506 and #2213 are about how it is compared.

Not tested

  • No local run: this is read from 426a5a7 without a checkout, and both points are visible in the source. The -Game fix should be checked under both powershell.exe and pwsh.exe, since 5.1 and 7 pass the same string to CreateProcess.

AI use

  • Claude (Opus 5.5) read scripts/smoke.ps1, scripts/smoke-title.tests.ps1 and scripts/test-smoke-artifacts.tests.ps1 on 426a5a7, wrote this report and the two fixes; the human account checked each claim against the files before opening it.
**@⁠itsonewi** on GitHub · 2026-11-25 11:42 UTC · [original](https://github.com/xcl-dev/xcl/issues/2259) ### Summary Two small defects in the run block of `scripts/smoke.ps1` (`426a5a7`). Neither changes the numbers in the block; both change what the machine does around it. ### 1. `XCL_NETWORK=0` is left set in the caller's session ```powershell $env:XCL_NETWORK = '0' $env:XCL_RUN_SECONDS = "$Seconds" $env:XCL_ACTIVITY = '1' $null = $p.Start() ... Remove-Item Env:XCL_RUN_SECONDS, Env:XCL_ACTIVITY ``` Three variables are set, two are removed. A script runs in the caller's process, so `XCL_NETWORK=0` stays in the PowerShell session after `.\scripts\smoke.ps1` returns, and everything started from that window afterwards inherits it: - a later `xcl run` in the same session is silently offline, which is easy to misread as a title or network bug; - someone checking the "`XCL_NETWORK=0` still connects, still binds UDP 3074" reports (#444, #568) in that window gets a misleading result whichever way it goes; - a wrapper inherits it too: `scripts/test-smoke-artifacts.tests.ps1` runs `smoke.ps1` twice in the runner's session; - and if the session already had `XCL_NETWORK` set to something else, the script overwrites it and never puts it back. The same three variables also survive any `throw` before the `Remove-Item` line - `XCL printed no log path` is one - because nothing restores them on the way out. A `try`/`finally` around the run covers both cases: save the three values first, restore them in the block. ### 2. A `-Game` path ending in a backslash breaks the command line ```powershell $psi.FileName = $Xcl $psi.Arguments = 'run "' + $Game + '"' ``` `ProcessStartInfo.Arguments` is one command-line string, so Windows parses it by its usual rules: a backslash directly before a quote does not escape anything, it makes that quote **literal**. So `-Game 'D:\Games\Foo\'` produces the command line `run "D:\Games\Foo\"`, and XCL receives `D:\Games\Foo"` with no closing quote - a path error that says nothing about the real cause. The `cmd.exe` branch (`/c ""<xcl>" run "<game>""`) has the same hole. This is not a hypothetical input shape: `scripts/smoke-title.tests.ps1` already passes `D:\Games\<name>\` with a trailing separator in its `foreach ($game in @(...))` loop, but it asserts only the `title:` hash, so the command line built from that value is never exercised - the fixture is a `.cmd` that ignores its arguments. ### Suggested fix ```powershell $Game = $Game.TrimEnd('\') ``` before the block that builds `$psi`, plus the save/restore above. Trimming the separator does not change the `title:` line, which hashes `(Split-Path $Game -Leaf).Trim()`. ### Not reported elsewhere Searched open and closed issues for `smoke.ps1`, `XCL_NETWORK`, `trailing backslash` and `command line escaping`: nothing covers either point. #717 and #1855 are about what the block *says*; #1506 and #2213 are about how it is compared. **Not tested** - No local run: this is read from `426a5a7` without a checkout, and both points are visible in the source. The `-Game` fix should be checked under both `powershell.exe` and `pwsh.exe`, since 5.1 and 7 pass the same string to `CreateProcess`. **AI use** - Claude (Opus 5.5) read `scripts/smoke.ps1`, `scripts/smoke-title.tests.ps1` and `scripts/test-smoke-artifacts.tests.ps1` on `426a5a7`, wrote this report and the two fixes; the human account checked each claim against the files before opening it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:24:51 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 11:57 UTC · original

@⁠itsonewi Both of these already have open PRs, in case that saves a third one:

  1. XCL_NETWORK=0 left set: #521 (wileyGray, 9bb6aa2, mergeable). It saves XCL_NETWORK, XCL_RUN_SECONDS and XCL_ACTIVITY before Start() and restores all three in a finally, so the caller's values come back, unset ones included.
  2. -Game ending in a backslash: #588 (luna020924, 1707802). It doubles the trailing backslashes before the closing quote ($Game -replace '\+\z', '$0$0'). It conflicts with main now, so it needs a rebase.

I only read the two diffs against main 1a0bbe3a; I didn't run them.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 11:57 UTC · [original](https://github.com/xcl-dev/xcl/issues/2259#issuecomment-7161723545) @⁠itsonewi Both of these already have open PRs, in case that saves a third one: 1. `XCL_NETWORK=0` left set: #521 (wileyGray, `9bb6aa2`, mergeable). It saves `XCL_NETWORK`, `XCL_RUN_SECONDS` and `XCL_ACTIVITY` before `Start()` and restores all three in a `finally`, so the caller's values come back, unset ones included. 2. `-Game` ending in a backslash: #588 (luna020924, `1707802`). It doubles the trailing backslashes before the closing quote (`$Game -replace '\+\z', '$0$0'`). It conflicts with `main` now, so it needs a rebase. I only read the two diffs against `main` `1a0bbe3a`; I didn't run them. AI-assisted (Claude Code).
Author
Owner

@⁠itsonewi on GitHub · 2026-11-25 12:00 UTC · original

Thanks @⁠upipibi - you are right, and both are open: I checked the two diffs against 1a0bbe3a and they cover the two halves of this report.

  • #521 restores XCL_NETWORK, XCL_RUN_SECONDS and XCL_ACTIVITY in a finally around Process.Start, which is what point 1 needs (and it goes further than the report: the caller's original values come back, absent ones included, and a failed launch is covered too).
  • #588 doubles the trailing backslashes before the closing quote, which is the fix for point 2, with a native fixture that checks zero, one and two trailing separators. GitHub currently reports it as conflicting with main, so it needs the rebase.

How I missed them: my duplicate search used is:issue, which drops pull requests from the results, so both PRs were invisible to it. That is my mistake, not a judgement call.

Closing this as a duplicate. The only thing worth keeping from it is the two fixes in one place: whoever lands first, the other's file and test do not overlap, so both can merge.

**@⁠itsonewi** on GitHub · 2026-11-25 12:00 UTC · [original](https://github.com/xcl-dev/xcl/issues/2259#issuecomment-7161791523) Thanks @⁠upipibi - you are right, and both are open: I checked the two diffs against `1a0bbe3a` and they cover the two halves of this report. - **#521** restores `XCL_NETWORK`, `XCL_RUN_SECONDS` and `XCL_ACTIVITY` in a `finally` around `Process.Start`, which is what point 1 needs (and it goes further than the report: the caller's original values come back, absent ones included, and a failed launch is covered too). - **#588** doubles the trailing backslashes before the closing quote, which is the fix for point 2, with a native fixture that checks zero, one and two trailing separators. GitHub currently reports it as conflicting with `main`, so it needs the rebase. How I missed them: my duplicate search used `is:issue`, which drops pull requests from the results, so both PRs were invisible to it. That is my mistake, not a judgement call. Closing this as a duplicate. The only thing worth keeping from it is the two fixes in one place: whoever lands first, the other's file and test do not overlap, so both can merge.
This discussion has been locked. Commenting is limited to contributors.
No description provided.