mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 22:38:39 +00:00
Two standard-library tests fail on native Windows and are skipped or pass
elsewhere:
- test_make_game_paths: since BUILD-2367 main() takes a drive-root dump's
top-level names from the version manifest, but the two drive-root cases
still mocked check() as {} and patched os.listdir, so main() raised
KeyError: 'expected_exe' before reaching the rule under test. They now
pass a manifest with the same entries.
- test_leonida_mods: test_run_print_builds_gta6rt_command wrote only
gta6rt.sh, and runtime_executable() accepts only gta6rt.exe on Windows.
It now writes the launcher of the platform it runs on.
Tests only; no tool changes.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
144 lines
6.8 KiB
Python
144 lines
6.8 KiB
Python
"""Build destinations must stay outside the game folder, including through directory links.
|
|
|
|
python -I tests/test_make_game_paths.py
|
|
|
|
Only empty temporary directories are used; no game files or build tools are needed.
|
|
"""
|
|
from contextlib import ExitStack
|
|
import io
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from unittest.mock import patch
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, ROOT)
|
|
import make_game
|
|
|
|
|
|
class BuildDestinationTest(unittest.TestCase):
|
|
def setUp(self):
|
|
tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(tmp.cleanup)
|
|
self.root = tmp.name
|
|
self.game = os.path.join(self.root, "game")
|
|
os.mkdir(self.game)
|
|
self.alias = os.path.join(self.root, "game-link")
|
|
|
|
def link(self, target, path):
|
|
if os.name == "nt":
|
|
# Junctions work without Developer Mode or symlink privileges on Windows.
|
|
result = subprocess.run(["cmd", "/c", "mklink", "/J", path, target],
|
|
capture_output=True, text=True)
|
|
if result.returncode:
|
|
self.skipTest("cannot create a directory junction: " + result.stderr)
|
|
self.addCleanup(os.rmdir, path)
|
|
else:
|
|
os.symlink(target, path, target_is_directory=True)
|
|
self.addCleanup(os.unlink, path)
|
|
|
|
@staticmethod
|
|
def version(*top_level):
|
|
"""A version manifest whose files sit in these top-level folders: at a drive-root --game, main() takes the
|
|
dump's own entries from the manifest (BUILD-2367), not from os.listdir."""
|
|
return {"expected_exe": top_level[0] + "\\game.exe",
|
|
"files": {f"{name}/a.rpf": {} for name in top_level}}
|
|
|
|
def run_build(self, game, out, work, rejected, version=None):
|
|
argv = ["make_game.py", "--game", game, "--out", out, "--work", work,
|
|
"--stages", "runtime", "--no-tui"]
|
|
with ExitStack() as stack:
|
|
stack.enter_context(patch.object(sys, "argv", argv))
|
|
stack.enter_context(patch("make_game.below_normal"))
|
|
stack.enter_context(patch("make_game.check", return_value=version or {}))
|
|
stack.enter_context(patch("make_game.log"))
|
|
preflight = stack.enter_context(patch("make_game.preflight"))
|
|
build_runtime = stack.enter_context(patch("make_game.runtime"))
|
|
stderr = stack.enter_context(patch("sys.stderr", new_callable=io.StringIO))
|
|
if rejected:
|
|
with self.assertRaises(SystemExit) as error:
|
|
make_game.main()
|
|
self.assertEqual(error.exception.code, 1)
|
|
self.assertIn("--out and --work must be outside the game folder", stderr.getvalue())
|
|
preflight.assert_not_called()
|
|
build_runtime.assert_not_called()
|
|
else:
|
|
self.assertEqual(make_game.main(), 0)
|
|
preflight.assert_called_once()
|
|
build_runtime.assert_called_once()
|
|
|
|
def test_destinations_through_game_link_are_rejected(self):
|
|
self.link(self.game, self.alias)
|
|
for option in ("out", "work"):
|
|
for suffix in ("", "new", os.path.join("new", "nested")):
|
|
with self.subTest(option=option, suffix=suffix):
|
|
destinations = {name: os.path.join(self.root, name) for name in ("out", "work")}
|
|
destinations[option] = os.path.join(self.alias, suffix)
|
|
self.run_build(self.game, **destinations, rejected=True)
|
|
self.assertFalse(os.path.exists(os.path.join(self.game, "new")))
|
|
|
|
def test_game_link_cannot_hide_destinations_in_real_game_folder(self):
|
|
self.link(self.game, self.alias)
|
|
for option in ("out", "work"):
|
|
with self.subTest(option=option):
|
|
destinations = {name: os.path.join(self.root, name) for name in ("out", "work")}
|
|
destinations[option] = os.path.join(self.game, "new")
|
|
self.run_build(self.alias, **destinations, rejected=True)
|
|
|
|
def test_link_to_unrelated_output_folder_is_allowed(self):
|
|
target = os.path.join(self.root, "output")
|
|
os.mkdir(target)
|
|
alias = os.path.join(self.root, "output-link")
|
|
self.link(target, alias)
|
|
self.run_build(self.game, os.path.join(alias, "new"),
|
|
os.path.join(self.root, "work"), rejected=False)
|
|
|
|
def test_drive_root_game_folder_rules(self):
|
|
if os.name != "nt":
|
|
self.skipTest("Windows drive root check")
|
|
drive = os.path.splitdrive(self.root)[0] + "\\"
|
|
content_dir = os.path.join(drive, "Content")
|
|
independent_dir = os.path.join(drive, "Leonida_Build")
|
|
version = self.version("Content")
|
|
# Allowed: destination is an independent folder on the drive root
|
|
self.run_build(drive, independent_dir, os.path.join(independent_dir, "work"), rejected=False, version=version)
|
|
# Rejected: destination is inside the game dump's own top-level entry
|
|
self.run_build(drive, os.path.join(content_dir, "out"), os.path.join(self.root, "work"), rejected=True,
|
|
version=version)
|
|
# Rejected: destination is the drive root itself
|
|
self.run_build(drive, drive, os.path.join(self.root, "work"), rejected=True, version=version)
|
|
|
|
def test_drive_root_checks_entries_on_each_volume(self):
|
|
if os.name != "nt":
|
|
self.skipTest("Windows drive root check")
|
|
root = os.path.splitdrive(self.root)[0] + "\\"
|
|
other_root = "Z:\\" if root.upper() != "Z:\\" else "Y:\\"
|
|
junction = os.path.join(root, "MountedContent")
|
|
mounted_content = os.path.join(other_root, "Package")
|
|
|
|
def realpath(path):
|
|
if os.path.normcase(path) == os.path.normcase(junction):
|
|
return mounted_content
|
|
return os.path.normpath(path)
|
|
|
|
# A junction target on a different volume must not end the search before the matching entry.
|
|
for entries, protected in (
|
|
(["MountedContent", "Content"], os.path.join(root, "Content")),
|
|
(["Content", "MountedContent"], mounted_content),
|
|
):
|
|
version = self.version(*entries)
|
|
with patch("os.path.realpath", side_effect=realpath):
|
|
for option in ("out", "work"):
|
|
with self.subTest(protected=protected, option=option):
|
|
destinations = {name: os.path.join(self.root, name) for name in ("out", "work")}
|
|
destinations[option] = os.path.join(protected, "build")
|
|
self.run_build(root, **destinations, rejected=True, version=version)
|
|
self.run_build(root, os.path.join(other_root, "Build"),
|
|
os.path.join(other_root, "Scratch"), rejected=False, version=version)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|