From bde9d535dc2b27a697ba79651fe960e25f48fba9 Mon Sep 17 00:00:00 2001 From: Ilia Denisov Date: Sat, 30 May 2026 15:16:17 +0200 Subject: [PATCH] =?UTF-8?q?chore(cleanup):=20purge=20/command=20residuals?= =?UTF-8?q?=20=E2=80=94=20fakeEngine,=20canon=20golden,=20openapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up tidy after the cross-service /command removal (#73): - Rename the router test double dummyExecutor -> fakeEngine (and the newExecutor / setupRouterExecutor helpers -> newFakeEngine / setupRouterEngine): it implements handler.Engine now, "executor" was a leftover of the removed adapter. Test-only. - Regenerate the ui/core canon signing golden onto user.games.order (request_user_games_command.json -> request_user_games_order.json, fresh canonical bytes + Ed25519 signature) and drop the last user.games.command references from the Go/TS tests and docs. - Align game openapi: CommandRequest.cmd no longer carries minItems: 1. It is now used only by PUT /api/v1/order, which accepts an empty batch (clearing the player's stored order, equivalent to removing every command); the contract test freezes the empty-allowed shape. Co-Authored-By: Claude Opus 4.8 (1M context) --- game/internal/router/battle_test.go | 20 ++++---- game/internal/router/order_test.go | 46 +++++++++---------- game/internal/router/router_helper_test.go | 26 +++++------ game/openapi.yaml | 15 +++--- game/openapi_contract_test.go | 3 +- ui/PLAN.md | 4 +- ui/core/README.md | 2 +- ui/core/canon/request_test.go | 4 +- ui/core/canon/signature_test.go | 2 +- ...and.json => request_user_games_order.json} | 6 +-- .../tests/wasm-core-canon-parity.test.ts | 2 +- 11 files changed, 67 insertions(+), 63 deletions(-) rename ui/core/canon/testdata/{request_user_games_command.json => request_user_games_order.json} (55%) diff --git a/game/internal/router/battle_test.go b/game/internal/router/battle_test.go index 5c4ab87..240304a 100644 --- a/game/internal/router/battle_test.go +++ b/game/internal/router/battle_test.go @@ -29,8 +29,8 @@ func TestGetBattleValidation(t *testing.T) { {"Invalid uuid", "0", invalidId, http.StatusBadRequest}, } { t.Run(tc.description, func(t *testing.T) { - e := &dummyExecutor{} - r := setupRouterExecutor(e) + e := &fakeEngine{} + r := setupRouterEngine(e) w := httptest.NewRecorder() path := fmt.Sprintf("/api/v1/battle/%s/%s", tc.turn, tc.battleID) @@ -81,11 +81,11 @@ func TestGetBattleFound(t *testing.T) { {Attacker: 0, AttackerShipClass: 10, Defender: 1, DefenderShipClass: 20, Destroyed: true}, }, } - e := &dummyExecutor{ + e := &fakeEngine{ FetchBattleResult: stored, FetchBattleOK: true, } - r := setupRouterExecutor(e) + r := setupRouterEngine(e) w := httptest.NewRecorder() path := fmt.Sprintf("/api/v1/battle/%d/%s", 7, id.String()) @@ -111,11 +111,11 @@ func TestGetBattleFound(t *testing.T) { func TestGetBattleTurnZero(t *testing.T) { id := uuid.New() - e := &dummyExecutor{ + e := &fakeEngine{ FetchBattleResult: &report.BattleReport{ID: id}, FetchBattleOK: true, } - r := setupRouterExecutor(e) + r := setupRouterEngine(e) w := httptest.NewRecorder() req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/battle/0/%s", id.String()), nil) @@ -128,8 +128,8 @@ func TestGetBattleTurnZero(t *testing.T) { func TestGetBattleNotFound(t *testing.T) { id := uuid.New() - e := &dummyExecutor{FetchBattleOK: false} - r := setupRouterExecutor(e) + e := &fakeEngine{FetchBattleOK: false} + r := setupRouterEngine(e) w := httptest.NewRecorder() req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/battle/3/%s", id.String()), nil) @@ -141,8 +141,8 @@ func TestGetBattleNotFound(t *testing.T) { } func TestGetBattleEngineError(t *testing.T) { - e := &dummyExecutor{FetchBattleErr: errors.New("engine boom")} - r := setupRouterExecutor(e) + e := &fakeEngine{FetchBattleErr: errors.New("engine boom")} + r := setupRouterEngine(e) w := httptest.NewRecorder() req, _ := http.NewRequest(http.MethodGet, fmt.Sprintf("/api/v1/battle/3/%s", uuid.NewString()), nil) diff --git a/game/internal/router/order_test.go b/game/internal/router/order_test.go index 1aad10c..22bce62 100644 --- a/game/internal/router/order_test.go +++ b/game/internal/router/order_test.go @@ -68,8 +68,8 @@ func TestOrderRaceQuit(t *testing.T) { payload = &rest.Command{ Actor: commandDefaultActor, } - exec := &dummyExecutor{} - emptyRouter := setupRouterExecutor(exec) + exec := &fakeEngine{} + emptyRouter := setupRouterEngine(exec) w = httptest.NewRecorder() req, _ = http.NewRequest(apiCommandMethod, apiOrderPath, asBody(payload)) @@ -927,8 +927,8 @@ func TestOrderPlanetRouteRemove(t *testing.T) { } func TestMultipleCommandOrder(t *testing.T) { - e := newExecutor() - r := setupRouterExecutor(e) + e := newFakeEngine() + r := setupRouterEngine(e) payload := &rest.Command{ Actor: commandDefaultActor, @@ -951,11 +951,11 @@ func TestMultipleCommandOrder(t *testing.T) { assert.Equal(t, commandNoErrorsStatus, w.Code, w.Body) - assert.Equal(t, 2, e.(*dummyExecutor).CommandsExecuted) + assert.Equal(t, 2, e.(*fakeEngine).CommandsExecuted) } func TestPutOrderResponseBody(t *testing.T) { - e := &dummyExecutor{ + e := &fakeEngine{ ValidateOrderResult: &order.UserGamesOrder{ GameID: uuid.New(), UpdatedAt: 1700, @@ -967,7 +967,7 @@ func TestPutOrderResponseBody(t *testing.T) { }, }, } - r := setupRouterExecutor(e) + r := setupRouterEngine(e) payload := &rest.Command{ Actor: commandDefaultActor, @@ -997,8 +997,8 @@ func TestPutOrderResponseBody(t *testing.T) { } func TestPutOrderEngineError(t *testing.T) { - e := &dummyExecutor{ValidateOrderErr: errors.New("engine boom")} - r := setupRouterExecutor(e) + e := &fakeEngine{ValidateOrderErr: errors.New("engine boom")} + r := setupRouterEngine(e) payload := &rest.Command{ Actor: commandDefaultActor, @@ -1054,8 +1054,8 @@ func TestPutOrderPerCommandRejection(t *testing.T) { }, }, } - executor := &dummyExecutor{ValidateOrderResult: result} - r := setupRouterExecutor(executor) + executor := &fakeEngine{ValidateOrderResult: result} + r := setupRouterEngine(executor) payload := &rest.Command{ Actor: commandDefaultActor, @@ -1112,8 +1112,8 @@ func TestPutOrderPerCommandRejection(t *testing.T) { // *GenericError on the input shelf, which must map to HTTP 400 with // the `{"generic_error","code"}` envelope rather than 500. func TestPutOrderStructuralRejection(t *testing.T) { - executor := &dummyExecutor{ValidateOrderErr: e.NewQuitCommandFollowedByCommandError()} - r := setupRouterExecutor(executor) + executor := &fakeEngine{ValidateOrderErr: e.NewQuitCommandFollowedByCommandError()} + r := setupRouterEngine(executor) payload := &rest.Command{ Actor: commandDefaultActor, @@ -1152,8 +1152,8 @@ func TestGetOrderQueryValidation(t *testing.T) { {"Non-numeric turn", "?player=Race_01&turn=abc", http.StatusBadRequest}, } { t.Run(tc.description, func(t *testing.T) { - e := &dummyExecutor{} - r := setupRouterExecutor(e) + e := &fakeEngine{} + r := setupRouterEngine(e) w := httptest.NewRecorder() req, _ := http.NewRequest(http.MethodGet, apiOrderPath+tc.query, nil) @@ -1176,11 +1176,11 @@ func TestGetOrderFound(t *testing.T) { }, }, } - e := &dummyExecutor{ + e := &fakeEngine{ FetchOrderResult: stored, FetchOrderOK: true, } - r := setupRouterExecutor(e) + r := setupRouterEngine(e) w := httptest.NewRecorder() req, _ := http.NewRequest(http.MethodGet, apiOrderPath+"?player=Race_01&turn=3", nil) @@ -1202,11 +1202,11 @@ func TestGetOrderFound(t *testing.T) { } func TestGetOrderTurnDefaultsToZero(t *testing.T) { - e := &dummyExecutor{ + e := &fakeEngine{ FetchOrderResult: &order.UserGamesOrder{GameID: uuid.New(), UpdatedAt: 1, Commands: []order.DecodableCommand{}}, FetchOrderOK: true, } - r := setupRouterExecutor(e) + r := setupRouterEngine(e) w := httptest.NewRecorder() req, _ := http.NewRequest(http.MethodGet, apiOrderPath+"?player=Race_01", nil) @@ -1217,8 +1217,8 @@ func TestGetOrderTurnDefaultsToZero(t *testing.T) { } func TestGetOrderNotFound(t *testing.T) { - e := &dummyExecutor{FetchOrderOK: false} - r := setupRouterExecutor(e) + e := &fakeEngine{FetchOrderOK: false} + r := setupRouterEngine(e) w := httptest.NewRecorder() req, _ := http.NewRequest(http.MethodGet, apiOrderPath+"?player=Race_01&turn=2", nil) @@ -1231,8 +1231,8 @@ func TestGetOrderNotFound(t *testing.T) { } func TestGetOrderEngineError(t *testing.T) { - e := &dummyExecutor{FetchOrderErr: errors.New("engine boom")} - r := setupRouterExecutor(e) + e := &fakeEngine{FetchOrderErr: errors.New("engine boom")} + r := setupRouterEngine(e) w := httptest.NewRecorder() req, _ := http.NewRequest(http.MethodGet, apiOrderPath+"?player=Race_01&turn=0", nil) diff --git a/game/internal/router/router_helper_test.go b/game/internal/router/router_helper_test.go index 2b3ba2d..0a601b0 100644 --- a/game/internal/router/router_helper_test.go +++ b/game/internal/router/router_helper_test.go @@ -31,7 +31,7 @@ func id() string { return uuid.New().String() } -type dummyExecutor struct { +type fakeEngine struct { CommandsExecuted int // ValidateOrderResult, when non-nil, is returned from ValidateOrder. @@ -55,7 +55,7 @@ type dummyExecutor struct { FetchBattleErr error } -func (e *dummyExecutor) ValidateOrder(actor string, cmd ...order.DecodableCommand) (*order.UserGamesOrder, error) { +func (e *fakeEngine) ValidateOrder(actor string, cmd ...order.DecodableCommand) (*order.UserGamesOrder, error) { e.CommandsExecuted = len(cmd) if e.ValidateOrderErr != nil { return nil, e.ValidateOrderErr @@ -70,48 +70,48 @@ func (e *dummyExecutor) ValidateOrder(actor string, cmd ...order.DecodableComman }, nil } -func (e *dummyExecutor) FetchOrder(actor string, turn uint) (*order.UserGamesOrder, bool, error) { +func (e *fakeEngine) FetchOrder(actor string, turn uint) (*order.UserGamesOrder, bool, error) { e.FetchOrderActor = actor e.FetchOrderTurn = turn return e.FetchOrderResult, e.FetchOrderOK, e.FetchOrderErr } -func (e *dummyExecutor) FetchBattle(turn uint, ID uuid.UUID) (*report.BattleReport, bool, error) { +func (e *fakeEngine) FetchBattle(turn uint, ID uuid.UUID) (*report.BattleReport, bool, error) { e.FetchBattleTurn = turn e.FetchBattleID = ID return e.FetchBattleResult, e.FetchBattleOK, e.FetchBattleErr } -func (e *dummyExecutor) GenerateGame(gameID uuid.UUID, races []string) (game.State, error) { +func (e *fakeEngine) GenerateGame(gameID uuid.UUID, races []string) (game.State, error) { return game.State{ID: gameID}, nil } -func (e *dummyExecutor) GenerateTurn() (game.State, error) { +func (e *fakeEngine) GenerateTurn() (game.State, error) { return game.State{}, nil } -func (e *dummyExecutor) BanishRace(raceName string) error { +func (e *fakeEngine) BanishRace(raceName string) error { return nil } -func (e *dummyExecutor) GameState() (game.State, error) { +func (e *fakeEngine) GameState() (game.State, error) { return game.State{}, nil } -func (e *dummyExecutor) LoadReport(actor string, turn uint) (*report.Report, error) { +func (e *fakeEngine) LoadReport(actor string, turn uint) (*report.Report, error) { return &report.Report{}, nil } func setupRouter() *gin.Engine { - return setupRouterExecutor(newExecutor()) + return setupRouterEngine(newFakeEngine()) } -func setupRouterExecutor(e handler.Engine) *gin.Engine { +func setupRouterEngine(e handler.Engine) *gin.Engine { return router.SetupRouter(e) } -func newExecutor() handler.Engine { - return &dummyExecutor{} +func newFakeEngine() handler.Engine { + return &fakeEngine{} } // newService builds a real controller.Service backed by a storage directory, diff --git a/game/openapi.yaml b/game/openapi.yaml index 9ee4e35..313f355 100644 --- a/game/openapi.yaml +++ b/game/openapi.yaml @@ -436,21 +436,24 @@ components: CommandRequest: type: object description: | - Batch command payload. `actor` identifies the race submitting the commands. - Each element of `cmd` is a polymorphic command object discriminated by the - `@type` field. At least one command is required. + Order payload for `PUT /api/v1/order`. `actor` identifies the race + submitting the order. Each element of `cmd` is a polymorphic command + object discriminated by the `@type` field. An empty `cmd` array is + valid: it clears the player's stored order for the turn (equivalent to + removing every command). required: - actor - cmd properties: actor: type: string - description: Race name of the actor submitting the commands. Must be non-blank. + description: Race name of the actor submitting the order. Must be non-blank. minLength: 1 cmd: type: array - description: One or more commands to execute in order. - minItems: 1 + description: >- + The player's commands, applied in submission order at turn + generation. May be empty to clear the stored order. items: $ref: "#/components/schemas/Command" UserGamesOrder: diff --git a/game/openapi_contract_test.go b/game/openapi_contract_test.go index da84a98..cccb614 100644 --- a/game/openapi_contract_test.go +++ b/game/openapi_contract_test.go @@ -275,7 +275,8 @@ func TestGameOpenAPISpecFreezesCommandRequest(t *testing.T) { cmdSchema := schema.Value.Properties["cmd"] require.NotNil(t, cmdSchema, "CommandRequest.cmd schema must exist") - require.Equal(t, uint64(1), cmdSchema.Value.MinItems, "CommandRequest.cmd minItems must be 1") + require.Zero(t, cmdSchema.Value.MinItems, + "CommandRequest.cmd must allow an empty batch — an empty order clears the player's stored order") } func TestGameOpenAPISpecFreezesGetBattleOperation(t *testing.T) { diff --git a/ui/PLAN.md b/ui/PLAN.md index f352374..9c36db4 100644 --- a/ui/PLAN.md +++ b/ui/PLAN.md @@ -469,7 +469,7 @@ Acceptance criteria: - canonical-bytes output matches gateway-side output byte-for-byte for the three Phase-3 message types (`user.account.get`, - `lobby.my.games.list`, `user.games.command`); + `lobby.my.games.list`, `user.games.order`); - a request signed by `ui/core` is accepted by the gateway's own verifier in a unit test (`TestParityRequestSignedByUICoreAcceptedByGateway`); - a response signed by `gateway/authn`'s `Ed25519ResponseSigner` is @@ -648,7 +648,7 @@ Acceptance criteria (met): KB measured); - `WasmCore.signRequest` produces canonical bytes byte-for-byte identical to the gateway-side fixtures for three message types - (`request_user_account_get`, `request_user_games_command`, + (`request_user_account_get`, `request_user_games_order`, `request_lobby_my_games_list`); - `WasmCore` exposes the same `Core` TypeScript types future `WailsCore` and `CapacitorCore` adapters will satisfy. diff --git a/ui/core/README.md b/ui/core/README.md index 00c2d61..65296ac 100644 --- a/ui/core/README.md +++ b/ui/core/README.md @@ -130,7 +130,7 @@ The `canon` test suite combines: - byte-equality on golden JSON fixtures under `canon/testdata/` for three request types (`user.account.get`, `lobby.my.games.list`, - `user.games.command`), one response (`ok`), and one event + `user.games.order`), one response (`ok`), and one event (`gateway.server_time`); - mutation tests proving every signed field is bound into the signature; diff --git a/ui/core/canon/request_test.go b/ui/core/canon/request_test.go index 50b1230..cf632a5 100644 --- a/ui/core/canon/request_test.go +++ b/ui/core/canon/request_test.go @@ -71,7 +71,7 @@ func TestBuildRequestSigningInputChangesWhenSignedFieldChanges(t *testing.T) { base := canon.RequestSigningFields{ ProtocolVersion: "v1", DeviceSessionID: "device-session-123", - MessageType: "user.games.command", + MessageType: "user.games.order", TimestampMS: 123456789, RequestID: "request-123", PayloadHash: sha256Sum([]byte("payload")), @@ -143,7 +143,7 @@ func TestRequestCanonicalBytesFixtures(t *testing.T) { fixtures := []string{ "request_user_account_get.json", "request_lobby_my_games_list.json", - "request_user_games_command.json", + "request_user_games_order.json", } for _, name := range fixtures { diff --git a/ui/core/canon/signature_test.go b/ui/core/canon/signature_test.go index e958029..6416349 100644 --- a/ui/core/canon/signature_test.go +++ b/ui/core/canon/signature_test.go @@ -22,7 +22,7 @@ func TestVerifyRequestSignature(t *testing.T) { fields := canon.RequestSigningFields{ ProtocolVersion: "v1", DeviceSessionID: "device-session-123", - MessageType: "user.games.command", + MessageType: "user.games.order", TimestampMS: 123456789, RequestID: "request-123", PayloadHash: sha256Sum([]byte("payload")), diff --git a/ui/core/canon/testdata/request_user_games_command.json b/ui/core/canon/testdata/request_user_games_order.json similarity index 55% rename from ui/core/canon/testdata/request_user_games_command.json rename to ui/core/canon/testdata/request_user_games_order.json index cfd6512..fd5d017 100644 --- a/ui/core/canon/testdata/request_user_games_command.json +++ b/ui/core/canon/testdata/request_user_games_order.json @@ -1,13 +1,13 @@ { - "message_type": "user.games.command", + "message_type": "user.games.order", "protocol_version": "v1", "device_session_id": "device-session-1", "timestamp_ms": 1700000001000, "request_id": "req-games-1", "payload": "games-payload", "payload_hash_hex": "a8322c99bf424939cd3a1e5a41b5edb67e567bff87c49e8ff229be60976960e0", - "expected_canonical_bytes_hex": "1167616c6178792d726571756573742d7631027631106465766963652d73657373696f6e2d3112757365722e67616d65732e636f6d6d616e640000018bcfe56be80b7265712d67616d65732d3120a8322c99bf424939cd3a1e5a41b5edb67e567bff87c49e8ff229be60976960e0", + "expected_canonical_bytes_hex": "1167616c6178792d726571756573742d7631027631106465766963652d73657373696f6e2d3110757365722e67616d65732e6f726465720000018bcfe56be80b7265712d67616d65732d3120a8322c99bf424939cd3a1e5a41b5edb67e567bff87c49e8ff229be60976960e0", "private_key_seed_hex": "0303030303030303030303030303030303030303030303030303030303030303", "public_key_base64": "7UkoxijRwsbq6QM4kFmVYSlZJzpcY/k2NsFGFKyHN9E=", - "expected_signature_hex": "262d5480451560d9b2ca96468b0e962e4288eabb4dff29dbc66c491a37dd92b779d2b89853083a695317f8535e49c402dcfd49a11fd2926f3af42ceb745e2b0a" + "expected_signature_hex": "b4a9a1eb2eb67777469d87ed7c513afd89f0c0a96ca9e0d945cd327830c11a7834ac073f6a872d8121cd7674b9491399a0256210292615bd424d11d0db37200c" } diff --git a/ui/frontend/tests/wasm-core-canon-parity.test.ts b/ui/frontend/tests/wasm-core-canon-parity.test.ts index 47d023f..5e896a6 100644 --- a/ui/frontend/tests/wasm-core-canon-parity.test.ts +++ b/ui/frontend/tests/wasm-core-canon-parity.test.ts @@ -79,7 +79,7 @@ beforeAll(async () => { describe("WasmCore canon parity with gateway fixtures", () => { test.each([ "request_user_account_get.json", - "request_user_games_command.json", + "request_user_games_order.json", "request_lobby_my_games_list.json", ])("%s — canonical bytes byte-for-byte equal", (name) => { const fixture = readJson(name); -- 2.52.0