feat(ignis): establish durable progression foundations
CI / build (push) Successful in 3m10s
Release / release (push) Failing after 3m50s

This commit is contained in:
dmg committed 2026-09-10 20:15:11 -04:00
commit 7a481f366c
27 files changed
+1213

No files matched your search

@@ -0,0 +1,80 @@
package games.dmg.spigotignis;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
class FileStateRepositoryTest {
@TempDir Path directory;
@Test
void missingStateStartsEmptyAndInterruptedTemporaryFilesAreNeverPromoted() throws Exception {
java.nio.file.Files.writeString(directory.resolve(".ignis-interrupted.tmp"), "incomplete");
assertEquals(IgnisState.empty(), new FileStateRepository(directory.resolve("state.bin")).load());
}
@Test
void malformedTruncatedFutureVersionAndTrailingDataAreRejectedWithoutRewriting() throws Exception {
Path path = directory.resolve("state.bin");
var repository = new FileStateRepository(path);
repository.save(IgnisState.empty());
byte[] valid = java.nio.file.Files.readAllBytes(path);
byte[] future = valid.clone();
future[7] = 2;
byte[] negativeCount = valid.clone();
java.util.Arrays.fill(negativeCount, 32, 36, (byte) 0xff);
for (byte[] invalid : java.util.List.of(new byte[0], java.util.Arrays.copyOf(valid, 12),
future, negativeCount, java.util.Arrays.copyOf(valid, valid.length + 1))) {
java.nio.file.Files.write(path, invalid);
assertThrows(java.io.IOException.class, repository::load);
assertArrayEquals(invalid, java.nio.file.Files.readAllBytes(path));
}
}
@Test
void malformedBooleanCannotSilentlyGrantAnUnlock() throws Exception {
Path path = directory.resolve("state.bin");
var repository = new FileStateRepository(path);
repository.save(new IgnisState(ProgressLimits.defaults(), Map.of(UUID.randomUUID(),
new PlayerState(Map.of(Track.MASK, TrackState.empty()), Map.of()))));
byte[] bytes = java.nio.file.Files.readAllBytes(path);
// Locate the schema's MASK tag, then corrupt the unlocked flag after the 8-byte counter.
byte[] marker = "MASK".getBytes(java.nio.charset.StandardCharsets.UTF_8);
int position = -1;
for (int i = 0; i <= bytes.length - marker.length; i++) {
if (java.util.Arrays.equals(marker, java.util.Arrays.copyOfRange(bytes, i, i + marker.length))) {
position = i + marker.length + Long.BYTES;
break;
}
}
assertTrue(position > 0);
bytes[position] = 2;
java.nio.file.Files.write(path, bytes);
assertThrows(java.io.IOException.class, repository::load);
}
@Test
void invalidDestinationFailsWithoutLeavingTemporaryFiles() throws Exception {
Path destination = directory.resolve("state.bin");
java.nio.file.Files.createDirectory(destination);
java.nio.file.Files.writeString(destination.resolve("preserve"), "unchanged");
assertThrows(java.io.IOException.class, () -> new FileStateRepository(destination).save(IgnisState.empty()));
assertEquals("unchanged", java.nio.file.Files.readString(destination.resolve("preserve")));
try (var files = java.nio.file.Files.list(directory)) { assertEquals(1, files.count()); }
}
@Test
void progressActivationPendingRewardsAndInvalidationSurviveRepositoryReopen() throws Exception {
var path = directory.resolve("ignis/state.bin");
var expected = new IgnisState(new ProgressLimits(120, 313, 60), Map.of(UUID.randomUUID(),
new PlayerState(Map.of(
Track.VOID, new TrackState(1, true, true, 8),
Track.MASK, new TrackState(119, false, false, 3)),
Map.of(UUID.randomUUID(), Track.HEART))));
new FileStateRepository(path).save(expected);
assertEquals(expected, new FileStateRepository(path).load());
}
}
@@ -0,0 +1,21 @@
package games.dmg.spigotignis;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
class PluginPackagingTest {
@Test
void packagedDescriptorHasExpandedVersionAndCorrectEntrypoint() throws Exception {
try (var input = getClass().getResourceAsStream("/plugin.yml")) {
assertNotNull(input, "A deployable plugin requires a descriptor");
String descriptor = new String(input.readAllBytes(), StandardCharsets.UTF_8);
assertTrue(descriptor.contains("name: SpigotIgnis"));
assertTrue(descriptor.contains("main: games.dmg.spigotignis.SpigotIgnisPlugin"));
assertFalse(descriptor.contains("${version}"));
assertTrue(org.bukkit.plugin.java.JavaPlugin.class.isAssignableFrom(
Class.forName("games.dmg.spigotignis.SpigotIgnisPlugin", false, getClass().getClassLoader())));
assertFalse(descriptor.contains("commands:"), "Do not advertise unimplemented commands");
}
}
}
@@ -0,0 +1,21 @@
package games.dmg.spigotignis;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.time.Duration;
import org.junit.jupiter.api.Test;
class ProgressLimitsTest {
@Test
void rejectsNonPositiveThresholdsBeforeTheyCanBecomeActive() {
assertThrows(IllegalArgumentException.class, () -> new ProgressLimits(0, 313, 1));
assertThrows(IllegalArgumentException.class, () -> new ProgressLimits(1, -1, 1));
assertThrows(IllegalArgumentException.class, () -> new ProgressLimits(1, 1, 0));
}
@Test
void defaultsUseApprovedTwelveHour313PearlAndSixHourThresholds() {
assertEquals(new ProgressLimits(Duration.ofHours(12).toMillis(), 313,
Duration.ofHours(6).toMillis()), ProgressLimits.defaults());
}
}
@@ -0,0 +1,23 @@
package games.dmg.spigotignis;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
/** Static guardrails, not proof of remote CI or credential validity. */
class ReleaseWorkflowTest {
@Test
void releaseScaffoldUsesVersionedAssetsAndProtectedCredentialInput() throws Exception {
Path path = Path.of(".gitea/workflows/release.yml");
assertTrue(Files.exists(path), "Release workflow must exist");
String workflow = Files.readString(path);
assertTrue(workflow.contains("spigot-ignis-${VERSION}.jar"));
assertTrue(workflow.contains("--header @-"));
assertTrue(workflow.contains("GIT_ASKPASS"));
assertTrue(workflow.contains("persist-credentials: false"));
assertFalse(workflow.contains("-H \"Authorization:"));
assertFalse(workflow.contains("GITHUB_TOKEN:"), "Do not pass a token for semantic-release to embed into git URLs");
assertFalse(workflow.contains("spigot-base"));
}
}
@@ -0,0 +1,101 @@
package games.dmg.spigotignis;
import static org.junit.jupiter.api.Assertions.*;
import java.nio.file.Path;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
class StateServiceTest {
@TempDir Path directory;
@Test
void failedWriteLeavesPreviousSnapshotAndAllowsRetryOffCallingThread() throws Exception {
var disk = new FileStateRepository(directory.resolve("state.bin"));
var fail = new java.util.concurrent.atomic.AtomicBoolean(true);
Thread caller = Thread.currentThread();
StateRepository boundary = new StateRepository() {
@Override public IgnisState load() throws java.io.IOException {
assertNotSame(caller, Thread.currentThread());
return disk.load();
}
@Override public void save(IgnisState state) throws java.io.IOException {
assertNotSame(caller, Thread.currentThread());
if (fail.get()) throw new java.io.IOException("Simulated disk failure");
disk.save(state);
}
};
try (var service = StateService.open(boundary).get(3, TimeUnit.SECONDS)) {
assertThrows(java.util.concurrent.ExecutionException.class,
() -> service.configure(100, 200, 300).get(3, TimeUnit.SECONDS));
assertEquals(IgnisState.empty(), service.snapshot());
assertEquals(IgnisState.empty(), disk.load());
fail.set(false);
service.configure(100, 200, 300).get(3, TimeUnit.SECONDS);
assertEquals(service.snapshot(), disk.load());
}
}
@Test
void concurrentQueuedUpdatesDoNotLoseProgressAndCloseRejectsNewWrites() throws Exception {
UUID id = UUID.randomUUID();
var repository = new FileStateRepository(directory.resolve("state.bin"));
var service = StateService.open(repository).get(3, TimeUnit.SECONDS);
try (service) {
var writes = new java.util.ArrayList<java.util.concurrent.CompletableFuture<IgnisState>>();
for (int i = 0; i < 30; i++) {
writes.add(service.update(state -> {
var player = state.players().getOrDefault(id, PlayerState.empty());
long count = player.track(Track.DAGGER).progress();
return new IgnisState(state.limits(), Map.of(id, new PlayerState(
Map.of(Track.DAGGER, new TrackState(count + 1, false, false, 0)), Map.of())));
}));
}
java.util.concurrent.CompletableFuture.allOf(writes.toArray(java.util.concurrent.CompletableFuture[]::new))
.get(5, TimeUnit.SECONDS);
assertEquals(30, repository.load().players().get(id).track(Track.DAGGER).progress());
}
assertThrows(java.util.concurrent.ExecutionException.class,
() -> service.configure(1, 1, 1).get(3, TimeUnit.SECONDS));
}
@Test
void malformedExistingStateFailsInitializationInsteadOfGrantingBlankState() throws Exception {
Path path = directory.resolve("state.bin");
java.nio.file.Files.writeString(path, "broken");
assertThrows(java.util.concurrent.ExecutionException.class,
() -> StateService.open(new FileStateRepository(path)).get(3, TimeUnit.SECONDS));
assertEquals("broken", java.nio.file.Files.readString(path));
}
@Test
void configurationValidatesBeforeChangingAnyDurableOrActiveSetting() throws Exception {
var repository = new FileStateRepository(directory.resolve("state.bin"));
try (var service = StateService.open(repository).get(3, TimeUnit.SECONDS)) {
assertThrows(java.util.concurrent.ExecutionException.class,
() -> service.configure(100, 0, 100).get(3, TimeUnit.SECONDS));
assertEquals(ProgressLimits.defaults(), service.snapshot().limits());
var limits = new ProgressLimits(100, 200, 300);
service.configure(100, 200, 300).get(3, TimeUnit.SECONDS);
assertEquals(limits, service.snapshot().limits());
assertEquals(limits, repository.load().limits());
}
}
@Test
void acknowledgedUpdatesAreDurableAcrossReopen() throws Exception {
var repository = new FileStateRepository(directory.resolve("state.bin"));
UUID id = UUID.randomUUID();
var expected = new IgnisState(ProgressLimits.defaults(), Map.of(id,
new PlayerState(Map.of(Track.DAGGER, new TrackState(12, false, false, 0)), Map.of())));
try (var service = StateService.open(repository).get(3, TimeUnit.SECONDS)) {
assertEquals(expected, service.update(ignored -> expected).get(3, TimeUnit.SECONDS));
assertEquals(expected, service.snapshot());
}
try (var reopened = StateService.open(repository).get(3, TimeUnit.SECONDS)) {
assertEquals(expected, reopened.snapshot());
}
}
}
@@ -0,0 +1,51 @@
package games.dmg.spigotignis;
import static org.junit.jupiter.api.Assertions.*;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
class ThresholdEvaluationTest {
@Test
void evaluationIsIdempotentAndHigherLimitsDoNotRevokeEarnedUnlocks() {
UUID id = UUID.randomUUID();
var state = new IgnisState(new ProgressLimits(1, 1, 1), Map.of(id,
new PlayerState(Map.of(
Track.MASK, new TrackState(1, true, true, 5),
Track.DAGGER, new TrackState(312, false, false, 0),
Track.HEART, new TrackState(100, false, false, 0),
Track.VOID, new TrackState(100, false, false, 0)), Map.of())));
var next = state.evaluate(new ProgressLimits(200, 313, 100));
assertTrue(next.players().get(id).track(Track.MASK).activated());
assertFalse(next.players().get(id).track(Track.DAGGER).unlocked());
assertTrue(next.players().get(id).track(Track.HEART).unlocked());
assertFalse(next.players().get(id).track(Track.VOID).unlocked());
assertEquals(next, next.evaluate(next.limits()));
}
@Test
void negativeStateAndMutableCallerCollectionsCannotCorruptSnapshots() {
assertThrows(IllegalArgumentException.class, () -> new TrackState(-1, false, false, 0));
assertThrows(IllegalArgumentException.class, () -> new TrackState(0, false, true, 0));
assertThrows(IllegalArgumentException.class, () -> new TrackState(0, false, false, -1));
var tracks = new java.util.HashMap<Track, TrackState>();
tracks.put(Track.MASK, TrackState.empty());
var player = new PlayerState(tracks, Map.of());
tracks.clear();
assertEquals(1, player.tracks().size());
assertThrows(UnsupportedOperationException.class, () -> player.tracks().clear());
}
@Test
void loweredThresholdUnlocksOnEvaluationWithoutChangingProgressOrRewards() {
UUID player = UUID.randomUUID();
UUID reward = UUID.randomUUID();
var before = new IgnisState(ProgressLimits.defaults(), Map.of(player,
new PlayerState(Map.of(Track.MASK, new TrackState(100, false, false, 2)),
Map.of(reward, Track.VOID))));
var after = before.evaluate(new ProgressLimits(100, 313, 1000));
assertEquals(new TrackState(100, true, false, 2), after.players().get(player).track(Track.MASK));
assertEquals(before.players().get(player).pendingRewards(), after.players().get(player).pendingRewards());
assertFalse(before.players().get(player).track(Track.MASK).unlocked());
}
}