Skip to content

Wine runner: preserve replaced drive mappings during cleanup (TEST-962) - #4446

Open
zzEmmazz wants to merge 4 commits into
ItsNotRexed:mainfrom
zzEmmazz:fix-wine-drive-cleanup-ownership
Open

zzEmmazz wants to merge 4 commits into
ItsNotRexed:mainfrom
zzEmmazz:fix-wine-drive-cleanup-ownership

Conversation

@zzEmmazz

@zzEmmazz zzEmmazz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

TEST-962 — claim before implementation, carried into coordination issue #4683. Found while doing the claimed independent reviews of #4359/#4378 (TEST-955).

Depends on: #4359

After successful Wine drive setup, DriveMap.__exit__() unlinked any symlink at the drive path. If another process replaced that mapping during the run, cleanup deleted the replacement. Cleanup now checks that the link still points at this context's scratch directory before unlinking it. If another process removes the mapping between that ownership check and unlink, FileNotFoundError is treated as already cleaned. Scratch cleanup runs in finally, including when unlink raises another error; those other errors still propagate.

This follows #4359's setup-failure cleanup as an attributed dependency and fixes the later context-exit phase. Synthetic regressions cover replacement symlinks, dangling replacements, regular files, removed mappings, an exception from the test body, removal after the ownership read, and a permission error during unlink. Before the corresponding source fixes the replacement cases deleted someone else's mapping, the removal race raised FileNotFoundError, and other unlink errors leaked scratch.

Validation at 5b7dd8ca, integrated with main 98fa503f, CPU only:

  • Linux under WSL, Python 3.13.3: python -I tests/test_run_wine_tests.py — 59/59 pass.
  • Windows 11, Python 3.14.0: 59 tests run, 47 passed and 12 expected POSIX-only skips.
  • Current main's Wine fixture-scheduling integration also passes its separate four-test Linux suite. The cleanup-race/error regressions failed before the corresponding source fix and pass afterward. Existing ownership, setup failure and body-exception cases remain green. git diff --check passes.
  • Initial ownership implementation also passed text-write line endings (3 tests), compileall, runner --help and the no-game-data check.

AI-assisted (Codex). No Wine installation, GPU, or game files used; all paths and contents in the regressions are temporary synthetic fixtures. Ready for review; merge #4359 before this PR. Its setup-cleanup implementation is included with the original author's attribution; the current dependency head has identical content to that included commit.

@AGInformatique81 AGInformatique81 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested b32f56c7 on Linux via WSL (CPython 3.14.7). All 55 Wine runner tests passed.

I also reproduced an exit-cleanup race with synthetic paths. After readlink confirms ownership, I made the unlink stub remove the link once before delegating to the real unlink. The second unlink raises FileNotFoundError, the exception escapes __exit__, and the scratch directory remains. This is the window where another process removes the mapping between the ownership check and unlink.

I tested a local adjustment that treats FileNotFoundError from unlink as already removed and runs scratch cleanup in finally. The race probe then passed (no exception and no scratch directory), and the full 55-test suite still passed. Could you cover this interleaving in the PR?

CPU-only synthetic test. AI-assisted with Codex.

@Atomic258

Copy link
Copy Markdown

Tested b32f56c7 on Linux (Ubuntu), CPython 3.10.12, CPU only, no game files: pass.

  • python -I tests/test_run_wine_tests.py: 55/55 OK.
  • Negative control: with main's scripts/run_wine_tests.py the 5 new DriveMapTest cases fail (the new drive-map helpers don't exist / cleanup drops the replaced mapping).
  • git diff --check clean; compileall clean. Real Wine behavior not exercised here — no Wine installed; the tests mock it.

AI-assisted (Devin).

@zzEmmazz

Copy link
Copy Markdown
Contributor Author

@AGInformatique81 Fixed in da67a855: FileNotFoundError from unlink after the ownership read is treated as an already-removed mapping, and owned scratch cleanup now runs in finally. Other unlink errors still propagate after scratch cleanup.

Added two deterministic synthetic regressions: one removes the link immediately after the ownership read, and the other injects PermissionError at drive unlink. Before the fix they produce the reported escaping exception and a scratch-leak failure respectively; both pass now. The removal test also checks the checkout fixture remains intact, and the existing replacement/dangling/regular-file cases remain green.

Validation: Linux under WSL/Python 3.13.3, 57/57 pass; Windows 11/Python 3.14.0, 45 passed and 12 expected POSIX-only skips; diff check clean. CPU only, synthetic paths, no Wine installation, game files or GPU/driver. AI-assisted (Codex). PR description updated; still draft pending #4359.

@AGInformatique81 AGInformatique81 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Retested da67a855 on Linux via WSL (Python 3.14.7). My original interleaving now passes: another process removes the mapping before unlink, no exception escapes, and the scratch directory is removed. All 57 runner tests passed.

I also combined this head (including #4359) with #4378 at 9beff025 and #4462 at a39e559c. Both merges were clean. Linux passed all 71 tests; Windows passed 59 with 12 POSIX-only skips.

Synthetic paths only. AI-assisted with Codex.

@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 da67a855 on Windows 11: python -I tests/test_run_wine_tests.py -> 57 tests, OK (12 skipped); git diff --check clean.

The Wine runner now preserves replaced drive mappings during cleanup, and the existing runner tests pass. No blocking issue.

@mrbean56

Copy link
Copy Markdown

Tested da67a8557f on Linux (Debian 13), Python 3.13.5: pass.

  • pytest tests/test_run_wine_tests.py -q: 57 passed, 47 subtests passed.
  • Negative control against 03b09a08: the two new cases fail (test_a_drive_removed_after_the_ownership_read_still_cleans_scratch, test_a_drive_unlink_error_still_cleans_scratch_and_propagates), so both the vanished-drive race and the unlink-error path are pinned.
  • The important property is kept: a failed unlink still cleans the rest of the scratch directory and propagates the error, so a drive that disappears mid-cleanup cannot leave the next run with stale mappings, and a real permission failure still fails the test run instead of being swallowed.
  • No Wine needed for these cases; the fake wine shim covers the ownership read, which is the right level for a race that a real prefix cannot reliably reproduce.

No game data. AI-assisted.

@zzEmmazz
zzEmmazz marked this pull request as ready for review November 23, 2026 05:02
@DenRakEiw

Copy link
Copy Markdown

Tested 5b7dd8c on Windows 11, Python 3.12.10 (CPU only, no game files): pass (POSIX symlink tests skipped on Windows).

  • Trial-merged onto origin/main (98fa503): merges cleanly; git diff --check clean.
  • python -I tests/test_run_wine_tests.py: 47 OK, 12 skipped (POSIX-only DriveMap symlink cases skipped on Windows).
  • Code read: DriveMap.enter cleans up scratch in inally if setup fails or os.symlink hits FileExistsError, and exit verifies os.readlink(self.link) == self.scratch before unlinking so replaced mappings are preserved. No blocking issues.

AI-assisted review (Gemini).

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.

6 participants