Refused unstageable takeovers

- Datapack staging refuses a takeover it cannot stage when the level has applied takeover state or Iris generation history, instead of silently leaving the mod generator in place
- A level's retained generation history now stages its takeover even when the installed pack is gone
- Takeover pack names and dimension keys are resolved to the installed folder and file names before staging, reconciliation, and recording, and the takeover command stores that form
- Reconciliation refuses to switch an applied level to an uninstalled pack before moving any data, and leaves a never-applied level untouched until its pack is installed
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-14 20:59:09 -04:00
1 parent cf0587c112
commit 038833e614
7 files changed
+361 -71

No files matched your search

@@ -30,6 +30,7 @@ import java.util.Map;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
@@ -130,4 +131,116 @@ public class ModdedDimensionTakeoversTest {
assertEquals("", ModdedDimensionTakeovers.fingerprint(Map.of()));
assertTrue(ModdedDimensionTakeovers.fingerprint(forward).contains("iristest:b=overworld:sky"));
}
@Test
public void installedPackTypeIsStagedForTheTakeover() throws IOException {
Path temporary = Files.createTempDirectory("iris-takeover-stage-installed");
try {
Path datapack = temporary.resolve("datapack");
ModdedDimensionTakeovers.StagedTypes staged = ModdedDimensionTakeovers.StagedTypes.create();
staged.installed().put("skypack:sky", "irisworldgen:packs/x/dimensions/y/dimension_type");
ModdedDimensionTakeovers.writeLevelStems(datapack, Map.of("aether:the_aether", "skypack:sky"), staged,
temporary.resolve("world"));
JSONObject stem = new JSONObject(Files.readString(datapack.resolve("data/aether/dimension/the_aether.json")));
assertEquals("irisworldgen:packs/x/dimensions/y/dimension_type", stem.getString("type"));
assertEquals("skypack:sky", stem.getJSONObject("generator").getString("dimension"));
} finally {
ModdedTakeoverReconcilerTest.deleteTree(temporary);
}
}
@Test
public void retainedHistoryOfTheLevelStagesTheTakeoverWithoutTheInstalledPack() throws IOException {
Path temporary = Files.createTempDirectory("iris-takeover-stage-retained");
try {
Path datapack = temporary.resolve("datapack");
Path worldRoot = temporary.resolve("world");
ModdedDimensionTakeovers.StagedTypes staged = ModdedDimensionTakeovers.StagedTypes.create();
staged.retained().put(worldRoot.resolve("dimensions/aether/the_aether").toAbsolutePath().normalize(),
"aether:the_aether");
ModdedDimensionTakeovers.writeLevelStems(datapack, Map.of("aether:the_aether", "skypack:sky"), staged, worldRoot);
JSONObject stem = new JSONObject(Files.readString(datapack.resolve("data/aether/dimension/the_aether.json")));
assertEquals("aether:the_aether", stem.getString("type"));
} finally {
ModdedTakeoverReconcilerTest.deleteTree(temporary);
}
}
@Test
public void unstageableTakeoverWithoutAnyRecordIsSkipped() throws IOException {
Path temporary = Files.createTempDirectory("iris-takeover-stage-skip");
try {
Path datapack = temporary.resolve("datapack");
Path worldRoot = temporary.resolve("world");
Files.createDirectories(worldRoot);
ModdedDimensionTakeovers.writeLevelStems(datapack, Map.of("aether:the_aether", "skypack:sky"),
ModdedDimensionTakeovers.StagedTypes.create(), worldRoot);
ModdedDimensionTakeovers.writeLevelStems(datapack, Map.of("aether:the_aether", "skypack:sky"),
ModdedDimensionTakeovers.StagedTypes.create(), null);
assertFalse(Files.exists(datapack.resolve("data/aether/dimension/the_aether.json")));
} finally {
ModdedTakeoverReconcilerTest.deleteTree(temporary);
}
}
@Test
public void unstageableTakeoverOfAnAppliedLevelRefusesStaging() throws IOException {
Path temporary = Files.createTempDirectory("iris-takeover-stage-applied");
try {
Path worldRoot = temporary.resolve("world");
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("aether:the_aether", "skypack:sky"));
IOException refused = assertThrows(IOException.class, () -> ModdedDimensionTakeovers.writeLevelStems(
temporary.resolve("datapack"), Map.of("aether:the_aether", "skypack:sky"),
ModdedDimensionTakeovers.StagedTypes.create(), worldRoot));
assertTrue(refused.getMessage(), refused.getMessage().contains("aether:the_aether"));
assertTrue(refused.getMessage(), refused.getMessage().contains("skypack"));
} finally {
ModdedTakeoverReconcilerTest.deleteTree(temporary);
}
}
@Test
public void unstageableTakeoverOfALevelWithIrisHistoryRefusesStaging() throws IOException {
Path temporary = Files.createTempDirectory("iris-takeover-stage-history");
try {
Path worldRoot = temporary.resolve("world");
Files.createDirectories(worldRoot.resolve("dimensions/aether/the_aether/iris/generation"));
assertThrows(IOException.class, () -> ModdedDimensionTakeovers.writeLevelStems(
temporary.resolve("datapack"), Map.of("aether:the_aether", "skypack:sky"),
ModdedDimensionTakeovers.StagedTypes.create(), worldRoot));
} finally {
ModdedTakeoverReconcilerTest.deleteTree(temporary);
}
}
@Test
public void canonicalTakeoverFollowsTheInstalledPackFolderCase() throws IOException {
Path packsRoot = Files.createTempDirectory("iris-takeover-canonical");
try {
Files.createDirectories(packsRoot.resolve("skypack/dimensions"));
Files.writeString(packsRoot.resolve("skypack/dimensions/sky.json"), "{}");
boolean caseInsensitive = Files.isDirectory(packsRoot.resolve("SKYPACK"));
Map<String, String> canonical = ModdedDimensionTakeovers.canonical(
Map.of("aether:the_aether", "SkyPack:Sky", "aether:other", "missing:sky"), packsRoot);
assertEquals(caseInsensitive ? "skypack:sky" : "SkyPack:Sky", canonical.get("aether:the_aether"));
assertEquals("missing:sky", canonical.get("aether:other"));
assertEquals("skypack:sky", ModdedDimensionTakeovers.canonical(
Map.of("aether:the_aether", "skypack:sky"), packsRoot).get("aether:the_aether"));
assertTrue(ModdedDimensionTakeovers.installed(ModdedDimensionTakeover.parse("aether:the_aether", "skypack:sky"), packsRoot));
assertFalse(ModdedDimensionTakeovers.installed(ModdedDimensionTakeover.parse("aether:the_aether", "skypack:void"), packsRoot));
} finally {
ModdedTakeoverReconcilerTest.deleteTree(packsRoot);
}
}
}
@@ -111,10 +111,10 @@ public class ModdedForcedDatapackTest {
Map.of(key, saved));
Class<?> stageType = Class.forName(ModdedForcedDatapack.class.getName() + "$PackStageContext");
Constructor<?> constructor = stageType.getDeclaredConstructor(Path.class, String.class, String.class,
String.class, boolean.class, boolean.class, boolean.class, Set.class, GenerationRegistryContract.class);
String.class, boolean.class, boolean.class, boolean.class, Set.class, GenerationRegistryContract.class, Path.class);
constructor.setAccessible(true);
IrisCustomBiomeAliasResolver resolver = (IrisCustomBiomeAliasResolver) constructor.newInstance(
Path.of("retained"), "test", "test", "iris:test_type", false, false, true, Set.of(), contract);
Path.of("retained"), "test", "test", "iris:test_type", false, false, true, Set.of(), contract, Path.of("dimension"));
assertEquals(source, resolver.generatedSource(key.registryKey(), key.resourceKey(), "{}", fixer));
assertThrows(IOException.class, () -> resolver.generatedSource(
key.registryKey(), "iris:missing_type", "{}", fixer));
@@ -67,10 +67,10 @@ public class ModdedTakeoverReconcilerTest {
touch(worldRoot.resolve("dimensions/minecraft/overworld/region/r.0.0.mca"));
touch(worldRoot.resolve("players/data/player.dat"));
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result result = reconcile(
worldRoot, Map.of("iristest:skylands", "overworld"), List.of(), recoveryParent);
assertEquals(Set.of("iristest:skylands"), result.changedLevels());
assertEquals(Set.of("iristest:skylands"), result.quarantinedLevels());
for (String folder : List.of("region", "entities", "poi", "mantle-hydrology", "iris")) {
assertFalse(folder, Files.exists(skylands.resolve(folder)));
assertTrue(folder, Files.isRegularFile(result.recovery()
@@ -95,17 +95,17 @@ public class ModdedTakeoverReconcilerTest {
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("iristest:skylands", "overworld"));
touch(region);
ModdedTakeoverReconciler.Result unchanged = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result unchanged = reconcile(
worldRoot, Map.of("iristest:skylands", "overworld"), List.of(), recoveryParent);
assertEquals(Set.of(), unchanged.changedLevels());
assertEquals(Set.of(), unchanged.quarantinedLevels());
assertNull(unchanged.recovery());
assertTrue(Files.isRegularFile(region));
ModdedTakeoverReconciler.Result removed = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result removed = reconcile(
worldRoot, Map.of(), List.of(), recoveryParent);
assertEquals(Set.of("iristest:skylands"), removed.changedLevels());
assertEquals(Set.of("iristest:skylands"), removed.quarantinedLevels());
assertFalse(Files.exists(region));
assertTrue(Files.isRegularFile(removed.recovery().resolve("dimensions/iristest/skylands/region/r.0.0.mca")));
assertEquals(Map.of(), ModdedTakeoverReconciler.readApplied(worldRoot));
@@ -122,10 +122,10 @@ public class ModdedTakeoverReconcilerTest {
try {
Files.createDirectories(worldRoot);
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result result = reconcile(
worldRoot, Map.of("aether:the_aether", "overworld"), List.of(), recoveryParent);
assertEquals(Set.of("aether:the_aether"), result.changedLevels());
assertEquals(Set.of("aether:the_aether"), result.quarantinedLevels());
assertNull(result.recovery());
assertFalse(Files.exists(recoveryParent));
assertEquals(Map.of(), ModdedTakeoverReconciler.readApplied(worldRoot));
@@ -145,7 +145,7 @@ public class ModdedTakeoverReconcilerTest {
touch(region);
List<String> problems = List.of("Iris could not read /srv/config/irisworldgen/modded.json: Unterminated object");
IOException refused = assertThrows(IOException.class, () -> ModdedTakeoverReconciler.reconcile(
IOException refused = assertThrows(IOException.class, () -> reconcile(
worldRoot, Map.of(), problems, recoveryParent));
assertTrue(refused.getMessage(), refused.getMessage().contains("modded.json"));
@@ -164,7 +164,7 @@ public class ModdedTakeoverReconcilerTest {
try {
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of());
assertThrows(IOException.class, () -> ModdedTakeoverReconciler.reconcile(
assertThrows(IOException.class, () -> reconcile(
worldRoot, Map.of(), List.of("invalid takeover entry"), temporary.resolve("config")));
} finally {
deleteTree(temporary);
@@ -178,10 +178,10 @@ public class ModdedTakeoverReconcilerTest {
try {
Files.createDirectories(worldRoot);
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result result = reconcile(
worldRoot, Map.of(), List.of("invalid takeover entry"), temporary.resolve("config"));
assertEquals(Set.of(), result.changedLevels());
assertEquals(Set.of(), result.quarantinedLevels());
} finally {
deleteTree(temporary);
}
@@ -196,10 +196,10 @@ public class ModdedTakeoverReconcilerTest {
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("iristest:skylands", "overworld"));
touch(region);
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result result = reconcile(
worldRoot, Map.of("iristest:skylands", "skypack"), List.of(), temporary.resolve("config"));
assertEquals(Set.of("iristest:skylands"), result.changedLevels());
assertEquals(Set.of("iristest:skylands"), result.quarantinedLevels());
assertFalse(Files.exists(region));
assertEquals(Map.of("iristest:skylands", "overworld"), ModdedTakeoverReconciler.readApplied(worldRoot));
} finally {
@@ -216,7 +216,7 @@ public class ModdedTakeoverReconcilerTest {
createHistory(temporary, skylands, ModdedWorldgenIds.dimensionTypeRef("skypack", "sky"), "sky", List.of());
touch(skylands.resolve("region/r.0.0.mca"));
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result result = reconcile(
worldRoot, Map.of("iristest:skylands", "skypack:sky"), List.of(), temporary.resolve("config"));
assertEquals(Set.of("iristest:skylands"), result.adoptedLevels());
@@ -237,7 +237,7 @@ public class ModdedTakeoverReconcilerTest {
createHistory(temporary, skylands, ModdedWorldgenIds.dimensionTypeRef("otherpack", "sky"), "sky", List.of());
touch(skylands.resolve("region/r.0.0.mca"));
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result result = reconcile(
worldRoot, Map.of("iristest:skylands", "skypack:sky"), List.of(), temporary.resolve("config"));
assertEquals(Set.of(), result.adoptedLevels());
@@ -259,7 +259,7 @@ public class ModdedTakeoverReconcilerTest {
List.of(ModdedWorldgenIds.biomeRef("skypack", "sky", "meadow")));
touch(aether.resolve("region/r.0.0.mca"));
ModdedTakeoverReconciler.Result other = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result other = reconcile(
worldRoot, Map.of("aether:the_aether", "otherpack:sky"), List.of(), temporary.resolve("config"));
assertEquals(Set.of(), other.adoptedLevels());
@@ -267,7 +267,7 @@ public class ModdedTakeoverReconcilerTest {
createHistory(temporary, aether, "aether:the_aether", "sky",
List.of(ModdedWorldgenIds.biomeRef("skypack", "sky", "meadow")));
ModdedTakeoverReconciler.Result matching = ModdedTakeoverReconciler.reconcile(
ModdedTakeoverReconciler.Result matching = reconcile(
worldRoot, Map.of("aether:the_aether", "skypack:sky"), List.of(), temporary.resolve("config"));
assertEquals(Set.of("aether:the_aether"), matching.adoptedLevels());
@@ -310,6 +310,53 @@ public class ModdedTakeoverReconcilerTest {
}
}
@Test
public void switchingAnAppliedLevelToAnUninstalledPackRefusesBeforeMovingAnything() throws IOException {
Path temporary = Files.createTempDirectory("iris-takeover-uninstalled-applied");
Path worldRoot = temporary.resolve("world");
try {
Path region = worldRoot.resolve("dimensions/iristest/skylands/region/r.0.0.mca");
ModdedTakeoverReconciler.writeApplied(worldRoot, Map.of("iristest:skylands", "overworld"));
touch(region);
IOException refused = assertThrows(IOException.class, () -> ModdedTakeoverReconciler.reconcile(
new ModdedTakeoverReconciler.Request(worldRoot, Map.of("iristest:skylands", "missing"), List.of(),
(ModdedDimensionTakeover takeover) -> false, temporary.resolve("config"))));
assertTrue(refused.getMessage(), refused.getMessage().contains("missing"));
assertTrue(Files.isRegularFile(region));
assertEquals(Map.of("iristest:skylands", "overworld"), ModdedTakeoverReconciler.readApplied(worldRoot));
} finally {
deleteTree(temporary);
}
}
@Test
public void newTakeoverOfAnUninstalledPackLeavesTheLevelAlone() throws IOException {
Path temporary = Files.createTempDirectory("iris-takeover-uninstalled-new");
Path worldRoot = temporary.resolve("world");
try {
Path region = worldRoot.resolve("dimensions/aether/the_aether/region/r.0.0.mca");
touch(region);
ModdedTakeoverReconciler.Result result = ModdedTakeoverReconciler.reconcile(
new ModdedTakeoverReconciler.Request(worldRoot, Map.of("aether:the_aether", "missing"), List.of(),
(ModdedDimensionTakeover takeover) -> false, temporary.resolve("config")));
assertEquals(Set.of(), result.quarantinedLevels());
assertTrue(Files.isRegularFile(region));
assertEquals(Map.of(), ModdedTakeoverReconciler.readApplied(worldRoot));
} finally {
deleteTree(temporary);
}
}
private static ModdedTakeoverReconciler.Result reconcile(Path worldRoot, Map<String, String> configured,
List<String> problems, Path recoveryParent) throws IOException {
return ModdedTakeoverReconciler.reconcile(new ModdedTakeoverReconciler.Request(
worldRoot, configured, problems, (ModdedDimensionTakeover takeover) -> true, recoveryParent));
}
private static void createHistory(Path temporary, Path dimensionRoot, String dimensionTypeKey, String dimensionKey,
List<String> biomeKeys) throws IOException {
Path source = Files.createTempDirectory(temporary, "pack");