File size: 2,479 Bytes
24010a2
 
 
 
31408fc
24010a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31408fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Verify exception logging does not replace vanilla's catch or success path."""
from pathlib import Path
import subprocess
import tempfile
import importlib.util

root = Path(__file__).resolve().parents[1]
with tempfile.TemporaryDirectory() as directory:
    folder = Path(directory)
    source = folder / "class_29.java"
    source.write_text('''package net.minecraft;
public class class_29 {
  public void method_262(boolean fail) {
    try { if(fail) throw new java.io.IOException("diagnostic sentinel"); }
    catch(Exception e) { System.out.println("original catch retained"); }
  }
  public static void main(String[] args) {
    new class_29().method_262(true);
    new class_29().method_262(false);
    System.out.println("normal return retained");
  }
}''')
    subprocess.run(["java", "-m", "jdk.compiler/com.sun.tools.javac.Main", "-d", directory, str(source)], check=True)
    result = subprocess.run([
        "java", "--add-exports=java.base/jdk.internal.org.objectweb.asm=ALL-UNNAMED",
        f"-javaagent:{root / 'diagnostics/player-save-diagnostics.jar'}",
        "-cp", directory, "net.minecraft.class_29",
    ], capture_output=True, text=True, check=True)
    assert result.stderr.count("java.io.IOException: diagnostic sentinel") == 1
    assert "exception logging hooks=1" in result.stderr
    assert result.stdout == "original catch retained\nnormal return retained\n"
    print("PASS player-save exception visible; original catch and normal return unchanged")

# Isolate the Fabric mod installer: only the known faulty JAR is removed.
spec = importlib.util.spec_from_file_location("minecraft_stack_test", root / "minecraft_stack.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
with tempfile.TemporaryDirectory() as directory:
    module.JAVA_DIR = Path(directory)
    module._download = lambda _url, path, _sha: path.write_bytes(b"unrelated mod")
    module._log = lambda _message: None
    mods = module.JAVA_DIR / "mods"
    mods.mkdir()
    faulty = mods / "better-respawn-fabric-1.19-2.0.0.jar"
    faulty.write_bytes(b"the pinned faulty mod")
    marker = mods / "custom-mod.jar"
    marker.write_bytes(b"preserve")
    module.MinecraftStack()._ensure_voyager_mods()
    assert not faulty.exists()
    assert marker.read_bytes() == b"preserve"
    assert len(list(mods.glob("*.jar"))) == 4  # Three required mods plus the marker.
    print("PASS faulty Better Respawn mixin excluded; other Fabric mods retained")