Skip to content

Improve test reliability: reconnect, retry, server console, packet fix#3873

Merged
rom1504 merged 12 commits into
masterfrom
improve-test-reliability-2
Mar 31, 2026
Merged

Improve test reliability: reconnect, retry, server console, packet fix#3873
rom1504 merged 12 commits into
masterfrom
improve-test-reliability-2

Conversation

@rom1504
Copy link
Copy Markdown
Member

@rom1504 rom1504 commented Mar 31, 2026

Summary

Follow-up to #3871. Further improves test reliability and fixes a real protocol bug.

Bug fix (inventory.js):

  • Add set_player_inventory packet handler for 1.21.9+ — the server uses this new packet for server-initiated inventory changes instead of set_slot. Without it, inventory events don't fire for server commands.

Test infrastructure (externalTest.js):

  • Auto-reconnect bot after disconnect — when a test crashes the bot (e.g. exampleDigger child process failure), create a fresh bot instance before the next test instead of cascading failures
  • Run example tests last (exampleBee, exampleDigger, exampleInventory) — these spawn child processes that can crash; running them last limits blast radius
  • Retry logging — prints [retry N] in CI logs so we can see which tests needed retries
  • Bail out of retries after 3 distinct test failures on first attempt — avoids wasting time retrying when there's a systemic issue

Test fixes:

  • Fix chatAddPattern test to filter by expected username U9G — prevents admin messages from /give or /clear matching the pattern
  • Use server console for gamemode changes and teleport — more reliable than bot.chat
  • Reduce default operation timeout from 20s to 5s (10s for clearInventory) — operations complete in <1s, so faster failure + faster retries

Test plan

  • Tested locally on 1.8.8 (45/45), 1.9.4 (45/45), 1.21.9 (41/41)
  • CI: 6/7 groups passing, 1.21.9 group pending verification with latest fix

🤖 Generated with Claude Code

rom1504 and others added 12 commits March 31, 2026 01:31
The test used once(bot, 'chat') which matches ANY chat message.
Admin messages from /give or /clear in resetState could arrive and
match before the test's tellraw. Now filters for username === 'U9G'.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Now that chatAddPattern test filters by username, server console
admin messages no longer interfere. Server console commands are
more reliable than bot.chat — they work even if the bot is in a
bad state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Operations like gamemode change, clear inventory, and teleport
complete in <1s. A 5s timeout fails faster and lets retries
kick in sooner instead of waiting 20s per failure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests that spawn child processes (exampleBee, exampleDigger,
exampleInventory) can crash and disconnect the bot, cascading
to fail all subsequent tests. Running them last ensures they
can only affect each other, not the main test suite.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When a test crashes and disconnects the bot (e.g. exampleDigger
child process failure), subsequent tests would cascade-fail.
Now detects !bot.entity and reconnects with a fresh bot instance
before running the next test.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Server console /give doesn't trigger updateSlot on 1.21.9+.
Use bot.chat('/give @A stone 1') for the give (works on all versions)
and wrap.writeServer for /clear (more reliable than chat for clear).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
MC 1.21.9+ uses a new set_player_inventory packet for server-initiated
inventory changes (e.g. console /give) instead of set_slot. Mineflayer
had no handler for it, so updateSlot events never fired.

This fixes server console /give on 1.21.9+ and also benefits any
user code that relies on inventory updates from server commands.

Also reverts clearInventory to use server console for both give and
clear now that the packet handler is in place.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Server console /give doesn't send inventory update packets to the
client on 1.21.9+ (no set_slot nor set_player_inventory). The item
gets added server-side but the client never knows about it.

Use bot.chat('/give @A stone 1') which goes through the player's
command executor and always sends proper set_slot packets.

Keep server console for /clear (which does send set_slot reliably).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The 5s timeout is fine for server console commands but bot.chat
goes through the network stack and can be slower on loaded runners
with 4 MC servers sharing one container.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Server console /clear also doesn't send proper inventory packets on
1.21.9+. Use bot.chat for both /give and /clear, waiting for the
chat message confirmation for /clear.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rom1504 rom1504 changed the title Improve test reliability: server console everywhere, reconnect, faster timeouts Improve test reliability: reconnect, retry, server console, packet fix Mar 31, 2026
@rom1504 rom1504 merged commit 23f60d2 into master Mar 31, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant