Minecraft-Friends-AI-ZeroGPU / tests /test_server_admin_config.py
Erinaldordso's picture
Restore Naldo Muse connection and start a fresh normal world
a625b1a verified
Raw History Blame Contribute Delete
2.88 kB
import json
import tempfile
from pathlib import Path
import minecraft_stack as mc
def test_operator_seed_preserves_other_operators():
with tempfile.TemporaryDirectory() as tmp:
path = Path(tmp) / "ops.json"
other = {"uuid": "other", "name": "ExistingAdmin", "level": 3, "bypassesPlayerLimit": False}
path.write_text(json.dumps([other]), encoding="utf-8")
mc._ensure_admin_operator(path, "IffyBinkie6134")
mc._ensure_admin_operator(path, "IffyBinkie6134")
entries = json.loads(path.read_text(encoding="utf-8"))
assert entries[0] == other
assert len(entries) == 2
assert entries[1] == {
"uuid": mc._offline_player_uuid("IffyBinkie6134"),
"name": "IffyBinkie6134", "level": 4, "bypassesPlayerLimit": True,
}
try:
mc._ensure_admin_operator(path, "bad name; op someone")
except ValueError:
pass
else:
raise AssertionError("invalid username accepted")
assert json.loads(path.read_text(encoding="utf-8")) == entries
def test_status_reports_real_configured_limits_and_operator():
with tempfile.TemporaryDirectory() as tmp:
base = Path(tmp)
old = (mc.JAVA_DIR, mc.RELAY_DIR, mc.WORLD_DIR, mc.LOG_PATH)
try:
mc.JAVA_DIR, mc.RELAY_DIR = base / "java", base / "relay"
mc.WORLD_DIR, mc.LOG_PATH = base / "world", base / "stack.log"
mc.JAVA_DIR.mkdir()
mc.RELAY_DIR.mkdir()
mc.WORLD_DIR.mkdir()
(mc.JAVA_DIR / "server.properties").write_text("max-players=100\n", encoding="utf-8")
(mc.RELAY_DIR / "config.json").write_text('{"max_players":100}', encoding="utf-8")
mc._ensure_admin_operator(mc.JAVA_DIR / "ops.json", mc.ADMIN_USERNAME)
status = mc.MinecraftStack().status()
assert status["player_limit"] == {"java": 100, "xbox_friends": 100}
assert status["world_profile"] == "minecraft:normal"
assert status["world_surface_y"] == 64
assert status["admin_operator"] is True
assert status["admin_player_file_exists"] is False
(mc.WORLD_DIR / "playerdata").mkdir()
(mc.WORLD_DIR / "playerdata" / f"{mc._offline_player_uuid(mc.ADMIN_USERNAME)}.dat").write_bytes(b"saved")
assert mc.MinecraftStack().status()["admin_player_file_exists"] is True
(mc.JAVA_DIR / "ops.json").write_text("[]", encoding="utf-8")
assert mc.MinecraftStack().status()["admin_operator"] is False
finally:
mc.JAVA_DIR, mc.RELAY_DIR, mc.WORLD_DIR, mc.LOG_PATH = old
if __name__ == "__main__":
test_operator_seed_preserves_other_operators()
test_status_reports_real_configured_limits_and_operator()
print("PASS player limit and persistent operator seed")