mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-03 03:31:32 +00:00
Validate studio packs after hotload by default
- Add studio.validateBeforeHotload, off by default - Run the full pack validator in the background once an update is active and report blocking errors through the studio hotload broadcast - Keep rejecting invalid packs before activation when the setting is on
This commit is contained in:
1 parent
3aa302e56c
commit
48db178008
10 files changed
+231
-15
No files matched your search
@@ -401,6 +401,7 @@ public class IrisSettings {
|
|||||||
public static class IrisSettingsStudio {
|
public static class IrisSettingsStudio {
|
||||||
public boolean openVSCode = true;
|
public boolean openVSCode = true;
|
||||||
public boolean blendChanges = true;
|
public boolean blendChanges = true;
|
||||||
|
public boolean validateBeforeHotload = false;
|
||||||
public boolean disableTimeAndWeather = true;
|
public boolean disableTimeAndWeather = true;
|
||||||
public boolean entitySpawning = true;
|
public boolean entitySpawning = true;
|
||||||
public boolean autoStartDefaultStudio = false;
|
public boolean autoStartDefaultStudio = false;
|
||||||
|
|||||||
@@ -236,7 +236,8 @@ final class EngineHotloader {
|
|||||||
long startedAt = System.nanoTime();
|
long startedAt = System.nanoTime();
|
||||||
engine.requireRunning("hotload the Studio pack");
|
engine.requireRunning("hotload the Studio pack");
|
||||||
GenerationHistory history = router.history();
|
GenerationHistory history = router.history();
|
||||||
update = StudioGenerationUpdate.prepare(engine, history, activatedStudioSource);
|
StudioPackValidation validation = StudioPackValidation.configured();
|
||||||
|
update = StudioGenerationUpdate.prepare(engine, history, activatedStudioSource, validation);
|
||||||
if (update == null) {
|
if (update == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -292,6 +293,9 @@ final class EngineHotloader {
|
|||||||
publishRestartRequirement(requirement);
|
publishRestartRequirement(requirement);
|
||||||
broadcastStudioHotload(false, restartNote(requirement));
|
broadcastStudioHotload(false, restartNote(requirement));
|
||||||
activatedStudioSource = update.activatedAs(activated.epochId());
|
activatedStudioSource = update.activatedAs(activated.epochId());
|
||||||
|
if (validation == StudioPackValidation.AFTER_ACTIVATION) {
|
||||||
|
auditActivatedPack(history, activated);
|
||||||
|
}
|
||||||
} catch (RegistryRestartRequiredException restart) {
|
} catch (RegistryRestartRequiredException restart) {
|
||||||
StudioRestartRequirement requirement = StudioRestartRequirement.blockedBy(restart);
|
StudioRestartRequirement requirement = StudioRestartRequirement.blockedBy(restart);
|
||||||
publishRestartRequirement(requirement);
|
publishRestartRequirement(requirement);
|
||||||
@@ -346,6 +350,18 @@ final class EngineHotloader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Never throws: it runs after the activation is durable, where any failure would mark the engine failed.
|
||||||
|
*/
|
||||||
|
private void auditActivatedPack(GenerationHistory history, GenerationActivation activated) {
|
||||||
|
try {
|
||||||
|
new StudioPackAudit(engine, history, activated.epochId(), message -> broadcastStudioHotload(true, message))
|
||||||
|
.runInBackground();
|
||||||
|
} catch (Throwable auditFailure) {
|
||||||
|
IrisLogging.reportError("Failed to start the Studio pack validation.", auditFailure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void publishRestartRequirement(StudioRestartRequirement requirement) {
|
private void publishRestartRequirement(StudioRestartRequirement requirement) {
|
||||||
engine.studioRestartRequirement = requirement;
|
engine.studioRestartRequirement = requirement;
|
||||||
if (requirement.isPending()) {
|
if (requirement.isPending()) {
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ record StudioGenerationUpdate(
|
|||||||
* @return null when the source still matches the active epoch
|
* @return null when the source still matches the active epoch
|
||||||
*/
|
*/
|
||||||
static StudioGenerationUpdate prepare(IrisEngine engine, GenerationHistory history,
|
static StudioGenerationUpdate prepare(IrisEngine engine, GenerationHistory history,
|
||||||
ActivatedStudioSource previous) throws IOException {
|
ActivatedStudioSource previous, StudioPackValidation validation)
|
||||||
|
throws IOException {
|
||||||
Path source = engine.getStudioGenerationSource().toRealPath();
|
Path source = engine.getStudioGenerationSource().toRealPath();
|
||||||
IrisData.invalidateLoadedAuthoringResources(source.toFile());
|
IrisData.invalidateLoadedAuthoringResources(source.toFile());
|
||||||
PackTreeState sourceState = PackTreeState.capture(source);
|
PackTreeState sourceState = PackTreeState.capture(source);
|
||||||
@@ -52,7 +53,7 @@ record StudioGenerationUpdate(
|
|||||||
Path stagingRoot = Files.createTempDirectory(history.paths().generationRoot(), ".studio-");
|
Path stagingRoot = Files.createTempDirectory(history.paths().generationRoot(), ".studio-");
|
||||||
try {
|
try {
|
||||||
StudioGenerationUpdate update = prepareStaged(
|
StudioGenerationUpdate update = prepareStaged(
|
||||||
engine, history, source, sourceState, activeSourceState, stagingRoot);
|
engine, history, source, sourceState, activeSourceState, stagingRoot, validation);
|
||||||
if (update == null) {
|
if (update == null) {
|
||||||
AtomicDirectoryPublisher.deleteTree(stagingRoot);
|
AtomicDirectoryPublisher.deleteTree(stagingRoot);
|
||||||
}
|
}
|
||||||
@@ -69,7 +70,8 @@ record StudioGenerationUpdate(
|
|||||||
|
|
||||||
private static StudioGenerationUpdate prepareStaged(IrisEngine engine, GenerationHistory history, Path source,
|
private static StudioGenerationUpdate prepareStaged(IrisEngine engine, GenerationHistory history, Path source,
|
||||||
PackTreeState sourceState, PackTreeState activeSourceState,
|
PackTreeState sourceState, PackTreeState activeSourceState,
|
||||||
Path stagingRoot) throws IOException {
|
Path stagingRoot, StudioPackValidation validation)
|
||||||
|
throws IOException {
|
||||||
Path snapshot = stagingRoot.resolve(source.getFileName());
|
Path snapshot = stagingRoot.resolve(source.getFileName());
|
||||||
GenerationPackRepository.snapshotPackTree(
|
GenerationPackRepository.snapshotPackTree(
|
||||||
source, snapshot, history.activePackLinkBasis().orElse(null), activeSourceState);
|
source, snapshot, history.activePackLinkBasis().orElse(null), activeSourceState);
|
||||||
@@ -80,7 +82,7 @@ record StudioGenerationUpdate(
|
|||||||
if (!sourceState.equals(PackTreeState.capture(source))) {
|
if (!sourceState.equals(PackTreeState.capture(source))) {
|
||||||
throw new IOException("Studio pack changed while its update snapshot was being captured.");
|
throw new IOException("Studio pack changed while its update snapshot was being captured.");
|
||||||
}
|
}
|
||||||
return prepareSnapshot(engine, history, stagingRoot, pack, sourceState);
|
return prepareSnapshot(engine, history, stagingRoot, pack, sourceState, validation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isActive(GenerationEpoch active, VerifiedPackTree pack) {
|
private static boolean isActive(GenerationEpoch active, VerifiedPackTree pack) {
|
||||||
@@ -90,12 +92,15 @@ record StudioGenerationUpdate(
|
|||||||
|
|
||||||
private static StudioGenerationUpdate prepareSnapshot(IrisEngine engine, GenerationHistory history,
|
private static StudioGenerationUpdate prepareSnapshot(IrisEngine engine, GenerationHistory history,
|
||||||
Path stagingRoot, VerifiedPackTree pack,
|
Path stagingRoot, VerifiedPackTree pack,
|
||||||
PackTreeState sourceState) throws IOException {
|
PackTreeState sourceState,
|
||||||
|
StudioPackValidation validation) throws IOException {
|
||||||
GenerationEpoch active = history.activeEpoch();
|
GenerationEpoch active = history.activeEpoch();
|
||||||
IrisData data = IrisData.openRuntime(pack.root().toFile());
|
IrisData data = IrisData.openRuntime(pack.root().toFile());
|
||||||
try {
|
try {
|
||||||
data.useVerifiedGenerationPackFingerprint(pack.fingerprint());
|
data.useVerifiedGenerationPackFingerprint(pack.fingerprint());
|
||||||
requireLoadable(pack, data);
|
if (validation == StudioPackValidation.BEFORE_ACTIVATION) {
|
||||||
|
requireLoadable(pack, data);
|
||||||
|
}
|
||||||
IrisDimension replacement = data.getDimensionLoader().load(active.dimensionContract().dimensionKey());
|
IrisDimension replacement = data.getDimensionLoader().load(active.dimensionContract().dimensionKey());
|
||||||
if (replacement == null) {
|
if (replacement == null) {
|
||||||
throw new IOException("Studio pack update is missing dimension '"
|
throw new IOException("Studio pack update is missing dimension '"
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package art.arcane.iris.generation.runtime;
|
||||||
|
|
||||||
|
import art.arcane.iris.generation.concurrent.MultiBurst;
|
||||||
|
import art.arcane.iris.pack.PackValidationResult;
|
||||||
|
import art.arcane.iris.pack.PackValidator;
|
||||||
|
import art.arcane.iris.spi.IrisLogging;
|
||||||
|
import art.arcane.iris.world.history.GenerationHistory;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the full pack validator against an activated Studio epoch after the hotload, so authoring mistakes the
|
||||||
|
* activation gate does not cover are still reported without holding up the cutover.
|
||||||
|
*/
|
||||||
|
final class StudioPackAudit {
|
||||||
|
private static final int LOGGED_WARNING_LIMIT = 3;
|
||||||
|
|
||||||
|
private final IrisEngine engine;
|
||||||
|
private final GenerationHistory history;
|
||||||
|
private final String epochId;
|
||||||
|
private final Consumer<String> blockingErrorReport;
|
||||||
|
|
||||||
|
StudioPackAudit(IrisEngine engine, GenerationHistory history, String epochId, Consumer<String> blockingErrorReport) {
|
||||||
|
this.engine = engine;
|
||||||
|
this.history = history;
|
||||||
|
this.epochId = epochId;
|
||||||
|
this.blockingErrorReport = blockingErrorReport;
|
||||||
|
}
|
||||||
|
|
||||||
|
CompletableFuture<Void> runInBackground() {
|
||||||
|
return MultiBurst.burst.completeValueAsync(this::validate)
|
||||||
|
.thenAccept(this::report)
|
||||||
|
.exceptionally(failure -> {
|
||||||
|
if (!engine.isClosed()) {
|
||||||
|
IrisLogging.reportError("Studio pack validation failed for '" + packKey() + "'.", failure);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackValidationResult validate() {
|
||||||
|
Path pack = history.paths().packRoot(epochId);
|
||||||
|
return PackValidator.validate(pack.toFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
void report(PackValidationResult result) {
|
||||||
|
if (engine.isClosed() || !history.activeEpoch().epochId().equals(epochId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
reportWarnings(result.getWarnings());
|
||||||
|
if (result.isLoadable()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String errors = String.join("; ", result.getBlockingErrors());
|
||||||
|
IrisLogging.warn("Studio pack '%s' is active but has blocking validation errors: %s", packKey(), errors);
|
||||||
|
blockingErrorReport.accept("Pack validation: " + errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reportWarnings(List<String> warnings) {
|
||||||
|
if (warnings.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<String> shown = warnings.subList(0, Math.min(LOGGED_WARNING_LIMIT, warnings.size()));
|
||||||
|
IrisLogging.warn("Studio pack '%s' has %d validation warnings: %s", packKey(), warnings.size(), String.join("; ", shown));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String packKey() {
|
||||||
|
return engine.getPackSource().getFileName().toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package art.arcane.iris.generation.runtime;
|
||||||
|
|
||||||
|
import art.arcane.iris.configuration.IrisSettings;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When a Studio hotload runs the full pack validator. Before activation an invalid pack is rejected and the hotload
|
||||||
|
* waits for the validator; after activation the pack goes live first and blocking errors are only reported.
|
||||||
|
*/
|
||||||
|
enum StudioPackValidation {
|
||||||
|
BEFORE_ACTIVATION,
|
||||||
|
AFTER_ACTIVATION;
|
||||||
|
|
||||||
|
static StudioPackValidation configured() {
|
||||||
|
return IrisSettings.get().getStudio().isValidateBeforeHotload() ? BEFORE_ACTIVATION : AFTER_ACTIVATION;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -84,6 +84,16 @@ public class IrisSettingsDefaultsTest {
|
|||||||
assertEquals(256, changed.getGenerator().getGenerationTransitionWidthBlocks());
|
assertEquals(256, changed.getGenerator().getGenerationTransitionWidthBlocks());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void studioValidatesAfterHotloadUnlessConfigured() {
|
||||||
|
assertFalse(new IrisSettings().getStudio().isValidateBeforeHotload());
|
||||||
|
assertFalse(new Gson().fromJson("{\"studio\":{}}", IrisSettings.class).getStudio().isValidateBeforeHotload());
|
||||||
|
|
||||||
|
IrisSettings changed = IrisSettings.parseHotloadSnapshot("{\"studio\":{\"validateBeforeHotload\":true}}");
|
||||||
|
|
||||||
|
assertTrue(changed.getStudio().isValidateBeforeHotload());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void hotloadSnapshotIsValidatedBeforeReplacingLiveSettings() {
|
public void hotloadSnapshotIsValidatedBeforeReplacingLiveSettings() {
|
||||||
IrisSettings previous = IrisSettings.settings;
|
IrisSettings previous = IrisSettings.settings;
|
||||||
|
|||||||
+1
-1
@@ -138,7 +138,7 @@ public class EngineHotloaderRecoveryTest {
|
|||||||
try (MockedStatic<StudioGenerationUpdate> updates = mockStatic(StudioGenerationUpdate.class);
|
try (MockedStatic<StudioGenerationUpdate> updates = mockStatic(StudioGenerationUpdate.class);
|
||||||
MockedStatic<IrisBoundarySignatureSampler> signatures = mockStatic(IrisBoundarySignatureSampler.class);
|
MockedStatic<IrisBoundarySignatureSampler> signatures = mockStatic(IrisBoundarySignatureSampler.class);
|
||||||
MockedStatic<IrisSettings> configuration = mockStatic(IrisSettings.class)) {
|
MockedStatic<IrisSettings> configuration = mockStatic(IrisSettings.class)) {
|
||||||
updates.when(() -> StudioGenerationUpdate.prepare(engine, history, null)).thenReturn(update);
|
updates.when(() -> StudioGenerationUpdate.prepare(engine, history, null, StudioPackValidation.AFTER_ACTIVATION)).thenReturn(update);
|
||||||
configuration.when(IrisSettings::get).thenReturn(settings);
|
configuration.when(IrisSettings::get).thenReturn(settings);
|
||||||
|
|
||||||
IllegalStateException thrown = assertThrows(IllegalStateException.class,
|
IllegalStateException thrown = assertThrows(IllegalStateException.class,
|
||||||
|
|||||||
+1
-1
@@ -77,7 +77,7 @@ public class EngineHotloaderRetirementTest {
|
|||||||
MockedStatic<IrisStructureLocator> structures = mockStatic(IrisStructureLocator.class);
|
MockedStatic<IrisStructureLocator> structures = mockStatic(IrisStructureLocator.class);
|
||||||
MockedStatic<StructureReachability> reachability = mockStatic(StructureReachability.class);
|
MockedStatic<StructureReachability> reachability = mockStatic(StructureReachability.class);
|
||||||
MockedStatic<IrisSettings> configuration = mockStatic(IrisSettings.class)) {
|
MockedStatic<IrisSettings> configuration = mockStatic(IrisSettings.class)) {
|
||||||
updates.when(() -> StudioGenerationUpdate.prepare(engine, history, null)).thenReturn(update);
|
updates.when(() -> StudioGenerationUpdate.prepare(engine, history, null, StudioPackValidation.AFTER_ACTIVATION)).thenReturn(update);
|
||||||
configuration.when(IrisSettings::get).thenReturn(settings);
|
configuration.when(IrisSettings::get).thenReturn(settings);
|
||||||
|
|
||||||
new EngineHotloader(engine).hotloadSilently();
|
new EngineHotloader(engine).hotloadSilently();
|
||||||
|
|||||||
+30
-6
@@ -16,6 +16,7 @@ import java.util.List;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.Assert.assertThrows;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -64,7 +65,7 @@ public final class StudioGenerationUpdateTest {
|
|||||||
when(active.epochId()).thenReturn("a".repeat(64));
|
when(active.epochId()).thenReturn("a".repeat(64));
|
||||||
ActivatedStudioSource recorded = new ActivatedStudioSource("a".repeat(64), PackTreeState.capture(source));
|
ActivatedStudioSource recorded = new ActivatedStudioSource("a".repeat(64), PackTreeState.capture(source));
|
||||||
|
|
||||||
assertNull(StudioGenerationUpdate.prepare(engine, history, recorded));
|
assertNull(StudioGenerationUpdate.prepare(engine, history, recorded, StudioPackValidation.BEFORE_ACTIVATION));
|
||||||
|
|
||||||
verify(history).activeEpoch();
|
verify(history).activeEpoch();
|
||||||
verifyNoMoreInteractions(history);
|
verifyNoMoreInteractions(history);
|
||||||
@@ -96,7 +97,7 @@ public final class StudioGenerationUpdateTest {
|
|||||||
when(active.packFingerprintVersion()).thenReturn(GenerationPackFingerprint.CURRENT_VERSION);
|
when(active.packFingerprintVersion()).thenReturn(GenerationPackFingerprint.CURRENT_VERSION);
|
||||||
when(active.packFingerprint()).thenReturn(fingerprint);
|
when(active.packFingerprint()).thenReturn(fingerprint);
|
||||||
|
|
||||||
assertNull(StudioGenerationUpdate.prepare(engine, history, null));
|
assertNull(StudioGenerationUpdate.prepare(engine, history, null, StudioPackValidation.BEFORE_ACTIVATION));
|
||||||
|
|
||||||
assertEquals("unchanged manifest", Files.readString(paths.manifest()));
|
assertEquals("unchanged manifest", Files.readString(paths.manifest()));
|
||||||
try (Stream<Path> entries = Files.list(paths.generationRoot())) {
|
try (Stream<Path> entries = Files.list(paths.generationRoot())) {
|
||||||
@@ -127,7 +128,7 @@ public final class StudioGenerationUpdateTest {
|
|||||||
when(active.packFingerprintVersion()).thenReturn(GenerationPackFingerprint.CURRENT_VERSION);
|
when(active.packFingerprintVersion()).thenReturn(GenerationPackFingerprint.CURRENT_VERSION);
|
||||||
when(active.packFingerprint()).thenReturn("0".repeat(64));
|
when(active.packFingerprint()).thenReturn("0".repeat(64));
|
||||||
|
|
||||||
IOException failure = assertThrows(IOException.class, () -> StudioGenerationUpdate.prepare(engine, history, null));
|
IOException failure = assertThrows(IOException.class, () -> StudioGenerationUpdate.prepare(engine, history, null, StudioPackValidation.BEFORE_ACTIVATION));
|
||||||
|
|
||||||
assertTrue(failure.getMessage(), failure.getMessage().contains(
|
assertTrue(failure.getMessage(), failure.getMessage().contains(
|
||||||
"Studio pack update is invalid: Dimension 'test' declares no regions."));
|
"Studio pack update is invalid: Dimension 'test' declares no regions."));
|
||||||
@@ -154,13 +155,36 @@ public final class StudioGenerationUpdateTest {
|
|||||||
when(engine.getStudioGenerationSource()).thenReturn(alias);
|
when(engine.getStudioGenerationSource()).thenReturn(alias);
|
||||||
GenerationHistory history = mock(GenerationHistory.class);
|
GenerationHistory history = mock(GenerationHistory.class);
|
||||||
|
|
||||||
IOException failure = assertThrows(IOException.class, () -> StudioGenerationUpdate.prepare(engine, history, null));
|
IOException failure = assertThrows(IOException.class, () -> StudioGenerationUpdate.prepare(engine, history, null, StudioPackValidation.BEFORE_ACTIVATION));
|
||||||
|
|
||||||
assertTrue(failure.getMessage(), failure.getMessage().contains("Pack contains a symbolic link"));
|
assertTrue(failure.getMessage(), failure.getMessage().contains("Pack contains a symbolic link"));
|
||||||
verifyNoInteractions(history);
|
verifyNoInteractions(history);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void validationAfterActivationDoesNotRejectAnInvalidPackInPrepare() throws Exception {
|
||||||
|
Path source = temporary.newFolder("unvalidated-pack").toPath();
|
||||||
|
Files.createDirectories(source.resolve("dimensions"));
|
||||||
|
Files.writeString(source.resolve("dimensions/test.json"), "{}");
|
||||||
|
GenerationHistoryPaths paths = GenerationHistoryPaths.forDimension(temporary.newFolder("unvalidated-world").toPath());
|
||||||
|
Files.createDirectories(paths.generationRoot());
|
||||||
|
IrisEngine engine = mock(IrisEngine.class);
|
||||||
|
GenerationHistory history = mock(GenerationHistory.class);
|
||||||
|
GenerationEpoch active = mock(GenerationEpoch.class);
|
||||||
|
when(engine.getStudioGenerationSource()).thenReturn(source);
|
||||||
|
when(history.activeEpoch()).thenReturn(active);
|
||||||
|
when(history.paths()).thenReturn(paths);
|
||||||
|
when(active.packFingerprintVersion()).thenReturn(GenerationPackFingerprint.CURRENT_VERSION);
|
||||||
|
when(active.packFingerprint()).thenReturn("0".repeat(64));
|
||||||
|
|
||||||
|
Throwable failure = assertThrows(Throwable.class, () -> StudioGenerationUpdate.prepare(
|
||||||
|
engine, history, null, StudioPackValidation.AFTER_ACTIVATION));
|
||||||
|
|
||||||
|
assertFalse(String.valueOf(failure.getMessage()),
|
||||||
|
String.valueOf(failure.getMessage()).contains("Studio pack update is invalid"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidPackLeavesManifestUntouchedAndRemovesItsTemporarySnapshot() throws Exception {
|
public void invalidPackLeavesManifestUntouchedAndRemovesItsTemporarySnapshot() throws Exception {
|
||||||
Path source = temporary.newFolder("invalid-pack").toPath();
|
Path source = temporary.newFolder("invalid-pack").toPath();
|
||||||
@@ -178,7 +202,7 @@ public final class StudioGenerationUpdateTest {
|
|||||||
when(active.packFingerprintVersion()).thenReturn(GenerationPackFingerprint.CURRENT_VERSION);
|
when(active.packFingerprintVersion()).thenReturn(GenerationPackFingerprint.CURRENT_VERSION);
|
||||||
when(active.packFingerprint()).thenReturn("0".repeat(64));
|
when(active.packFingerprint()).thenReturn("0".repeat(64));
|
||||||
|
|
||||||
IOException failure = assertThrows(IOException.class, () -> StudioGenerationUpdate.prepare(engine, history, null));
|
IOException failure = assertThrows(IOException.class, () -> StudioGenerationUpdate.prepare(engine, history, null, StudioPackValidation.BEFORE_ACTIVATION));
|
||||||
|
|
||||||
assertTrue(failure.getMessage(), failure.getMessage().contains("Missing dimensions/ folder"));
|
assertTrue(failure.getMessage(), failure.getMessage().contains("Missing dimensions/ folder"));
|
||||||
assertEquals("unchanged manifest", Files.readString(paths.manifest()));
|
assertEquals("unchanged manifest", Files.readString(paths.manifest()));
|
||||||
@@ -212,7 +236,7 @@ public final class StudioGenerationUpdateTest {
|
|||||||
when(active.packFingerprintVersion()).thenReturn(GenerationPackFingerprint.CURRENT_VERSION);
|
when(active.packFingerprintVersion()).thenReturn(GenerationPackFingerprint.CURRENT_VERSION);
|
||||||
when(active.packFingerprint()).thenReturn("0".repeat(64));
|
when(active.packFingerprint()).thenReturn("0".repeat(64));
|
||||||
|
|
||||||
IOException failure = assertThrows(IOException.class, () -> StudioGenerationUpdate.prepare(engine, history, null));
|
IOException failure = assertThrows(IOException.class, () -> StudioGenerationUpdate.prepare(engine, history, null, StudioPackValidation.BEFORE_ACTIVATION));
|
||||||
|
|
||||||
assertTrue(failure.getMessage(), failure.getMessage().contains(
|
assertTrue(failure.getMessage(), failure.getMessage().contains(
|
||||||
"Dimension 'test' structures[0].anchor must be omitted, null, or LEGACY for nativeStructures."));
|
"Dimension 'test' structures[0].anchor must be omitted, null, or LEGACY for nativeStructures."));
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package art.arcane.iris.generation.runtime;
|
||||||
|
|
||||||
|
import art.arcane.iris.pack.PackValidationResult;
|
||||||
|
import art.arcane.iris.pack.PackValidator;
|
||||||
|
import art.arcane.iris.world.history.GenerationEpoch;
|
||||||
|
import art.arcane.iris.world.history.GenerationHistory;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
public final class StudioPackAuditTest {
|
||||||
|
private static final String ACTIVE_EPOCH = "a".repeat(64);
|
||||||
|
private static final String SUPERSEDED_EPOCH = "b".repeat(64);
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final TemporaryFolder temporary = new TemporaryFolder();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void blockingErrorsOfTheActiveEpochAreReported() throws Exception {
|
||||||
|
List<String> reports = new ArrayList<>();
|
||||||
|
|
||||||
|
audit(ACTIVE_EPOCH, false, reports).report(invalidAnchorValidation());
|
||||||
|
|
||||||
|
assertEquals(1, reports.size());
|
||||||
|
assertTrue(reports.getFirst(), reports.getFirst().startsWith("Pack validation: "));
|
||||||
|
assertTrue(reports.getFirst(), reports.getFirst().contains(
|
||||||
|
"Dimension 'test' structures[0].anchor must be omitted, null, or LEGACY for nativeStructures."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void supersededEpochsAndClosedEnginesStayQuiet() throws Exception {
|
||||||
|
List<String> reports = new ArrayList<>();
|
||||||
|
PackValidationResult invalid = invalidAnchorValidation();
|
||||||
|
|
||||||
|
audit(SUPERSEDED_EPOCH, false, reports).report(invalid);
|
||||||
|
audit(ACTIVE_EPOCH, true, reports).report(invalid);
|
||||||
|
|
||||||
|
assertTrue(reports.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
private StudioPackAudit audit(String epochId, boolean engineClosed, List<String> reports) {
|
||||||
|
IrisEngine engine = mock(IrisEngine.class);
|
||||||
|
when(engine.isClosed()).thenReturn(engineClosed);
|
||||||
|
when(engine.getPackSource()).thenReturn(temporary.getRoot().toPath().resolve("test-pack"));
|
||||||
|
GenerationHistory history = mock(GenerationHistory.class);
|
||||||
|
GenerationEpoch active = mock(GenerationEpoch.class);
|
||||||
|
when(history.activeEpoch()).thenReturn(active);
|
||||||
|
when(active.epochId()).thenReturn(ACTIVE_EPOCH);
|
||||||
|
return new StudioPackAudit(engine, history, epochId, reports::add);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PackValidationResult invalidAnchorValidation() throws Exception {
|
||||||
|
Path pack = temporary.newFolder().toPath();
|
||||||
|
Files.createDirectories(pack.resolve("dimensions"));
|
||||||
|
Files.writeString(pack.resolve("dimensions/test.json"), """
|
||||||
|
{"structures":[{"placementId":"village","anchor":"SURFACE",
|
||||||
|
"nativeStructures":[{"structure":"minecraft:village_plains"}]}]}
|
||||||
|
""");
|
||||||
|
return PackValidator.validate(pack.toFile());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user