Skip to content

test_run_wine_tests: quote the interpreter passed as --wine so a path with spaces stays one argument - #4562

Open
Halfect wants to merge 1 commit into
ItsNotRexed:mainfrom
Halfect:test/run-wine-tests-quoted-interpreter
Open

Halfect wants to merge 1 commit into
ItsNotRexed:mainfrom
Halfect:test/run-wine-tests-quoted-interpreter

Conversation

@Halfect

@Halfect Halfect commented Nov 23, 2026 •

Copy link
Copy Markdown

Claim: #4421 (comment)

What: The four main() call sites in tests/test_run_wine_tests.py pass the Python interpreter to --wine as an unquoted sys.executable.replace(os.sep, "/"). The runner's wine_command splits the value with shlex.split, which is correct command-line behaviour, so an interpreter path that contains a space — C:\Program Files\Python314 on Windows, or any venv/CI path with a space, which includes this test machine's .../Application Support/... — is cut at the first space and the subprocess cannot start. Quoting the path keeps it one argument through the split. Same class of bug as #379 (which fixed make_game.tool_available); this one is in the test's own command-line construction — the runner itself is fine.

Tested: macOS 15.6.1 (Apple silicon), CPython 3.14, interpreter path containing spaces. CPU only, no game files. AI-assisted.

  • Before: python -I tests/test_run_wine_tests.py → 3 failures (test_main_maps_the_drive_while_the_tests_run, test_a_required_test_that_passes_exits_zero, test_the_summary_table_is_appended), each could not start /Users/<local-user>/Library/Application: No such file or directory — the path truncated at the space.
  • After: 51/51 OK, including a new regression test asserting wine_command(python_wine()) round-trips to exactly one argument. On a machine without spaces the quotes are stripped by shlex.split and behaviour is unchanged.

No overlap with #4462 (different file, scripts/run_wine_tests.py).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 49449b0560 on Linux, Python 3.10, CPU only, synthetic fixtures, no game files: pass (with a note).

  • python -I tests/test_run_wine_tests.py → 51/51; tests/test_first_look_rebuild.py → 2 skipped (PowerShell-only).
  • This PR does not change scripts/run_wine_tests.py — it quotes the interpreter path in the tests and adjusts scripts/first_look.ps1. The same 51/51 also pass with main's tool, so no negative control applies; the Linux run covers the test change only.
  • first_look.ps1 not executed here (no pwsh on this box).
  • git diff --check and check_no_game_data.py clean.

AI-assisted (Devin).

@Kam471 Kam471 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.

Ran this at 49449b05 on Windows 11: python -I tests/test_run_wine_tests.py -> 51 tests, OK (5 skipped); git diff --check clean.

The --wine interpreter is quoted so a path with spaces stays a single argument, and the added cases cover it. No blocking issue.

@Halfect

Halfect commented Nov 23, 2026

Copy link
Copy Markdown
Author

@Atomic258 thanks for testing! One clarification: this PR touches only tests/test_run_wine_tests.py (+13/−4, single file) — it does not touch scripts/first_look.ps1; you may be thinking of #4568. Your 51/51 pass covers this PR's change on a space-free Linux path, which matches the expectation that the added quotes are stripped by shlex.split and behaviour is unchanged there.

@Atomic258

Copy link
Copy Markdown
Contributor

Correction to my earlier comment: this PR touches only tests/test_run_wine_tests.py (+13/−4) and does not touch scripts/first_look.ps1 — that belongs to #4568, and my mention of it here was a mix-up. The results stand as run on head 49449b05601c73a1284c8ebab32995a74c47fa29: python -I tests/test_run_wine_tests.py → 51/51. Because the PR changes no tool code, the same 51/51 pass with main's tool too, so no negative control applies; the Linux run covers the test change only. AI-assisted (Devin).

@whattheflop whattheflop 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.

AI-assisted Windows x64 verification at 49449b05, uv CPython 3.12.13, with a real disposable interpreter path. With an ordinary spaced path, Windows could still launch the child after shlex.split() split the unquoted interpreter. In a path with two adjacent spaces, unquoted launch failed whereas python_wine() kept the exact path as one argument and the child launched with the same interpreter and version.

On that two-space path, base d0835dd9 had 43 passes, 5 skips and 2 failures. #4562 had 46 passes and 5 skips. The clean scratch integration with #4558 e7ac88ea had 48 passes and 5 skips. Both added scheduler tests already call the quoted helper through run_main(). The integration used a Python stand-in for Wine.

@tupacfan04

Copy link
Copy Markdown
Contributor

SOUND (test-only). The premise checks out: scripts/run_wine_tests.py:214 uses shlex.split, so an unquoted C:/Program Files/... splits into two args and the quoted form round-trips to one; backslash paths survive POSIX quoting too. tests/test_run_wine_tests.py gives 46 passed / 5 skipped / 44 subtests, compileall clean, and the merge is clean.

One weakness: the negative control cannot fail here because sys.executable has no spaces - reverting the helper to unquoted still passes. The new test (:525) only asserts the quoted round-trip, never that unquoted spaced input splits. A case that feeds a synthetic C:\Program Files\wine string through the same helper (asserting one argument after quoting and two without) would make the guard real on every platform.

Approve with that. AI-assisted review, no game files, no GPU.

@Halfect

Halfect commented Nov 23, 2026

Copy link
Copy Markdown
Author

@tupacfan04 good point — done in 1b79ac92: test_an_unquoted_spaced_wine_splits_but_the_quoted_form_does_not feeds a synthetic C:/Program Files/Python314/python.exe through wine_command and pins both sides (unquoted splits into two arguments, quoted stays one), so the guard now fails on any platform if the quoting is dropped, not just where the interpreter's path has a space. python -I tests/test_run_wine_tests.py → 52/52 OK here (macOS 15.6.1, CPython 3.12, spaced interpreter path).

@kapitche

kapitche commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 1b79ac9 merged with main d0835dd on WSL2 Ubuntu, Python 3.12.16: pass.

  • python -I tests/test_run_wine_tests.py: 52 tests OK. The PR only changes this test file, so the negative control is a mutation: shlex.split(text) -> text.split() in scripts/run_wine_tests.py::wine_command gives 7 failures, including both new tests (test_python_wine_command_line_stays_one_argument, test_an_unquoted_spaced_wine_splits_but_the_quoted_form_does_not) and the existing quoting tests.
  • Read: python_wine() quotes sys.executable once and all the --wine call sites use it. No issue found.

Windows 11 (Python 3.13.1, PowerShell 5.1): 52 tests OK (5 skipped). I did not check which tests are among the 5 skips.

@Halfect

Halfect commented Nov 23, 2026

Copy link
Copy Markdown
Author

Overlap check for the queue: #4558 also edits tests/test_run_wine_tests.py (adds fixture-ordering tests around the old line 418). I applied this PR's diff on top of #4558's head e7ac88ea — the changes touch different regions, apply cleanly, and the combined file passes 52/52 (macOS 15.6.1, CPython 3.12). No rebase needed between these two PRs in either order.

@memorypressure

Copy link
Copy Markdown

Merged cleanly into main 3faac55; the suite passes 54/54 under python -I (re-run). The quoted --wine form matches wine_command's shlex.split on main, and the synthetic spaced-path case pins the quoting contract even where the local interpreter path has no spaces. Shares tests/test_run_wine_tests.py with #4558, which my independent check found superseded by main's ba02066 — the two merge cleanly and yours stands alone if that one closes. No CI checks reported. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

Keep the interpreter as one argument through shlex.split and pin both the quoted and unquoted behavior with a synthetic spaced path.
@Halfect
Halfect force-pushed the test/run-wine-tests-quoted-interpreter branch from 1b79ac9 to 88791f2 Compare November 23, 2026 12:31
@Halfect

Halfect commented Nov 23, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (561b65a832) and updated head to 88791f20f. The only conflict was in run_main: the resolution keeps both upstream's optional root handling and this PR's quoted python_wine() helper. The PR remains one file, +19/−4.

Validation on Windows, CPU only, no game data:

  • python -I tests/test_run_wine_tests.py with TEMP/TMP set to a non-short workspace path: 62 tests, OK (8 skipped).
  • python -I scripts/check_no_game_data.py: passed.
  • git diff --check upstream/main...HEAD: clean.

The short-path temporary-directory form also fails the new upstream relative-root test on unmodified main; using the non-short path avoids that unrelated environment issue. No GPU tests were run.

AI-assisted: Kimi Work

@shipped-it

Copy link
Copy Markdown

Tested 88791f20f on Linux (Arch, /usr/bin/python3 3.14.8, CPU-only, no game files): compileall -q make_game.py tools tests clean; test_run_wine_tests 62 OK; scripts/check_no_game_data.py clean on all changed files. VERDICT: pass. AI-assisted (omp coding assistant).

@antoinecaputo

Copy link
Copy Markdown

Tested 88791f2 on macOS / CPython 3.14.7: pass — python -I tests/test_run_wine_tests.py 62/62, and still 62/62 with the interpreter copied to a path containing a space. Clean main there fails 5 main() tests with could not start .../wine: No such file or directory (the path cut at the space by shlex.split); all green at head. The runner's shlex contract is unchanged and the new one-argument tests pin it. Note: the body's counts are from an older base (main's file now has 60+ tests, 5 failing with a spaced interpreter). AI-assisted.

@mewajda

mewajda commented Nov 23, 2026

Copy link
Copy Markdown

Code read (CPU) — Linux, Python 3.10, no Wine, no game files.

  • python -I tests/test_run_wine_tests.py: 61 pass, 1 error, and the error is not this PR's: test_relative_root_launches_the_artifact_from_its_working_directory calls contextlib.chdir, which is Python 3.11+. The same file from origin/main gives the identical 61 + 1 error here, so it is the interpreter version, not the change.
  • The fix itself is right: wine_command splits with shlex.split, so an unquoted C:/Program Files/… becomes two arguments, and quoting at the four call sites is the correct place to fix it. All four --wine sites that pass the interpreter are the changed ones (lines 462, 499, 578, 657); the two other --wine uses pass deliberate bad values ("", an unclosed quote) for the error paths and are correctly left alone.

One finding: the helper's quoting is not guarded on a machine whose interpreter path has no space. I removed the quotes from python_wine() and re-ran: still 61 pass and the same 1 pre-existing error — nothing fails. sys.executable here is /usr/bin/python3.10, so test_python_wine_command_line_stays_one_argument passes either way, and the synthetic test only pins wine_command's shlex behaviour, which was already correct before the PR. On this box the regression would therefore come back silently.

A one-line direct assertion closes that without depending on the machine:

def test_python_wine_quotes_the_interpreter(self):
    self.assertEqual(python_wine(), f'"{sys.executable.replace(os.sep, "/")}"')

That fails on every platform if the quotes are dropped, and the synthetic case stays as the explanation of why it matters.

Verdict: correct change, passes here; one suggested assertion so the fix stays pinned everywhere. AI-assisted.

@Urban225

Copy link
Copy Markdown
Contributor

Reviewed 88791f2 (code read + tests on Linux, Python 3.13, no GPU): pass with remarks.

  • python3 -I tests/test_run_wine_tests.py: PR 62/62 OK; base (561b65a) 60/60 OK.
  • Interpreter symlinked into a directory whose name has a space: base FAILED (failures=5, "could not start .../py: No such file or directory"); PR 62/62 OK. So the failure reproduces on Linux too, not only on macOS.
  • python3 -m compileall -q scripts tests: exit 0.
  • tests/test_run_wine_tests.py:43: wine_command (scripts/run_wine_tests.py:280) always uses POSIX shlex.split. Plain "..." quoting still breaks on a path containing " or ending in \; shlex.quote(...) is the exact inverse and handles those. Minor.
  • The description's counts (51 tests, 3 failures) don't match the current branch (62 tests, 5 failures on the base).
  • No assertions weakened; one file changed.
  • Not checked: Windows, macOS, real Wine, Python 3.14.

AI-assisted review: Claude ran the tests in a Linux sandbox and wrote this; I am relaying it.

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.