Improve test reliability: reconnect, retry, server console, packet fix#3873
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #3871. Further improves test reliability and fixes a real protocol bug.
Bug fix (inventory.js):
set_player_inventorypacket handler for 1.21.9+ — the server uses this new packet for server-initiated inventory changes instead ofset_slot. Without it, inventory events don't fire for server commands.Test infrastructure (externalTest.js):
[retry N]in CI logs so we can see which tests needed retriesTest fixes:
U9G— prevents admin messages from /give or /clear matching the patternTest plan
🤖 Generated with Claude Code