Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/test_leonida_mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ def test_run_print_builds_gta6rt_command(self):
game = Path(tmp, "game")
port.mkdir()
game.mkdir()
port.joinpath("gta6rt.sh").write_text("#!/bin/sh\n", encoding="utf-8")
# the launcher runtime_executable() looks for here: Windows takes only gta6rt.exe
launcher = "gta6rt.exe" if os.name == "nt" else "gta6rt.sh"
port.joinpath(launcher).write_bytes(b"MZ" if os.name == "nt" else b"#!/bin/sh\n")
port.joinpath("game_path.txt").write_text(str(game) + "\n", encoding="utf-8")
image = game / leonida_mods.EXPECTED_EXE
image.write_bytes(b"MZ")
Expand Down
33 changes: 21 additions & 12 deletions tests/test_make_game_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ def link(self, target, path):
os.symlink(target, path, target_is_directory=True)
self.addCleanup(os.unlink, path)

def run_build(self, game, out, work, rejected):
@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={}))
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"))
Expand Down Expand Up @@ -94,13 +101,14 @@ def test_drive_root_game_folder_rules(self):
drive = os.path.splitdrive(self.root)[0] + "\\"
content_dir = os.path.join(drive, "Content")
independent_dir = os.path.join(drive, "Leonida_Build")
with patch("os.listdir", return_value=["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)
# 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)
# Rejected: destination is the drive root itself
self.run_build(drive, drive, os.path.join(self.root, "work"), rejected=True)
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":
Expand All @@ -120,14 +128,15 @@ def realpath(path):
(["MountedContent", "Content"], os.path.join(root, "Content")),
(["Content", "MountedContent"], mounted_content),
):
with patch("os.listdir", return_value=entries), patch("os.path.realpath", side_effect=realpath):
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)
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)
os.path.join(other_root, "Scratch"), rejected=False, version=version)


if __name__ == "__main__":
Expand Down