package online.astradev.cauldron.mixing; import static org.junit.jupiter.api.Assertions.*; import com.google.gson.JsonParser; import java.nio.file.Files; import java.nio.file.Path; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; class MixingRuntimeTest { @TempDir Path directory; @Test void existingConfigurationAddsEngineDefaultsInMemoryWithoutWritingOrMergingAuthoredMaps() throws Exception { var file = directory.resolve("native.json"); String nativeJson = "{\"ingredientColors\":{\"carrot\":\"#010203\"},\"extension\":true,\"engine\":{\"orbitRadius\":0.1}}"; Files.writeString(file, nativeJson); var config = MixingFixtures.load(file); assertEquals(nativeJson, Files.readString(file)); assertEquals(.1, config.runtime().decimal("orbitRadius")); assertEquals(0x010203, config.ingredientColor("carrot")); assertEquals(MixingConfig.rgb(config.defaultColor), config.ingredientColor("apple")); assertEquals("astradev_soups:combined_soup", config.runtime().text("model")); } @Test void authoredGeometryAndLimitsDriveRuntimeInsteadOfSourceConstants() { var document = JsonParser.parseString(MixingFixtures.defaults()).getAsJsonObject(); var engine = document.getAsJsonObject("engine"); engine.addProperty("maxIngredientCount", 5); engine.addProperty("orbitAngles", "0,72,144,216,288"); engine.addProperty("orbitRadius", .1); engine.addProperty("bobHeight", 0); engine.addProperty("ingredientSubmersion", .1); engine.addProperty("waterBaseHeight", .2); engine.addProperty("waterStepHeight", .1); document.addProperty("ingredientCount", 5); var config = MixingFixtures.parse(document.toString()); var frame = MixingAnimation.frame(config.runtime(), 0, 3, 0, 0, 0); assertEquals(.6, frame.x(), .000001); assertEquals(.4, frame.y(), .000001); assertEquals(.5, frame.z(), .000001); engine.addProperty("maxIngredientCount", 6); assertThrows(IllegalArgumentException.class, () -> MixingFixtures.parse(document.toString())); } @Test void surfaceBoundsAreRejectedBeforeRuntimePublication() { assertThrows(IllegalArgumentException.class, () -> MixingFixtures.parse("{\"engine\":{\"waterBaseHeight\":0.9,\"waterStepHeight\":0.2}}")); assertThrows(IllegalArgumentException.class, () -> MixingFixtures.parse("{\"engine\":{\"liquidBaseHeight\":0.1}}")); } @Test void immutableCompatibilityKeepsOldWorldKeysAndRejectsTraversal() throws Exception { String json; try (var stream = getClass().getResourceAsStream("/editor/combination-compatibility.json")) { json = new String(stream.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8); } var raw = JsonParser.parseString(json).getAsJsonObject(); var profile = MixingProfile.parse(raw); assertEquals("astracauldron/cauldrons.json", profile.soupPath()); assertEquals("astracauldron:combined_soup", profile.markerTag()); raw.addProperty("soupPath", "../outside.json"); assertThrows(IllegalArgumentException.class, () -> MixingProfile.parse(raw)); } }