fix: use server-minted matchId in smoke test actions

This commit is contained in:
Keith Solomon
2026-07-26 03:32:54 -05:00
parent d118920739
commit 4c2586908f
+12 -10
View File
@@ -15,7 +15,6 @@ use PHPUnit\Framework\TestCase;
final class PostMatchActionSmokeTest extends TestCase final class PostMatchActionSmokeTest extends TestCase
{ {
private const SECRET = 'e2e-smoke-secret'; private const SECRET = 'e2e-smoke-secret';
private const MATCH_ID = '0123456789abcdef';
private const BASE_URL = 'http://127.0.0.1:8765'; private const BASE_URL = 'http://127.0.0.1:8765';
private const CSRF_COOKIE_NAME = '__csrf'; private const CSRF_COOKIE_NAME = '__csrf';
@@ -60,14 +59,15 @@ final class PostMatchActionSmokeTest extends TestCase
$matchId = $startResponse['body']['matchId'] ?? null; $matchId = $startResponse['body']['matchId'] ?? null;
$turnToken = $startResponse['body']['turnToken'] ?? null; $turnToken = $startResponse['body']['turnToken'] ?? null;
self::assertIsArray($match); self::assertIsArray($match);
self::assertSame(self::MATCH_ID, $matchId); self::assertIsString($matchId);
self::assertMatchesRegularExpression('/^[a-f0-9]{16,}$/', $matchId);
self::assertMatchesRegularExpression('/^[a-f0-9]{32}$/', $turnToken); self::assertMatchesRegularExpression('/^[a-f0-9]{32}$/', $turnToken);
for ($i = 0; $i < 200; $i += 1) { for ($i = 0; $i < 200; $i += 1) {
if (!empty($match['winnerTeamId'])) { if (!empty($match['winnerTeamId'])) {
break; break;
} }
$action = $this->pickAction($match); $action = $this->pickAction($match, $matchId);
$response = $this->postJson("/matches/current/{$action['verb']}", $action['body']); $response = $this->postJson("/matches/current/{$action['verb']}", $action['body']);
$errMsg = "Step {$i} verb={$action['verb']} failed: " . ($response['body']['error'] ?? ''); $errMsg = "Step {$i} verb={$action['verb']} failed: " . ($response['body']['error'] ?? '');
self::assertSame(200, $response['status'], $errMsg); self::assertSame(200, $response['status'], $errMsg);
@@ -83,10 +83,11 @@ final class PostMatchActionSmokeTest extends TestCase
$startResponse = $this->postJson('/scenarios/skirmish/start', $scenario); $startResponse = $this->postJson('/scenarios/skirmish/start', $scenario);
self::assertSame(200, $startResponse['status']); self::assertSame(200, $startResponse['status']);
$match = $startResponse['body']['match']; $match = $startResponse['body']['match'];
$staleToken = TurnToken::issue(self::SECRET, self::MATCH_ID, 'alpha', 99, 0); $matchId = $startResponse['body']['matchId'];
$staleToken = TurnToken::issue(self::SECRET, $matchId, 'alpha', 99, 0);
$response = $this->postJson('/matches/current/end-turn', [ $response = $this->postJson('/matches/current/end-turn', [
'matchId' => self::MATCH_ID, 'matchId' => $matchId,
'match' => $match, 'match' => $match,
], $staleToken); ], $staleToken);
@@ -217,7 +218,7 @@ final class PostMatchActionSmokeTest extends TestCase
$headers[] = 'X-Turn-Token: ' . $turnToken; $headers[] = 'X-Turn-Token: ' . $turnToken;
} elseif (isset($body['match'])) { } elseif (isset($body['match'])) {
$match = $body['match']; $match = $body['match'];
$matchId = (string) ($body['matchId'] ?? self::MATCH_ID); $matchId = (string) ($body['matchId'] ?? '');
$turnToken = TurnToken::issue( $turnToken = TurnToken::issue(
self::SECRET, self::SECRET,
$matchId, $matchId,
@@ -254,9 +255,10 @@ final class PostMatchActionSmokeTest extends TestCase
* - if no enemy is reachable this turn, end the turn. * - if no enemy is reachable this turn, end the turn.
* *
* @param array<string, mixed> $match * @param array<string, mixed> $match
* @param string $matchId
* @return array{verb: string, body: array<string, mixed>} * @return array{verb: string, body: array<string, mixed>}
*/ */
private function pickAction(array $match): array private function pickAction(array $match, string $matchId): array
{ {
$units = $match['units']; $units = $match['units'];
$active = $match['activeTeamId']; $active = $match['activeTeamId'];
@@ -275,7 +277,7 @@ final class PostMatchActionSmokeTest extends TestCase
return [ return [
'verb' => 'attack', 'verb' => 'attack',
'body' => [ 'body' => [
'matchId' => self::MATCH_ID, 'matchId' => $matchId,
'match' => $match, 'match' => $match,
'attackerId' => $unit['id'], 'attackerId' => $unit['id'],
'targetId' => $other['id'], 'targetId' => $other['id'],
@@ -345,7 +347,7 @@ final class PostMatchActionSmokeTest extends TestCase
return [ return [
'verb' => 'move', 'verb' => 'move',
'body' => [ 'body' => [
'matchId' => self::MATCH_ID, 'matchId' => $matchId,
'match' => $match, 'match' => $match,
'unitId' => $unit['id'], 'unitId' => $unit['id'],
'x' => $c['x'], 'x' => $c['x'],
@@ -358,7 +360,7 @@ final class PostMatchActionSmokeTest extends TestCase
return [ return [
'verb' => 'end-turn', 'verb' => 'end-turn',
'body' => [ 'body' => [
'matchId' => self::MATCH_ID, 'matchId' => $matchId,
'match' => $match, 'match' => $match,
], ],
]; ];