-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(core): gate all client spawn intents on the spawn phase (follow-up to #4657) #4660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,37 @@ | ||||||||||||||
| import { Executor } from "../../../src/core/execution/ExecutionManager"; | ||||||||||||||
| import { SpawnExecution } from "../../../src/core/execution/SpawnExecution"; | ||||||||||||||
| import { PlayerInfo, PlayerType } from "../../../src/core/game/Game"; | ||||||||||||||
| import { StampedIntent } from "../../../src/core/Schemas"; | ||||||||||||||
| import { setup } from "../../util/Setup"; | ||||||||||||||
|
|
||||||||||||||
| describe("Executor.createExec", () => { | ||||||||||||||
| test("marks a client spawn intent with fromIntent so it is gated by the spawn phase", async () => { | ||||||||||||||
| const playerInfo = new PlayerInfo( | ||||||||||||||
| "player", | ||||||||||||||
| PlayerType.Human, | ||||||||||||||
| "client_id", | ||||||||||||||
| "player_id", | ||||||||||||||
| ); | ||||||||||||||
| // setup() ends the spawn phase by default, so the game is already underway. | ||||||||||||||
| const game = await setup("half_land_half_ocean", {}, [playerInfo]); | ||||||||||||||
|
|
||||||||||||||
| const executor = new Executor(game, "game_id", "client_id"); | ||||||||||||||
| const exec = executor.createExec({ | ||||||||||||||
| type: "spawn", | ||||||||||||||
| tile: 20, | ||||||||||||||
| clientID: "client_id", | ||||||||||||||
| } as StampedIntent); | ||||||||||||||
|
|
||||||||||||||
| expect(exec).toBeInstanceOf(SpawnExecution); | ||||||||||||||
| expect((exec as SpawnExecution).tile).toBe(20); | ||||||||||||||
|
|
||||||||||||||
| // Because it originated from a client intent (fromIntent = true), executing | ||||||||||||||
| // it after the spawn phase must be a no-op — the player never spawns. | ||||||||||||||
| game.addExecution(exec); | ||||||||||||||
| game.executeNextTick(); | ||||||||||||||
| game.executeNextTick(); | ||||||||||||||
| expect(game.playerByClientID("client_id")?.hasSpawned() ?? false).toBe( | ||||||||||||||
| false, | ||||||||||||||
| ); | ||||||||||||||
|
Comment on lines
+33
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Do not mask a missing player in this assertion.
Suggested fix- expect(game.playerByClientID("client_id")?.hasSpawned() ?? false).toBe(
- false,
- );
+ const player = game.playerByClientID("client_id");
+ expect(player).toBeDefined();
+ expect(player!.hasSpawned()).toBe(false);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| }); | ||||||||||||||
| }); | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: openfrontio/OpenFrontIO
Length of output: 161
🏁 Script executed:
Repository: openfrontio/OpenFrontIO
Length of output: 50379
🏁 Script executed:
Repository: openfrontio/OpenFrontIO
Length of output: 50379
🏁 Script executed:
Repository: openfrontio/OpenFrontIO
Length of output: 11590
Add a small test for the
"spawn"intent path.tests/core/execution/SpawnExecution.test.tscoversfromIntent = trueby buildingSpawnExecutiondirectly, but it does not exerciseExecutionManager.createExecfor a stamped"spawn"intent. Add one test there so this wiring cannot regress.🤖 Prompt for AI Agents
Source: Coding guidelines