Commit 7af5e2c
Improve test reliability: server console gamemode, retries, NaN guard (#3871)
* Use server console for gamemode changes in tests
Replace the fragile triple-chat-command trick in setCreativeMode with
wrap.writeServer(), which sends the gamemode command directly to the
server console. Wait for the game_state_change packet to confirm.
This eliminates the most common source of flaky test timeouts:
"Event message did not fire within timeout of 20000ms" in
setCreativeMode/becomeCreative.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix game_state_change check for newer MC versions
The reason field is a string ('change_game_mode') on newer versions
and a number (3) on older ones. gameMode is a float, so use Math.floor.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Use server console for clearInventory too
Replace chat-based /give + /clear with wrap.writeServer('clear flatbot').
Wait for set_slot packet confirming items removed. Skip if inventory
is already empty. Eliminates updateSlot timeout flakiness.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix internal test timeOfDay race condition
bot.time is initialized when the bot processes the login packet.
Setting bot.time.timeOfDay before the login is processed causes
"Cannot set properties of undefined" on fast/loaded runners.
Wait for the bot's 'login' event before accessing bot.time.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix clearInventory: wait for updateSlot with empty inventory check
The set_slot packet format differs across MC versions (blockId vs
present field). Instead of checking packet fields, wait for the
higher-level updateSlot event and verify inventory is actually empty.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix clearInventory: handle empty inventory + wait for sync
When inventory is already empty, wait 2 ticks for any pending set_slot
packets to arrive. When inventory has items, wait until all slots are
cleared via updateSlot events. The server console command is reliable
but we need to wait for the inventory state to sync.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix: prevent sending NaN position packets after death
After death, bot.entity.position can become NaN (not null). NaN
serializes as null in JSON, causing "Invalid move packet received"
kicks. Guard all position send functions with Number.isFinite checks.
Also simplify clearInventory to not use waitForTicks (which hangs
when physics tick returns early due to NaN position).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix clearInventory race: don't send /clear when inventory is empty
Sending /clear when inventory is already empty causes a race on 1.8.x
where the server processes the clear after the next test has already
set inventory slots, wiping them.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix clearInventory: give stone before clear to guarantee events
The /clear command produces no events when inventory is already empty
(stale local state). Give a stone first via server console to ensure
the server always has something to clear, guaranteeing updateSlot events.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix: use bot.chat for /give, server console for /clear
Server console /give produces admin chat messages that interfere with
chat pattern tests. Use bot.chat for /give (as before) and server
console only for /clear (which is the part that was flaky).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Move resetState from beforeEach hook into test runner
Mocha's --retries only retries tests, not hooks. When resetState was
in beforeEach, any timeout there failed the test with no retry.
Now resetState runs inside runTest(), so --retries 2 covers both the
reset and the actual test together. One change, no test files modified.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix clearInventory: use creative setInventorySlot instead of chat /give
bot.chat('/give') generates chat messages that interfere with chat
pattern tests (especially now that resetState runs inside the test
where patterns are still registered). Use creative setInventorySlot
which is silent.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix clearInventory: use raw set_creative_slot instead of creative API
bot.creative.setInventorySlot waits for server confirmation, which
conflicts with the subsequent /clear command that removes the same slot.
Use a raw set_creative_slot packet write instead — no waiting, no
conflict with the clear.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix clearInventory: use bot.chat for /clear, creative packet for /give
Server console commands generate system_chat messages that interfere
with chat pattern tests. Use:
- set_creative_slot packet for giving stone (silent, no chat)
- bot.chat('/clear') for clearing (the original reliable approach)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Log retry attempts for visibility
Print "[retry N]" when a test is being retried, so we can see in CI
logs whether --retries 2 is actually catching transient failures.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Increase retries to 3
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix: use this.test._currentRetry for retry logging
this.currentRetry doesn't exist on mocha Context — the retry count
is on this.test._currentRetry.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Disable retries after 3 distinct test failures
When 3+ different tests fail, it indicates a systemic issue (not
transient flakiness). Disable retries for remaining tests to avoid
wasting time on cascading failures.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Revert clearInventory to original bot.chat approach
The set_creative_slot packet doesn't produce updateSlot events on
1.19.2-1.19.3, causing 5 failures per version. Go back to the
original bot.chat('/give @A stone 1') + bot.chat('/clear') which
works across all versions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* Fix bail-out: count failures on first attempt, not after all retries
The bail-out was counting failures only after a test exhausted all
retries, so the first 3 failing tests each wasted 3 retries before
triggering the bail-out. Now count on first attempt — after 3
different tests fail, remaining tests run without retries.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: rom1504 <rom1504@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 85a164d commit 7af5e2c
File tree
5 files changed
+52
-39
lines changed- .github/workflows
- lib/plugins
- test
- externalTests/plugins
5 files changed
+52
-39
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| 103 | + | |
102 | 104 | | |
103 | 105 | | |
104 | 106 | | |
| |||
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
| 127 | + | |
125 | 128 | | |
126 | 129 | | |
127 | 130 | | |
| |||
153 | 156 | | |
154 | 157 | | |
155 | 158 | | |
| 159 | + | |
| 160 | + | |
156 | 161 | | |
157 | 162 | | |
158 | 163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | 112 | | |
119 | 113 | | |
120 | 114 | | |
| |||
131 | 125 | | |
132 | 126 | | |
133 | 127 | | |
| 128 | + | |
134 | 129 | | |
135 | 130 | | |
136 | 131 | | |
| |||
139 | 134 | | |
140 | 135 | | |
141 | 136 | | |
142 | | - | |
143 | | - | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
144 | 155 | | |
145 | 156 | | |
146 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
106 | | - | |
107 | | - | |
108 | 106 | | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
114 | 114 | | |
115 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
116 | 120 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 121 | + | |
| 122 | + | |
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
127 | | - | |
| 126 | + | |
| 127 | + | |
128 | 128 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
| 137 | + | |
| 138 | + | |
143 | 139 | | |
144 | 140 | | |
145 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
868 | 868 | | |
869 | 869 | | |
870 | 870 | | |
871 | | - | |
872 | 871 | | |
873 | 872 | | |
| 873 | + | |
| 874 | + | |
874 | 875 | | |
875 | 876 | | |
876 | 877 | | |
| |||
0 commit comments