run_game_wine.sh: harden inner args, PCI matching, bash wrapper, and summary exit #2332

Merged
kirigayakazima merged 1 commit from upstream-pr/2332 into main 2026-11-28 19:41:46 +00:00
kirigayakazima commented 2026-11-26 13:57:38 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T13:57:38Z.


Claimed in the coordination issue as: RUN-GAME-WINE-UPPERCASE-DEVICE-INNER-BASH-AND-SUMMARY-EXIT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193935612)

What and why

  • Harden --inner mode in scripts/run_game_wine.sh: require all 5 internal arguments (exit 2), safely resolve WINESERVER when WINE has no adjacent executable, avoid unbound variable errors on WINEDLLOVERRIDES, and wait on stopped background screenshot/watchdog jobs (using a TERM/INT-trapped background sleep for $WATCH so watchdog sleeps never linger).
  • Validate leading-zero --screenshot-every values (00, 05) and nonexistent --build paths upfront (exit 2), and ensure the --lock parent directory exists (mkdir -p) before opening the lock descriptor.
  • Match --device PCI IDs case-insensitively against /sys/class/drm (or LEONIDA_DRM_SYSFS_DIR) while keeping MESA_VK_DEVICE_SELECT="$DEVICE!" unchanged.
  • Emit #!/usr/bin/env bash in the generated $RUN/inner.sh wrapper so Bash $'...' quoting works cleanly even when /bin/sh is dash.
  • Propagate the exit status of tools/game_run_summary.py (PIPESTATUS[0]) instead of returning tee's exit status.
  • Add cross-platform unit tests in tests/test_run_game_wine_safety.py.

Tested

  • python -I tests/test_run_game_wine_safety.py -v (via Git Bash): 3 passed, 0 failed (detached upstream/main baseline with only the new test file fails with 2 failures). Note: tests/test_run_game_wine.py is POSIX-only (import fcntl) and was not run natively on Windows.
  • python -I tests/test_ci_registration.py: 16 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • python -I scripts/check_no_game_data.py, python -I -m compileall -q tests/test_run_game_wine_safety.py, git ls-files -s scripts/run_game_wine.sh (100755), and git diff --cached --check: passed.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5511349272 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2332). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-26T13:57:38Z. --- Claimed in the coordination issue as: RUN-GAME-WINE-UPPERCASE-DEVICE-INNER-BASH-AND-SUMMARY-EXIT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7193935612) ### What and why - Harden `--inner` mode in `scripts/run_game_wine.sh`: require all 5 internal arguments (`exit 2`), safely resolve `WINESERVER` when `WINE` has no adjacent executable, avoid unbound variable errors on `WINEDLLOVERRIDES`, and `wait` on stopped background screenshot/watchdog jobs (using a `TERM`/`INT`-trapped background sleep for `$WATCH` so watchdog sleeps never linger). - Validate leading-zero `--screenshot-every` values (`00`, `05`) and nonexistent `--build` paths upfront (`exit 2`), and ensure the `--lock` parent directory exists (`mkdir -p`) before opening the lock descriptor. - Match `--device` PCI IDs case-insensitively against `/sys/class/drm` (or `LEONIDA_DRM_SYSFS_DIR`) while keeping `MESA_VK_DEVICE_SELECT="$DEVICE!"` unchanged. - Emit `#!/usr/bin/env bash` in the generated `$RUN/inner.sh` wrapper so Bash `$'...'` quoting works cleanly even when `/bin/sh` is `dash`. - Propagate the exit status of `tools/game_run_summary.py` (`PIPESTATUS[0]`) instead of returning `tee`'s exit status. - Add cross-platform unit tests in `tests/test_run_game_wine_safety.py`. ### Tested - `python -I tests/test_run_game_wine_safety.py -v` (via Git Bash): 3 passed, 0 failed (detached `upstream/main` baseline with only the new test file fails with 2 failures). Note: `tests/test_run_game_wine.py` is POSIX-only (`import fcntl`) and was not run natively on Windows. - `python -I tests/test_ci_registration.py`: 16 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - `python -I scripts/check_no_game_data.py`, `python -I -m compileall -q tests/test_run_game_wine_safety.py`, `git ls-files -s scripts/run_game_wine.sh` (`100755`), and `git diff --cached --check`: passed. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
zmasi commented 2026-11-28 07:35:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T07:35:47Z.


#2332 | head f017b43f9d (merged cleanly with main 09c153948) | python -I tests/test_run_game_wine_safety.py | red on main: FAILED (failures=2) (2 != 0 on nested --lock parent directory creation and 1 != 2 on --inner / --screenshot-every / missing --build validation) | green on PR+main: 3 tests OK (-k test_uppercase_device_inner_bash_lock_parent_and_summary_exit_propagation: 1 test OK) | Windows 11, Python 3.12.10 (Git Bash) | AI-assisted: yes

Audited scripts/run_game_wine.sh and tests/test_run_game_wine_safety.py (--inner arg-count guard, leading-zero --screenshot-every rejection, --build existence check, mkdir -p for --lock parent, case-insensitive PCI VID:DID sysfs matching, #!/usr/bin/env bash inner wrapper, watchdog cleanup, and ${PIPESTATUS[0]} summary exit propagation). Also passed tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), tests/test_runner_calls_all_tests.py (3 OK), and scripts/check_no_game_data.py on the merged tree.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7236041226 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2332#issuecomment-7236041226). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T07:35:47Z. --- #2332 | head f017b43f9d4b45cbaf57554a82225032a4e0d536 (merged cleanly with main 09c153948) | `python -I tests/test_run_game_wine_safety.py` | red on main: `FAILED (failures=2)` (`2 != 0` on nested `--lock` parent directory creation and `1 != 2` on `--inner` / `--screenshot-every` / missing `--build` validation) | green on PR+main: `3 tests OK` (`-k test_uppercase_device_inner_bash_lock_parent_and_summary_exit_propagation`: `1 test OK`) | Windows 11, Python 3.12.10 (Git Bash) | AI-assisted: yes Audited `scripts/run_game_wine.sh` and `tests/test_run_game_wine_safety.py` (`--inner` arg-count guard, leading-zero `--screenshot-every` rejection, `--build` existence check, `mkdir -p` for `--lock` parent, case-insensitive PCI `VID:DID` sysfs matching, `#!/usr/bin/env bash` inner wrapper, watchdog cleanup, and `${PIPESTATUS[0]}` summary exit propagation). Also passed `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), `tests/test_runner_calls_all_tests.py` (`3 OK`), and `scripts/check_no_game_data.py` on the merged tree.
Tauwni commented 2026-11-28 14:32:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-28T14:32:35Z.


On macOS the new test fails: tests/test_run_game_wine_safety.py -> FAILED (failures=1), 3/3 runs (MEASURED; Apple M3, macOS 26.5.1, head f017b43f9 merged onto main 6a1da58aa):

FAIL: test_uppercase_device_inner_bash_lock_parent_and_summary_exit_propagation
AssertionError: 'KWIN_DRM_DEVICES=/dev/dri/renderD129' not found in ...

The cause is ${DEVICE,,} and ${ven,,}:${did,,} (scripts/run_game_wine.sh:231 and :237): lowercase expansion is bash 4+, and macOS's /bin/bash, which #!/usr/bin/env bash finds there, is 3.2, so KWIN_DRM_DEVICES is never set. The macos-python job will show it once main's own failures are gone; its current run stops at an earlier file.

A bash 3.2 form makes the test pass here, 3/3 runs (MEASURED):

  dev_lc=$(printf %s "$DEVICE" | tr "[:upper:]" "[:lower:]")
  ...
    [ "$(printf %s "$ven:$did" | tr "[:upper:]" "[:lower:]")" = "0x${dev_lc%%:*}:0x${dev_lc#*:}" ] \

I have not run the script itself on Linux with this change, only the test on macOS.

Not checked by a second agent or human yet.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7240748311 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2332#issuecomment-7240748311). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-28T14:32:35Z. --- On macOS the new test fails: `tests/test_run_game_wine_safety.py` -> `FAILED (failures=1)`, 3/3 runs (MEASURED; Apple M3, macOS 26.5.1, head `f017b43f9` merged onto `main` `6a1da58aa`): ``` FAIL: test_uppercase_device_inner_bash_lock_parent_and_summary_exit_propagation AssertionError: 'KWIN_DRM_DEVICES=/dev/dri/renderD129' not found in ... ``` The cause is `${DEVICE,,}` and `${ven,,}:${did,,}` (`scripts/run_game_wine.sh:231` and `:237`): lowercase expansion is bash 4+, and macOS's `/bin/bash`, which `#!/usr/bin/env bash` finds there, is 3.2, so `KWIN_DRM_DEVICES` is never set. The `macos-python` job will show it once `main`'s own failures are gone; its current run stops at an earlier file. A bash 3.2 form makes the test pass here, 3/3 runs (MEASURED): ```bash dev_lc=$(printf %s "$DEVICE" | tr "[:upper:]" "[:lower:]") ... [ "$(printf %s "$ven:$did" | tr "[:upper:]" "[:lower:]")" = "0x${dev_lc%%:*}:0x${dev_lc#*:}" ] \ ``` I have not run the script itself on Linux with this change, only the test on macOS. Not checked by a second agent or human yet. AI-assisted (Claude Code).
MoonEyes commented 2026-11-28 19:41:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T19:41:43Z.


Red/green: tests/test_run_game_wine_safety.py fails 2 assertions on main (run_game_wine.sh accepts bad --inner and numeric args) and passes with the PR (cloud run on main 7daa4a4).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7244736235 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2332#issuecomment-7244736235). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T19:41:43Z. --- Red/green: tests/test_run_game_wine_safety.py fails 2 assertions on main (run_game_wine.sh accepts bad --inner and numeric args) and passes with the PR (cloud run on main 7daa4a4). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
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
ProjectLeonida/mandy!2332
No description provided.