Prepare: require only this platform's libraries; accept republished 26.3 manifests
lab.prepare imported every client library in the version JSON, ignoring its OS rules, so a Linux install failed on the macOS-only java-objc-bridge the official launcher never downloads there. The rule evaluation moves from runtime.py into lab.py and one selector, client_library_artifacts, now serves preparation, the runtime and the model baking harness: OS rules as the launcher applies them, and the natives for this architecture (classifier suffixes, plain natives being the x64 build only when an ARM variant is listed). Required libraries are still checksummed and a missing one still errors. Mojang republished 26.3.json twice (702fe591, then 11f1aefe, the current one) with only assetIndex changed: non-English translations, same jars and libraries. The lock pins the current file and accepts both earlier ones; preparation takes the launcher's copy so it matches the asset index installed with it, and an unknown republish errors clearly. Fixes #41 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,6 +71,7 @@ class ArtifactTests(unittest.TestCase):
|
||||
version.mkdir(parents=True)
|
||||
(version / "26.3.json").write_text(json.dumps(manifest))
|
||||
(version / "26.3.jar").write_bytes(client)
|
||||
lock["minecraft"]["manifest_sha1"] = lab.digest(version / "26.3.json", "sha1")
|
||||
loaded, jar = lab.import_client(lock, cache, launcher)
|
||||
self.assertEqual((loaded["id"], jar.read_bytes()), ("26.3", client))
|
||||
with self.assertRaisesRegex(FileNotFoundError, "server jar yourself"):
|
||||
@@ -91,6 +92,29 @@ class ArtifactTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ValueError, "pinned 26.3 release"):
|
||||
lab.import_manifest(lock, Path(temp) / "cache", Path(temp))
|
||||
|
||||
def test_republished_launcher_manifests_are_accepted_and_unknown_ones_rejected(self):
|
||||
manifest = {"id": "26.3", "javaVersion": {"majorVersion": 25}, "assetIndex": {"sha1": "a"},
|
||||
"downloads": {"client": {"sha1": "1" * 40}, "server": {"sha1": "2" * 40}}}
|
||||
older = json.dumps({**manifest, "assetIndex": {"sha1": "b"}})
|
||||
lock = {"minecraft": {"version": "26.3", "java_major": 25, "client_sha1": "1" * 40, "server_sha1": "2" * 40,
|
||||
"manifest_sha1": hashlib.sha1(json.dumps(manifest).encode()).hexdigest(),
|
||||
"accepted_manifest_sha1": [hashlib.sha1(older.encode()).hexdigest()]}}
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
launcher, cache = Path(temp) / "minecraft", Path(temp) / "cache"
|
||||
source = launcher / "versions" / "26.3" / "26.3.json"
|
||||
source.parent.mkdir(parents=True)
|
||||
source.write_text(older)
|
||||
self.assertEqual(lab.import_manifest(lock, cache, launcher)["assetIndex"], {"sha1": "b"})
|
||||
# The launcher's newer copy replaces the cached one, keeping it in step with its asset index.
|
||||
source.write_text(json.dumps(manifest))
|
||||
self.assertEqual(lab.import_manifest(lock, cache, launcher)["assetIndex"], {"sha1": "a"})
|
||||
source.unlink()
|
||||
self.assertEqual(lab.import_manifest(lock, cache, launcher)["assetIndex"], {"sha1": "a"})
|
||||
source.write_text(json.dumps({**manifest, "assetIndex": {"sha1": "c"}}))
|
||||
with self.assertRaisesRegex(ValueError, "does not know yet"):
|
||||
lab.import_manifest(lock, cache, launcher)
|
||||
|
||||
|
||||
def test_sourcefile_metadata_covers_inner_classes(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
path = Path(temp) / "game.jar"
|
||||
@@ -177,5 +201,89 @@ class PublicationTests(unittest.TestCase):
|
||||
self.assertIn(".local/artifact.txt", check_public_tree.paths_in_repository(history=True))
|
||||
|
||||
|
||||
def library(name, os_name=None):
|
||||
entry = {"name": name, "downloads": {"artifact": {"path": name.replace(":", "/") + ".jar",
|
||||
"sha1": hashlib.sha1(name.encode()).hexdigest()}}}
|
||||
if os_name:
|
||||
entry["rules"] = [{"action": "allow", "os": {"name": os_name}}]
|
||||
return entry
|
||||
|
||||
|
||||
# The shapes of 26.3's libraries: OS-only rules, ARM and x64 natives told apart by classifier.
|
||||
PLATFORM_MANIFEST = {"libraries": [
|
||||
library("com.mojang:brigadier:1.3.10"),
|
||||
library("ca.weblite:java-objc-bridge:1.1", "osx"),
|
||||
library("org.lwjgl:lwjgl:3.4.3"),
|
||||
library("org.lwjgl:lwjgl:3.4.3:natives-linux", "linux"),
|
||||
library("org.lwjgl:lwjgl:3.4.3:natives-macos", "osx"),
|
||||
library("org.lwjgl:lwjgl:3.4.3:natives-macos-arm64", "osx"),
|
||||
library("org.lwjgl:lwjgl:3.4.3:natives-windows", "windows"),
|
||||
library("org.lwjgl:lwjgl:3.4.3:natives-windows-arm64", "windows"),
|
||||
library("io.netty:netty-transport-native-epoll:4.2.16.Final:linux-aarch_64", "linux"),
|
||||
library("io.netty:netty-transport-native-epoll:4.2.16.Final:linux-x86_64", "linux"),
|
||||
library("io.netty:netty-transport-native-kqueue:4.2.16.Final:osx-aarch_64", "osx"),
|
||||
library("io.netty:netty-transport-native-kqueue:4.2.16.Final:osx-x86_64", "osx"),
|
||||
{"name": "org.example:no-artifact:1.0", "downloads": {}},
|
||||
]}
|
||||
|
||||
|
||||
class PlatformLibraryTests(unittest.TestCase):
|
||||
def selected(self, system, architecture):
|
||||
names = {entry["downloads"]["artifact"]["path"]: entry["name"]
|
||||
for entry in PLATFORM_MANIFEST["libraries"] if entry["downloads"]}
|
||||
return {names[artifact["path"]]
|
||||
for artifact in lab.client_library_artifacts(PLATFORM_MANIFEST, system, architecture)}
|
||||
|
||||
def test_each_platform_requires_only_what_the_official_launcher_installs(self):
|
||||
common = {"com.mojang:brigadier:1.3.10", "org.lwjgl:lwjgl:3.4.3"}
|
||||
expected = {
|
||||
("linux", "x86_64"): {"org.lwjgl:lwjgl:3.4.3:natives-linux",
|
||||
"io.netty:netty-transport-native-epoll:4.2.16.Final:linux-x86_64"},
|
||||
# No ARM build of natives-linux is listed, so the plain one is the only one.
|
||||
("linux", "aarch64"): {"org.lwjgl:lwjgl:3.4.3:natives-linux",
|
||||
"io.netty:netty-transport-native-epoll:4.2.16.Final:linux-aarch_64"},
|
||||
("osx", "arm64"): {"ca.weblite:java-objc-bridge:1.1", "org.lwjgl:lwjgl:3.4.3:natives-macos-arm64",
|
||||
"io.netty:netty-transport-native-kqueue:4.2.16.Final:osx-aarch_64"},
|
||||
("osx", "x86_64"): {"ca.weblite:java-objc-bridge:1.1", "org.lwjgl:lwjgl:3.4.3:natives-macos",
|
||||
"io.netty:netty-transport-native-kqueue:4.2.16.Final:osx-x86_64"},
|
||||
("windows", "AMD64"): {"org.lwjgl:lwjgl:3.4.3:natives-windows"},
|
||||
("windows", "ARM64"): {"org.lwjgl:lwjgl:3.4.3:natives-windows-arm64"},
|
||||
}
|
||||
for (system, architecture), specific in expected.items():
|
||||
with self.subTest(system=system, architecture=architecture):
|
||||
self.assertEqual(self.selected(system, architecture), common | specific)
|
||||
|
||||
def test_rules_follow_the_launcher_last_match_and_arch_aliases(self):
|
||||
rules = [{"action": "allow"}, {"action": "disallow", "os": {"name": "osx", "arch": "aarch64"}}]
|
||||
self.assertTrue(lab.library_allowed({"rules": rules}, "osx", "x86_64"))
|
||||
self.assertFalse(lab.library_allowed({"rules": rules}, "osx", "arm64"))
|
||||
self.assertFalse(lab.library_allowed({"rules": rules}, "osx", "aarch64"))
|
||||
self.assertTrue(lab.library_allowed({"rules": rules}, "linux", "aarch64"))
|
||||
self.assertTrue(lab.library_allowed({"rules": [{"action": "allow", "os": {"arch": "x86_64"}}]}, "windows", "AMD64"))
|
||||
self.assertFalse(lab.library_allowed({"rules": [{"action": "allow", "features": {"is_demo_user": True}}]}, "linux"))
|
||||
|
||||
def test_prepare_on_linux_skips_macos_libraries_and_still_checks_required_ones(self):
|
||||
with tempfile.TemporaryDirectory() as temp:
|
||||
launcher, cache = Path(temp) / "minecraft", Path(temp) / "cache"
|
||||
artifacts = lab.client_library_artifacts(PLATFORM_MANIFEST, "linux", "x86_64")
|
||||
# A Linux install: the launcher never fetched the macOS bridge. Each fixture
|
||||
# jar's content is its Maven name, which is what its sha1 covers.
|
||||
for entry in PLATFORM_MANIFEST["libraries"]:
|
||||
artifact = entry["downloads"].get("artifact")
|
||||
if artifact in artifacts:
|
||||
path = launcher / "libraries" / artifact["path"]
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(entry["name"].encode())
|
||||
imported = [lab.import_library(a, cache, launcher) for a in artifacts]
|
||||
self.assertFalse(any("objc" in str(path) for path in imported))
|
||||
required = next(a for a in artifacts if "natives-linux" in a["path"])
|
||||
(launcher / "libraries" / required["path"]).write_bytes(b"tampered")
|
||||
with self.assertRaisesRegex(ValueError, "not the pinned file"):
|
||||
lab.import_library(required, Path(temp) / "other", launcher)
|
||||
(launcher / "libraries" / required["path"]).unlink()
|
||||
with self.assertRaisesRegex(FileNotFoundError, "official launcher"):
|
||||
lab.import_library(required, Path(temp) / "other", launcher)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user