From 89f99f29cd8766361609c7c813f0edc68830629c Mon Sep 17 00:00:00 2001 From: BreadMoirai Date: Wed, 16 Sep 2026 21:12:13 -0700 Subject: [PATCH 1/3] Publish on PR merge, test on pull requests - Publish Mod runs only when a pull request is merged (checks out the merge commit); tests no longer run there. - New Test workflow runs game tests on pull requests. - Create the GitHub release with GITHUB_TOKEN instead of the G_TOKEN secret. - Move actions to their Node 24 versions (checkout v6, setup-java v5, action-gh-release v3). --- .github/workflows/modrinth.yml | 14 +++++++++----- .github/workflows/test.yml | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/modrinth.yml b/.github/workflows/modrinth.yml index ec51e18..5c1d153 100644 --- a/.github/workflows/modrinth.yml +++ b/.github/workflows/modrinth.yml @@ -1,6 +1,8 @@ name: Publish Mod -on: [ pull_request, workflow_dispatch ] +on: + pull_request: + types: [ closed ] env: MOD_VERSION: 2.3.1 @@ -10,17 +12,19 @@ permissions: jobs: build: + if: github.event.pull_request.merged == true runs-on: ubuntu-latest permissions: contents: write steps: - name: Checkout Repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: + ref: ${{ github.event.pull_request.merge_commit_sha }} submodules: true - name: Setup Java - uses: actions/setup-java@v4 + uses: actions/setup-java@v5 with: distribution: temurin java-version: | @@ -31,9 +35,9 @@ jobs: run: bash ./gradlew buildAndCollect - name: Create GitHub Release - uses: softprops/action-gh-release@v2 + uses: softprops/action-gh-release@v3 with: - token: ${{ secrets.G_TOKEN }} + token: ${{ secrets.GITHUB_TOKEN }} tag_name: ${{ env.MOD_VERSION }} name: ${{ env.MOD_VERSION }} files: build/libs/${{ env.MOD_VERSION }}/*.jar diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..48bd47b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Test + +on: [ pull_request ] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v6 + with: + submodules: true + + - name: Setup Java + uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: | + 21 + 25 + + # Client game tests launch a real Minecraft client per version, so they need a virtual display. + # Capped workers: each client is memory/GPU heavy and too many in parallel can hang. + - name: Run Client Game Tests + run: xvfb-run -a bash ./gradlew runTestClient --max-workers=2 From 3051d2b29467c3c4cd6fdfde3683890b80b63610 Mon Sep 17 00:00:00 2001 From: BreadMoirai Date: Wed, 16 Sep 2026 21:51:23 -0700 Subject: [PATCH 2/3] Make repeat-key tests wait on the result, not a tick count The repeat-last tests held the repeat key for a fixed number of ticks, tuned on a desktop. On a GitHub runner crafting is slower, so 1.21.11 released the key after 61 of 64 crafts. Hold until the expected output is in the inventory (or on the ground for the drop test), then keep holding briefly so the client resyncs before release. Test workflow: drop the redundant xvfb-run (Loom already wraps clients in it on CI), keep going past a failing version, and time out hung runs. --- .github/workflows/test.yml | 7 +- .../testmod/suite/RepeatLastTests.java | 28 ++++---- .../testmod/suite/TestSuite.java | 69 +++++++++++-------- 3 files changed, 57 insertions(+), 47 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48bd47b..b83aa01 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,6 +5,8 @@ on: [ pull_request ] jobs: test: runs-on: ubuntu-latest + # A Minecraft client that fails to start can hang instead of exiting; don't burn the 6h default. + timeout-minutes: 60 steps: - name: Checkout Repository uses: actions/checkout@v6 @@ -19,7 +21,8 @@ jobs: 21 25 - # Client game tests launch a real Minecraft client per version, so they need a virtual display. + # Loom runs each client under xvfb-run on CI, so no display setup is needed here. # Capped workers: each client is memory/GPU heavy and too many in parallel can hang. + # --continue so one failing version doesn't hide the results of the others. - name: Run Client Game Tests - run: xvfb-run -a bash ./gradlew runTestClient --max-workers=2 + run: bash ./gradlew runTestClient --max-workers=2 --continue diff --git a/src/test/java/com/github/breadmoirai/oneclickcrafting/testmod/suite/RepeatLastTests.java b/src/test/java/com/github/breadmoirai/oneclickcrafting/testmod/suite/RepeatLastTests.java index 0109538..00ba411 100644 --- a/src/test/java/com/github/breadmoirai/oneclickcrafting/testmod/suite/RepeatLastTests.java +++ b/src/test/java/com/github/breadmoirai/oneclickcrafting/testmod/suite/RepeatLastTests.java @@ -20,6 +20,13 @@ public class RepeatLastTests extends OneClickTests { public static int REPEAT_KEY_CODE = InputConstants.KEY_R; + /** Upper bound for holding the repeat key until all crafts are done (slow CI machines need far more + * ticks than a desktop, so the hold waits on the result instead of a fixed tick count). */ + private static final int REPEAT_TIMEOUT_TICKS = 400; + /** Keep holding briefly after the last craft: releasing mid-attempt can leave the client inventory + * out of sync with the server until the next repeat attempt resyncs it. */ + private static final int REPEAT_SETTLE_TICKS = 20; + public RepeatLastTests(ClientGameTestContext context, TestSingleplayerContext world) { super(context, world); } @@ -75,11 +82,8 @@ public void repeatLastStack() { wait(2); input.holdRepeatKey(); - //? if <1.21.8 { - /*wait(200); - *///? } else { - wait(65); - //? } + waitUntil(mc -> inventoryCount(mc, ctx.outputItem) >= ctx.outputCount * 64, REPEAT_TIMEOUT_TICKS); + wait(REPEAT_SETTLE_TICKS); input.releaseRepeatKey(); ctx.close(); @@ -101,11 +105,8 @@ public void repeatLastStacksFullInventory() { input.holdShift(); input.holdRepeatKey(); - //? if <1.21.8 { - /*wait(35); - *///? } else { - wait(24); - //? } + waitUntil(mc -> inventoryCount(mc, ctx.outputItem) >= ctx.outputCount * 9 * 64, REPEAT_TIMEOUT_TICKS); + wait(REPEAT_SETTLE_TICKS); input.releaseShift(); input.releaseRepeatKey(); @@ -130,11 +131,8 @@ public void repeatLastDropKeyDropsManyItems() { wait(2); input.holdRepeatKey(); - //? if <1.21.8 { - /*wait(200); - *///? } else { - wait(66); - //? } + waitUntil(mc -> groundCount(mc, ctx.outputItem) >= ctx.outputCount * 64, REPEAT_TIMEOUT_TICKS); + wait(REPEAT_SETTLE_TICKS); input.releaseRepeatKey(); input.releaseDrop(); diff --git a/src/test/java/com/github/breadmoirai/oneclickcrafting/testmod/suite/TestSuite.java b/src/test/java/com/github/breadmoirai/oneclickcrafting/testmod/suite/TestSuite.java index 3a07b13..8d05327 100644 --- a/src/test/java/com/github/breadmoirai/oneclickcrafting/testmod/suite/TestSuite.java +++ b/src/test/java/com/github/breadmoirai/oneclickcrafting/testmod/suite/TestSuite.java @@ -8,6 +8,7 @@ import com.mojang.blaze3d.platform.InputConstants; import com.github.breadmoirai.oneclickcrafting.mixin.KeyMappingAccessor; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.InventoryScreen; import net.minecraft.core.BlockPos; @@ -24,6 +25,7 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.function.Predicate; @SuppressWarnings("UnstableApiUsage") public abstract class TestSuite { @@ -144,6 +146,19 @@ protected void wait(int ticks) { context.waitTicks(ticks); } + /** + * Waits until {@code condition} holds on the client, or {@code timeoutTicks} pass. A timeout is not a + * failure: use this to bound a held key that should be released once the work is done (so the test + * doesn't depend on how many ticks the machine needs), then assert on the result. + */ + protected void waitUntil(Predicate condition, int timeoutTicks) { + try { + context.waitFor(condition, timeoutTicks); + } catch (AssertionError timeout) { + // The assertion that follows reports what actually happened. + } + } + // ------------------------------------------------------------------------- // Inventory assertions // ------------------------------------------------------------------------- @@ -186,16 +201,7 @@ protected void assertInventoryExact(Map items) { } protected void assertInventoryCount(String itemId, int expectedCount) { - int actual = context.computeOnClient(mc -> { - if (mc.player == null) return 0; - var inv = mc.player.getInventory(); - int total = 0; - for (int i = 0; i < inv.getContainerSize(); i++) { - ItemStack stack = inv.getItem(i); - if (BuiltInRegistries.ITEM.getKey(stack.getItem()).toString().equals(itemId)) total += stack.getCount(); - } - return total; - }); + int actual = context.computeOnClient(mc -> inventoryCount(mc, itemId)); if (actual != expectedCount) { throw new AssertionError( "Expected exactly %d of %s in inventory, found %d" @@ -205,27 +211,9 @@ protected void assertInventoryCount(String itemId, int expectedCount) { protected void assertInventoryAtLeast(String itemId, int minCount) { try { - context.waitFor(mc -> { - if (mc.player == null) return false; - var inv = mc.player.getInventory(); - int total = 0; - for (int i = 0; i < inv.getContainerSize(); i++) { - ItemStack stack = inv.getItem(i); - if (BuiltInRegistries.ITEM.getKey(stack.getItem()).toString().equals(itemId)) total += stack.getCount(); - } - return total >= minCount; - }, 20); + context.waitFor(mc -> inventoryCount(mc, itemId) >= minCount, 20); } catch (AssertionError timeout) { - int actual = context.computeOnClient(mc -> { - if (mc.player == null) return 0; - var inv = mc.player.getInventory(); - int total = 0; - for (int i = 0; i < inv.getContainerSize(); i++) { - ItemStack stack = inv.getItem(i); - if (BuiltInRegistries.ITEM.getKey(stack.getItem()).toString().equals(itemId)) total += stack.getCount(); - } - return total; - }); + int actual = context.computeOnClient(mc -> inventoryCount(mc, itemId)); throw new AssertionError( "Expected >= %d of %s in inventory, found %d" .formatted(minCount, itemId, actual)); @@ -274,6 +262,27 @@ protected int stacks(int stacks) { return stacks * 64; } + /** Total count of {@code itemId} in the player's inventory (0 if there is no player). */ + protected static int inventoryCount(Minecraft mc, String itemId) { + if (mc.player == null) return 0; + var inv = mc.player.getInventory(); + int total = 0; + for (int i = 0; i < inv.getContainerSize(); i++) { + ItemStack stack = inv.getItem(i); + if (BuiltInRegistries.ITEM.getKey(stack.getItem()).toString().equals(itemId)) total += stack.getCount(); + } + return total; + } + + /** Total count of {@code itemId} in item entities within 16 blocks of the player. */ + protected static int groundCount(Minecraft mc, String itemId) { + if (mc.player == null || mc.level == null) return 0; + AABB box = mc.player.getBoundingBox().inflate(16.0); + return mc.level.getEntitiesOfClass(ItemEntity.class, box, + e -> BuiltInRegistries.ITEM.getKey(e.getItem().getItem()).toString().equals(itemId)) + .stream().mapToInt(e -> e.getItem().getCount()).sum(); + } + // ------------------------------------------------------------------------- // Private helpers // ------------------------------------------------------------------------- From 7e48d7ae888ea56ad0d107a85962e0cfbd3f1a69 Mon Sep 17 00:00:00 2001 From: BreadMoirai Date: Wed, 16 Sep 2026 22:03:52 -0700 Subject: [PATCH 3/3] Test workflow: install Mesa Vulkan driver for the 26.3 client Under Xvfb, 26.3's SDL window can't find a GLX visual, so the client falls back to Vulkan and hangs when no Vulkan driver is installed. Fabric API's CI installs mesa-vulkan-drivers for the same reason. --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b83aa01..04e7c29 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,6 +21,11 @@ jobs: 21 25 + # MC 26.3 (SDL) can't get an OpenGL context under Xvfb and falls back to Vulkan; this provides + # Mesa's software Vulkan driver (lavapipe). Without it the 26.3 client hangs on startup. + - name: Install Software Vulkan Driver + run: sudo apt-get update && sudo apt-get install -y mesa-vulkan-drivers + # Loom runs each client under xvfb-run on CI, so no display setup is needed here. # Capped workers: each client is memory/GPU heavy and too many in parallel can hang. # --continue so one failing version doesn't hide the results of the others.