rook/val Public Public: anyone can read this; nobody can change it.
forked from benjivers/val
workbenchthis machine
Test the plant through the socket command path
The round rules are tested headlessly already; this drives the same plant through arena.command(), which is the only door a browser has, and checks that a malformed input and a seat nobody holds both change nothing. Co-Authored-By: Claude Opus 5 <[email protected]>
1 file
changed +24
−0
src/server.test.ts +24
| @@ -138,6 +138,30 @@ test("a snapshot only carries the enemies that viewer can see", () => { | ||
| 138 | 138 | expect(JSON.stringify(far.board)).not.toContain('"x"'); |
| 139 | 139 | }); |
| 140 | 140 | |
| 141 | test("a command from a seat plants the spike, and nonsense from anyone else does nothing", async () => { | |
| 142 | const { command } = await import("./arena.ts"); | |
| 143 | const { siteCentre } = await import("./map.ts"); | |
| 144 | const state = match(); | |
| 145 | state.phase = "live"; | |
| 146 | state.clock = 100; | |
| 147 | const spot = siteCentre("B"); | |
| 148 | const carrier = state.players.find((p) => p.side === "atk")!; | |
| 149 | carrier.bot = false; | |
| 150 | carrier.x = spot.x; | |
| 151 | carrier.y = spot.y; | |
| 152 | carrier.spike = true; | |
| 153 | state.spike = { carried: carrier.id, x: spot.x, y: spot.y, planted: false, fuse: 0, site: null, defuse: 0, checkpoint: 0 }; | |
| 154 | // Garbage is ignored, and a seat nobody holds cannot be driven. | |
| 155 | command(carrier.id, { t: "i", mx: "left" as unknown as number, a: Number.NaN, u: "yes" }); | |
| 156 | command("nobody", { t: "i", u: true }); | |
| 157 | expect(carrier.input.use).toBe(false); | |
| 158 | command(carrier.id, { t: "i", u: true, mx: 0, my: 0 }); | |
| 159 | advance(5); | |
| 160 | expect(state.spike.planted).toBe(true); | |
| 161 | expect(state.spike.site).toBe("B"); | |
| 162 | carrier.bot = true; | |
| 163 | }); | |
| 164 | ||
| 141 | 165 | test("the match keeps running and is never parked", () => { |
| 142 | 166 | const state = match(); |
| 143 | 167 | const before = state.now; |