From f8a1f83f4fd65f38e7d390237045dc629ab3b794 Mon Sep 17 00:00:00 2001 From: Michael Gilardi <11632652+mgilardi@users.noreply.github.com> Date: Tue, 10 Nov 2026 00:39:57 -0700 Subject: [PATCH] Add the first test audit, and tests for two cases it found untested The audit maps each promise to its tests. Two gaps: - If GriefPrevention's claims can't be read, every spot counts as near a claim, so nobody is moved. The code did this; nothing tested it. The part after finding the data store moves into fromDataStore (behavior unchanged), and GriefPreventionClaimsTest covers it: 5 tests, with a positive control. - skip-existing-players also counts only XP, or only an ender-chest item. Two bot checks added; the existing-players section passed 9/9 on Paper 26.1.2. The full suite wasn't rerun. Co-Authored-By: Claude Opus 5.5 --- docs/test-audit.md | 35 +++++++++++++ .../claims/GriefPreventionClaims.java | 6 ++- .../claims/GriefPreventionClaimsTest.java | 49 +++++++++++++++++++ test/suite.mjs | 11 +++++ 4 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 docs/test-audit.md create mode 100644 src/test/java/com/extantape/homesteader/claims/GriefPreventionClaimsTest.java diff --git a/docs/test-audit.md b/docs/test-audit.md new file mode 100644 index 0000000..6e4e9d7 --- /dev/null +++ b/docs/test-audit.md @@ -0,0 +1,35 @@ +# Test audit + +Kept by this repo's owning session (Minecraft: Plugins Lead), per `~/Code/CLAUDE.md`, "Test self-audits". Newest first. + +## 2026-11-10: first full audit (at 0.1.0) + +What Homesteader promises (README and `docs/decisions.md`), and what proves it. "Unit" is `src/test`; "live" is `test/suite.mjs` on throwaway Paper 26.1.2, 26.2 and 26.3 servers with Multiverse-Core, Multiverse-Inventories, GriefPrevention and bots. + +### Covered + +**Once per player and group** +- **Never repeated by leaving, dying, relogging or restarts:** live "leaving and returning", "relog", "death and respawn", "records survived the restart". +- **Items never land in another group's inventory; hopping straight through gives nothing:** live "beta items never appear in alpha", "in and out of alpha within the settle time". +- **Crashes and disconnects at every step give exactly one starter:** live, four `kill -9` points and two disconnect points. +- **A damaged record file is kept with a copy, nobody gets anything, admin commands won't write over it, and fixing it works:** unit `damagedFileIsKeptReportedAndBlocksChanges` and three more; live. + +**Full inventories** +- **Nothing given or dropped until there's room, and the player is told how many slots:** live, with a count of every stone. + +**Existing players and admins** +- **`skip-existing-players` detects inventory, ender chest and XP:** live. **New in this audit:** only XP, and only an ender-chest item, each count as existing (they had no checks; the existing-players section passed 9/9 on Paper 26.1.2). +- **Only `homesteader.admin` can use the admin commands:** live "a player without homesteader.admin can't", with an op as the control. + +**The one-time move** +- **A safe landing, every rule:** unit `SpotRulesTest`, 15 tests, and `randomTerrainOnlyEverYieldsSafeSpots`; live, 300 searches over hazards, and a bot that checked every landing itself. +- **Inside the ring and the world border:** unit `AnnulusTest`; live. +- **Never in or within 12 blocks of a claim:** live, with real claims. +- **New in this audit: if GriefPrevention's claims can't be read, every spot counts as near a claim, so nobody is moved.** Unit `GriefPreventionClaimsTest` (5 tests, with a positive control): a store with no `getClaims`, claims that can't be listed, a claim from a renamed API, and something that isn't a claim. The code already did this; nothing tested it. +- **No safe spot: they stay, are told, still get the starter, and the move is tried again next visit:** live. +- **Never changes a block:** live, a scan of the plugin for any block-changing call. + +### Skipped, with reasons + +- **How a landing looks while chunks load, and how the messages read:** real-client list. +- **The fallback `ClaimCheck` in `HomesteaderPlugin` when `create` throws.** It's a two-line class that always answers "near"; the new tests prove `create` throws in each broken case. Testing the plugin's start-up would need a server. diff --git a/src/main/java/com/extantape/homesteader/claims/GriefPreventionClaims.java b/src/main/java/com/extantape/homesteader/claims/GriefPreventionClaims.java index 712327f..5250634 100644 --- a/src/main/java/com/extantape/homesteader/claims/GriefPreventionClaims.java +++ b/src/main/java/com/extantape/homesteader/claims/GriefPreventionClaims.java @@ -24,7 +24,11 @@ private GriefPreventionClaims(Object dataStore, Method getClaims) { public static GriefPreventionClaims create(Plugin gp) throws ReflectiveOperationException { Field f = gp.getClass().getField("dataStore"); - Object ds = f.get(gp); + return fromDataStore(f.get(gp)); + } + + /** The part of {@link #create} after finding the data store, so it can be tested without GriefPrevention. */ + static GriefPreventionClaims fromDataStore(Object ds) throws ReflectiveOperationException { Method m = ds.getClass().getMethod("getClaims"); GriefPreventionClaims c = new GriefPreventionClaims(ds, m); c.claims(); // Fail now, not on the first player. diff --git a/src/test/java/com/extantape/homesteader/claims/GriefPreventionClaimsTest.java b/src/test/java/com/extantape/homesteader/claims/GriefPreventionClaimsTest.java new file mode 100644 index 0000000..eb09820 --- /dev/null +++ b/src/test/java/com/extantape/homesteader/claims/GriefPreventionClaimsTest.java @@ -0,0 +1,49 @@ +package com.extantape.homesteader.claims; + +import org.bukkit.Location; +import org.junit.jupiter.api.Test; + +import java.util.Collection; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +/** If GriefPrevention's claims can't be read, every spot counts as near a claim, so nobody is moved. */ +class GriefPreventionClaimsTest { + static final Location SPOT = new Location(null, 100, 70, 100); + + public static final class Store { + public final Collection claims; + public Store(Collection claims) { this.claims = claims; } + public Collection getClaims() { return claims; } + } + + public static final class Broken { + public Collection getClaims() { throw new IllegalStateException("not loaded"); } + } + + /** A claim from a GriefPrevention version that renamed its corner methods. */ + public static final class OddClaim { + public Location getLowerCorner() { return SPOT; } + } + + @Test void controlNoClaimsMeansNotNearOne() throws Exception { + assertFalse(GriefPreventionClaims.fromDataStore(new Store(List.of())).nearClaim(SPOT, 12)); + } + + @Test void aDataStoreWithoutGetClaimsFailsAtStartNotLater() { + assertThrows(NoSuchMethodException.class, () -> GriefPreventionClaims.fromDataStore(new Object())); + } + + @Test void claimsThatCantBeListedFailAtStart() { + assertThrows(ReflectiveOperationException.class, () -> GriefPreventionClaims.fromDataStore(new Broken())); + } + + @Test void aClaimThatCantBeReadCountsAsNear() throws Exception { + assertTrue(GriefPreventionClaims.fromDataStore(new Store(List.of(new OddClaim()))).nearClaim(SPOT, 12)); + } + + @Test void somethingThatIsntAClaimCountsAsNear() throws Exception { + assertTrue(GriefPreventionClaims.fromDataStore(new Store(List.of("not a claim"))).nearClaim(SPOT, 12)); + } +} diff --git a/test/suite.mjs b/test/suite.mjs index fe4163e..ae51144 100644 --- a/test/suite.mjs +++ b/test/suite.mjs @@ -292,11 +292,22 @@ if (want('existing')) { await go('Oldtimer', 'delta', 3000) s.cmd('give Oldtimer cookie 1'); await sleep(800) await go('Oldtimer', 'world', 3000) + // The other two signs of an existing player: only XP, or only something in the ender chest. + const x = await join('Xpman'); await go('Xpman', 'delta', 3000) + s.cmd('xp add Xpman 30 points'); await sleep(800) + await go('Xpman', 'world', 3000) + const e = await join('Enderman'); await go('Enderman', 'delta', 3000) + s.cmd('item replace entity Enderman enderchest.0 with cookie 1'); await sleep(800) + await go('Enderman', 'world', 3000) writeConfig(dir, config({ delta: true })); await s.ask('homesteader reload', 1500) const m0 = s.mark() await go('Oldtimer', 'delta', 4000) check('existing inventory is detected, no starter', s.since(m0).some(l => /Oldtimer arrived in 'delta' with items or XP already/.test(l)) && has(o, 'cookie') === 1 && has(o, 'chest') === 0, JSON.stringify(inv(o)) + '\n' + s.since(m0).filter(l => /Homesteader/.test(l)).join('\n')) + await go('Xpman', 'delta', 4000); await go('Enderman', 'delta', 4000) + check('only XP counts as existing too: no starter', gave('Xpman', 'delta', m0) === 0 && has(x, 'chest') === 0 && s.since(m0).some(l => /Xpman arrived in 'delta' with items or XP already/.test(l))) + check('only an ender chest item counts as existing too: no starter', gave('Enderman', 'delta', m0) === 0 && has(e, 'chest') === 0 && s.since(m0).some(l => /Enderman arrived in 'delta' with items or XP already/.test(l))) + await leave('Xpman'); await leave('Enderman') const n = await join('Newcomer'); await go('Newcomer', 'delta', 4000) check('a new player in the same group still gets it', eq({ chest: has(n, 'chest'), cookie: has(n, 'cookie') }, { chest: 1, cookie: 5 }), JSON.stringify(inv(n))) const out = await s.ask('homesteader reset Oldtimer delta', 4000)