Skip to content
Open
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
13 changes: 12 additions & 1 deletion tools/modsync-ci/fullrun_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
the local game-cache unpack process, never to an application process.
"""
import argparse
import errno
import hashlib
import os
from pathlib import Path
Expand Down Expand Up @@ -206,7 +207,17 @@ def verify(candidate, label):
shutil.copyfile(seal, staging)
os.replace(staging, seal_dir / game_backup.RESTORED_SEAL)
game_dir.parent.mkdir(parents=True, exist_ok=True)
verified_game.rename(game_dir)
try:
verified_game.rename(game_dir)
except OSError as error:
# Exhaustive lanes put the game on a loop-mounted filesystem, so the
# verified tree under RUNNER_TEMP cannot be renamed into it. Restore
# the same verified seal directly at the destination instead of
# copying, so only freshly verified bytes are ever materialized.
if error.errno != errno.EXDEV:
raise
verify_seal(game, seal_dir / game_backup.RESTORED_SEAL, game_dir, environ)
print("baseline verified at destination (separate filesystem)", flush=True)
result["available"] = True
return result

Expand Down
48 changes: 48 additions & 0 deletions tools/modsync-ci/test_fullrun_baseline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Credential-free recovery/namespace tests; no Rust or game processes run."""
import contextlib
import errno
import io
import os
from pathlib import Path
Expand Down Expand Up @@ -91,6 +92,53 @@ def test_valid_cache_is_verified_and_missing_current_backup_requires_publication
self.assertEqual(self.verified, [b"cache-good"])
self.assertEqual(self.clients, [("owner/current", "current-only")])

def rename_raising(self, code):
original = Path.rename

def rename(path, target):
if Path(target) == self.game:
raise OSError(code, os.strerror(code))
return original(path, target)
return mock.patch.object(Path, "rename", autospec=True, side_effect=rename)

def test_a_game_dir_on_another_filesystem_is_restored_from_the_verified_seal(self):
# Exhaustive lanes loop-mount the game storage, so the verified tree under
# RUNNER_TEMP cannot be renamed into it (EXDEV).
self.cached()
with self.rename_raising(errno.EXDEV):
result = self.recover()
self.assertEqual(result, {"available": True, "origin": "cache", "backup_required": True})
self.assertEqual((self.game / "verified.txt").read_bytes(), b"cache-good")
# Verified once as a candidate and once again at the destination, never copied.
self.assertEqual(self.verified, [b"cache-good", b"cache-good"])

def test_a_failed_restore_on_another_filesystem_exits_1_and_leaves_no_game_tree(self):
self.cached()
calls = []

def verify_then_fail(game, candidate, destination, environ):
calls.append(destination)
if len(calls) == 2: # the restore at the destination fails verification
raise subprocess.CalledProcessError(1, ["game_cache.py", "inventory"])
return self.verify(game, candidate, destination, environ)

output = io.StringIO()
with self.rename_raising(errno.EXDEV), \
mock.patch.object(baseline, "verify_seal", side_effect=verify_then_fail), \
mock.patch.dict(os.environ, self.environ, clear=True), contextlib.redirect_stdout(output):
code = baseline.main(["--game", "k1", "--seal-dir", str(self.seals), "--game-dir", str(self.game),
"--required", "--local-only"])
self.assertEqual(code, 1)
self.assertEqual(len(calls), 2)
self.assertFalse(self.game.exists())
self.assertIn("::error::No verified k1 baseline", output.getvalue())

def test_other_rename_failures_still_fail_recovery(self):
self.cached()
with self.rename_raising(errno.EACCES), self.assertRaises(PermissionError):
self.recover()
self.assertFalse(self.game.exists())

def test_corrupt_cache_tries_current_before_legacy_and_preserves_other_candidates(self):
self.cached(b"bad-cache", "old.seal")
self.backup()
Expand Down
Loading